changeset 147:075705ad664a

Added a border widget.
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 11 Feb 2009 13:02:30 +0000
parents 783969f4665c
children 17438f17bfb5
files data/conf/guiDemo.mtt mde/gui/WidgetManager.d mde/gui/renderer/IRenderer.d mde/gui/renderer/SimpleRenderer.d mde/gui/widget/Floating.d mde/gui/widget/ParentContent.d
diffstat 6 files changed, 98 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/data/conf/guiDemo.mtt	Wed Feb 11 12:00:12 2009 +0000
+++ b/data/conf/guiDemo.mtt	Wed Feb 11 13:02:30 2009 +0000
@@ -43,6 +43,7 @@
 <WidgetData|slider={0:[0x2031],1:["MiscOptions.pollInterval","sliderW"]}>
 <WidgetData|sliderW={0:[0x4044]}>
 
-<WidgetData|context={0:[0x4040, 0,2]}>
+<WidgetData|context={0:[0x4204, 1],1:["contextDesc"]}>
+<WidgetData|contextDesc={0:[0x4040, 0,2]}>
 {Basic}
 <WidgetData|root={0:[0x21,0x90D970],1:["A string!"]}>
--- a/mde/gui/WidgetManager.d	Wed Feb 11 12:00:12 2009 +0000
+++ b/mde/gui/WidgetManager.d	Wed Feb 11 13:02:30 2009 +0000
@@ -525,6 +525,7 @@
     ContentList		= TAKES_CONTENT | 0x110,
     
     FloatingArea	= TAKES_CONTENT | 0x200,
+    Border		= TAKES_CONTENT | 0x204,
     Switch		= TAKES_CONTENT | 0x210,
     Collapsible		= TAKES_CONTENT | 0x214,
 }
@@ -545,6 +546,7 @@
 	"GridLayout",
 	"ContentList",
 	"FloatingArea",
+	"Border",
 	"Switch",
 	"Collapsible",
 	"editContent",
--- a/mde/gui/renderer/IRenderer.d	Wed Feb 11 12:00:12 2009 +0000
+++ b/mde/gui/renderer/IRenderer.d	Wed Feb 11 13:02:30 2009 +0000
@@ -161,8 +161,8 @@
     void restrict (wdim x, wdim y, wdim w, wdim h);
     void relax ();      /// ditto
     
-    /** Draw a window border plus background. */
-    void drawWindow (Border* border, wdim x, wdim y, wdim w, wdim h);
+    /** Draw a border. */
+    void drawBorder (Border* border, wdim x, wdim y, wdim w, wdim h);
     
     /** Draw vertical and horizontal spacers.
      *
--- a/mde/gui/renderer/SimpleRenderer.d	Wed Feb 11 12:00:12 2009 +0000
+++ b/mde/gui/renderer/SimpleRenderer.d	Wed Feb 11 13:02:30 2009 +0000
@@ -64,7 +64,7 @@
     override void restrict (wdim x, wdim y, wdim w, wdim h) {}
     override void relax () {}
     
-    override void drawWindow (Border* border, wdim x, wdim y, wdim w, wdim h) {
+    override void drawBorder (Border* border, wdim x, wdim y, wdim w, wdim h) {
         glColor3f (0f, 0f, .8f);
         glRecti(x, y+h, x+w, y);
         
@@ -93,8 +93,8 @@
             glEnd ();
         }
         
-        glColor3f (0f, 0f, 0f);
-        glRecti(x+border.x1, y+h-border.y2, x+w-border.x2, y+border.y1);
+        //glColor3f (0f, 0f, 0f);
+        //glRecti(x+border.x1, y+h-border.y2, x+w-border.x2, y+border.y1);
     }
 
     override void drawSpacers (wdabs x, wdabs y, wdsize w, wdsize h, wdims cols, wdims rows) {
--- a/mde/gui/widget/Floating.d	Wed Feb 11 12:00:12 2009 +0000
+++ b/mde/gui/widget/Floating.d	Wed Feb 11 13:02:30 2009 +0000
@@ -13,7 +13,7 @@
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
-/** The Window class. Becoming a widget. */
+/** The "window" class − a widget. */
 module mde.gui.widget.Floating;
 
 import mde.gui.widget.AParentWidget;
@@ -159,7 +159,7 @@
         mgr.renderer.restrict (x,y, w,h);
         foreach (i; sWOrder)
             with (sWData[i]) {
-                mgr.renderer.drawWindow (&border, this.x + x, this.y + y, w, h);
+                mgr.renderer.drawBorder (&border, this.x + x, this.y + y, w, h);
                 subWidgets[i].draw;
             }
         mgr.renderer.relax;
--- a/mde/gui/widget/ParentContent.d	Wed Feb 11 12:00:12 2009 +0000
+++ b/mde/gui/widget/ParentContent.d	Wed Feb 11 13:02:30 2009 +0000
@@ -14,8 +14,10 @@
 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 /******************************************************************************
- * A pop-up widget and a switch (tab) widget (both parent widgets using
- * content).
+ * A pop-up widget, a switch (tab) widget, and a collapsible widget
+ * (all parent widgets using content).
+ *
+ * Also a border widget (parent not using content).
  *****************************************************************************/
 module mde.gui.widget.ParentContent;
 
@@ -338,3 +340,86 @@
     bool collapsed = false;
     BoolContent content_;
 }
+
+/** Puts a border around its child widget.
+ *
+ * This doesn't allow dragging like widgets in a floating area.
+ * 
+ * data.ints[1] is interpreted as flags from IRenderer.Border.BTYPE.
+ * data.strings[0] is an ID for the child widget. */
+class BorderWidget : AParentWidget
+{
+    this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
+        super (mgr, parent, id);
+        WDCheck (data, 2, 1);
+        
+        subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
+	borderType = cast(BTYPE) data.ints[1];
+    }
+    
+    override bool setup (uint n, uint flags) {
+        if (!subWidgets[0].setup (n, flags) && !(flags & 1)) return false;
+        
+        border = mgr.renderer.getBorder (borderType, false, false);
+        mw = subWidgets[0].minWidth  + border.x1 + border.x2;
+        mh = subWidgets[0].minHeight + border.y1 + border.y2;
+        if (w < mw || !subWidgets[0].isWSizable) w = mw;
+        if (h < mh || !subWidgets[0].isHSizable) h = mh;
+        return true;
+    }
+    
+    override void setWidth (wdim nw, int) {
+        debug assert (nw >= mw);
+        w = nw;
+        subWidgets[0].setWidth  (w - border.x1 - border.x2, -1);
+    }
+    override void setHeight (wdim nh, int) {
+        debug assert (nh >= mh);
+        h = nh;
+        subWidgets[0].setHeight (h - border.y1 - border.y2, -1);
+    }
+    
+    override bool isWSizable () {
+        return subWidgets[0].isWSizable;
+    }
+    override bool isHSizable () {
+        return subWidgets[0].isHSizable;
+    }
+    
+    override void setPosition (wdim nx, wdim ny) {
+        x = nx;
+        y = ny;
+        subWidgets[0].setPosition (x + border.x1, y + border.y1);
+    }
+    
+    override void minWChange (IChildWidget widget, wdim nmw) {
+        debug assert (widget is subWidgets[0]);
+        mw = nmw + border.x1 + border.x2;
+        parent.minWChange (this, nmw);
+    }
+    override void minHChange (IChildWidget widget, wdim nmh) {
+        debug assert (widget is subWidgets[0]);
+        mh = nmh + border.y1 + border.y2;
+        parent.minHChange (this, nmh);
+    }
+    
+    override void draw () {
+        mgr.renderer.drawBorder (&border, x, y, w, h);
+        subWidgets[0].draw;
+    }
+    
+    override IChildWidget getWidget (wdim cx, wdim cy) {
+        debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)");
+        
+        if (subWidgets[0].onSelf (cx, cy))
+            return subWidgets[0];
+        else
+            return this;
+    }
+    
+protected:
+    alias IRenderer.Border.BTYPE BTYPE;
+    alias IRenderer.Border.RESIZE RESIZE;
+    BTYPE borderType;       // what type of border to put around the widget
+    IRenderer.Border border;
+}