Mercurial > projects > mde
diff mde/gui/widget/Floating.d @ 160:ccd01fde535e
Replaced WidgetManager's click and motion callbacks with a drag event system.
This is less flexible, but much closer to what is required (and is simpler and less open to bugs through unintended use).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 21 May 2009 22:15:32 +0200 |
parents | b06b04c75e86 |
children | 0dd49f333189 |
line wrap: on
line diff
--- a/mde/gui/widget/Floating.d Thu May 21 20:55:10 2009 +0200 +++ b/mde/gui/widget/Floating.d Thu May 21 22:15:32 2009 +0200 @@ -209,46 +209,19 @@ else if (resizeType & RESIZE.Y2) yDrag = h - cy; - mgr.addClickCallback (&endCallback); - mgr.addMotionCallback (&resizeCallback); + return 2; } else if (borderType & BTYPE.MOVE) { // window is being moved xDrag = cx - x; yDrag = cy - y; - mgr.addClickCallback (&endCallback); - mgr.addMotionCallback (&moveCallback); + return 2; } } } return 0; } - -protected: - /** Return the index of the floating object under (cx,cy). If no widget is, - * return size_t.max. - * - * Params: - * raiseWidget = if true, the widget returned is raised to be the top- - * most floating widget. */ - size_t getFloatingWidget (wdim cx, wdim cy, bool raiseWidget = false) { - debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)"); - - foreach_reverse (j,i; sWOrder) with (sWData[i]) { - wdim lx = cx - (this.x + x); - wdim ly = cy - (this.y + y); - if (lx >= 0 && lx < w && ly >= 0 && ly < h) { - if (raiseWidget) { - sWOrder[j..$-1] = sWOrder[j+1..$].dup; - sWOrder[$-1] = i; - mgr.requestRedraw; - } - return i; - } - } - return size_t.max; // no match - } - - void moveCallback (wdabs cx, wdabs cy) { + void dragMotion (wdabs cx, wdabs cy, IChildWidget) { + if (resizeType == RESIZE.NONE) { with (sWData[active]) { x = cx-xDrag; y = cy-yDrag; @@ -265,8 +238,7 @@ subWidgets[active].setPosition (this.x + x + border.x1, this.y + y + border.y1); } mgr.requestRedraw; - } - void resizeCallback (wdabs cx, wdabs cy) { + } else { with (sWData[active]) { if (resizeType & RESIZE.X1) { wdim ow = w; @@ -309,14 +281,37 @@ } mgr.requestRedraw; } - bool endCallback (wdabs, wdabs, ubyte b, bool state) { - if (b == 1 && state == false) { // end of a move/resize - mgr.removeCallbacks (cast(void*) this); - return true; // we've handled the up-click - } - return false; // we haven't handled it + } + bool dragRelease (wdabs, wdabs, IChildWidget) { + return true; // we've handled the up-click } +protected: + /** Return the index of the floating object under (cx,cy). If no widget is, + * return size_t.max. + * + * Params: + * raiseWidget = if true, the widget returned is raised to be the top- + * most floating widget. */ + size_t getFloatingWidget (wdim cx, wdim cy, bool raiseWidget = false) { + debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)"); + + foreach_reverse (j,i; sWOrder) with (sWData[i]) { + wdim lx = cx - (this.x + x); + wdim ly = cy - (this.y + y); + if (lx >= 0 && lx < w && ly >= 0 && ly < h) { + if (raiseWidget) { + sWOrder[j..$-1] = sWOrder[j+1..$].dup; + sWOrder[$-1] = i; + mgr.requestRedraw; + } + return i; + } + } + return size_t.max; // no match + } + + struct SWData { // NOTE: x,y,w,h must be first elements; search (&d.x) wdim x,y; // position (corner of border) wdim w,h; // size (including border)