doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PropTreeItemColor.cpp
Go to the documentation of this file.
1 // PropTreeItemColor.cpp : implementation file
2 //
3 // Copyright (C) 1998-2001 Scott Ramsay
4 // sramsay@gonavi.com
5 // http://www.gonavi.com
6 //
7 // This material is provided "as is", with absolutely no warranty expressed
8 // or implied. Any use is at your own risk.
9 //
10 // Permission to use or copy this software for any purpose is hereby granted
11 // without fee, provided the above notices are retained on all copies.
12 // Permission to modify the code and to distribute modified code is granted,
13 // provided the above notices are retained, and a notice that the code was
14 // modified is included with the above copyright notice.
15 //
16 // If you use this code, drop me an email. I'd like to know if you find the code
17 // useful.
18 
19 //#include "stdafx.h"
20 #include "../../../idlib/precompiled.h"
21 #pragma hdrstop
22 
23 #include "PropTree.h"
24 #include "../../../sys/win32/rc/proptree_Resource.h"
25 #include "PropTreeItemColor.h"
26 
27 #ifdef _DEBUG
28 #define new DEBUG_NEW
29 #undef THIS_FILE
30 static char THIS_FILE[] = __FILE__;
31 #endif
32 
33 extern HINSTANCE ghInst;
34 
35 typedef struct _ColorTableEntry
36 {
37  COLORREF color;
38  RECT rcSpot;
40 
41 static ColorTableEntry _crColors[] =
42 {
43  {RGB(0x00, 0x00, 0x00)},
44  {RGB(0xA5, 0x2A, 0x00)},
45  {RGB(0x00, 0x40, 0x40)},
46  {RGB(0x00, 0x55, 0x00)},
47  {RGB(0x00, 0x00, 0x5E)},
48  {RGB(0x00, 0x00, 0x8B)},
49  {RGB(0x4B, 0x00, 0x82)},
50  {RGB(0x28, 0x28, 0x28)},
51 
52  {RGB(0x8B, 0x00, 0x00)},
53  {RGB(0xFF, 0x68, 0x20)},
54  {RGB(0x8B, 0x8B, 0x00)},
55  {RGB(0x00, 0x93, 0x00)},
56  {RGB(0x38, 0x8E, 0x8E)},
57  {RGB(0x00, 0x00, 0xFF)},
58  {RGB(0x7B, 0x7B, 0xC0)},
59  {RGB(0x66, 0x66, 0x66)},
60 
61  {RGB(0xFF, 0x00, 0x00)},
62  {RGB(0xFF, 0xAD, 0x5B)},
63  {RGB(0x32, 0xCD, 0x32)},
64  {RGB(0x3C, 0xB3, 0x71)},
65  {RGB(0x7F, 0xFF, 0xD4)},
66  {RGB(0x7D, 0x9E, 0xC0)},
67  {RGB(0x80, 0x00, 0x80)},
68  {RGB(0x7F, 0x7F, 0x7F)},
69 
70  {RGB(0xFF, 0xC0, 0xCB)},
71  {RGB(0xFF, 0xD7, 0x00)},
72  {RGB(0xFF, 0xFF, 0x00)},
73  {RGB(0x00, 0xFF, 0x00)},
74  {RGB(0x40, 0xE0, 0xD0)},
75  {RGB(0xC0, 0xFF, 0xFF)},
76  {RGB(0x48, 0x00, 0x48)},
77  {RGB(0xC0, 0xC0, 0xC0)},
78 
79  {RGB(0xFF, 0xE4, 0xE1)},
80  {RGB(0xD2, 0xB4, 0x8C)},
81  {RGB(0xFF, 0xFF, 0xE0)},
82  {RGB(0x98, 0xFB, 0x98)},
83  {RGB(0xAF, 0xEE, 0xEE)},
84  {RGB(0x68, 0x83, 0x8B)},
85  {RGB(0xE6, 0xE6, 0xFA)},
86  {RGB(0xFF, 0xFF, 0xFF)}
87 };
88 
89 static void ColorBox(CDC* pDC, CPoint pt, COLORREF clr, BOOL bHover)
90 {
91  CBrush br(clr);
92 
93  CBrush* obr = pDC->SelectObject(&br);
94 
95  pDC->PatBlt(pt.x, pt.y, 13, 13, PATCOPY);
96  pDC->SelectObject(obr);
97 
98  CRect rc;
99  rc.SetRect(pt.x - 2, pt.y - 2, pt.x + 15, pt.y + 15);
100 
101  pDC->DrawEdge(&rc, (bHover) ? BDR_SUNKENOUTER : BDR_RAISEDINNER, BF_RECT);
102 }
103 
104 
105 
106 static LONG FindSpot(CPoint point)
107 {
108  for (LONG i=0; i<40; i++)
109  {
110  if (PtInRect(&_crColors[i].rcSpot, point))
111  return i;
112  }
113 
114  return -1;
115 }
116 
117 
119 // CPropTreeItemColor
120 
122 
124  m_cColor(0),
125  m_cPrevColor(0),
126  m_nSpot(-1),
127  m_bButton(FALSE),
128  m_bInDialog(FALSE)
129 {
130 }
131 
133 {
134 }
135 
136 
137 BEGIN_MESSAGE_MAP(CPropTreeItemColor, CWnd)
138  //{{AFX_MSG_MAP(CPropTreeItemColor)
139  ON_WM_KILLFOCUS()
140  ON_WM_PAINT()
141  ON_WM_CLOSE()
142  ON_WM_MOUSEMOVE()
143  ON_WM_SETCURSOR()
144  ON_WM_LBUTTONDOWN()
145  //}}AFX_MSG_MAP
146 END_MESSAGE_MAP()
147 
148 
150 // CPropTreeItemColor message handlers
151 
152 void CPropTreeItemColor::SetDefaultColorsList(COLORREF* pColors)
153 {
154  s_pColors = pColors;
155 }
156 
157 
158 void CPropTreeItemColor::DrawAttribute(CDC* pDC, const RECT& rc)
159 {
160  ASSERT(m_pProp!=NULL);
161 
162  CRect r(rc);
163 
164  pDC->SelectObject(IsReadOnly() ? m_pProp->GetNormalFont() : m_pProp->GetBoldFont());
165 
166  if (!m_pProp->IsWindowEnabled())
167  pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
168  else
169  pDC->SetTextColor(RGB(0,0,0));
170 
171  r.top += 1;
172  r.right = r.left + r.Height() - 1;
173 
174  CBrush br(m_cColor);
175  CBrush* pold = pDC->SelectObject(&br);
176  pDC->PatBlt(r.left, r.top, r.Width(), r.Height(), PATCOPY);
177  pDC->SelectObject(pold);
178 
179  pDC->DrawEdge(&r, EDGE_SUNKEN, BF_RECT);
180 
181  CString s;
182 
183  r = rc;
184  r.left += r.Height();
185  s.Format(_T("R = %d, G = %d, B = %d"), GetRValue(m_cColor),GetGValue(m_cColor), GetBValue(m_cColor));
186  pDC->DrawText(s, r, DT_SINGLELINE|DT_VCENTER);
187 }
188 
189 
191 {
192  return m_cColor;
193 }
194 
195 
197 {
198  m_cColor = lParam;
199 }
200 
201 
203 {
204 }
205 
206 
208 {
209 }
210 
211 
213 {
214  ShowWindow(SW_HIDE);
215 }
216 
217 
218 void CPropTreeItemColor::OnActivate(int activateType, CPoint point)
219 {
220  CRect r;
221 
223 
224  r = m_rc;
225  r.right = r.left + 150;
226  r.bottom = r.top + 120;
227 
228  ASSERT(m_pProp!=NULL);
229  m_pProp->GetCtrlParent()->ClientToScreen(r);
230 
231  if (!IsWindow(m_hWnd))
232  {
233  LPCTSTR pszClassName;
234 
235  pszClassName = AfxRegisterWndClass(CS_VREDRAW|CS_HREDRAW, LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_BTNFACE + 1));
236 
237  DWORD dwStyle = WS_POPUP|WS_DLGFRAME;
238 
239  CreateEx(0, pszClassName, _T(""), dwStyle, r, m_pProp->GetCtrlParent(), 0);
240  m_rcButton.SetRect(40, 94, 110, 114);
241  }
242 
243  SetWindowPos(NULL, r.left, r.top, r.Width() + 1, r.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
244  SetFocus();
245 }
246 
247 
249 {
250  CWnd::OnKillFocus(pNewWnd);
251 
252  if (!m_bInDialog)
253  CommitChanges();
254 }
255 
256 
258 {
259  CPaintDC dc(this);
260  CPoint pt;
261 
262  for (LONG i=0; i<40; i++)
263  {
264  pt.x = (i & 7) * 18 + 3;
265  pt.y = (i >> 3) * 18 + 3;
266  ColorBox(&dc, pt, _crColors[i].color, m_nSpot==i);
267  SetRect(&_crColors[i].rcSpot, pt.x, pt.y, pt.x + 13, pt.y + 13);
268  }
269 
270  ASSERT(m_pProp!=NULL);
271 
272  dc.SelectObject(m_pProp->GetNormalFont());
273 
274  CString s(_T("More Colors"));
275 
276  dc.SetBkMode(TRANSPARENT);
277  dc.SetTextColor(GetSysColor(COLOR_BTNTEXT));
278  dc.DrawText(s, &m_rcButton, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
279 
280  dc.DrawEdge(&m_rcButton, m_bButton ? BDR_SUNKENOUTER : BDR_RAISEDINNER, BF_RECT);
281 }
282 
283 
285 {
286  CommitChanges();
287 }
288 
289 
291 {
292  BOOL bButton;
293  LONG nSpot;
294 
295  nSpot = FindSpot(point);
296  if (nSpot!=m_nSpot)
297  {
298  Invalidate(FALSE);
299  m_nSpot = nSpot;
300  }
301 
302  bButton = m_rcButton.PtInRect(point);
303 
304  if (bButton!=m_bButton)
305  {
306  m_bButton = bButton;
307  Invalidate(FALSE);
308  }
309 }
310 
311 
312 BOOL CPropTreeItemColor::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
313 {
314  if (nHitTest==HTCLIENT)
315  {
316  CPoint point;
317 
318  GetCursorPos(&point);
319  ScreenToClient(&point);
320 
321  if (FindSpot(point)!=-1 || m_rcButton.PtInRect(point))
322  {
323  SetCursor(LoadCursor(ghInst, MAKEINTRESOURCE(IDC_FPOINT)));
324  return TRUE;
325  }
326 
327  }
328 
329  return CWnd::OnSetCursor(pWnd, nHitTest, message);
330 }
331 
332 
334 {
335  if (m_nSpot!=-1)
336  {
337  m_cColor = _crColors[m_nSpot].color;
338  CommitChanges();
339  }
340  else
341  if (m_rcButton.PtInRect(point))
342  {
343  CHOOSECOLOR cc;
344  COLORREF clr[16];
345 
346  ZeroMemory(&cc, sizeof(CHOOSECOLOR));
347  cc.Flags = CC_FULLOPEN|CC_ANYCOLOR|CC_RGBINIT;
348  cc.lStructSize = sizeof(CHOOSECOLOR);
349  cc.hwndOwner = m_hWnd;
350  cc.rgbResult = m_cColor;
351  cc.lpCustColors = s_pColors ? s_pColors : clr;
352 
353  memset(clr, 0xff, sizeof(COLORREF) * 16);
354  clr[0] = m_cColor;
355 
356  m_bInDialog = TRUE;
357 
358  ASSERT(m_pProp!=NULL);
360 
361  ShowWindow(SW_HIDE);
362 
363  if (ChooseColor(&cc))
364  m_cColor = cc.rgbResult;
365 
367  CommitChanges();
368  }
369 }
byte color[4]
Definition: MegaTexture.cpp:54
static CFont * GetNormalFont()
Definition: PropTree.cpp:272
static COLORREF * s_pColors
virtual void OnRefresh()
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
struct _ColorTableEntry ColorTableEntry
DWORD
Definition: win_qgl.cpp:61
afx_msg void OnLButtonDown(UINT nFlags, CPoint point)
afx_msg BOOL OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
static CFont * GetBoldFont()
Definition: PropTree.cpp:278
GLdouble s
Definition: glext.h:2935
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
void CommitChanges()
#define IDC_FPOINT
#define NULL
Definition: Lib.h:88
CPropTree * m_pProp
Definition: PropTreeItem.h:147
virtual LPARAM GetItemValue()
virtual void OnActivate(int activateType, CPoint point)
RECT rcSpot
long LONG
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
HINSTANCE ghInst
Definition: PropTree.cpp:38
CWnd * GetCtrlParent()
Definition: PropTree.cpp:180
afx_msg void OnKillFocus(CWnd *pNewWnd)
COLORREF color
#define FALSE
Definition: mprintf.c:70
virtual void SetItemValue(LPARAM lParam)
#define TRUE
Definition: mprintf.c:69
void DisableInput(BOOL bDisable=TRUE)
Definition: PropTree.cpp:671
virtual void DrawAttribute(CDC *pDC, const RECT &rc)
afx_msg void OnMouseMove(UINT nFlags, CPoint point)