-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole_gui.cpp
More file actions
75 lines (65 loc) · 2.66 KB
/
console_gui.cpp
File metadata and controls
75 lines (65 loc) · 2.66 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
// * ************************************************************************ //
// * * ConsoleGUI source * * //
// * * : implimentation of WIN32 console GUI elements * * //
// * * * * //
// * * Disclaimer: This document represents no significant intellectual * * //
// * * property and my be used freely. The author(s) takes no * * //
// * * responsibility for any loss or damage arising from the use of * * //
// * * the computer code contained herein. Where this document is * * //
// * * submitted as part of an assessment task this header must remain * * //
// * * intact and the student must make clear indication which parts * * //
// * * have been added by themselves. * * //
// * * * * //
// * ********************************************************************** * //
// * ********************************************************************** * //
// * * ConsoleGUI.cpp * * //
// * * Author: Tim Wilkin * * //
// * * Created: 26/03/11 Last Modified: 31/03/11 * * //
// * ********************************************************************** * //
#if defined(_WIN32)
#include "console_gui.h"
GUIPanel::GUIPanel(HANDLE hOut, SHORT top, SHORT left, SHORT bottom, SHORT right)
: m_ciBuffer(), m_hOut(hOut), m_fpCallback(0)
{
m_srRegion.Top = top;
m_srRegion.Bottom = bottom;
m_srRegion.Left = left;
m_srRegion.Right = right;
SHORT rows = bottom - top + 1;
SHORT cols = right - left + 1;
m_ciBuffer.resize(rows, cols);
}
GUIPanel::GUIPanel(HANDLE hOut, COORD2 pos, SHORT rows, SHORT cols)
: m_ciBuffer(), m_hOut(hOut), m_fpCallback(0)
{
m_srRegion.Top = pos.row;
m_srRegion.Left = pos.col;
m_srRegion.Bottom = pos.row + rows - 1;
m_srRegion.Right = pos.col + cols - 1;
m_ciBuffer.resize(rows, cols);
}
GUIPanel::~GUIPanel()
{
SAFE_DELETE(m_fpCallback);
}
void GUIPanel::Draw()
{
if (m_hOut == INVALID_HANDLE_VALUE)
return;
COORD pos = { 0, 0 };
SMALL_RECT srDrawRegion = m_srRegion;
COORD2 dim = m_ciBuffer.size();
COORD size = { dim.col, dim.row };
WriteConsoleOutput(m_hOut, m_ciBuffer.buffer(), size, pos, &srDrawRegion);
}
void GUIPanel::SetCallback(GUIPanel::FPCALLBACK fpFunc)
{
SAFE_DELETE(m_fpCallback);
m_fpCallback = fpFunc;
}
void GUIPanel::notify()
{
(*m_fpCallback)(m_ciBuffer);
Draw();
}
#endif