comparison mde/gui/widget/miscContent.d @ 105:08651e8a8c51

Quit button, big changes to content system. Moved mde.gui.content to mde.content to reflect it's not only used by the gui. Split Content module into Content and AStringContent. New AContent and EventContent class. Callbacks are now generic and implemented in AContent. Renamed TextContent to StringContent and ValueContent to AStringContent.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 29 Nov 2008 12:36:39 +0000
parents 42e241e7be3e
children 1655693702fc
comparison
equal deleted inserted replaced
104:ee209602770d 105:08651e8a8c51
22 import mde.gui.exception; 22 import mde.gui.exception;
23 import mde.gui.widget.textContent; 23 import mde.gui.widget.textContent;
24 import mde.gui.widget.layout; 24 import mde.gui.widget.layout;
25 25
26 import mde.gui.renderer.IRenderer; 26 import mde.gui.renderer.IRenderer;
27 import mde.gui.content.Content; 27 import mde.content.AStringContent;
28 import Items = mde.gui.content.Items; 28 import Items = mde.content.Items;
29 29
30 /************************************************************************************************* 30 /*************************************************************************************************
31 * A function which uses Items.get (data.strings[0]) to get a content and creates a widget from 31 * A function which uses Items.get (data.strings[0]) to get a content and creates a widget from
32 * data.ints[1]. The first item in each ints and strings is removed before passing data to the new 32 * data.ints[1]. The first item in each ints and strings is removed before passing data to the new
33 * widget. 33 * widget.
50 *************************************************************************************************/ 50 *************************************************************************************************/
51 IChildWidget editContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { 51 IChildWidget editContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
52 if (c is null) throw new ContentException; 52 if (c is null) throw new ContentException;
53 if (cast(BoolContent) c) 53 if (cast(BoolContent) c)
54 return new BoolContentWidget(mgr,id,data,c); 54 return new BoolContentWidget(mgr,id,data,c);
55 else if (cast(ValueContent) c) 55 else if (cast(AStringContent) c)
56 return new ValueContentWidget(mgr,id,data,c); 56 return new AStringContentWidget(mgr,id,data,c);
57 else if (cast(ContentList) c) 57 else if (cast(ContentList) c)
58 return new ContentListWidget(mgr,id,data,c); 58 return new ContentListWidget(mgr,id,data,c);
59 else // generic uneditable option 59 else // generic uneditable option
60 return new DisplayContentWidget(mgr,id,data,c); 60 return new DisplayContentWidget(mgr,id,data,c);
61 } 61 }
83 83
84 protected: 84 protected:
85 BoolContent content; 85 BoolContent content;
86 } 86 }
87 87
88 /// A button connected to an EventContent
89 class ButtonContentWidget : AButtonWidget
90 {
91 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
92 WDCheck (data, 1);
93 content = cast(EventContent) c;
94 if (!content) throw new ContentException ();
95 adapter = mgr.renderer.getAdapter (content.toString (1));
96 adapter.getDimensions (mw, mh);
97 w = mw;
98 h = mh;
99 super (mgr, id, data);
100 }
101
102 void draw () {
103 super.draw();
104 adapter.draw (x,y);
105 }
106
107 void activated () {
108 content.endEvent;
109 }
110
111 protected:
112 IRenderer.TextAdapter adapter;
113 EventContent content;
114 int index;
115 }
116