Mercurial > projects > dynamin
annotate dynamin/gui/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:
0
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:
0
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:
0
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:
0
diff
changeset
|
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
0 | 8 * |
9 */ | |
10 | |
11 module dynamin.gui.theme; | |
12 | |
13 import dynamin.core.string; | |
14 import dynamin.all_painting; | |
15 import dynamin.all_gui; | |
16 import dynamin.c.cairo; | |
17 import tango.stdc.stdlib; | |
18 | |
19 /** | |
20 * Draws a rectangle with 1 pixel wide lines inside the specified bounds. The | |
21 * left and top are drawn with the first color, and the right and | |
22 * bottom are drawn with the second color. | |
23 */ | |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
24 void draw3dRectangle(Graphics g, double x, double y, double width, double height, |
0 | 25 Color c1, Color c2) { |
26 g.lineWidth = 1; | |
27 | |
28 g.source = c1; | |
29 g.moveTo(x+0.5, y+height-1); | |
30 g.lineTo(x+0.5, y+0.5); | |
31 g.lineTo(x+width-1, y+0.5); | |
32 g.stroke(); | |
33 | |
34 g.source = c2; | |
35 g.moveTo(x+width-0.5, y); | |
36 g.lineTo(x+width-0.5, y+height-0.5); | |
37 g.lineTo(x, y+height-0.5); | |
38 g.stroke(); | |
39 } | |
40 | |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
41 void drawCheckerboard(Graphics g, double x, double y, double width, double height, |
0 | 42 Color c1, Color c2, int squareSize = 1) { |
43 drawCheckerboard(g, Rect(x, y, width, height), c1, c2, squareSize); | |
44 } | |
45 void drawCheckerboard(Graphics g, Rect rect, | |
46 Color c1, Color c2, int squareSize = 1) { | |
47 int width = cast(int)rect.width; | |
48 int height = cast(int)rect.height; | |
49 auto format = c1.A == 255 && c2.A == 255 ? | |
50 CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32; | |
51 int* data = cast(int*)malloc(width*height*4); | |
52 scope(exit) free(data); | |
53 c1.R = c1.R*c1.A/255; | |
54 c1.G = c1.G*c1.A/255; | |
55 c1.B = c1.B*c1.A/255; | |
56 c2.R = c2.R*c2.A/255; | |
57 c2.G = c2.G*c2.A/255; | |
58 c2.B = c2.B*c2.A/255; | |
59 int pixel1 = *cast(int*)&c1; | |
60 int pixel2 = *cast(int*)&c2; | |
61 | |
62 bool oddRow; | |
63 int squareSize2 = squareSize * 2; | |
64 for(int i = 0; i < height; ++i) { | |
65 oddRow = i % squareSize2 < squareSize; | |
66 for(int j = 0; j < width; ++j) { | |
67 if(oddRow ^ j % squareSize2 < squareSize) | |
68 data[j+i*width] = pixel1; | |
69 else | |
70 data[j+i*width] = pixel2; | |
71 } | |
72 } | |
73 | |
74 auto surface = cairo_image_surface_create_for_data(cast(char*)data, format, width, height, width*4); | |
75 g.save(); | |
76 cairo_set_source_surface(g.handle, surface, rect.x, rect.y); | |
77 g.rectangle(rect); | |
78 g.fill(); | |
79 g.restore(); | |
80 cairo_surface_destroy(surface); | |
81 } | |
82 | |
83 abstract class Theme { | |
84 static { | |
85 int _curIndex = 0; | |
86 Theme[] _themes; | |
87 Theme[] getAll() { return _themes.dup; } | |
88 void add(Theme theme) { // TODO: rename to register()? | |
89 _themes.length = _themes.length+1; | |
90 _themes[$-1] = theme; | |
91 } | |
92 Theme current() { return _themes[_curIndex]; } | |
93 void current(Theme theme) { | |
94 foreach(i, t; _themes) { | |
95 if(t is theme) { | |
96 _curIndex = i; | |
97 // TODO: relayout all windows | |
98 } | |
99 } | |
100 } | |
101 //Theme system() { return ; } | |
102 } | |
103 string name(); | |
104 | |
105 //all theme methods follow | |
106 | |
107 // TODO: need to have bestSize, BorderSize, foreColor, backColor, | |
108 // Font, and Paint for all controls | |
109 // TODO: have default imps for foreColor, backColor, and Font: | |
110 // { return Control_ForeColor; } | |
111 // { return Control_Font; } | |
112 void Window_paint(Window c, Graphics g); | |
113 Size Button_bestSize(Button c); | |
114 void Button_paint(Button c, Graphics g); | |
115 void CheckBox_paint(CheckBox c, Graphics g); | |
116 void RadioButton_paint(CheckBox c, Graphics g); | |
117 void ScrollBarTrack_paint(ScrollBarTrack c, Graphics g); | |
118 void ScrollBarThumb_paint(ScrollBarThumb c, Graphics g); | |
104
5c8c1c2e12c0
Change from real to double.
Jordan Miner <jminer7@gmail.com>
parents:
103
diff
changeset
|
119 double ScrollBar_size(); |
0 | 120 void ArrowButton_paint(ArrowButton c, Graphics g); |
121 BorderSize Scrollable_borderSize(Scrollable c); | |
122 void Scrollable_paint(Scrollable c, Graphics g); | |
123 BorderSize Notebook_borderSize(Notebook c); | |
124 void Tab_paint(TabPage page, Notebook c, Graphics g); | |
125 void Notebook_paint(Notebook c, Graphics g); | |
126 } | |
127 | |
128 |