-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotter.cpp
102 lines (58 loc) · 1.96 KB
/
Plotter.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
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
#include "Plotter.h"
#include <iostream>
using namespace std;
Plotter::Plotter(int x, int y)
{
startX = x;
startY = y;
coordScreen.X = startX;
coordScreen.Y = startY;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsoleOutput, green);
}
void Plotter::setStartPoint(int x,int y)
{
startX = x;
startY = y;
}
void Plotter::draw(const Matrix &n)
{
coordScreen.X = startX;
coordScreen.Y = startY;
SetConsoleCursorPosition( hConsoleOutput, coordScreen );
for(int c = 0 ; c < n.getColumns(); c++)
{
for(int r = 0; r < n.getRows(); r++)
{
coordScreen.X = c+startX;
coordScreen.Y = r+startY;
SetConsoleTextAttribute(hConsoleOutput, n.getElement(r,c));
SetConsoleCursorPosition( hConsoleOutput, coordScreen );
cout << SQUARE << endl;
}
cout << endl;
}
}
void Plotter::clear()
{
cls( hConsoleOutput );
}
void Plotter::cls( HANDLE hConsole )
{
COORD coordScreen = { startX, startY }; // 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;
}