-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.cpp
More file actions
80 lines (53 loc) · 1.75 KB
/
plotter.cpp
File metadata and controls
80 lines (53 loc) · 1.75 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
#include <iostream>
using namespace std;
#include "plotter.h"
Plotter::Plotter()
{
coordScreen.X = 0;
coordScreen.Y = 0;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsoleOutput, green);
}
void Plotter::move(int x, int y)
{
coordScreen.X = x;
coordScreen.Y = y;
//SetConsoleTextAttribute(hConsoleOutput, c);
SetConsoleCursorPosition( hConsoleOutput, coordScreen );
}
void Plotter::plot(int x, int y, char c)
{
coordScreen.X = x;
coordScreen.Y = y;
//SetConsoleTextAttribute(hConsoleOutput, c);
SetConsoleCursorPosition( hConsoleOutput, coordScreen );
cout << c;
cout.flush();
}
void Plotter::setColor(ink c)
{
SetConsoleTextAttribute(hConsoleOutput, c);
}
void Plotter::clear()
{
cls( hConsoleOutput );
}
void Plotter::cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; // here's where we'll home the cursor
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; // to get buffer info
DWORD dwConSize; // number of character cells in the current buffer
// get the number of character cells in the current buffer
GetConsoleScreenBufferInfo( hConsole, &csbi );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// fill the entire screen with blanks
FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten );
// get the current text attribute
GetConsoleScreenBufferInfo( hConsole, &csbi );
// now set the buffer's attributes accordingly
FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten );
// put the cursor at (0, 0)
SetConsoleCursorPosition( hConsole, coordScreen );
return;
}