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