comparison mde/gui/widget/TextWidget.d @ 93:08a4ae11454b

Widgets now save dimensions without preventing structural changes in the base config file from applying. Widget dimensional data separated from other data in files, hence above change. Moved TextAdapter from TextWidget to IRenderer.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 21 Oct 2008 11:35:15 +0100
parents 4d5d53e4f881
children 9520cc0448e5
comparison
equal deleted inserted replaced
92:085f2ca31914 93:08a4ae11454b
22 import mde.gui.widget.Widget; 22 import mde.gui.widget.Widget;
23 import mde.gui.exception; 23 import mde.gui.exception;
24 import mde.gui.renderer.IRenderer; 24 import mde.gui.renderer.IRenderer;
25 import mde.gui.content.Content; 25 import mde.gui.content.Content;
26 26
27 import mde.font.font;
28
29 /// Adapter to ease use of ContentLabelWidget
30 struct TextAdapter {
31 void set (char[] c, int col) {
32 //FIXME tie font to renderer or so
33 if (font is null) font = FontStyle.get("default");
34
35 content = c;
36 colour = Colour (col);
37 }
38
39 void getDimensions (out wdsize w, out wdsize h) {
40 font.updateBlock (content, textCache);
41 w = cast(wdim) textCache.w;
42 h = cast(wdim) textCache.h;
43 }
44
45 void draw (wdabs x, wdabs y) {
46 font.textBlock (x,y, content, textCache, colour);
47 }
48
49 char[] content;
50 TextBlock textCache;
51 Colour colour;
52 static FontStyle font;
53 }
54
55 /// Basic text widget 27 /// Basic text widget
56 class TextLabelWidget : Widget 28 class TextLabelWidget : Widget
57 { 29 {
58 /** Constructor for a widget containing [fixed] content. 30 /** Constructor for a widget containing [fixed] content.
59 * 31 *
61 * [widgetID, contentID, colour] 33 * [widgetID, contentID, colour]
62 * where contentID is an ID for the string ID of the contained content 34 * where contentID is an ID for the string ID of the contained content
63 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */ 35 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */
64 this (IWidgetManager mgr, widgetID id, WidgetData data) { 36 this (IWidgetManager mgr, widgetID id, WidgetData data) {
65 WDCheck (data, 2, 1); 37 WDCheck (data, 2, 1);
66 adapter.set (data.strings[0], data.ints[1]); 38 adapter = mgr.renderer.getAdapter (data.strings[0], data.ints[1]);
67 adapter.getDimensions (mw, mh); 39 adapter.getDimensions (mw, mh);
68 super (mgr, id, data); 40 super (mgr, id, data);
69 } 41 }
70 42
71 void draw () { 43 void draw () {
72 super.draw(); 44 super.draw();
73 adapter.draw (x,y); 45 adapter.draw (x,y);
74 } 46 }
75 47
76 protected: 48 protected:
77 TextAdapter adapter; 49 IRenderer.TextAdapter adapter;
78 } 50 }
79 51
80 /// Basic widget displaying a label from a content. 52 /// Basic widget displaying a label from a content.
81 class ContentLabelWidget : Widget 53 class ContentLabelWidget : Widget
82 { 54 {
83 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 55 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
84 WDCheck (data, 3, 0); 56 WDCheck (data, 3, 0);
85 content = c; 57 content = c;
86 index = data.ints[1]; 58 index = data.ints[1];
87 adapter.set (content.toString(index), data.ints[2]); 59 adapter = mgr.renderer.getAdapter (content.toString(index), data.ints[2]);
88 adapter.getDimensions (mw, mh); 60 adapter.getDimensions (mw, mh);
89 super (mgr, id,data); 61 super (mgr, id,data);
90 } 62 }
91 63
92 void draw () { 64 void draw () {
93 super.draw(); 65 super.draw();
94 adapter.draw (x,y); 66 adapter.draw (x,y);
95 } 67 }
96 68
97 protected: 69 protected:
98 TextAdapter adapter; 70 IRenderer.TextAdapter adapter;
99 IContent content; 71 IContent content;
100 int index; 72 int index;
101 } 73 }