Mercurial > projects > mde
changeset 177:af40e9679436
Release-clicks don't cause problems now.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 12 Sep 2009 09:50:33 +0200 |
parents | d5d5fe04ca6c |
children | 62aa8845edd2 |
files | codeDoc/jobs.txt mde/gui/widget/AChildWidget.d mde/gui/widget/AParentWidget.d mde/gui/widget/Floating.d mde/gui/widget/Ifaces.d mde/gui/widget/ParentContent.d mde/gui/widget/TextWidget.d mde/gui/widget/WidgetManager.d mde/gui/widget/layout.d mde/gui/widget/miscContent.d |
diffstat | 10 files changed, 56 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/codeDoc/jobs.txt Sat Sep 12 09:14:43 2009 +0200 +++ b/codeDoc/jobs.txt Sat Sep 12 09:50:33 2009 +0200 @@ -13,7 +13,7 @@ To do (importance 0-5: 0 pointless, 1 no obvious impact now, 2 todo sometime, 3 useful, 4 important, 5 urgent): Also search for FIXME/NOTE/BUG/WARNING comment marks. 4 Move createWidget code out of WidgetManager. -4 GUI: up-clicks get passed as events and activate objects +3 Make clickEvent only for down-clicks? 3 RequestRedraw should become a function of the renderer. 3 Implement a RootWidget moving functionality out of AWidgetManager, etc., now, or later? 3 May be useful to make all widgets override draw() to ensure the invariant runs locally.
--- a/mde/gui/widget/AChildWidget.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/AChildWidget.d Sat Sep 12 09:50:33 2009 +0200 @@ -120,6 +120,11 @@ return this; } + // Parent widgets should override. + override bool isDescendant (IChildWidget widget) { + return widget is this; + } + // Should be valid for any widget. override bool onSelf (wdabs cx, wdabs cy) { return cx >= x && cx < x + w && cy >= y && cy < y + h; @@ -132,7 +137,7 @@ /* Dummy functions; many widgets don't need to respond to dragging. */ override void dragMotion (wdabs cx, wdabs cy, IChildWidget) {} - override bool dragRelease (wdabs cx, wdabs cy, IChildWidget) { + override bool dragRelease (wdabs cx, wdabs cy, ubyte b, IChildWidget) { return false; // any widgets not handling events should let them be passed as normal to clickEvent } @@ -306,7 +311,7 @@ } /// Called when a mouse click event occurs while held; handles up-click - override bool dragRelease (wdabs cx, wdabs cy, IChildWidget) { + override bool dragRelease (wdabs cx, wdabs cy, ubyte b, IChildWidget) { if (pushed) { // on button parentIPPW.menuDone; activated();
--- a/mde/gui/widget/AParentWidget.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/AParentWidget.d Sat Sep 12 09:50:33 2009 +0200 @@ -97,6 +97,13 @@ widget.setHeight (nmh, -1); } + override bool isDescendant (IChildWidget widget) { + foreach (w; subWidgets) + if (w.isDescendant (widget)) + return true; + return super.isDescendant (widget); + } + debug public override void logWidgetSize () { super.logWidgetSize; foreach (widg; subWidgets)
--- a/mde/gui/widget/Floating.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/Floating.d Sat Sep 12 09:50:33 2009 +0200 @@ -288,7 +288,7 @@ mgr.requestRedraw; } } - override bool dragRelease (wdabs, wdabs, IChildWidget) { + override bool dragRelease (wdabs, wdabs, ubyte, IChildWidget) { return true; // we've handled the up-click }
--- a/mde/gui/widget/Ifaces.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/Ifaces.d Sat Sep 12 09:50:33 2009 +0200 @@ -435,7 +435,7 @@ void setContent (IContent); //END Content -//BEGIN Events +//BEGIN Subwidgets /** Recursively scan the widget tree to find the widget under (cx,cy). * * If called on a widget, that widget should assume the location is over itself, and so should @@ -447,6 +447,12 @@ * Note: use global coordinates (cx,cy) not coordinates relative to the widget. */ IChildWidget getWidget (wdabs cx, wdabs cy); + /** Return true if widget is + * this widget, a child of this widget or another descendant. */ + bool isDescendant (IChildWidget widget); +//END Subwidgets + +//BEGIN Events /** Return true if (cx,cy) is on self's box (doesn't matter if actually on a subwidget). */ bool onSelf (wdabs cx, wdabs cy); @@ -472,13 +478,17 @@ /** Called at the end of a drag which originated from this widget. * - * Params: target = The widget under the mouse when the click was released + * Params: + * cx = X coord of click + * cy = Y coord of click + * b = Mouse button pressed + * target = The widget under the mouse when the click was released * - * Returns: true if the up-click event should not be passed to - * clickEvent on the relevent widget. + * Returns: (true if the up-click event should not be passed to + * clickEvent on the relevent widget). Irrelevant now. * * Only called if requested by clickEvent. */ - bool dragRelease (wdabs cx, wdabs cy, IChildWidget target); + bool dragRelease (wdabs cx, wdabs cy, ubyte b, IChildWidget target); /** Receives keyboard events when requested. *
--- a/mde/gui/widget/ParentContent.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/ParentContent.d Sat Sep 12 09:50:33 2009 +0200 @@ -96,6 +96,7 @@ parentIPPW.addChildIPPW (this); parentIPPW.menuActive = mgr.positionPopup (this, popup); pushed = true; + return 2; } else if (!parentIPPW.parentMenuActive) { // if not a submenu parentIPPW.removeChildIPPW (this); } @@ -115,6 +116,15 @@ pushed = true; } } + override bool dragRelease (wdabs cx, wdabs cy, ubyte b, IChildWidget target) { + if (isDescendant (target)) { + // Allow release-clicks to trigger menus. NOTE: Possibly we should use a different function for this, and make clickEvent only for down-clicks? + int code = target.clickEvent (cast(wdabs)cx,cast(wdabs)cy,b,false); + debug if (code != 0 && code != 4) // flag 4 without 2 does nothing anyway + logger.warn ("clickEvent returned code {}; unable to add requested callback", code); + } + return true; + } override void draw () { mgr.renderer.drawButton (x,y, w,h, pushed);
--- a/mde/gui/widget/TextWidget.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/TextWidget.d Sat Sep 12 09:50:33 2009 +0200 @@ -183,7 +183,7 @@ } } - override bool dragRelease (wdabs, wdabs, IChildWidget widg) { + override bool dragRelease (wdabs, wdabs, ubyte, IChildWidget widg) { if (widg !is this) { // don't copy content to self widg.dropContent (content_); return true; // don't pass click as well as copy
--- a/mde/gui/widget/WidgetManager.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/WidgetManager.d Sat Sep 12 09:50:33 2009 +0200 @@ -406,13 +406,16 @@ updateUnderMouse (cx, cy, state); // end of a drag? - if (dragStart !is null && b == dragButton && state == false) { - IChildWidget dS = dragStart; - dragStart = null; - childDragged = null; - requestRedraw; - if (dS.dragRelease (cx, cy, underMouse)) - return; + if (state == false) { + if (dragStart !is null && b == dragButton) { + IChildWidget dS = dragStart; + dragStart = null; + childDragged = null; + requestRedraw; + if (dS.dragRelease (cx, cy, b, underMouse)) + return; + } + return; // don't do other actions for releases } // Disable keyboard input if on another widget: @@ -423,7 +426,7 @@ } // Finally, post the actual event: - if (b == 3 && state) { // right click - open context menu + if (b == 3) { // right click - open context menu Content contextContent = cast(Content) underMouse.content; if (contextContent !is null) { serviceContent.setContent (contextContent);
--- a/mde/gui/widget/layout.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/layout.d Sat Sep 12 09:50:33 2009 +0200 @@ -346,7 +346,7 @@ y + row.pos[i / cols]); mgr.requestRedraw; } - override bool dragRelease (wdabs cx, wdabs cy, IChildWidget) { + override bool dragRelease (wdabs, wdabs, ubyte, IChildWidget) { return true; // we've handled the up-click } //END Col/row resizing callback
--- a/mde/gui/widget/miscContent.d Sat Sep 12 09:14:43 2009 +0200 +++ b/mde/gui/widget/miscContent.d Sat Sep 12 09:50:33 2009 +0200 @@ -119,8 +119,8 @@ return super.clickEvent (cx,cy, b, state) | 4; } - override bool dragRelease (wdabs cx, wdabs cy, IChildWidget widg) { - super.dragRelease (cx, cy, widg); + override bool dragRelease (wdabs cx, wdabs cy, ubyte b, IChildWidget widg) { + super.dragRelease (cx, cy, b, widg); if (widg !is this) { // don't copy content to self widg.dropContent (content_); }