-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.cpccWindow.h
155 lines (110 loc) · 3.3 KB
/
gui.cpccWindow.h
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* *****************************************
* File: cpccWindow.h
* Version: see function getClassVersion()
* Purpose: Portable (cross-platform), light-weight, window drawing class
* *****************************************
* Library: Cross Platform C++ Classes (cpcc)
* Copyright: 2013 StarMessage software.
* License: Free for opensource projects.
* Commercial license for closed source projects.
* Web: http://www.StarMessageSoftware.com
* Download: https://code.google.com/p/cpcc/
* https://github.com/starmessage/cpcc
* email: sales -at- starmessage.info
* *****************************************
*/
#pragma once
#include "gui.cpccCSS.h"
#include "io.cpccLog.h"
#if defined(__APPLE__)
#include "gui.cpccWindowMac.h"
typedef cpccWindowMac windowImpl;
#elif defined(_WIN32)
#include "gui.cpccWindowWin.h"
typedef cpccWindowWin windowImpl;
#else
#error #4367: Unknown platform for cpccWindow
#endif
class cpccWindow: public windowImpl
{
private:
protected:
public: // constructor
explicit cpccWindow(const cpccNativeWindowHandle wHandle): windowImpl(wHandle)
{
if (!wHandle)
infoLog().add(_T("Error: cpccWindow(wHandle) with NIL wHandle"));
else
infoLog().addf( _T("cpccWindow(wHandle:%X) constructor start"), (long) wHandle );
}
public: // data
public: // functions
void clear(void) override
{
//infoLog().add(_T("cpccWindow.clear()"));
fillWithColor(bgColor.getCurrent());
}
void pushCss(cpccCSS *aCssPtr) override
{
if (!aCssPtr)
return;
if (!aCssPtr->textAlign.isNull())
{
eTextAlign alignment = taLeft; // left
switch (aCssPtr->textAlign)
{
case cpccCSS::taRight: alignment= taRight; break;
case cpccCSS::taCenter: alignment= taCenter; break;
case cpccCSS::taNone:
case cpccCSS::taLeft: ;
}
textAlign.push(alignment);
}
// text color
if (!aCssPtr->color.isNull())
drawColor.push( aCssPtr->color);
// text font
if (!aCssPtr->fontName.isNull())
fontName.push(aCssPtr->fontName);
if (!aCssPtr->fontSize.isNull())
fontSize.push(aCssPtr->fontSize);
}
void popCss(cpccCSS* aCssPtr) override
{
if (!aCssPtr)
return;
// restore drawing parameters
if (!aCssPtr->textAlign.isNull())
textAlign.pop();
if (!aCssPtr->fontName.isNull())
fontName.pop();
if (!aCssPtr->fontSize.isNull())
fontSize.pop();
if (!aCssPtr->color.isNull())
drawColor.pop();
}
void drawText(const int x, const int y, const cpcc_char *text, cpccCSS *aCssPtr) override
{
// prepare drawing tools
pushCss(aCssPtr);
// at last, do the drawing
textOut_impl(x, y, text);
popCss(aCssPtr);
}
cpccColor getPixel(const int x, const int y) const override
{
if (x<0 || x>= (int) getWidth())
return cpccBlack;
if (y<0 || y>=(int) getHeight())
return cpccBlack;
return getPixel_impl(x, y);
}
void setPixel(int x, int y, const cpccColor &aColor) override
{
if (x<0 || x>= (int) getWidth())
return;
if (y<0 || y>=(int) getHeight())
return;
setPixel_impl(x, y, aColor);
}
};