-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleController.cpp
More file actions
44 lines (37 loc) · 1.63 KB
/
ConsoleController.cpp
File metadata and controls
44 lines (37 loc) · 1.63 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
#include "ConsoleController.h"
const int ConsoleController::nScreenHeight = DEFAULT_SCREEN_HEIGHT;
const int ConsoleController::nScreenWidth = DEFAULT_SCREEN_WIDTH;
WCHAR* ConsoleController::screen;
HANDLE ConsoleController::hConsole;
DWORD ConsoleController::dwBytesWritten = 0;
ConsoleController::ConsoleController() /*: nScreenWidth(DEFAULT_SCREEN_WIDTH), nScreenHeight(DEFAULT_SCREEN_HEIGHT)*/
{
screen = new WCHAR[nScreenWidth * nScreenHeight + 1]; // Cèìâîëû þíèêîäà
hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
SetConsoleActiveScreenBuffer(hConsole);
dwBytesWritten = 0;
SetConsoleScreenBufferSize(hConsole, { DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT });
}
ConsoleController::ConsoleController(int width, int height) /*: nScreenWidth(width), nScreenHeight(height)*/
{
screen = new WCHAR[nScreenWidth * nScreenHeight + 1]; // Cèìâîëû þíèêîäà
hConsole = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
SetConsoleActiveScreenBuffer(hConsole);
dwBytesWritten = 0;
SetConsoleScreenBufferSize(hConsole, { (short)width, (short)height });
}
ConsoleController::ConsoleController(ConsoleController& exemp)
{
screen = exemp.screen;
hConsole = exemp.hConsole;
dwBytesWritten = exemp.dwBytesWritten;
}
ConsoleController::~ConsoleController()
{
delete[] screen;
}
void ConsoleController::UpdateFrame()
{
screen[nScreenWidth * nScreenHeight] = '\0'; // Ïîñëåäíèé ñèìâîë - îêîí÷àíèå ñòðîêè
WriteConsoleOutputCharacter(hConsole, screen, nScreenWidth * nScreenHeight, { 0, 0 }, &dwBytesWritten);
}