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
|
#include "ASCIIRenderer.h"
class ASCIIRenderer
{
private:
CHAR_INFO m_ScreenBuffer[SCREEN_WIDTH * SCREEN_HEIGHT];
HANDLE m_hConsole;
void GetConsoleHandle()
{
m_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
}
void SetScreenSize()
{
COORD MaxWindowSize = GetLargestConsoleWindowSize(m_hConsole);
int targetWidth = min(MaxWindowSize.X, SCREEN_WIDTH);
int targetHeight = min(MaxWindowSize.Y, SCREEN_HEIGHT);
SMALL_RECT rect = { 0, 0, targetWidth - 1, targetHeight - 1 };
COORD coord = { targetWidth, targetHeight };
bool bufferSizeSet = SetConsoleScreenBufferSize(m_hConsole, coord);
bool windowInfoSet = SetConsoleWindowInfo(m_hConsole, TRUE, &rect);
}
void InitialiseScreenBuffer()
{
CHAR asciiChar = 0;
WORD attributes = 15;
for (int i = 0; i < SCREEN_WIDTH; i++)
{
for (int j = 0; j < SCREEN_HEIGHT; j++)
{
m_ScreenBuffer[SCREEN_WIDTH * j + i].Char.AsciiChar = asciiChar;
m_ScreenBuffer[SCREEN_WIDTH * j + i].Attributes = attributes;
}
}
}
public:
ASCIIRenderer();
~ASCIIRenderer();
void Initialise()
{
GetConsoleHandle();
SetScreenSize();
InitialiseScreenBuffer();
SetConsoleTitle("4107COMP PONGOUT");
}
void RenderBufferToConsole()
{
COORD coord = { SCREEN_WIDTH, SCREEN_HEIGHT };
COORD coord2 = { 0, 0 };
SMALL_RECT write = { 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1 };// Region to write to
WriteConsoleOutput(m_hConsole, (const CHAR_INFO *)(&m_ScreenBuffer), coord, coord2, &write);
}
void ClearScreen()
{
InitialiseScreenBuffer();
}
void FillScreen()
{
InitialiseScreenBuffer();
{
CHAR asciiChar = 0;
WORD attributes = 15;
}
}
};
ASCIIRenderer::ASCIIRenderer()
{
Initialise();
}
ASCIIRenderer::~ASCIIRenderer()
{
}
|