Mercurial > projects > dynamin
annotate dynamin/gui/windows_theme.d @ 104:5c8c1c2e12c0
Change from real to double.
double is not dependant on the platform, and it uses less space.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Fri, 06 Jul 2012 18:39:45 -0500 |
parents | 73060bc3f004 |
children | acdbb30fee7e |
rev | line source |
---|---|
0 | 1 |
2 /* | |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
62
diff
changeset
|
3 * Copyright Jordan Miner |
0 | 4 * |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
62
diff
changeset
|
5 * This Source Code Form is subject to the terms of the Mozilla Public |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
62
diff
changeset
|
6 * License, v. 2.0. If a copy of the MPL was not distributed with this |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
62
diff
changeset
|
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
0 | 8 * |
9 */ | |
10 | |
11 module dynamin.gui.windows_theme; | |
12 | |
13 import dynamin.core.string; | |
14 import dynamin.all_painting; | |
15 import dynamin.all_gui; | |
16 import tango.io.Stdout; | |
17 import Utf = tango.text.convert.Utf; | |
18 version(Windows) import dynamin.c.windows; | |
19 version(Windows) import dynamin.c.windows_tmschema; | |
20 import dynamin.gui_backend; | |
21 | |
22 version(Windows) { | |
23 } else { | |
24 enum { | |
25 COLOR_SCROLLBAR = 0, | |
26 COLOR_BACKGROUND = 1, | |
27 COLOR_ACTIVECAPTION = 2, | |
28 COLOR_INACTIVECAPTION = 3, | |
29 COLOR_MENU = 4, | |
30 COLOR_WINDOW = 5, | |
31 COLOR_WINDOWFRAME = 6, | |
32 COLOR_MENUTEXT = 7, | |
33 COLOR_WINDOWTEXT = 8, | |
34 COLOR_CAPTIONTEXT = 9, | |
35 COLOR_ACTIVEBORDER = 10, | |
36 COLOR_INACTIVEBORDER = 11, | |
37 COLOR_APPWORKSPACE = 12, | |
38 COLOR_HIGHLIGHT = 13, | |
39 COLOR_HIGHLIGHTTEXT = 14, | |
40 COLOR_BTNFACE = 15, | |
41 COLOR_BTNSHADOW = 16, | |
42 COLOR_GRAYTEXT = 17, | |
43 COLOR_BTNTEXT = 18, | |
44 COLOR_INACTIVECAPTIONTEXT = 19, | |
45 COLOR_BTNHIGHLIGHT = 20, | |
46 | |
47 COLOR_3DDKSHADOW = 21, | |
48 COLOR_3DLIGHT = 22, | |
49 COLOR_INFOTEXT = 23, | |
50 COLOR_INFOBK = 24, | |
51 | |
52 COLOR_HOTLIGHT = 26, | |
53 COLOR_GRADIENTACTIVECAPTION = 27, | |
54 COLOR_GRADIENTINACTIVECAPTION = 28, | |
55 COLOR_MENUHILIGHT = 29, | |
56 COLOR_MENUBAR = 30, | |
57 | |
58 COLOR_DESKTOP = COLOR_BACKGROUND, | |
59 COLOR_3DFACE = COLOR_BTNFACE, | |
60 COLOR_3DSHADOW = COLOR_BTNSHADOW, | |
61 COLOR_3DHIGHLIGHT = COLOR_BTNHIGHLIGHT, | |
62 COLOR_3DHILIGHT = COLOR_BTNHIGHLIGHT, | |
63 COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT | |
64 } | |
65 } | |
66 | |
67 /** | |
68 * This file/module, even though it starts with 'windows_', is not part | |
69 * of the windows backend. It is a theme that should run on any system, | |
70 * but can only show visual styles under Windows because the | |
71 * Windows API is needed. | |
72 */ | |
73 | |
74 static this() { | |
75 Theme.add(new WindowsTheme()); | |
76 } | |
77 | |
78 /** | |
79 * This theme should work with any backend, but can only paint the Windows | |
80 * classic look if not on Windows XP, Vista, or newer. | |
81 */ | |
82 class WindowsTheme : Theme { | |
83 version(Windows) { | |
84 static string defaultFont() { // TODO: rename | |
85 NONCLIENTMETRICS ncMetrics; | |
86 ncMetrics.cbSize = NONCLIENTMETRICS.sizeof; | |
87 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, | |
88 NONCLIENTMETRICS.sizeof, &ncMetrics, 0); | |
89 // TODO: need to strip the nulls off the name | |
90 return Utf.toString(ncMetrics.lfMessageFont.lfFaceName); | |
91 } | |
92 } | |
93 version(Windows) { | |
94 static void printSysColors() { | |
95 int[string] colors = [ | |
96 "COLOR_SCROLLBAR"[] : COLOR_SCROLLBAR, | |
97 "COLOR_BACKGROUND" : COLOR_BACKGROUND, | |
98 "COLOR_ACTIVECAPTION" : COLOR_ACTIVECAPTION, | |
99 "COLOR_INACTIVECAPTION" : COLOR_INACTIVECAPTION, | |
100 "COLOR_MENU" : COLOR_MENU, | |
101 "COLOR_WINDOW" : COLOR_WINDOW, | |
102 "COLOR_WINDOWFRAME" : COLOR_WINDOWFRAME, | |
103 "COLOR_MENUTEXT" : COLOR_MENUTEXT, | |
104 "COLOR_WINDOWTEXT" : COLOR_WINDOWTEXT, | |
105 "COLOR_CAPTIONTEXT" : COLOR_CAPTIONTEXT, | |
106 "COLOR_ACTIVEBORDER" : COLOR_ACTIVEBORDER, | |
107 "COLOR_INACTIVEBORDER" : COLOR_INACTIVEBORDER, | |
108 "COLOR_APPWORKSPACE" : COLOR_APPWORKSPACE, | |
109 "COLOR_HIGHLIGHT" : COLOR_HIGHLIGHT, | |
110 "COLOR_HIGHLIGHTTEXT" : COLOR_HIGHLIGHTTEXT, | |
111 "COLOR_BTNFACE" : COLOR_BTNFACE, | |
112 "COLOR_BTNSHADOW" : COLOR_BTNSHADOW, | |
113 "COLOR_GRAYTEXT" : COLOR_GRAYTEXT, | |
114 "COLOR_BTNTEXT" : COLOR_BTNTEXT, | |
115 "COLOR_INACTIVECAPTIONTEXT" : COLOR_INACTIVECAPTIONTEXT, | |
116 "COLOR_BTNHIGHLIGHT" : COLOR_BTNHIGHLIGHT, | |
117 "COLOR_3DDKSHADOW" : COLOR_3DDKSHADOW, | |
118 "COLOR_3DLIGHT" : COLOR_3DLIGHT, | |
119 "COLOR_INFOTEXT" : COLOR_INFOTEXT, | |
120 "COLOR_INFOBK" : COLOR_INFOBK, | |
121 "COLOR_HOTLIGHT" : COLOR_HOTLIGHT, | |
122 "COLOR_GRADIENTACTIVECAPTION" : COLOR_GRADIENTACTIVECAPTION, | |
123 "COLOR_GRADIENTINACTIVECAPTION" : COLOR_GRADIENTINACTIVECAPTION, | |
124 "COLOR_MENUHILIGHT" : COLOR_MENUHILIGHT, | |
125 "COLOR_MENUBAR" : COLOR_MENUBAR, | |
126 | |
127 "COLOR_DESKTOP" : COLOR_DESKTOP, | |
128 "COLOR_3DFACE" : COLOR_3DFACE, | |
129 "COLOR_3DSHADOW" : COLOR_3DSHADOW, | |
130 "COLOR_3DHIGHLIGHT" : COLOR_3DHIGHLIGHT, | |
131 "COLOR_3DHILIGHT" : COLOR_3DHILIGHT, | |
132 "COLOR_BTNHILIGHT" : COLOR_BTNHILIGHT | |
133 ]; | |
134 foreach(key, value; colors) | |
135 Stdout.format("{,-27} : {}", key, getColor(value).toUtf8).newline; | |
136 | |
137 } | |
138 } | |
139 static Color getColor(int index) { | |
140 version(Windows) { | |
141 uint sysColor = GetSysColor(index); | |
142 return Color(GetRValue(sysColor), GetGValue(sysColor), GetBValue(sysColor)); | |
143 } else { | |
144 return Color.Black; // TODO: temp to get X backend to compile | |
145 | |
146 uint sysColor = 0; | |
147 switch(sysColor) { | |
148 default: | |
149 assert(0, "error: default case hit"); | |
150 } | |
151 } | |
152 } | |
153 | |
154 //{{{ utility functions | |
155 int findUxState(Button c, int disabled, int normal, int hot, int pressed) { | |
156 if(c.state == ButtonState.Normal) | |
157 return normal; | |
158 else if(c.state == ButtonState.Hot) | |
159 return hot; | |
160 else if(c.state == ButtonState.Pressed) | |
161 return pressed; | |
162 } | |
163 | |
164 /// draws a classic check, which is 7 wide and 7 high | |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
165 void drawCheck(Graphics g, double x, double y) { |
0 | 166 g.source = getColor(COLOR_WINDOWTEXT); |
167 auto checkYs = [2, 3, 4, 3, 2, 1, 0]; | |
168 foreach(i, cy; checkYs) { | |
169 g.moveTo(x + i + 0.5, y + cy); | |
170 g.lineTo(x + i + 0.5, y + cy + 3); | |
171 g.stroke(); | |
172 } | |
173 } | |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
174 /// draws a dotted focus rectangle |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
175 void drawFocus(Graphics g, int colorIndex, double x, double y, double w, double h) { |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
176 g.lineWidth = 1; |
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
177 g.source = getColor(colorIndex); |
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
178 g.setDash([1, 1], 0.5); |
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
179 g.rectangle(x, y, w, h); |
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
180 g.stroke(); |
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
181 } |
0 | 182 //}}} |
183 | |
184 string name() { | |
185 return "Windows"; | |
186 } | |
187 | |
188 void Window_paint(Window c, Graphics g) { | |
189 g.source = getColor(COLOR_3DFACE); | |
190 g.paint(); | |
191 } | |
192 //{{{ Button | |
193 Size Button_bestSize(Button c) { | |
194 // default button size is 17 points tall | |
195 return Size(75, 23); | |
196 } | |
197 | |
198 void Button_paint(Button c, Graphics g) { | |
199 version(Windows) { | |
200 if(Ux.isThemeActive()) { | |
201 auto uxState = findUxState(c, PBS_DISABLED, PBS_NORMAL, PBS_HOT, PBS_PRESSED); | |
62 | 202 if(uxState == PBS_NORMAL && c.isDefault) |
203 uxState = PBS_DEFAULTED; | |
0 | 204 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "BUTTON", BP_PUSHBUTTON, uxState); |
205 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
52
diff
changeset
|
206 if(c.focused && c.showFocus) |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
207 drawFocus(g, COLOR_WINDOWTEXT, 3.5, 3.5, c.width-7, c.height-7); |
0 | 208 g.source = getColor(COLOR_WINDOWTEXT); |
209 c.paintFore(g); | |
210 return; | |
211 } | |
212 } | |
213 g.source = getColor(COLOR_3DFACE); | |
214 g.paint(); | |
215 if(c.state == ButtonState.Pressed) { | |
216 draw3dRectangle(g, 0, 0, c.width, c.height, | |
217 getColor(COLOR_3DDKSHADOW), getColor(COLOR_3DHIGHLIGHT)); | |
218 draw3dRectangle(g, 1, 1, c.width-2, c.height-2, | |
219 getColor(COLOR_3DSHADOW), getColor(COLOR_3DLIGHT)); | |
220 } else { | |
221 draw3dRectangle(g, 0, 0, c.width, c.height, | |
222 getColor(COLOR_3DHIGHLIGHT), getColor(COLOR_3DDKSHADOW)); | |
223 draw3dRectangle(g, 1, 1, c.width-2, c.height-2, | |
224 getColor(COLOR_3DLIGHT), getColor(COLOR_3DSHADOW)); | |
225 } | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
52
diff
changeset
|
226 if(c.focused && c.showFocus) |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
227 drawFocus(g, COLOR_WINDOWTEXT, 3.5, 3.5, c.width-7, c.height-7); |
0 | 228 g.source = getColor(COLOR_WINDOWTEXT); |
229 c.paintFore(g); | |
230 } | |
231 //}}} | |
232 | |
233 //{{{ CheckBox | |
234 void CheckBox_paint(CheckBox c, Graphics g) { | |
235 version(Windows) { | |
236 if(Ux.isThemeActive()) { | |
237 int uxState; | |
238 if(c.checked) { | |
239 uxState = findUxState(c, CBS_CHECKEDDISABLED, CBS_CHECKEDNORMAL, CBS_CHECKEDHOT, CBS_CHECKEDPRESSED); | |
240 } else { | |
241 uxState = findUxState(c, CBS_UNCHECKEDDISABLED, CBS_UNCHECKEDNORMAL, CBS_UNCHECKEDHOT, CBS_UNCHECKEDPRESSED); | |
242 } | |
243 Ux.drawBackground(g, Rect(0, 0, 13, c.height), "BUTTON", BP_CHECKBOX, uxState); | |
244 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
52
diff
changeset
|
245 if(c.focused && c.showFocus) |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
246 drawFocus(g, COLOR_WINDOWTEXT, |
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
247 15.5, 0.5, c.width-16, c.height-1); |
0 | 248 g.source = getColor(COLOR_WINDOWTEXT); |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
249 g.translate(16, 0); |
0 | 250 c.paintFore(g); |
251 return; | |
252 } | |
253 } | |
254 | |
255 if(c.state == ButtonState.Pressed) | |
256 g.source = getColor(COLOR_3DFACE); | |
257 else | |
258 g.source = getColor(COLOR_WINDOW); | |
259 | |
260 g.rectangle(0, 0, 13, 13); | |
261 g.fill(); | |
262 draw3dRectangle(g, 0, 0, 13, 13, | |
263 getColor(COLOR_3DSHADOW), getColor(COLOR_3DHIGHLIGHT)); | |
264 draw3dRectangle(g, 1, 1, 11, 11, | |
265 getColor(COLOR_3DDKSHADOW), getColor(COLOR_3DLIGHT)); | |
266 | |
267 if(c.checked) | |
268 drawCheck(g, 3, 3); | |
269 // drawCheck(g, 0, 0, 13, 13); | |
270 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
52
diff
changeset
|
271 if(c.focused && c.showFocus) |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
272 drawFocus(g, COLOR_WINDOWTEXT, 15.5, 0.5, c.width-16, c.height-1); |
0 | 273 g.source = getColor(COLOR_WINDOWTEXT); |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
274 g.translate(16, 0); |
0 | 275 c.paintFore(g); |
276 } | |
277 //}}} | |
278 | |
279 //{{{ RadioButton | |
280 void RadioButton_paint(CheckBox c, Graphics g) { | |
281 version(Windows) { | |
282 if(Ux.isThemeActive()) { | |
283 int uxState; | |
284 if(c.checked) { | |
285 uxState = findUxState(c, RBS_CHECKEDDISABLED, RBS_CHECKEDNORMAL, RBS_CHECKEDHOT, RBS_CHECKEDPRESSED); | |
286 } else { | |
287 uxState = findUxState(c, RBS_UNCHECKEDDISABLED, RBS_UNCHECKEDNORMAL, RBS_UNCHECKEDHOT, RBS_UNCHECKEDPRESSED); | |
288 } | |
289 Ux.drawBackground(g, Rect(0, 0, 13, c.height), "BUTTON", BP_RADIOBUTTON, uxState); | |
290 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
52
diff
changeset
|
291 if(c.focused && c.showFocus) |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
292 drawFocus(g, COLOR_WINDOWTEXT, |
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
293 15.5, 0.5, c.width-16, c.height-1); |
0 | 294 g.source = getColor(COLOR_WINDOWTEXT); |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
295 g.translate(16, 0); |
0 | 296 c.paintFore(g); |
297 return; | |
298 } | |
299 } | |
300 | |
301 if(c.state == ButtonState.Pressed) | |
302 g.source = getColor(COLOR_3DFACE); | |
303 else | |
304 g.source = getColor(COLOR_WINDOW); | |
305 | |
306 g.rectangle(2, 2, 8, 8); | |
307 g.fill(); | |
308 const double[][] outerLines = [ | |
309 [1.5, 8, 1.5, 10], [0.5, 4, 0.5, 8], | |
310 [1.5, 2, 1.5, 4], [2.0, 1.5, 4, 1.5], | |
311 [4.0, 0.5, 8, 0.5], [8.0, 1.5, 10, 1.5]]; | |
312 const double[][] innerLines = [ | |
313 [2.5, 8, 2.5, 9], [1.5, 4, 1.5, 8], | |
314 [2.5, 2, 2.5, 4], [3.0, 2.5, 4, 2.5], | |
315 [4.0, 1.5, 8, 1.5], [8.0, 2.5, 10, 2.5]]; | |
316 g.source = getColor(COLOR_3DSHADOW); | |
317 foreach(line; outerLines) { | |
318 g.moveTo(line[0], line[1]); | |
319 g.lineTo(line[2], line[3]); | |
320 g.stroke(); | |
321 } | |
322 g.source = getColor(COLOR_3DDKSHADOW); | |
323 foreach(line; innerLines) { | |
324 g.moveTo(line[0], line[1]); | |
325 g.lineTo(line[2], line[3]); | |
326 g.stroke(); | |
327 } | |
328 g.source = getColor(COLOR_3DHIGHLIGHT); | |
329 foreach(line; outerLines) { | |
330 g.moveTo(12-line[0], 12-line[1]); | |
331 g.lineTo(12-line[2], 12-line[3]); | |
332 g.stroke(); | |
333 } | |
334 g.source = getColor(COLOR_3DLIGHT); | |
335 foreach(line; innerLines) { | |
336 g.moveTo(12-line[0], 12-line[1]); | |
337 g.lineTo(12-line[2], 12-line[3]); | |
338 g.stroke(); | |
339 } | |
340 | |
341 if(c.checked) { | |
342 g.source = getColor(COLOR_WINDOWTEXT); | |
343 g.translate(4, 4); | |
344 g.rectangle(1, 0, 2, 1); | |
345 g.rectangle(0, 1, 4, 2); | |
346 g.rectangle(1, 3, 2, 1); | |
347 g.fill(); | |
348 g.translate(-4, -4); | |
349 } | |
350 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
52
diff
changeset
|
351 if(c.focused && c.showFocus) |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
352 drawFocus(g, COLOR_WINDOWTEXT, 15.5, 0.5, c.width-16, c.height-1); |
0 | 353 g.source = getColor(COLOR_WINDOWTEXT); |
52
d82c7e5b037b
Draw focus rectangles for buttons, check boxes, and radio buttons in WindowsTheme.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
354 g.translate(16, 0); |
0 | 355 c.paintFore(g); |
356 } | |
357 //}}} | |
358 | |
359 //{{{ ScrollBar | |
360 void ScrollBarTrack_paint(ScrollBarTrack c, Graphics g) { | |
361 version(Windows) { | |
362 if(Ux.isThemeActive()) { | |
363 auto uxState = findUxState(c, SCRBS_DISABLED, SCRBS_NORMAL, SCRBS_HOT, SCRBS_PRESSED); | |
364 if(cast(VScrollBar)c.parent) { | |
365 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "SCROLLBAR", SBP_UPPERTRACKVERT, uxState); | |
366 } else { | |
367 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "SCROLLBAR", SBP_UPPERTRACKHORZ, uxState); | |
368 } | |
369 return; | |
370 } | |
371 } | |
372 | |
373 Color c1 = getColor(COLOR_3DHIGHLIGHT), c2 = getColor(COLOR_SCROLLBAR); | |
374 if(c.state == ButtonState.Pressed) { | |
375 c1.invert(); | |
376 c2.invert(); | |
377 } | |
378 int x = cast(int)round(c.x), y = cast(int)round(c.y); | |
379 drawCheckerboard(g, -(x & 1), -(y & 1), c.width + 1, c.height + 1, | |
380 c1, c2); | |
381 } | |
382 | |
383 void ScrollBarThumb_paint(ScrollBarThumb c, Graphics g) { | |
384 version(Windows) { | |
385 if(Ux.isThemeActive()) { | |
386 auto uxState = findUxState(c, SCRBS_DISABLED, SCRBS_NORMAL, SCRBS_HOT, SCRBS_PRESSED); | |
387 if(cast(VScrollBar)c.parent) { | |
388 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "SCROLLBAR", SBP_THUMBBTNVERT, uxState); | |
389 if(c.height > 16) | |
390 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "SCROLLBAR", SBP_GRIPPERVERT, 0); | |
391 } else { | |
392 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "SCROLLBAR", SBP_THUMBBTNHORZ, uxState); | |
393 if(c.width > 16) | |
394 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "SCROLLBAR", SBP_GRIPPERHORZ, 0); | |
395 } | |
396 return; | |
397 } | |
398 } | |
399 | |
400 g.source = getColor(COLOR_3DFACE); | |
401 g.paint(); | |
402 draw3dRectangle(g, 0, 0, c.width, c.height, | |
403 getColor(COLOR_3DLIGHT), getColor(COLOR_3DDKSHADOW)); | |
404 draw3dRectangle(g, 1, 1, c.width-2, c.height-2, | |
405 getColor(COLOR_3DHIGHLIGHT), getColor(COLOR_3DSHADOW)); | |
406 } | |
407 | |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
408 double ScrollBar_size() { |
0 | 409 // TODO: all themes should get this from SystemGui.ScrollBarSize |
410 version(Windows) | |
411 return GetSystemMetrics(SM_CXVSCROLL); | |
412 else | |
413 return 18; | |
414 } | |
415 | |
416 void ArrowButton_paint(ArrowButton c, Graphics g) { | |
417 version(Windows) { | |
418 if(Ux.isThemeActive()) { | |
419 int uxState; | |
420 if(c.direction == ArrowDirection.Left) | |
421 uxState = findUxState(c, ABS_LEFTDISABLED, ABS_LEFTNORMAL, ABS_LEFTHOT, ABS_LEFTPRESSED); | |
422 else if(c.direction == ArrowDirection.Right) | |
423 uxState = findUxState(c, ABS_RIGHTDISABLED, ABS_RIGHTNORMAL, ABS_RIGHTHOT, ABS_RIGHTPRESSED); | |
424 else if(c.direction == ArrowDirection.Up) | |
425 uxState = findUxState(c, ABS_UPDISABLED, ABS_UPNORMAL, ABS_UPHOT, ABS_UPPRESSED); | |
426 else | |
427 uxState = findUxState(c, ABS_DOWNDISABLED, ABS_DOWNNORMAL, ABS_DOWNHOT, ABS_DOWNPRESSED); | |
428 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "SCROLLBAR", SBP_ARROWBTN, uxState); | |
429 return; | |
430 } | |
431 } | |
432 | |
433 g.source = getColor(COLOR_3DFACE); | |
434 g.paint(); | |
435 if(c.state == ButtonState.Pressed) { | |
436 g.source = getColor(COLOR_3DDKSHADOW); | |
437 g.rectangle(0.5, 0.5, c.width-1, c.height-1); | |
438 g.stroke(); | |
439 } else { | |
440 draw3dRectangle(g, 0, 0, c.width, c.height, | |
441 getColor(COLOR_3DLIGHT), getColor(COLOR_3DDKSHADOW)); | |
442 draw3dRectangle(g, 1, 1, c.width-2, c.height-2, | |
443 getColor(COLOR_3DHIGHLIGHT), getColor(COLOR_3DSHADOW)); | |
444 } | |
445 } | |
446 //}}} | |
447 | |
448 //{{{ Scrollable | |
449 BorderSize Scrollable_borderSize(Scrollable c) { | |
450 return BorderSize(2, 2, 2, 2); | |
451 } | |
452 | |
453 void Scrollable_paint(Scrollable c, Graphics g) { | |
454 version(Windows) { | |
455 if(Ux.isThemeActive()) { | |
456 Ux.drawBackground(g, Rect(0, 0, c.width, c.height), "EDIT", EP_EDITTEXT, ETS_NORMAL); | |
457 // TODO: get this working | |
458 //g.Source = c.backColor; | |
459 g.source = getColor(COLOR_WINDOW); | |
460 g.rectangle(1.5, 1.5, c.width-3, c.height-3); | |
461 g.stroke(); | |
462 return; | |
463 } | |
464 } | |
465 draw3dRectangle(g, 0, 0, c.width, c.height, | |
466 getColor(COLOR_3DSHADOW), getColor(COLOR_3DHIGHLIGHT)); | |
467 draw3dRectangle(g, 1, 1, c.width-2, c.height-2, | |
468 getColor(COLOR_3DDKSHADOW), getColor(COLOR_3DLIGHT)); | |
469 } | |
470 //}}} | |
471 | |
472 //{{{ Notebook | |
473 BorderSize Notebook_borderSize(Notebook c) { | |
474 version(Windows) { | |
475 if(Ux.isThemeActive()) | |
476 return BorderSize(2, 2, 4, 4); | |
477 } | |
478 return BorderSize(2, 2, 2, 2); | |
479 } | |
480 void Tab_paint(TabPage page, Notebook c, Graphics g) { | |
481 version(Windows) { | |
482 if(Ux.isThemeActive()) { | |
483 g.translate(page.tabLocation); | |
484 //auto uxState = findUxState(c, PBS_DISABLED, PBS_NORMAL, PBS_HOT, PBS_PRESSED); | |
485 auto uxState = TIS_NORMAL; | |
486 BorderSize selectedDelta; | |
487 if(page is c.selectedTabPage) { | |
488 uxState = TIS_SELECTED; | |
489 selectedDelta = BorderSize(2, 2, 2, 2); | |
490 } | |
491 Ux.drawBackground(g, Point() + page.tabSize + selectedDelta, "TAB", TABP_TABITEM, uxState); | |
492 g.drawText(page.text, 5, (page.tabSize.height-g.getTextExtents(page.text).height)/2); | |
493 g.translate(-page.tabLocation); | |
494 return; | |
495 } | |
496 } | |
497 g.translate(page.tabLocation); | |
498 g.source = getColor(COLOR_3DHIGHLIGHT); | |
499 g.moveTo(0.5, 2); | |
500 g.lineTo(0.5, page.tabSize.height); | |
501 g.moveTo(1, 1.5); | |
502 g.lineTo(2, 1.5); | |
503 g.moveTo(2, 0.5); | |
504 g.lineTo(page.tabSize.width-2, 0.5); | |
505 g.stroke(); | |
506 g.source = Color(128, 128, 128); | |
507 g.moveTo(page.tabSize.width-1.5, 2); | |
508 g.lineTo(page.tabSize.width-1.5, page.tabSize.height); | |
509 g.stroke(); | |
510 g.source = Color(64, 64, 64); | |
511 g.moveTo(page.tabSize.width-2, 1.5); | |
512 g.lineTo(page.tabSize.width-1, 1.5); | |
513 g.moveTo(page.tabSize.width-0.5, 2); | |
514 g.lineTo(page.tabSize.width-0.5, page.tabSize.height); | |
515 g.stroke(); | |
516 g.source = getColor(COLOR_WINDOWTEXT); | |
517 g.drawText(page.text, 5, (page.tabSize.height-g.getTextExtents(page.text).height)/2); | |
518 g.translate(-page.tabLocation); | |
519 } | |
520 void Notebook_paint(Notebook c, Graphics g) { | |
521 version(Windows) { | |
522 if(Ux.isThemeActive()) { | |
523 //auto uxState = findUxState(c, PBS_DISABLED, PBS_NORMAL, PBS_HOT, PBS_PRESSED); | |
524 Ux.drawBackground(g, Rect(0, c._tabAreaSize, c.width, c.height-c._tabAreaSize), "TAB", TABP_PANE, 0); | |
525 g.save(); | |
526 g.rectangle(4, 4, c.width-8, c.height-8); | |
527 g.clip(); | |
528 for(float i = 4; i < c.width-8+10; i += 10) | |
529 Ux.drawBackground(g, Rect(i, c._tabAreaSize+4, 10, c.height*1.7-8-(c._tabAreaSize+4)), "TAB", TABP_BODY, 0); | |
530 g.restore(); | |
531 | |
532 return; | |
533 } | |
534 } | |
535 draw3dRectangle(g, 0, c._tabAreaSize, c.width, c.height, | |
536 getColor(COLOR_3DHIGHLIGHT), Color(64, 64, 64)); | |
537 draw3dRectangle(g, 1, c._tabAreaSize+1, c.width-2, c.height-2, | |
538 Color(212, 208, 200), Color(128, 128, 128)); | |
539 | |
540 } | |
541 //}}} | |
542 | |
543 } | |
544 |