0
|
1 // Written in the D programming language
|
|
2 // www.digitalmars.com/d/
|
|
3
|
|
4 /*
|
|
5 * The contents of this file are subject to the Mozilla Public License Version
|
|
6 * 1.1 (the "License"); you may not use this file except in compliance with
|
|
7 * the License. You may obtain a copy of the License at
|
|
8 * http://www.mozilla.org/MPL/
|
|
9 *
|
|
10 * Software distributed under the License is distributed on an "AS IS" basis,
|
|
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
12 * for the specific language governing rights and limitations under the
|
|
13 * License.
|
|
14 *
|
|
15 * The Original Code is the Dynamin library.
|
|
16 *
|
|
17 * The Initial Developer of the Original Code is Jordan Miner.
|
|
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009
|
|
19 * the Initial Developer. All Rights Reserved.
|
|
20 *
|
|
21 * Contributor(s):
|
|
22 * Jordan Miner <jminer7@gmail.com>
|
|
23 *
|
|
24 */
|
|
25
|
|
26 module dynamin.gui.basic_theme;
|
|
27
|
|
28 import dynamin.core.string;
|
|
29 import dynamin.all_painting;
|
|
30 import dynamin.all_gui;
|
|
31 import dynamin.core.math;
|
|
32
|
|
33 static this() {
|
|
34 Theme.add(new BasicTheme());
|
|
35 }
|
|
36
|
|
37 /*
|
|
38 * Four colors used in this theme:
|
|
39 * - white (255, 255, 255)
|
|
40 * - black (0, 0, 0)
|
|
41 * - light gray (220, 220, 220)
|
|
42 * - dark gray (70, 70, 70)
|
|
43 */
|
|
44 class BasicTheme : Theme {
|
|
45 string name() {
|
|
46 return "Basic";
|
|
47 }
|
|
48
|
|
49 void Window_paint(Window c, Graphics g) {
|
|
50 g.source = Color.White;
|
|
51 g.paint();
|
|
52 }
|
|
53 Size Button_bestSize(Button c) {
|
|
54 return Size(60, 25);
|
|
55 }
|
|
56
|
|
57 void Button_paint(Button c, Graphics g) {
|
|
58 with(g) {
|
|
59 if(c.state == ButtonState.Pressed)
|
|
60 g.source = Color.Black;
|
|
61 else
|
|
62 g.source = Color.White;
|
|
63 paint();
|
|
64
|
|
65 source = Color.Black;
|
|
66 rectangle(0.5, 0.5, c.width-1, c.height-1);
|
|
67 stroke();
|
|
68 if(c.state == ButtonState.Hot) {
|
|
69 rectangle(1.5, 1.5, c.width-3, c.height-3);
|
|
70 stroke();
|
|
71 }
|
|
72 if(c.state == ButtonState.Pressed)
|
|
73 g.source = Color.White;
|
|
74 else
|
|
75 g.source = c.foreColor;
|
|
76 c.paintFore(g);
|
|
77 }
|
|
78 }
|
|
79
|
|
80 void CheckBox_paint(CheckBox c, Graphics g) {
|
|
81 with(g) {
|
|
82 Point box = Point(2, cast(int)(c.height/2-6));
|
|
83 fontSize = 13;
|
|
84 drawText(c.text, box.x+18, 2);
|
|
85
|
|
86 source = c.state == ButtonState.Pressed ? Color.Black : Color.White;
|
|
87 rectangle(box.x, box.y, 13, 13);
|
|
88 fill();
|
|
89 source = Color.Black;
|
|
90 rectangle(box.x+0.5, box.y+0.5, 12, 12);
|
|
91 stroke();
|
|
92 if(c.state == ButtonState.Hot) {
|
|
93 rectangle(box.x+1.5, box.y+1.5, 10, 10);
|
|
94 stroke();
|
|
95 }
|
|
96
|
|
97 source = c.state == ButtonState.Pressed ? Color.White : Color.Black;
|
|
98 if(c.checked) {
|
|
99 moveTo(box.x+2.5, box.y+7.5);
|
|
100 relLineTo(2, 3);
|
|
101 relLineTo(6, -8);
|
|
102 stroke();
|
|
103 }
|
|
104 }
|
|
105 }
|
|
106 void RadioButton_paint(CheckBox c, Graphics g) {
|
|
107 with(g) {
|
|
108 int radius = 6;
|
|
109 Point circle = Point(2, cast(int)(c.height/2-radius));
|
|
110 fontSize = 13;
|
|
111 drawText(c.text, circle.x+18, 2);
|
|
112
|
|
113 source = c.state == ButtonState.Pressed ? Color.Black : Color.White;
|
|
114 ellipse(circle.x+radius, circle.y+radius, radius);
|
|
115 fill();
|
|
116 source = Color.Black;
|
|
117 if(c.state == ButtonState.Hot) {
|
|
118 lineWidth = 2;
|
|
119 ellipse(circle.x+radius, circle.y+radius, radius-1);
|
|
120 } else {
|
|
121 ellipse(circle.x+radius, circle.y+radius, radius-0.5);
|
|
122 }
|
|
123 stroke();
|
|
124 lineWidth = 1;
|
|
125
|
|
126 source = c.state == ButtonState.Pressed ? Color.White : Color.Black;
|
|
127 if(c.checked) {
|
|
128 ellipse(circle.x+radius, circle.y+radius, radius-4);
|
|
129 fill();
|
|
130 }
|
|
131 }
|
|
132 }
|
|
133
|
|
134 void ScrollBarTrack_paint(ScrollBarTrack c, Graphics g) {
|
|
135 if(c.state == ButtonState.Pressed)
|
|
136 g.paint();
|
|
137 else if(isOdd(cast(int)round(c.x)) || isOdd(cast(int)round(c.y)))
|
|
138 drawCheckerboard(g, 0, 0, c.width, c.height,
|
|
139 Color.White, Color.Black);
|
|
140 else
|
|
141 drawCheckerboard(g, 0, 0, c.width, c.height,
|
|
142 Color.Black, Color.White);
|
|
143 }
|
|
144
|
|
145 void ScrollBarThumb_paint(ScrollBarThumb c, Graphics g) {
|
|
146 with(g) {
|
|
147 source = Color.White;
|
|
148 paint();
|
|
149 source = Color.Black;
|
|
150 rectangle(0.5, 0.5, c.width-1, c.height-1);
|
|
151 stroke();
|
|
152 }
|
|
153 }
|
|
154
|
|
155 real ScrollBar_size() {
|
|
156 // TODO: all themes should get this from SystemGui.ScrollBarSize
|
|
157 return 18;
|
|
158 }
|
|
159
|
|
160 void ArrowButton_paint(ArrowButton c, Graphics g) {
|
|
161 Button_paint(c, g);
|
|
162 }
|
|
163
|
|
164 BorderSize Scrollable_borderSize(Scrollable c) {
|
|
165 return BorderSize(1, 1, 1, 1);
|
|
166 }
|
|
167
|
|
168 void Scrollable_paint(Scrollable c, Graphics g) {
|
|
169 g.source = Color.White;
|
|
170 g.paint();
|
|
171 g.source = Color.Black;
|
|
172 g.rectangle(0.5, 0.5, c.width-0.5, c.height-0.5);
|
|
173 g.stroke();
|
|
174 }
|
|
175
|
|
176 BorderSize Notebook_borderSize(Notebook c) {
|
|
177 return BorderSize(1, 1, 1, 1);
|
|
178 }
|
|
179 void Tab_paint(TabPage page, Notebook c, Graphics g){}
|
|
180 void Notebook_paint(Notebook c, Graphics g){}
|
|
181
|
|
182 }
|
|
183
|