-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEButton.cpp
More file actions
327 lines (286 loc) · 6.82 KB
/
Copy pathEButton.cpp
File metadata and controls
327 lines (286 loc) · 6.82 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
This file is part of W3ZMapEditor (c).
W3ZMapEditor is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
W3ZMapEditor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with W3ZMapEditor; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// EButton.cpp : implementation file
//
#include "stdafx.h"
#include "W3ZMapEdit.h"
#include "EButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEButton
CEButton::CEButton()
{
m_crTextColor = GetSysColor(COLOR_WINDOWTEXT);
m_crBkColor = GetSysColor(COLOR_3DFACE);
m_crBkColorState0 = GetSysColor(COLOR_3DFACE);//RGB(0,191,0); // green
m_crBkColorState1 = RGB(255,0,0); // red
m_crBkColorState2 = RGB(255,159,0); // yellow
m_iOldState = m_iNewState = m_iState = EB_STATE0;
m_bTextOnly = FALSE;
m_bFocus = FALSE;
m_bKbTracking = FALSE;
m_bLTracking = FALSE;
m_bMouseOver = FALSE;
m_bTriState = FALSE;
}
CEButton::~CEButton()
{
}
BEGIN_MESSAGE_MAP(CEButton, CButton)
//{{AFX_MSG_MAP(CEButton)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_WM_KEYDOWN()
ON_WM_KEYUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEButton message handlers
void CEButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC); //Get device context object
CRect rt, rtofs, rtCircle;
CPoint pt1,pt2;
CBrush brush;
CBrush* pOldBrush;
CPen pen;
CString strTemp;
int space;
rt = lpDrawItemStruct->rcItem; // get button rect
rtofs = rt;
if ((m_bMouseOver && m_bLTracking) || (m_bKbTracking)) // check for an offset
{
rtofs.OffsetRect(1,1);
}
if (!m_bTextOnly)
{
dc.FillSolidRect(rt, m_crBkColor); // erase button background
// set position of the state dot
space = (int)((rtofs.TopLeft().y + rtofs.BottomRight().y - EB_CIRCLE_DIAM + 0.5) / 2.);
pt1.x = rtofs.TopLeft().x + space;
pt1.y = space + 1;
pt2.x = pt1.x + EB_CIRCLE_DIAM;
pt2.y = pt1.y + EB_CIRCLE_DIAM;
rtCircle.SetRect(pt1, pt2);
if (EB_STATE1 == m_iState)
{
brush.CreateSolidBrush(m_crBkColorState1); // create the dot brush
}
else if (EB_STATE2 == m_iState)
{
brush.CreateSolidBrush(m_crBkColorState2); // create the dot brush
}
else
{
brush.CreateSolidBrush(m_crBkColorState0); // create the dot brush
}
pOldBrush = dc.GetCurrentBrush(); // save old brush
if (m_bFocus) // If the button is focused, make the dot larger
{rtCircle.InflateRect(1,1);}
pen.CreatePen(PS_SOLID, 1, m_crTextColor);
dc.SelectObject(&brush);
dc.SelectObject(pen);
if (EB_STATE0 != m_iState)
{
dc.Ellipse(rtCircle); // draws the dot
}
dc.SelectObject(pOldBrush);
rtofs.DeflateRect(EB_CIRCLE_DIAM + 2*space,0,0,0);
}
else
{
if (EB_STATE1 == m_iState)
{
dc.FillSolidRect(rt, m_crBkColorState1); // erase button background
}
else if (EB_STATE2 == m_iState)
{
dc.FillSolidRect(rt, m_crBkColorState2); // erase button background
}
else
{
dc.FillSolidRect(rt, m_crBkColorState0); // erase button background
}
}
GetWindowText(strTemp); // Get the caption which have been set
// Set the color of the caption
/* if (m_bTextOnly)
{
if (EB_STATE1 == m_iState)
{
dc.SetTextColor(m_crBkColorState1);
}
else if (EB_STATE2 == m_iState)
{
dc.SetTextColor(m_crBkColorState2);
}
else
{
dc.SetTextColor(m_crBkColorState0);
}
}
else
{
*/ dc.SetTextColor(m_crTextColor);
// }
dc.SetBkMode(TRANSPARENT);
if (m_bTextOnly)
{
dc.DrawText(strTemp, rtofs, DT_CENTER|DT_VCENTER|DT_SINGLELINE); // Draw out the caption
}
else
{
dc.DrawText(strTemp, rtofs, DT_LEFT|DT_VCENTER|DT_SINGLELINE); // Draw out the caption
}
if ((EB_STATE1 == m_iState) || (EB_STATE2 == m_iState) || (m_bMouseOver && m_bLTracking)) // If it is pressed
{
dc.DrawEdge(rt,EDGE_SUNKEN,BF_RECT); // Draw a sunken face
}
else
{
dc.DrawEdge(rt,EDGE_RAISED,BF_RECT); // Draw a raised face
}
dc.Detach();
}
void CEButton::OnLButtonDown(UINT nFlags, CPoint point)
{
SetCapture();
m_bLTracking = TRUE;
m_bFocus = TRUE;
m_iOldState = ToggleState();
m_iNewState = m_iState;
CButton::OnLButtonDown(nFlags, point);
}
void CEButton::OnLButtonUp(UINT nFlags, CPoint point)
{
if (m_bLTracking)
{
if (!m_bMouseOver)
{
m_iState = m_iOldState;
}
m_iOldState = m_iNewState = m_iState;
m_bLTracking = FALSE;
}
CButton::OnLButtonUp(nFlags, point);
RedrawWindow();
ReleaseCapture();
}
void CEButton::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rect;
GetClientRect(rect);
if (rect.PtInRect(point))
{
if (m_bLTracking)
{m_iState = m_iNewState;}
m_bMouseOver = TRUE;
}
else
{
if (m_bLTracking)
{m_iState = m_iOldState;}
m_bMouseOver = FALSE;
}
CButton::OnMouseMove(nFlags, point);
}
void CEButton::OnSetFocus(CWnd* pOldWnd)
{
CButton::OnSetFocus(pOldWnd);
m_bFocus = TRUE;
RedrawWindow();
}
void CEButton::OnKillFocus(CWnd* pNewWnd)
{
CButton::OnKillFocus(pNewWnd);
m_bFocus = FALSE;
RedrawWindow();
}
UINT CEButton::ToggleState()
{
UINT oldState = m_iState;
if (EB_STATE0 == m_iState)
{
m_iState = EB_STATE1;
}
else if ((EB_STATE1 == m_iState) && (m_bTriState))
{
m_iState = EB_STATE2;
}
else
{
m_iState = EB_STATE0;
}
return oldState;
}
UINT CEButton::GetState()
{
return m_iState;
}
void CEButton::SetState(UINT state)
{
m_iOldState = m_iNewState = m_iState = state;
}
void CEButton::SetTriState(BOOL tristate)
{
m_bTriState = tristate;
}
void CEButton::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (!m_bLTracking && !m_bKbTracking)
{
if (nChar == 0x20)
{
m_iOldState = ToggleState();
m_bKbTracking = TRUE;
}
RedrawWindow();
}
CButton::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CEButton::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (!m_bLTracking)
{
m_bKbTracking = FALSE;
m_iOldState = m_iNewState = m_iState;
}
RedrawWindow();
CButton::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CEButton::SetTextOnly(BOOL textonly)
{
m_bTextOnly = textonly;
}
void CEButton::SetColorState0(COLORREF newcolor)
{
m_crBkColorState0 = newcolor;
}
void CEButton::SetColorState1(COLORREF newcolor)
{
m_crBkColorState1 = newcolor;
}
void CEButton::SetColorState2(COLORREF newcolor)
{
m_crBkColorState2 = newcolor;
}