comparison dynamin/gui/silver_theme.d @ 19:e4dabffaa784

Add silver theme, which was referred to, but missing in last commit.
author Jordan Miner <jminer7@gmail.com>
date Fri, 24 Jul 2009 00:40:31 -0500
parents
children 73060bc3f004
comparison
equal deleted inserted replaced
18:836a064828e8 19:e4dabffaa784
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) 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.silver_theme;
27
28 import dynamin.core.string;
29 import dynamin.all_painting;
30 import dynamin.all_gui;
31 import dynamin.core.math;
32 import dynamin.c.cairo;
33
34 static this() {
35 Theme.add(new SilverTheme());
36 }
37
38 /*
39 * Colors used in this theme:
40 * - Silver (192, 192, 192)
41 * - Light Silver (220, 220, 220)
42 * - Dark Silver (170, 170, 170)
43 * - (150, 150, 150)
44 */
45 class SilverTheme : Theme {
46 string name() {
47 return "Silver";
48 }
49
50 void Window_paint(Window c, Graphics g) {
51 g.source = Color.Silver;
52 g.paint();
53 }
54 Size Button_bestSize(Button c) {
55 return Size(70, 25);
56 }
57
58 private Color _silver = Color(192, 192, 192);
59 private Color _lightSilver = Color(220, 220, 220);
60 private Color _darkSilver = Color(170, 170, 170);
61 private Color _gray = Color(150, 150, 150);
62 private Color _black = Color(0, 0, 0);
63 private Color _white = Color(255, 255, 255);
64 //{{{ common
65 void drawButtonBack(Graphics g, real x, real y, real width, real height, ButtonState state) {
66 with(g) {
67 if(state == ButtonState.Normal)
68 source = _silver;
69 else if(state == ButtonState.Hot) {
70 auto grad = cairo_pattern_create_radial(width/2, height, 0,
71 width/2, height, height);
72 cairo_pattern_add_color_stop_rgb(grad, 0, 0.863, 0.863, 0.863);
73 cairo_pattern_add_color_stop_rgb(grad, 1, 0.753, 0.753, 0.753);
74 cairo_set_source(handle, grad);
75 } else if(state == ButtonState.Pressed)
76 source = _darkSilver;
77 roundedRectangle(x+0.5, y+0.5, width-1, height-1, 2);
78 fill();
79
80 if(state == ButtonState.Normal)
81 source = _lightSilver;
82 else if(state == ButtonState.Hot)
83 source = _white;
84 else if(state == ButtonState.Pressed)
85 source = _gray;
86 roundedRectangle(x+0.5, y+0.5, width-1, height-1, 2);
87 stroke();
88 }
89 }
90 //}}}
91
92 void Button_paint(Button c, Graphics g) {
93 with(g) {
94 drawButtonBack(g, 0, 0, c.width, c.height, c.state);
95 source = _black;
96 c.paintFore(g);
97 }
98 }
99
100 void CheckBox_paint(CheckBox c, Graphics g) {
101 with(g) {
102 Point box = Point(2, cast(int)(c.height/2-6));
103 fontSize = 13;
104 drawText(c.text, box.x+18, 2);
105
106 source = c.state == ButtonState.Pressed ? Color.Black : Color.White;
107 rectangle(box.x, box.y, 13, 13);
108 fill();
109 source = Color.Black;
110 rectangle(box.x+0.5, box.y+0.5, 12, 12);
111 stroke();
112 if(c.state == ButtonState.Hot) {
113 rectangle(box.x+1.5, box.y+1.5, 10, 10);
114 stroke();
115 }
116
117 source = c.state == ButtonState.Pressed ? Color.White : Color.Black;
118 if(c.checked) {
119 moveTo(box.x+2.5, box.y+7.5);
120 relLineTo(2, 3);
121 relLineTo(6, -8);
122 stroke();
123 }
124 }
125 }
126 void RadioButton_paint(CheckBox c, Graphics g) {
127 with(g) {
128 int radius = 6;
129 Point circle = Point(2, cast(int)(c.height/2-radius));
130 fontSize = 13;
131 drawText(c.text, circle.x+18, 2);
132
133 source = c.state == ButtonState.Pressed ? Color.Black : Color.White;
134 ellipse(circle.x+radius, circle.y+radius, radius);
135 fill();
136 source = Color.Black;
137 if(c.state == ButtonState.Hot) {
138 lineWidth = 2;
139 ellipse(circle.x+radius, circle.y+radius, radius-1);
140 } else {
141 ellipse(circle.x+radius, circle.y+radius, radius-0.5);
142 }
143 stroke();
144 lineWidth = 1;
145
146 source = c.state == ButtonState.Pressed ? Color.White : Color.Black;
147 if(c.checked) {
148 ellipse(circle.x+radius, circle.y+radius, radius-4);
149 fill();
150 }
151 }
152 }
153
154 void ScrollBarTrack_paint(ScrollBarTrack c, Graphics g) {
155 if(c.state == ButtonState.Pressed)
156 g.paint();
157 else if(isOdd(cast(int)round(c.x)) || isOdd(cast(int)round(c.y)))
158 drawCheckerboard(g, 0, 0, c.width, c.height,
159 Color.White, Color.Black);
160 else
161 drawCheckerboard(g, 0, 0, c.width, c.height,
162 Color.Black, Color.White);
163 }
164
165 void ScrollBarThumb_paint(ScrollBarThumb c, Graphics g) {
166 with(g) {
167 source = Color.White;
168 paint();
169 source = Color.Black;
170 rectangle(0.5, 0.5, c.width-1, c.height-1);
171 stroke();
172 }
173 }
174
175 real ScrollBar_size() {
176 // TODO: all themes should get this from SystemGui.ScrollBarSize
177 return 18;
178 }
179
180 void ArrowButton_paint(ArrowButton c, Graphics g) {
181 Button_paint(c, g);
182 }
183
184 BorderSize Scrollable_borderSize(Scrollable c) {
185 return BorderSize(1, 1, 1, 1);
186 }
187
188 void Scrollable_paint(Scrollable c, Graphics g) {
189 g.source = Color.White;
190 g.paint();
191 g.source = Color.Black;
192 g.rectangle(0.5, 0.5, c.width-0.5, c.height-0.5);
193 g.stroke();
194 }
195
196 BorderSize Notebook_borderSize(Notebook c) {
197 return BorderSize(1, 1, 1, 1);
198 }
199 void Tab_paint(TabPage page, Notebook c, Graphics g){
200 g.translate(page.tabLocation);
201 g.drawText(page.text, 5, (page.tabSize.height-g.getTextExtents(page.text).height)/2);
202 g.translate(-page.tabLocation);
203 }
204 void Notebook_paint(Notebook c, Graphics g){}
205
206 }
207