# HG changeset patch # User Diggory Hardy # Date 1209741635 -3600 # Node ID 928db3c75ed3158ac83eacc5b0774669ac6d554b # Parent 6b4116e6355c14992bc71fb03db1680c65f12645 Windows can now be moved. committer: Diggory Hardy diff -r 6b4116e6355c -r 928db3c75ed3 codeDoc/jobs.txt --- a/codeDoc/jobs.txt Fri May 02 16:03:52 2008 +0100 +++ b/codeDoc/jobs.txt Fri May 02 16:20:35 2008 +0100 @@ -3,6 +3,7 @@ In progress: +Making Window dragable. @@ -48,6 +49,3 @@ Done (for git log message): -Implemented getWidget(x,y) to find the widget under this location for IWidgets (but not Gui). -Made Window an IWidget and made it work a little more similarly to widgets. -Implemented callbacks on the Gui for mouse events (enabling drag & drop, etc.). diff -r 6b4116e6355c -r 928db3c75ed3 mde/gui/Gui.d --- a/mde/gui/Gui.d Fri May 02 16:03:52 2008 +0100 +++ b/mde/gui/Gui.d Fri May 02 16:20:35 2008 +0100 @@ -115,9 +115,12 @@ foreach (dg; clickCallbacks) dg (cx, cy, b, state); - foreach (w; windows) { + foreach (i,w; windows) { IWidget widg = w.getWidget (cx,cy); if (widg !is null) { + // Bring to front + windows = w ~ windows[0..i] ~ windows[i+1..$]; + widg.clickEvent (cx,cy,b,state); return; // only pass to first window } diff -r 6b4116e6355c -r 928db3c75ed3 mde/gui/widget/Window.d --- a/mde/gui/widget/Window.d Fri May 02 16:03:52 2008 +0100 +++ b/mde/gui/widget/Window.d Fri May 02 16:20:35 2008 +0100 @@ -149,15 +149,17 @@ } void setPosition (int x, int y) { - /+ Note: this is currently unused. Maybe only use it internally? + // Currently only used internally this.x = x; this.y = y; + xw = x+w; + yh = y+h; + widgetX = x + rend.windowBorder; widgetY = y + rend.windowBorder; widget.setPosition (widgetX, widgetY); - +/ } IWidget getWidget (int cx, int cy) { @@ -170,8 +172,13 @@ return this; } void clickEvent (ushort cx, ushort cy, ubyte b, bool state) { - //if (cx >= x && cx < xw && cy >= y && cy < yh) { // click on window? - // FIXME: repositioning? + if (b == 1 && state == true) { + xDrag = cx; + yDrag = cy; + + gui_.addClickCallback (&dragEndCallback); // handle repositioning + gui_.addMotionCallback (&dragCallback); // handle repositioning + } } void draw () { @@ -184,6 +191,20 @@ //END IWidget methods private: + /* For window dragging. */ + void dragCallback (ushort cx, ushort cy) { + setPosition (x+cx-xDrag, y+cy-yDrag); + xDrag = cx; + yDrag = cy; + } + void dragEndCallback (ushort cx, ushort cy, ubyte b, bool state) { + if (b == 1 && state == false) { + setPosition (x+cx-xDrag, y+cy-yDrag); + gui_.removeCallbacks (cast(void*) this); + } + } + int xDrag, yDrag; // locations where a drag starts (used by dragCallback). + char[] name; // The window's name (id from config file) IGui gui_; // The gui managing this window