Mercurial > projects > mde
comparison mde/gui/widget/AChildWidget.d @ 174:3d58adc17d20
Temporary commit to allow backup
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 13:54:23 +0200 |
parents | 0dd49f333189 |
children | 1cbde9807293 |
comparison
equal
deleted
inserted
replaced
173:a1ba9157510e | 174:3d58adc17d20 |
---|---|
37 * An abstract base widget class for IChildWidgets. | 37 * An abstract base widget class for IChildWidgets. |
38 * | 38 * |
39 * This abstract class, and the more concrete FixedWidget and ScalableWidget | 39 * This abstract class, and the more concrete FixedWidget and ScalableWidget |
40 * classes provides useful basic implementations for widgets. | 40 * classes provides useful basic implementations for widgets. |
41 *****************************************************************************/ | 41 *****************************************************************************/ |
42 abstract class AChildWidget : IChildWidget | 42 abstract class AChildWidget : IChildWidget, IWidget |
43 { | 43 { |
44 //BEGIN Load and save | 44 //BEGIN Load and save |
45 // Base this() for child Widgets. | 45 // Base this() for child Widgets. |
46 protected this (IWidgetManager mgr, IParentWidget parent, widgetID id) { | 46 protected this (IWidgetManager mgr, IParentWidget parent, widgetID id) { |
47 this.mgr = mgr; | 47 this.mgr = mgr; |
53 override bool setup (uint n,uint) { | 53 override bool setup (uint n,uint) { |
54 return n == 0; | 54 return n == 0; |
55 } | 55 } |
56 | 56 |
57 // Don't save any data: fine for many widgets. | 57 // Don't save any data: fine for many widgets. |
58 override bool saveChanges () { | 58 public override bool saveChanges () { |
59 return false; | 59 return false; |
60 } | 60 } |
61 | 61 |
62 // Widgets with content need to override these | 62 // Widgets with content need to override these |
63 override IContent content () { | 63 override IContent content () { |
131 override int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) { | 131 override int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) { |
132 return 0; | 132 return 0; |
133 } | 133 } |
134 | 134 |
135 /* Dummy functions; many widgets don't need to respond to dragging. */ | 135 /* Dummy functions; many widgets don't need to respond to dragging. */ |
136 void dragMotion (wdabs cx, wdabs cy, IChildWidget) {} | 136 override void dragMotion (wdabs cx, wdabs cy, IChildWidget) {} |
137 bool dragRelease (wdabs cx, wdabs cy, IChildWidget) { | 137 override bool dragRelease (wdabs cx, wdabs cy, IChildWidget) { |
138 return false; // any widgets not handling events should let them be passed as normal to clickEvent | 138 return false; // any widgets not handling events should let them be passed as normal to clickEvent |
139 } | 139 } |
140 | 140 |
141 /* Dummy functions: suitable for widgets with no text input. */ | 141 /* Dummy functions: suitable for widgets with no text input. */ |
142 override void keyEvent (ushort, char[]) {} | 142 public override void keyEvent (ushort, char[]) {} |
143 override void keyFocusLost () {} | 143 public override void keyFocusLost () {} |
144 | 144 |
145 // Called when mouse moves over or off this | 145 // Called when mouse moves over or off this |
146 override void underMouse (bool state) {} | 146 override void underMouse (bool state) {} |
147 | 147 |
148 override bool dropContent (IContent content) { | 148 public override bool dropContent (IContent content) { |
149 return parent.dropContent (content); | 149 return parent.dropContent (content); |
150 } | 150 } |
151 | 151 |
152 // Only useful to widgets creating popups. | 152 // Only useful to widgets creating popups. |
153 override void popupClose () {} | 153 protected override void popupClose () {} |
154 override bool popupParentClick () { | 154 protected override bool popupParentClick () { |
155 return true; | 155 return true; |
156 } | 156 } |
157 //END Events | 157 //END Events |
158 | 158 |
159 /* Basic draw method: draw the background (all widgets should do this). */ | 159 /* Basic draw method: draw the background (all widgets should do this). */ |
160 override void draw () { | 160 public override void draw () { |
161 //TODO: possibly enforce all widgets to implement this so their invariant runs: | |
162 //assert (false, "all widgets should override draw"); | |
161 mgr.renderer.drawWidgetBack (x,y, w,h); | 163 mgr.renderer.drawWidgetBack (x,y, w,h); |
162 } | 164 } |
163 | 165 |
164 // Debug function to print size info. Intended to be correct not optimal. | 166 // Debug function to print size info. Intended to be correct not optimal. |
165 debug override void logWidgetSize () { | 167 debug public override void logWidgetSize () { |
166 logger.trace ("size: {,4},{,4}; minimal: {,4},{,4}; sizable: {},{} - {,-50} {}", this.width, this.height, this.minWidth, this.minHeight, cast(int)this.isWSizable, cast(int)this.isHSizable, this, id); | 168 logger.trace ("size: {,4},{,4}; minimal: {,4},{,4}; sizable: {},{} - {,-50} {}", this.width, this.height, this.minWidth, this.minHeight, cast(int)this.isWSizable, cast(int)this.isHSizable, this, id); |
167 } | 169 } |
168 | 170 |
169 protected: | 171 protected: |
170 /************************************************************************** | 172 /************************************************************************** |
209 * mgr.requestRedraw could be hooked in directly if the prototype changed. */ | 211 * mgr.requestRedraw could be hooked in directly if the prototype changed. */ |
210 void contentRedraw (IContent) { | 212 void contentRedraw (IContent) { |
211 mgr.requestRedraw; | 213 mgr.requestRedraw; |
212 } | 214 } |
213 | 215 |
216 invariant { | |
217 assert (w >= mw); | |
218 assert (h >= mh); | |
219 } | |
220 | |
214 IWidgetManager mgr; // the enclosing window | 221 IWidgetManager mgr; // the enclosing window |
215 IParentWidget parent; // the parent widget | 222 IParentWidget parent; // the parent widget |
216 wdim x, y; // position | 223 wdim x, y; // position |
217 widgetID id; // The widget's ID, used for saving data | 224 widgetID id; // The widget's ID, used for saving data |
218 wdim w, h; // size | 225 wdim w, h; // size |
307 if (oldPushed != pushed) | 314 if (oldPushed != pushed) |
308 mgr.requestRedraw; | 315 mgr.requestRedraw; |
309 } | 316 } |
310 | 317 |
311 /// The action triggered when the button is clicked... | 318 /// The action triggered when the button is clicked... |
312 void activated (); | 319 abstract void activated (); |
313 | 320 |
314 protected: | 321 protected: |
315 bool pushed = false; /// True if button is pushed in (visually) | 322 bool pushed = false; /// True if button is pushed in (visually) |
316 IPopupParentWidget parentIPPW; | 323 IPopupParentWidget parentIPPW; |
317 } | 324 } |