Mercurial > projects > mde
diff mde/gui/WMScreen.d @ 159:b06b04c75e86
Finished last commit, rearranged code for the WidgetManager class.
There is now a GUI options section.
Created a third WidgetManager class called WidgetLoader to handle file loading/saving.
Moved most of the code in WMScreen's draw/clickEvent/motionEvent functions to WidgetManager.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 21 May 2009 20:55:10 +0200 |
parents | a86f8445ccc8 |
children | 7f7b2011b759 |
line wrap: on
line diff
--- a/mde/gui/WMScreen.d Fri Apr 24 17:35:53 2009 +0100 +++ b/mde/gui/WMScreen.d Thu May 21 20:55:10 2009 +0200 @@ -22,6 +22,7 @@ module mde.gui.WMScreen; import mde.gui.WidgetManager; +import mde.gui.WidgetLoader; import mde.gui.widget.Ifaces; import mde.gui.renderer.createRenderer; @@ -46,9 +47,10 @@ * sense to translate them and possibly drop events for some uses, such as if * the gui is drawn to a texture. * - * Public non IWidget* methods should be thread-safe. + * Public non IWidget* methods should be thread-safe, even to the same + * instance (by locking on a mutex). *****************************************************************************/ -scope class WMScreen : AWidgetManager, Screen.IDrawable { +scope class WMScreen : AWidgetLoader, Screen.IDrawable { /** Construct a new widget manager. * * Must be run after static this. @@ -72,71 +74,27 @@ synchronized(mutex) { debug (mdeDrawEvents) logger.trace ("drawing"); - if (child) - child.draw; - if (childIPPW) - childIPPW.drawPopup; - drawPopup; + wmDrawWidgets(); } } - /** For mouse click events. - * - * Sends the event on to the relevant windows and all click callbacks. */ + /** For mouse click events. */ void clickEvent (ushort usx, ushort usy, ubyte b, bool state) { try { - mutex.lock; - scope(exit) mutex.unlock; - if (child is null) return; - - wdabs cx = cast(wdabs) usx, cy = cast(wdabs) usy; - - // Callbacks have the highest priority receiving events (e.g. a button release) - foreach (dg; clickCallbacks) - if (dg (cx, cy, b, state)) return; - - // Update underMouse to get the widget clicked on - updateUnderMouse (cx, cy, state); - - // Disable keyboard input if on another widget: - if (keyFocus && keyFocus !is underMouse) { - keyFocus.keyFocusLost; - keyFocus = null; - input.setLetterCallback (null); - } - - // Finally, post the actual event: - if (b == 3 && state) { // right click - open context menu - IContent contextContent = underMouse.content; - if (contextContent is null) return; - // NOTE: Creates new widgets every time; not optimal - popupContext = makeWidget (this, "context", contextContent); - popupContext.setup (0, 3); - positionPopup (underMouse, popupContext); - requestRedraw; - } else // post other button presses to clickEvent - if (underMouse.clickEvent (cast(wdabs)cx,cast(wdabs)cy,b,state) & 1) { - // keyboard input requested - keyFocus = underMouse; - input.setLetterCallback (&underMouse.keyEvent); - } + mutex.lock; + scope(exit) mutex.unlock; + wmMouseClick (cast(wdabs) usx, cast(wdabs) usy, b, state); } catch (Exception e) { logger.error ("clickEvent: exception processing event: {}", e.msg); } } - /** For mouse motion events. - * - * Sends the event on to all motion callbacks. */ + /** For mouse motion events. */ void motionEvent (ushort scx, ushort scy) { try { mutex.lock; scope(exit) mutex.unlock; - wdabs cx = cast(wdabs) scx, cy = cast(wdabs) scy; - foreach (dg; motionCallbacks) - dg (cx, cy); - - updateUnderMouse (cx, cy, false); + wmMouseMotion (cast(wdabs) scx, cast(wdabs) scy); } catch (Exception e) { logger.error ("motionEvent: exception processing event: {}", e.msg); } @@ -166,6 +124,10 @@ } protected: + final override void setLetterCallback(void delegate(ushort, char[]) dlg) { + input.setLetterCallback (dlg); + } + /* Second stage of widget loading. * Note: sizeEvent should be called with window size before this. */ final override void createRootWidget () {