2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "ColorButton.h"
34 static const int ARROW_SIZE_CX = 4 ;
35 static const int ARROW_SIZE_CY = 2 ;
41 Sets the current color button color
44 void ColorButton_SetColor ( HWND hWnd, COLORREF color )
50 SetWindowLong ( hWnd, GWL_USERDATA, color );
51 InvalidateRect ( hWnd, NULL, FALSE );
54 void ColorButton_SetColor ( HWND hWnd, const char* color )
66 sscanf ( color, "%f,%f,%f,%f", &red, &green, &blue, &alpha );
68 ColorButton_SetColor ( hWnd, RGB(red*255.0f, green*255.0f, blue*255.0f) );
71 void AlphaButton_SetColor ( HWND hWnd, const char* color )
83 sscanf ( color, "%f,%f,%f,%f", &red, &green, &blue, &alpha );
85 ColorButton_SetColor ( hWnd, RGB(alpha*255.0f, alpha*255.0f, alpha*255.0f) );
92 Retrieves the current color button color
95 COLORREF ColorButton_GetColor ( HWND hWnd )
97 return (COLORREF) GetWindowLong ( hWnd, GWL_USERDATA );
102 ColorButton_DrawArrow
104 Draws the arrow on the color button
107 static void ColorButton_DrawArrow ( HDC hDC, RECT* pRect, COLORREF color )
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;
118 HBRUSH arrowBrush = CreateSolidBrush ( color );
119 HPEN arrowPen = CreatePen ( PS_SOLID, 1, color );
121 HGDIOBJ oldBrush = SelectObject ( hDC, arrowBrush );
122 HGDIOBJ oldPen = SelectObject ( hDC, arrowPen );
124 SetPolyFillMode(hDC, WINDING);
125 Polygon(hDC, ptsArrow, 3);
127 SelectObject ( hDC, oldBrush );
128 SelectObject ( hDC, oldPen );
130 DeleteObject ( arrowBrush );
131 DeleteObject ( arrowPen );
138 Draws the actual color button as as reponse to a WM_DRAWITEM message
141 void ColorButton_DrawItem ( HWND hWnd, LPDRAWITEMSTRUCT dis )
146 UINT state = dis->itemState;
147 RECT rDraw = dis->rcItem;
151 UINT uFrameState = DFCS_BUTTONPUSH|DFCS_ADJUSTRECT;
153 if (state & ODS_SELECTED)
155 uFrameState |= DFCS_PUSHED;
158 if (state & ODS_DISABLED)
160 uFrameState |= DFCS_INACTIVE;
163 DrawFrameControl ( hDC, &rDraw, DFC_BUTTON, uFrameState );
166 if (state & ODS_SELECTED)
168 OffsetRect(&rDraw, 1,1);
171 if (state & ODS_FOCUS)
173 RECT rFocus = {rDraw.left,
178 DrawFocusRect ( hDC, &rFocus );
181 InflateRect ( &rDraw, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE) );
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;
189 ColorButton_DrawArrow ( hDC, &rArrow, (state & ODS_DISABLED) ? ::GetSysColor(COLOR_GRAYTEXT) : RGB(0,0,0) );
191 rDraw.right = rArrow.left - GetSystemMetrics(SM_CXEDGE)/2;
194 DrawEdge ( hDC, &rDraw, EDGE_ETCHED, BF_RIGHT);
196 rDraw.right -= (GetSystemMetrics(SM_CXEDGE) * 2) + 1 ;
199 if ((state & ODS_DISABLED) == 0)
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 );