comparison mde/gui/widget/Window.d @ 36:57d000574d75

Enabled drawing on demand, and made the polling interval configurable. Renamed mde.global to mde.imde. Enabled drawing on demand. Allowed options to take double values. Made the main loop's polling interval (sleep duration) settable from config files. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 02 May 2008 17:38:43 +0100
parents 928db3c75ed3
children 052df9b2fe07
comparison
equal deleted inserted replaced
35:928db3c75ed3 36:57d000574d75
105 IWidget makeWidget (widgetID i, IWidget parent) 105 IWidget makeWidget (widgetID i, IWidget parent)
106 in { 106 in {
107 // widgetData is normally left to be garbage collected after widgets have been created: 107 // widgetData is normally left to be garbage collected after widgets have been created:
108 assert (widgetData !is null, "Window.makeWidget ("~name~"): widgetData is null"); 108 assert (widgetData !is null, "Window.makeWidget ("~name~"): widgetData is null");
109 } body { 109 } body {
110 // See if it's already been created: 110 /* Each widget returned should be a unique object; if multiple widgets are requested with
111 IWidget* p = i in widgets; 111 * the same ID, a new widget is created each time. */
112 if (p !is null) { // yes 112
113 char[128] tmp; 113 int[]* d = i in widgetData;
114 logger.warn (logger.format (tmp, "Window.makeWidget ("~name~"): widget {} has multiple uses!", i)); 114 if (d is null)
115 return *p; 115 throw new WindowLoadException ("Window.makeWidget ("~name~"): Widget not found");
116 } 116
117 else { // no 117 // Throws WidgetDataException (a WindowLoadException) if bad data:
118 int[]* d = i in widgetData; 118 IWidget widg = createWidget (this, parent, *d);
119 if (d is null) throw new WindowLoadException ("Window.makeWidget ("~name~"): Widget not found"); 119 widgets ~= widg;
120 120 return widg;
121 // Throws WidgetDataException (a WindowLoadException) if bad data:
122 IWidget widg = createWidget (this, parent, *d);
123 widgets[i] = widg;
124 return widg;
125 }
126 } 121 }
127 122
128 IGui gui () { 123 IGui gui () {
129 return gui_; 124 return gui_;
130 } 125 }
158 153
159 widgetX = x + rend.windowBorder; 154 widgetX = x + rend.windowBorder;
160 widgetY = y + rend.windowBorder; 155 widgetY = y + rend.windowBorder;
161 156
162 widget.setPosition (widgetX, widgetY); 157 widget.setPosition (widgetX, widgetY);
158
159 gui_.requestRedraw (); // obviously necessary whenever the window is moved
163 } 160 }
164 161
165 IWidget getWidget (int cx, int cy) { 162 IWidget getWidget (int cx, int cy) {
166 if (cx < x || cx >= xw || cy < y || cy >= yh) // not over window 163 if (cx < x || cx >= xw || cy < y || cy >= yh) // not over window
167 return null; 164 return null;
207 204
208 char[] name; // The window's name (id from config file) 205 char[] name; // The window's name (id from config file)
209 IGui gui_; // The gui managing this window 206 IGui gui_; // The gui managing this window
210 207
211 int[][widgetID] widgetData; // Data for all widgets under this window (deleted after loading) 208 int[][widgetID] widgetData; // Data for all widgets under this window (deleted after loading)
212 IWidget[widgetID] widgets; // List of all widgets under this window (created on demand). 209 IWidget[] widgets; // List of all widgets under this window (created on demand). Use for saving?
213 IWidget widget; // The primary widget in this window. 210 IWidget widget; // The primary widget in this window.
214 211
215 IRenderer rend; // The window's renderer 212 IRenderer rend; // The window's renderer
216 // FIXME: revise which parameters are stored once Gui knows window position 213 // FIXME: revise which parameters are stored once Gui knows window position
217 int x,y; // Window position 214 int x,y; // Window position