Mercurial > projects > mde
comparison mde/gui/widget/TextWidget.d @ 91:4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Some debugging improvements.
When multiple .mtt files are read for merging, files with invalid headers are ignored and no error is thrown so long as at least one file os valid.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 16 Oct 2008 17:43:48 +0100 |
parents | b525ff28774b |
children | 08a4ae11454b |
comparison
equal
deleted
inserted
replaced
90:b525ff28774b | 91:4d5d53e4f881 |
---|---|
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; | 27 import mde.font.font; |
28 | 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 | |
29 /// Basic text widget | 55 /// Basic text widget |
30 class TextLabelWidget : Widget | 56 class TextLabelWidget : Widget |
31 { | 57 { |
32 /** Constructor for a widget containing [fixed] content. | 58 /** Constructor for a widget containing [fixed] content. |
33 * | 59 * |
34 * Widget uses the initialisation data: | 60 * Widget uses the initialisation data: |
35 * [widgetID, contentID, colour] | 61 * [widgetID, contentID, colour] |
36 * where contentID is an ID for the string ID of the contained content | 62 * where contentID is an ID for the string ID of the contained content |
37 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */ | 63 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */ |
38 this (IWidgetManager mgr, WidgetData data) { | 64 this (IWidgetManager mgr, widgetID id, WidgetData data) { |
39 WDCheck (data, 2, 1); | 65 WDCheck (data, 2, 1); |
40 if (font is null) font = FontStyle.get("default"); | 66 adapter.set (data.strings[0], data.ints[1]); |
41 font.updateBlock (data.strings[0], textCache); | |
42 mw = cast(wdim) textCache.w; | |
43 mh = cast(wdim) textCache.h; | |
44 colour = Colour (data.ints[1]); | |
45 super (mgr,data); | |
46 } | |
47 | |
48 void draw () { | |
49 super.draw(); | |
50 font.textBlock (x,y, text, textCache, colour); | |
51 } | |
52 | |
53 protected: | |
54 char[] text; | |
55 Colour colour; | |
56 TextBlock textCache; | |
57 static FontStyle font; | |
58 } | |
59 | |
60 | |
61 /// Adapter to ease use of ContentLabelWidget | |
62 struct ContentLabelAdapter { | |
63 void set (IContent c, int col) { | |
64 if (font is null) font = FontStyle.get("default"); | |
65 | |
66 content = c; | |
67 colour = Colour (cast(ubyte) (col >> 16u), | |
68 cast(ubyte) (col >> 8u), | |
69 cast(ubyte) col ); | |
70 } | |
71 | |
72 void getDimensions (out wdsize w, out wdsize h) { | |
73 font.updateBlock (content.toString, textCache); | |
74 w = cast(wdim) textCache.w; | |
75 h = cast(wdim) textCache.h; | |
76 } | |
77 | |
78 void draw (wdabs x, wdabs y) { | |
79 font.textBlock (x,y, content.toString, textCache, colour); | |
80 } | |
81 | |
82 IContent content; | |
83 TextBlock textCache; | |
84 Colour colour; | |
85 static FontStyle font; | |
86 } | |
87 | |
88 /// Basic widget displaying a label from a content. | |
89 class ContentLabelWidget : Widget | |
90 { | |
91 this (IWidgetManager mgr, WidgetData data, IContent c) { | |
92 WDCheck (data, 2, 0); | |
93 adapter.set (c, data.ints[1]); | |
94 adapter.getDimensions (mw, mh); | 67 adapter.getDimensions (mw, mh); |
95 super (mgr,data); | 68 super (mgr, id, data); |
96 } | 69 } |
97 | 70 |
98 void draw () { | 71 void draw () { |
99 super.draw(); | 72 super.draw(); |
100 adapter.draw (x,y); | 73 adapter.draw (x,y); |
101 } | 74 } |
102 | 75 |
103 protected: | 76 protected: |
104 ContentLabelAdapter adapter; | 77 TextAdapter adapter; |
105 } | 78 } |
79 | |
80 /// Basic widget displaying a label from a content. | |
81 class ContentLabelWidget : Widget | |
82 { | |
83 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { | |
84 WDCheck (data, 3, 0); | |
85 content = c; | |
86 index = data.ints[1]; | |
87 adapter.set (content.toString(index), data.ints[2]); | |
88 adapter.getDimensions (mw, mh); | |
89 super (mgr, id,data); | |
90 } | |
91 | |
92 void draw () { | |
93 super.draw(); | |
94 adapter.draw (x,y); | |
95 } | |
96 | |
97 protected: | |
98 TextAdapter adapter; | |
99 IContent content; | |
100 int index; | |
101 } |