Mercurial > projects > mde
diff mde/gui/widget/miscContent.d @ 95:2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Fixed a minor bug where layouts with the same id but without shared alignments would be messed up.
Tracked down the "nothing trawn until a resize" bug (see jobs.txt).
If widgets throw during creation they're now replaced by debug widgets.
Function pointers are converted to delegates using a safer method.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 06 Nov 2008 11:07:18 +0000 |
parents | |
children | 5de5810e3516 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mde/gui/widget/miscContent.d Thu Nov 06 11:07:18 2008 +0000 @@ -0,0 +1,73 @@ +/* LICENSE BLOCK +Part of mde: a Modular D game-oriented Engine +Copyright © 2007-2008 Diggory Hardy + +This program is free software: you can redistribute it and/or modify it under the terms +of the GNU General Public License as published by the Free Software Foundation, either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/** Some content widgets. */ +module mde.gui.widget.miscContent; + +import mde.gui.widget.Widget; +import mde.gui.widget.TextWidget; +import mde.gui.exception; +import mde.gui.renderer.IRenderer; + +import mde.gui.content.Content; + +/// Chooses the most appropriate content editing widget +IChildWidget editContent (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { + if (cast(BoolContent) c) + return new BoolContentWidget(mgr,id,data,c); + else // generic uneditable option + return new DisplayContentWidget(mgr,id,data,c); +} + +/// Just displays the content +class DisplayContentWidget : ATextWidget +{ + this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { + WDCheck(data, 1); + content = c; + if (!content) throw new ContentException (); + adapter = mgr.renderer.getAdapter (content.toString(0)); + super (mgr, id, data); + } + +protected: + IContent content; +} + +/// Editable boolean widget +class BoolContentWidget : AButtonWidget +{ + this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { + WDCheck(data, 1); + content = cast(BoolContent) c; + if (!content) throw new ContentException (); + wdimPair s = mgr.renderer.getToggleSize; + w = mw = s.x; + h = mh = s.y; + super (mgr, id, data); + } + + void draw () { + mgr.renderer.drawToggle (x,y, content(), pushed); + } + + void activated () { + content = !content(); + } + +protected: + BoolContent content; +} +