changeset 76:65780e0e48e6

Re-enabled click event passing in the gui to make ButtonWidget work. Bugfix (pass void* not class reference). Change to allow compilation with dmd 1.027 (don't use DefaultData's Arg!() template).
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 28 Jul 2008 18:49:18 +0100
parents 25cb7420dc91
children 3dfd934100f7
files mde/font/font.d mde/gui/WidgetData.d mde/gui/WidgetManager.d mde/gui/widget/Ifaces.d mde/gui/widget/Widget.d mde/gui/widget/miscWidgets.d
diffstat 6 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mde/font/font.d	Mon Jul 28 18:17:48 2008 +0100
+++ b/mde/font/font.d	Mon Jul 28 18:49:18 2008 +0100
@@ -106,7 +106,7 @@
                 reader.read;
                 
                 // get fallback name
-                char[]* p = "fallback" in reader.dataset.header.Arg!(char[]);
+                char[]* p = "fallback" in reader.dataset.header._charA;
                 if (p is null)
                     throw new fontException ("No fallback font style specified");
                 fallbackName = *p;
--- a/mde/gui/WidgetData.d	Mon Jul 28 18:17:48 2008 +0100
+++ b/mde/gui/WidgetData.d	Mon Jul 28 18:49:18 2008 +0100
@@ -92,7 +92,7 @@
             
             // Read from the HEADER:
             // Get the renderer
-            char[]* p = "Renderer" in reader.dataset.header.Arg!(char[]);
+            char[]* p = "Renderer" in reader.dataset.header._charA;
             if (p is null || *p is null) {
                 logger.warn ("No renderer specified: using \"Simple\"");
                 rendName = "Simple";
@@ -101,7 +101,7 @@
                 rendName = *p;
             
             // Get which section to use
-            p = "Design" in reader.dataset.header.Arg!(char[]);
+            p = "Design" in reader.dataset.header._charA;
             if (p is null || *p is null) {
                 logger.warn ("No gui design specified: trying \"Default\"");
                 defaultDesign = "Default";
--- a/mde/gui/WidgetManager.d	Mon Jul 28 18:17:48 2008 +0100
+++ b/mde/gui/WidgetManager.d	Mon Jul 28 18:49:18 2008 +0100
@@ -90,7 +90,11 @@
             // See IWidgetManager.addClickCallback's documentation:
             if (dg (cast(wdabs)cx, cast(wdabs)cy, b, state)) return;
         
-        /+
+        // NOTE: do we need to test if the click was on the gui (and thus child)?
+        IChildWidget widg = child.getWidget (cast(wdabs)cx,cast(wdabs)cy);
+        if (widg !is null)
+            widg.clickEvent (cast(wdabs)cx,cast(wdabs)cy,b,state);
+        /+ FIXME: remove
         foreach (i,w; windows) {
             IWidget widg = w.getWidget (cast(wdabs)cx,cast(wdabs)cy);
             if (widg !is null) {
@@ -150,9 +154,9 @@
     void addMotionCallback (void delegate(wdabs, wdabs) dg) {
         motionCallbacks[dg.ptr] = dg;
     }
-    void removeCallbacks (IChildWidget frame) {
-        clickCallbacks.remove(cast(void*) frame);
-        motionCallbacks.remove(cast(void*) frame);
+    void removeCallbacks (void* frame) {
+        clickCallbacks.remove(frame);
+        motionCallbacks.remove(frame);
     }
     //END IWidgetManager methods
     
--- a/mde/gui/widget/Ifaces.d	Mon Jul 28 18:17:48 2008 +0100
+++ b/mde/gui/widget/Ifaces.d	Mon Jul 28 18:49:18 2008 +0100
@@ -108,7 +108,10 @@
     
     
     // User input:
-    /** Add a mouse click callback: delegate will be called for all mouse click events recieved.
+    /** Add a mouse click callback.
+     * 
+     * This is a delegate this will be called for all mouse click events recieved by the gui, not
+     * simply all click events on the widget (as clickEvent recieves).
      *
      * The delegate should return true if it accepts the event and no further processing is
      * required (i.e. the event should not be handled by anything else), false otherwise.
@@ -117,13 +120,15 @@
      * may be removed (so event handling cannot be cut short). */
     void addClickCallback (bool delegate (wdabs cx, wdabs cy, ubyte b, bool state) dg);
     
-    /** Add a mouse motion callback: delegate will be called for all motion events recieved. */
+    /** Add a mouse motion callback: delegate will be called for all motion events recieved by the
+     * gui. */
     void addMotionCallback (void delegate (wdabs cx, wdabs cy) dg);
     
     // FIXME: keyboard callback (letter only, for text input? Also used for setting keybindings though...)
     
     /** Remove all event callbacks on this widget (according to the delegate's .ptr). */
-    void removeCallbacks (IChildWidget frame);
+    // Note: don't try to pass a reference and cast to void* in the function; it's a different address.
+    void removeCallbacks (void* frame);
 }
 
 
@@ -236,7 +241,7 @@
      * (x,y).
      *
      * Note: use global coordinates (x,y) not coordinates relative to the widget. */
-    IWidget getWidget (wdim x, wdim y);
+    IChildWidget getWidget (wdim x, wdim y);
     
     /** Receive a mouse click event.
      *
--- a/mde/gui/widget/Widget.d	Mon Jul 28 18:17:48 2008 +0100
+++ b/mde/gui/widget/Widget.d	Mon Jul 28 18:49:18 2008 +0100
@@ -77,7 +77,7 @@
 //BEGIN Events
     /* This method is only called when the location is over this widget; hence for all widgets
      * without children this method is valid. */
-    IWidget getWidget (wdim,wdim) {
+    IChildWidget getWidget (wdim,wdim) {
         return this;
     }
     
--- a/mde/gui/widget/miscWidgets.d	Mon Jul 28 18:17:48 2008 +0100
+++ b/mde/gui/widget/miscWidgets.d	Mon Jul 28 18:49:18 2008 +0100
@@ -85,7 +85,7 @@
             
             pushed = false;
             mgr.requestRedraw;
-            mgr.removeCallbacks (this);
+            mgr.removeCallbacks (cast(void*) this);
             
             return true;
         }