changeset 35:928db3c75ed3

Windows can now be moved. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 02 May 2008 16:20:35 +0100
parents 6b4116e6355c
children 57d000574d75
files codeDoc/jobs.txt mde/gui/Gui.d mde/gui/widget/Window.d
diffstat 3 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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.).
--- 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
             }
--- 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