diff mde/input/Input.d @ 37:052df9b2fe07

Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions. Enabled widget resizing. Removed IRenderer's temporary drawBox method and added drawButton for ButtonWidget. Made the Widget class abstract and added FixedWidget and SizableWidget classes. Rewrote much of createWidget to use meta-code; changed widget IDs. Made Input catch callback exceptions and report error messages. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 05 May 2008 14:47:25 +0100
parents 6b4116e6355c
children 23a1d2b1ec5f
line wrap: on
line diff
--- a/mde/input/Input.d	Fri May 02 17:38:43 2008 +0100
+++ b/mde/input/Input.d	Mon May 05 14:47:25 2008 +0100
@@ -196,17 +196,25 @@
         switch (event.type) {
             case SDL_MOUSEBUTTONDOWN:
             case SDL_MOUSEBUTTONUP:
-                foreach (dg; mouseClickCallbacks)
-                    dg (event.button.x - 1, event.button.y - 1,
-                        event.button.button, event.button.state == SDL_PRESSED);
+                foreach (dg; mouseClickCallbacks) {
+                    try
+                        dg (event.button.x - 1, event.button.y - 1,
+                            event.button.button, event.button.state == SDL_PRESSED);
+                    catch (Exception e)
+                        logger.error (CB_EXC ~ e.msg);
+                }
                 break;
             
             case SDL_MOUSEMOTION:
                 mouse_x = event.motion.x - 1;
                 mouse_y = event.motion.y - 1;
                 
-                foreach (dg; mouseMotionCallbacks)
-                    dg (event.motion.x - 1, event.motion.y - 1);
+                foreach (dg; mouseMotionCallbacks) {
+                    try
+                        dg (event.motion.x - 1, event.motion.y - 1);
+                    catch (Exception e)
+                        logger.error (CB_EXC ~ e.msg);
+                }
                 break;
             
             default:
@@ -369,6 +377,8 @@
         }
     }
     
+    static const CB_EXC = "Callback exception: ";
+    
     static Logger logger;
 
     Config config;			// Configuration
@@ -485,7 +495,12 @@
         myThis.button[id] = b;
         
         ButtonCallback[]* cb_p = id in myThis.buttonCallbacks;
-        if (cb_p) foreach (cb; *cb_p) cb (id, b);
+        if (cb_p) foreach (cb; *cb_p) {
+            try
+                cb (id, b);
+            catch (Exception e)
+                logger.error (CB_EXC ~ e.msg);
+        }
     }
     // Adjuster to check modifier keys
     static void es_b_modifier (Input myThis, bool b, readOutQueue s);
@@ -497,7 +512,12 @@
         myThis.axis[id] = x;
         
         AxisCallback[]* cb_p = id in myThis.axisCallbacks;
-        if (cb_p) foreach (cb; *cb_p) cb (id, x);
+        if (cb_p) foreach (cb; *cb_p) {
+            try
+                cb (id, x);
+            catch (Exception e)
+                logger.error (CB_EXC ~ e.msg);
+        }
     }
     
     // Just reverses an axis's value
@@ -512,7 +532,12 @@
         myThis.relMotion[id] = RelPair(x,y);
         
         RelMotionCallback[]* cb_p = id in myThis.relMotionCallbacks;
-        if (cb_p) foreach (cb; *cb_p) cb (id, x,y);
+        if (cb_p) foreach (cb; *cb_p) {
+            try
+                cb (id, x,y);
+            catch (Exception e)
+                logger.error (CB_EXC ~ e.msg);
+        }
     }
     //END ES Functions
     //END Event stream functionality