# HG changeset patch # User Diggory Hardy # Date 1234357350 0 # Node ID 075705ad664a027b7d3ee326962721bcb4e6aee3 # Parent 783969f4665cbd5aacce51aa2783a7d0f761b831 Added a border widget. diff -r 783969f4665c -r 075705ad664a data/conf/guiDemo.mtt --- 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 @@ - + + {Basic} diff -r 783969f4665c -r 075705ad664a mde/gui/WidgetManager.d --- 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", diff -r 783969f4665c -r 075705ad664a mde/gui/renderer/IRenderer.d --- 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. * diff -r 783969f4665c -r 075705ad664a mde/gui/renderer/SimpleRenderer.d --- 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) { diff -r 783969f4665c -r 075705ad664a mde/gui/widget/Floating.d --- 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 . */ -/** 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; diff -r 783969f4665c -r 075705ad664a mde/gui/widget/ParentContent.d --- 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 . */ /****************************************************************************** - * 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; +}