Mercurial > projects > mde
annotate mde/gui/widget/contentFunctions.d @ 170:e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Added files missing from previous commits.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Mon, 29 Jun 2009 21:20:16 +0200 |
parents | 620d4ea30228 |
children | 3d58adc17d20 |
rev | line source |
---|---|
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /****************************************************************************** |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 * Functions returning new content widgets dependant on content. |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 *****************************************************************************/ |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
19 module mde.gui.widget.contentFunctions; |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 import mde.gui.exception; |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 import mde.gui.widget.Ifaces; |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 import mde.gui.widget.TextWidget; |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
24 import mde.gui.widget.layout; |
143
2ac3e0012788
Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
138
diff
changeset
|
25 import mde.gui.widget.ParentContent; |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 import mde.gui.widget.miscContent; |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
27 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
28 import mde.content.AStringContent; |
143
2ac3e0012788
Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
138
diff
changeset
|
29 import mde.content.miscContent; |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
30 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 /****************************************************************************** |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 * A function which uses Items.get (data.strings[0]) to get a content and |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
33 * creates a widget from data.ints[1]. The first item in each ints and strings |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
34 * is removed before passing data to the new widget. |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 *****************************************************************************/ |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 IChildWidget addContent (IWidgetManager mgr, IParentWidget parent, widgetID, WidgetData data, IContent) { |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
37 if (data.strings.length != 2) throw new WidgetDataException; |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
38 return mgr.makeWidget (parent, data.strings[1], Content.get (data.strings[0])); |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
39 } |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 /****************************************************************************** |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
42 * A function which returns the most appropriate content editing widget. |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
43 * |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
44 * Widgets which can be returned: BoolContentWidget (toggle button), |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
45 * ValueContentWidget (generic text-box editor), DisplayContentWidget (generic |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
46 * text label). |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 *****************************************************************************/ |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
48 IChildWidget editContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
49 // Note: SAFE_RECURSION enabled |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
50 if (c is null) throw new ContentException; |
167
620d4ea30228
Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
165
diff
changeset
|
51 // Normally only EventContents are used for buttons, but any Content can be: |
620d4ea30228
Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
165
diff
changeset
|
52 if (cast(IEventContent) c) |
620d4ea30228
Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
165
diff
changeset
|
53 return new ButtonContentWidget(mgr,parent,id,data,c); |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
54 if (cast(AStringContent) c) { |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
55 if (cast(EnumContent) c) // can be PopupMenuWidget or ContentListWidget |
138
3468e9bfded1
Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
56 return new PopupMenuWidget(mgr,parent,id,data,c); |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
167
diff
changeset
|
57 if (cast(IBoolContent) c) |
165
bb2f1a76346d
Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
163
diff
changeset
|
58 return new BoolContentWidget(mgr,parent,id,data,c); |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
59 return new AStringContentWidget(mgr,parent,id,data,c); |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
60 } |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
61 if (cast(IContentList) c) |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
62 return new ContentListWidget(mgr,parent,id,data,c); |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
63 // generic uneditable option |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
64 return new DisplayContentWidget(mgr,parent,id,data,c); |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
65 } |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
66 |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
67 /****************************************************************************** |
132
264028f4115a
Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
68 * PopupMenuContent will create a popup for any content. This function more |
264028f4115a
Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
69 * conservatively only creates a popup for a ContentList, and otherwise returns |
264028f4115a
Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
70 * the same as editContent. |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
71 *****************************************************************************/ |
132
264028f4115a
Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
72 IChildWidget popupListContent (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
73 if (c is null) throw new ContentException; |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
74 if (cast(IContentList) c) |
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
75 return new PopupMenuWidget(mgr,parent,id,data,c); |
132
264028f4115a
Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
131
diff
changeset
|
76 else return editContent (mgr, parent, id, data, c); |
131
9cff74f68b84
Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
77 } |