comparison mde/gui/widget/Widget.d @ 44:07bd1a09e161

Started implementing text rendering. Can now position glyphs accurately and render them, in a very basic way. A basic TextWidget. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 16 May 2008 12:22:10 +0100
parents 1530d9c04d4d
children 0fd51d2c6c8a
comparison
equal deleted inserted replaced
43:1530d9c04d4d 44:07bd1a09e161
17 module mde.gui.widget.Widget; 17 module mde.gui.widget.Widget;
18 18
19 public import mde.gui.widget.Ifaces; 19 public import mde.gui.widget.Ifaces;
20 import mde.gui.exception; 20 import mde.gui.exception;
21 import mde.gui.renderer.IRenderer; 21 import mde.gui.renderer.IRenderer;
22
23 import mde.resource.font;
22 24
23 import tango.io.Stdout; 25 import tango.io.Stdout;
24 26
25 /** An abstract base widget class. 27 /** An abstract base widget class.
26 * 28 *
40 int[] adjust (int[] data) { 42 int[] adjust (int[] data) {
41 setSize (0,0); 43 setSize (0,0);
42 return data; 44 return data;
43 } 45 }
44 46
47 bool isWSizable () { return false; }
48 bool isHSizable () { return false; }
49
45 // Widget type should always be the first value. 50 // Widget type should always be the first value.
46 int[] getCreationData () { 51 int[] getCreationData () {
47 return [widgetType]; 52 return [widgetType];
48 } 53 }
49 // Most widgets don't use mutable data. 54 // Most widgets don't use mutable data.
82 int w, h; // size 87 int w, h; // size
83 } 88 }
84 /** A base for fixed-size widgets. */ 89 /** A base for fixed-size widgets. */
85 class FixedWidget : Widget { 90 class FixedWidget : Widget {
86 this (IWindow wind, int[] data) { 91 this (IWindow wind, int[] data) {
87 super (wind, data); 92 w = wF;
88 w = wF = data[1]; 93 h = hF;
89 h = hF = data[2]; 94 super (wind, data);
90 } 95 }
91 96
92 int[] getCreationData () { 97 int[] getCreationData () {
93 return [widgetType, wF, hF]; 98 return [widgetType, wF, hF];
94 } 99 }
95
96 bool isWSizable () { return false; }
97 bool isHSizable () { return false; }
98 100
99 /* Not resizable, so return current size. */ 101 /* Not resizable, so return current size. */
100 void getMinimalSize (out int mw, out int mh) { 102 void getMinimalSize (out int mw, out int mh) {
101 mw = wF; 103 mw = wF;
102 mh = hF; 104 mh = hF;
140 /// A fixed-size blank widget. 142 /// A fixed-size blank widget.
141 class FixedBlankWidget : FixedWidget 143 class FixedBlankWidget : FixedWidget
142 { 144 {
143 this (IWindow wind, int[] data) { 145 this (IWindow wind, int[] data) {
144 if (data.length != 3) throw new WidgetDataException; 146 if (data.length != 3) throw new WidgetDataException;
147 wF = data[1];
148 hF = data[2];
145 super (wind, data); 149 super (wind, data);
146 } 150 }
147 void draw () { 151 void draw () {
148 super.draw; 152 super.draw;
149 153
167 // pushed is not the same as the button being clicked but not yet released. 171 // pushed is not the same as the button being clicked but not yet released.
168 // it is whether the mouse is over the button after being clicked. 172 // it is whether the mouse is over the button after being clicked.
169 173
170 this (IWindow wind, int[] data) { 174 this (IWindow wind, int[] data) {
171 if (data.length != 3) throw new WidgetDataException; 175 if (data.length != 3) throw new WidgetDataException;
176 wF = data[1];
177 hF = data[2];
172 super (wind, data); 178 super (wind, data);
173 } 179 }
174 180
175 void draw () { 181 void draw () {
176 window.renderer.drawButton (x,y, w,h, pushed); 182 window.renderer.drawButton (x,y, w,h, pushed);
204 else pushed = false; 210 else pushed = false;
205 if (oldPushed != pushed) 211 if (oldPushed != pushed)
206 window.requestRedraw; 212 window.requestRedraw;
207 } 213 }
208 } 214 }
215
216 /// Basic text widget
217 class TextWidget : FixedWidget
218 {
219 this (IWindow wind, int[] data) {
220 if (data.length != 1) throw new WidgetDataException;
221 wF = 100; //FIXME: set properly
222 hF = 25;
223 super (wind,data);
224 }
225
226 void draw () {
227 super.draw();
228 if (font is null) font = Font.get("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
229 font.drawStr (x,y, "Text Widget");
230 }
231
232 protected:
233 static Font font;
234 }
209 //END Widgets 235 //END Widgets