comparison mde/gui/widget/contentFunctions.d @ 131:9cff74f68b84

Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module. Moved Widget.AWidget to AChildWidget.AChildWidget and Widget.AParentWidget to AParentWidget.AParentWidget. Removed ASingleParentWidget to improve code sharing. AChildWidget doesn't implement IParentWidget like AWidget did. New IPopupParentWidget extending IParentWidget for the WM and some widgets to handle popups. Cut old popup management code. New underMouse() function replacing highlight(); called on all widgets. Separate menu-popup and button widgets aren't needed for menus now. Functions returning content widgets have been moved to their own module. Cleaned up jobs.txt. Switched to 80 line length for Ddoc.
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 21 Jan 2009 13:01:40 +0000
parents
children 264028f4115a
comparison
equal deleted inserted replaced
130:c5c38eaadb64 131:9cff74f68b84
1 /* LICENSE BLOCK
2 Part of mde: a Modular D game-oriented Engine
3 Copyright © 2007-2008 Diggory Hardy
4
5 This program is free software: you can redistribute it and/or modify it under the terms
6 of the GNU General Public License as published by the Free Software Foundation, either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16 /******************************************************************************
17 * Functions returning new content widgets dependant on content.
18 *****************************************************************************/
19 module mde.gui.widget.contentFunctions;
20
21 import mde.gui.exception;
22 import mde.gui.widget.Ifaces;
23 import mde.gui.widget.TextWidget;
24 import mde.gui.widget.layout;
25 import mde.gui.widget.PopupMenu;
26 import mde.gui.widget.miscContent;
27
28 import mde.content.AStringContent;
29 import mde.content.miscContent;
30 import Items = mde.content.Items;
31
32 /******************************************************************************
33 * A function which uses Items.get (data.strings[0]) to get a content and
34 * creates a widget from data.ints[1]. The first item in each ints and strings
35 * is removed before passing data to the new widget.
36 *****************************************************************************/
37 IChildWidget addContent (IWidgetManager mgr, IParentWidget parent, widgetID, WidgetData data, IContent) {
38 if (data.strings.length != 2) throw new WidgetDataException;
39 return mgr.makeWidget (parent, data.strings[1], Items.get (data.strings[0]));
40 }
41
42 /******************************************************************************
43 * A function which returns the most appropriate content editing widget.
44 *
45 * Widgets which can be returned: BoolContentWidget (toggle button),
46 * ValueContentWidget (generic text-box editor), DisplayContentWidget (generic
47 * text label).
48 *****************************************************************************/
49 IChildWidget editContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
50 // Note: SAFE_RECURSION enabled
51 if (c is null) throw new ContentException;
52 if (cast(AStringContent) c) {
53 if (cast(EnumContent) c) // can be PopupMenuWidget or ContentListWidget
54 return new ContentListWidget(mgr,parent,id,data,c);
55 if (cast(BoolContent) c)
56 return new BoolContentWidget(mgr,parent,id,data,c);
57 return new AStringContentWidget(mgr,parent,id,data,c);
58 }
59 if (cast(IContentList) c)
60 return new ContentListWidget(mgr,parent,id,data,c);
61 if (cast(EventContent) c)
62 return new ButtonContentWidget(mgr,parent,id,data,c);
63 // generic uneditable option
64 return new DisplayContentWidget(mgr,parent,id,data,c);
65 }
66
67 /******************************************************************************
68 * A function which returns a ContentListWidget or MenuButtonContentWidget.
69 *****************************************************************************/
70 IChildWidget flatMenuContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
71 if (c is null) throw new ContentException;
72 if (cast(IContentList) c)
73 return new ContentListWidget(mgr,parent,id,data,c);
74 if (cast(EventContent) c)
75 return new ButtonContentWidget(mgr,parent,id,data,c);
76 // generic uneditable option
77 return new DisplayContentWidget(mgr,parent,id,data,c);
78 }
79
80 /******************************************************************************
81 * A function which returns a PopupMenuWidget or MenuButtonContentWidget.
82 *****************************************************************************/
83 IChildWidget subMenuContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
84 if (c is null) throw new ContentException;
85 if (cast(IContentList) c)
86 return new PopupMenuWidget(mgr,parent,id,data,c);
87 if (cast(EventContent) c)
88 return new ButtonContentWidget(mgr,parent,id,data,c);
89 // generic uneditable option
90 return new DisplayContentWidget(mgr,parent,id,data,c);
91 }