doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ColorButton.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "ColorButton.h"
33 
34 static const int ARROW_SIZE_CX = 4 ;
35 static const int ARROW_SIZE_CY = 2 ;
36 
37 /*
38 ================
39 ColorButton_SetColor
40 
41 Sets the current color button color
42 ================
43 */
44 void ColorButton_SetColor ( HWND hWnd, COLORREF color )
45 {
46  if ( NULL == hWnd )
47  {
48  return;
49  }
50  SetWindowLong ( hWnd, GWL_USERDATA, color );
51  InvalidateRect ( hWnd, NULL, FALSE );
52 }
53 
54 void ColorButton_SetColor ( HWND hWnd, const char* color )
55 {
56  float red;
57  float green;
58  float blue;
59  float alpha;
60 
61  if ( NULL == hWnd )
62  {
63  return;
64  }
65 
66  sscanf ( color, "%f,%f,%f,%f", &red, &green, &blue, &alpha );
67 
68  ColorButton_SetColor ( hWnd, RGB(red*255.0f, green*255.0f, blue*255.0f) );
69 }
70 
71 void AlphaButton_SetColor ( HWND hWnd, const char* color )
72 {
73  float red;
74  float green;
75  float blue;
76  float alpha;
77 
78  if ( NULL == hWnd )
79  {
80  return;
81  }
82 
83  sscanf ( color, "%f,%f,%f,%f", &red, &green, &blue, &alpha );
84 
85  ColorButton_SetColor ( hWnd, RGB(alpha*255.0f, alpha*255.0f, alpha*255.0f) );
86 }
87 
88 /*
89 ================
90 ColorButton_GetColor
91 
92 Retrieves the current color button color
93 ================
94 */
95 COLORREF ColorButton_GetColor ( HWND hWnd )
96 {
97  return (COLORREF) GetWindowLong ( hWnd, GWL_USERDATA );
98 }
99 
100 /*
101 ================
102 ColorButton_DrawArrow
103 
104 Draws the arrow on the color button
105 ================
106 */
107 static void ColorButton_DrawArrow ( HDC hDC, RECT* pRect, COLORREF color )
108 {
109  POINT ptsArrow[3];
110 
111  ptsArrow[0].x = pRect->left;
112  ptsArrow[0].y = pRect->top;
113  ptsArrow[1].x = pRect->right;
114  ptsArrow[1].y = pRect->top;
115  ptsArrow[2].x = (pRect->left + pRect->right)/2;
116  ptsArrow[2].y = pRect->bottom;
117 
118  HBRUSH arrowBrush = CreateSolidBrush ( color );
119  HPEN arrowPen = CreatePen ( PS_SOLID, 1, color );
120 
121  HGDIOBJ oldBrush = SelectObject ( hDC, arrowBrush );
122  HGDIOBJ oldPen = SelectObject ( hDC, arrowPen );
123 
124  SetPolyFillMode(hDC, WINDING);
125  Polygon(hDC, ptsArrow, 3);
126 
127  SelectObject ( hDC, oldBrush );
128  SelectObject ( hDC, oldPen );
129 
130  DeleteObject ( arrowBrush );
131  DeleteObject ( arrowPen );
132 }
133 
134 /*
135 ================
136 ColorButton_DrawItem
137 
138 Draws the actual color button as as reponse to a WM_DRAWITEM message
139 ================
140 */
141 void ColorButton_DrawItem ( HWND hWnd, LPDRAWITEMSTRUCT dis )
142 {
143  assert ( dis );
144 
145  HDC hDC = dis->hDC;
146  UINT state = dis->itemState;
147  RECT rDraw = dis->rcItem;
148  RECT rArrow;
149 
150  // Draw outter edge
151  UINT uFrameState = DFCS_BUTTONPUSH|DFCS_ADJUSTRECT;
152 
153  if (state & ODS_SELECTED)
154  {
155  uFrameState |= DFCS_PUSHED;
156  }
157 
158  if (state & ODS_DISABLED)
159  {
160  uFrameState |= DFCS_INACTIVE;
161  }
162 
163  DrawFrameControl ( hDC, &rDraw, DFC_BUTTON, uFrameState );
164 
165  // Draw Focus
166  if (state & ODS_SELECTED)
167  {
168  OffsetRect(&rDraw, 1,1);
169  }
170 
171  if (state & ODS_FOCUS)
172  {
173  RECT rFocus = {rDraw.left,
174  rDraw.top,
175  rDraw.right - 1,
176  rDraw.bottom};
177 
178  DrawFocusRect ( hDC, &rFocus );
179  }
180 
181  InflateRect ( &rDraw, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE) );
182 
183  // Draw the arrow
184  rArrow.left = rDraw.right - ARROW_SIZE_CX - GetSystemMetrics(SM_CXEDGE) /2;
185  rArrow.right = rArrow.left + ARROW_SIZE_CX;
186  rArrow.top = (rDraw.bottom + rDraw.top)/2 - ARROW_SIZE_CY / 2;
187  rArrow.bottom = (rDraw.bottom + rDraw.top)/2 + ARROW_SIZE_CY / 2;
188 
189  ColorButton_DrawArrow ( hDC, &rArrow, (state & ODS_DISABLED) ? ::GetSysColor(COLOR_GRAYTEXT) : RGB(0,0,0) );
190 
191  rDraw.right = rArrow.left - GetSystemMetrics(SM_CXEDGE)/2;
192 
193  // Draw separator
194  DrawEdge ( hDC, &rDraw, EDGE_ETCHED, BF_RIGHT);
195 
196  rDraw.right -= (GetSystemMetrics(SM_CXEDGE) * 2) + 1 ;
197 
198  // Draw Color
199  if ((state & ODS_DISABLED) == 0)
200  {
201  HBRUSH color = CreateSolidBrush ( (COLORREF)GetWindowLong ( hWnd, GWL_USERDATA ) );
202  FillRect ( hDC, &rDraw, color );
203  FrameRect ( hDC, &rDraw, (HBRUSH)::GetStockObject(BLACK_BRUSH));
204  DeleteObject( color );
205  }
206 }
byte color[4]
Definition: MegaTexture.cpp:54
assert(prefInfo.fullscreenBtn)
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
void ColorButton_DrawItem(HWND hWnd, LPDRAWITEMSTRUCT dis)
GLclampf GLclampf blue
Definition: glext.h:2843
GLclampf GLclampf GLclampf alpha
Definition: glext.h:2843
#define NULL
Definition: Lib.h:88
HDC hDC
Definition: wglext.h:383
void AlphaButton_SetColor(HWND hWnd, const char *color)
Definition: ColorButton.cpp:71
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(void)
tuple f
Definition: idal.py:89
void ColorButton_SetColor(HWND hWnd, COLORREF color)
Definition: ColorButton.cpp:44
#define FALSE
Definition: mprintf.c:70
COLORREF ColorButton_GetColor(HWND hWnd)
Definition: ColorButton.cpp:95
GLclampf green
Definition: glext.h:2843