-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderer.cpp
56 lines (44 loc) · 1.44 KB
/
Renderer.cpp
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
#include "Renderer.h"
// PRIVATE
// PUBLIC
Renderer::Renderer(Point2D size) : m_size(size)
{
m_charactersToBeWritten = std::vector<CHAR_INFO>(size.x * size.y);
for (unsigned short i = 0; i < size.x * size.y; i++)
{
m_charactersToBeWritten[i].Attributes = 0xF0;
m_charactersToBeWritten[i].Char.UnicodeChar = ' ';
}
}
const short Renderer::get_width() const
{
return m_size.x;
}
const short Renderer::get_height() const
{
return m_size.y;
}
void Renderer::SetCharacter(short x, short y, WCHAR character)
{
m_charactersToBeWritten[x + y * m_size.x].Char.UnicodeChar = character;
}
void Renderer::SetAttribute(short x, short y, WORD attributes)
{
m_charactersToBeWritten[x + y * m_size.x].Attributes = attributes | 0xF0;
}
void Renderer::Render()
{
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
if (output == INVALID_HANDLE_VALUE)
throw std::exception("GetStdHandle failed.");
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(output, &csbi))
throw std::exception("GetConsoleScreenBufferInfo failed.");
if (!WriteConsoleOutput(output, m_charactersToBeWritten.data(), { m_size.x, m_size.y }, { 0, 0 }, &csbi.srWindow))
throw std::exception("WriteConsoleOutput failed");
for (unsigned short i = 0; i < m_size.x * m_size.y; i++)
{
m_charactersToBeWritten[i].Attributes = 0xF0;
m_charactersToBeWritten[i].Char.UnicodeChar = ' ';
}
}