-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcol.cpp
More file actions
160 lines (148 loc) · 5.78 KB
/
concol.cpp
File metadata and controls
160 lines (148 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// concol.cpp: implementation of the concol class.
//
//////////////////////////////////////////////////////////////////////
/*********************************************************************************
** Author : C.Brown (c)COPYRIGHT C.Brown 2001-2026 ALL RIGHTS RESERVED **
** Date : 19/09/2001 **
** Purpose : Provide GUI function for C/C++ Programs **
** Version : 1.2 **
** St_num : **
** History : have made this version more generalised and **
** improved naming conventions. Still would like to improve the **
** colour selection choice and should be improved next version **
** Added Orange to the color scheme( ugly) **
** FIXED warnings when using light background colours **
** I have not commented this file as it is only for screen **
** manipulation and has is not part of the assignment **
** requirements **
*********************************************************************************/
#include "concol.hpp"
#include <algorithm>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
concol::concol()
{
}
//===============================================================================
short concol::getPosY()
{ //gets screen info and returns the Y coordinate
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hCon;
hCon = getBufferOut();
GetConsoleScreenBufferInfo(hCon, &csbi);
return(csbi.dwSize.Y);
}
//===============================================================================
short concol::getPosX()
{ //gets screen info and returns the X coordinate
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hCon =getBufferOut();
GetConsoleScreenBufferInfo(hCon, &csbi);
return(csbi.dwSize.X);
}
//===============================================================================
void concol::resizeWindow(short xSize, short ySize)
{ // gets the screen buffer information
CONSOLE_SCREEN_BUFFER_INFO csbi;
SMALL_RECT srWindowRect;
COORD coordScreen;
HANDLE hConsole=getBufferOut();
GetConsoleScreenBufferInfo(hConsole, &csbi);
coordScreen = GetLargestConsoleWindowSize(hConsole);
srWindowRect.Right = (SHORT) (std::min((int)xSize, (int)coordScreen.X) - 1);
srWindowRect.Bottom = (SHORT) (std::min((int)ySize, (int)coordScreen.Y) - 1);
srWindowRect.Left = srWindowRect.Top = (SHORT) 0;
coordScreen.X = xSize; //reset size measurements
coordScreen.Y = ySize;
if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize)
{ //if size different reset
SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
SetConsoleScreenBufferSize(hConsole, coordScreen);
}
if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize)
{
SetConsoleScreenBufferSize(hConsole, coordScreen);
SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect);
}
return;
}
//===============================================================================
void concol::ClearScreen()
{ //clear screeen
COORD coordScreen = { 0, 0 }; //start top left hand
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole= getBufferOut();
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, (TCHAR) ' ',//fill screen with blanks
dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen); //reset cursor pos
}
//===============================================================================
void concol::ClearSect(short X, short Y)
{ //i wrote this to create a panneled feel to the game
COORD coordScreen= { X, Y };//set your start pos,
DWORD cCharsWritten; //clear all after it
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole= getBufferOut();
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
//===============================================================================
void concol::setColour(int fore, int back)
{ //seting the screen colors
HANDLE hConsole;
static int BackGround; //used static because it allowed me
static int ForeGround; // to change which ever element i wanted
if(back==-1) //without effecting the other
back = BackGround;
BackGround=back;
if (fore ==-1)
fore =ForeGround;
ForeGround=fore;
hConsole = CreateFile(
"CONOUT$", GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);
SetConsoleTextAttribute( hConsole, (WORD) ( (BackGround) |
ForeGround) );
}
//===============================================================================
void concol::goto_XY(short X_in, short Y_in)
{
//simple goto to set cursor positon
COORD coordScreen;
HANDLE hCon= getBufferOut();
coordScreen.X = X_in;
coordScreen.Y = Y_in;
SetConsoleCursorPosition(hCon,coordScreen);
}
//===============================================================================
void concol::setBackground(int back)
{ //as the name says
int fore=-1;
setColour(fore,back);
}
//===============================================================================
void concol::setForeground(int fore)
{
int back=-1;
setColour(fore,back);
}
//===============================================================================
concol::~concol()
{
}