diff mde/gui/widget/Widget.d @ 75:25cb7420dc91

A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken. imde's classes are created in a static this instead of mde's main. gl setup code moved from gl/basic.d to gl/draw.d mergetag.DefaultData: now HIGH_LOW priority instead of LOW_HIGH. Reduced type list to only used types; small fix for indent function. setup.paths: new NoFileException thrown instead of MTFileIOException
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 28 Jul 2008 18:17:48 +0100
parents f54ae4fc2b2f
children 65780e0e48e6
line wrap: on
line diff
--- a/mde/gui/widget/Widget.d	Mon Jul 07 15:54:47 2008 +0100
+++ b/mde/gui/widget/Widget.d	Mon Jul 28 18:17:48 2008 +0100
@@ -28,32 +28,17 @@
 * This abstract class, and the more concrete FixedWidget and ScalableWidget classes provides a
 * useful basic implementation for widgets. Widgets need not inherit these (they only need implement
 * IWidget); they are simply provided for convenience and to promote code reuse. */
-abstract class Widget : IWidget
+abstract class Widget : IChildWidget
 {
 //BEGIN Load and save
-    // Base this(). All widgets must check data.length is correct before calling this method.
-    // The widget ID is saved to widgetType, for correct saving.
-    this (IWindow wind, int[] data) {
-        window = wind;
-        widgetType = data[0];
+    // Base this() for child Widgets.
+    this (IWidgetManager mgr, WidgetData data) {
+        this.mgr = mgr;
     }
     
-    // Most widgets don't need to do adjustments based on mutable data, however they usually do
-    // still need to set their size.
-    int[] adjust (int[] data) {
-        setWidth (0,-1);
-        setHeight (0,-1);
-        return data;
-    }
-    
-    // Widget type should always be the first value. Any widget using extra creation data will need
-    // to reimplemnt this method.
-    int[] getCreationData () {
-        return [widgetType];
-    }
-    // Most widgets don't use mutable data.
-    int[] getMutableData () {
-        return [];
+    // Very basic implementation which assumes the renderer cannot affect the widget's size.
+    bool rendererChanged () {
+        return false;
     }
 //END Load and save
     
@@ -69,7 +54,7 @@
         return mh;
     }
     
-    void getCurrentSize (out wdim cw, out wdim ch) {
+    deprecated void getCurrentSize (out wdim cw, out wdim ch) {
         cw = w;
         ch = h;
     }
@@ -102,12 +87,11 @@
     
     /* Basic draw method: draw the background (all widgets should do this). */
     void draw () {
-        window.renderer.drawWidgetBack (x,y, w,h);
+        mgr.renderer.drawWidgetBack (x,y, w,h);
     }
     
 protected:
-    final int widgetType;	// the type (stored for saving)
-    IWindow window;		// the enclosing window
+    IWidgetManager mgr;		// the enclosing window
     wdim x, y;			// position
     wdim w, h;			// size
     wdim mw = 0, mh = 0;	// minimal or fixed size, depending on whether the widget is
@@ -122,24 +106,21 @@
      * Widget uses the initialisation data:
      * [widgetID, w, h]
      * where w, h is the fixed size. */
-    this (IWindow wind, int[] data) {
-        mw = cast(wdim) data[1];
-        mh = cast(wdim) data[2];
-        super (wind, data);
+    this (IWidgetManager mgr, WidgetData data) {
+        super (mgr, data);
+        mw = cast(wdim) data.ints[1];
+        mh = cast(wdim) data.ints[2];
         w = mw;
         h = mh;
     }
-    
-    int[] getCreationData () {
-        return [widgetType, mw, mh];
-    }
 }
+
 /** A base for resizable widgets. */
 class SizableWidget : Widget {
     // Check data.length is at least 1 before calling!
     /// Constructor for a completely resizable [blank] widget.
-    this (IWindow wind, int[] data) {
-        super (wind, data);
+    this (IWidgetManager mgr, WidgetData data) {
+        super (mgr, data);
     }
     
     bool isWSizable () {    return true;    }