diff mde/gui/widget/Window.d @ 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
line wrap: on
line diff
--- 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