Mercurial > projects > mde
annotate mde/gui/widget/miscContent.d @ 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.
Content restrutured a lot:
New IContent module, Content module includes more functionality.
New ContentLoader module to manage content loading/saving/translation.
Translation module moved to content dir and cut down to reflect current usage.
File format unchanged except renames: FontOptions -> Font, VideoOptions -> Screen.
Font render mode and LCD filter options are now enums.
GUI loading needs to create content (and set type for enums), but doesn't save/load value.
Some setup of mainSchedule moved to mde.mainLoop.
Content callbacks are called on content change now.
ContentLists are set up implicitly from content symbols. Not as fast but much easier!
Bug-fix in the new MTTagReader.
Renamed MT *Reader maker functions to avoid confusion in paths.d.
New mde.setup.logger module to allow logger setup before any other module's static this().
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 07 Feb 2009 12:46:03 +0000 |
parents | 9cff74f68b84 |
children | c94ec5594449 |
rev | line source |
---|---|
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
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 |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
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; |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
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:
130
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:
130
diff
changeset
|
17 * Widgets using content not organised into other modules. |
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:
130
diff
changeset
|
18 *****************************************************************************/ |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
19 module mde.gui.widget.miscContent; |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 |
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:
130
diff
changeset
|
21 import mde.gui.widget.AParentWidget; |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
101
diff
changeset
|
22 import mde.gui.exception; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
101
diff
changeset
|
23 |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
24 import mde.content.AStringContent; |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
25 |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
26 debug { |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
27 import tango.util.log.Log : Log, Logger; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
28 private Logger logger; |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
29 static this () { |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
30 logger = Log.getLogger ("mde.gui.widget.miscContent"); |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
31 } |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
32 } |
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
33 |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
34 /// Editable boolean widget |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 class BoolContentWidget : AButtonWidget |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 { |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
37 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { |
112
fe061009029d
EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
111
diff
changeset
|
38 content = cast(BoolContent) c; |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
39 if (content is null) throw new ContentException (this); |
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
40 super (mgr, parent, id); |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 wdimPair s = mgr.renderer.getToggleSize; |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
42 w = mw = s.x; |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
43 h = mh = s.y; |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
44 } |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
45 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
46 override void draw () { |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 mgr.renderer.drawToggle (x,y, content(), pushed); |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
48 } |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
49 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
50 override void activated () { |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
51 content = !content(); |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
52 } |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
54 protected: |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
55 BoolContent content; |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
56 } |
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
57 |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
58 /// A button connected to an EventContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
59 class ButtonContentWidget : AButtonWidget |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
60 { |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
61 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData, IContent c) { |
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:
131
diff
changeset
|
62 content = cast(Content) c; |
121
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
63 if (content is null) throw new ContentException (this); |
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
64 adapter = mgr.renderer.getAdapter (); |
5b37d0400732
Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
119
diff
changeset
|
65 super (mgr, parent, id); |
111
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
66 } |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
67 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
68 override bool setup (uint n, uint flags) { |
111
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
69 if (!(flags & 3)) return false; // string or renderer (and possibly font) changed |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
70 adapter.text = content.toString(1); |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
71 adapter.getDimensions (mw, mh); |
111
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
72 if (mw != w || mh != h) { |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
73 w = mw; |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
74 h = mh; |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
75 } |
1655693702fc
Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
76 return true; |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
77 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
78 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
79 override void draw () { |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
80 super.draw(); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
81 adapter.draw (x,y); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
82 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
83 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
84 override void activated () { |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
85 content.endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
86 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
87 |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
88 protected: |
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
89 IRenderer.TextAdapter adapter; |
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:
131
diff
changeset
|
90 Content content; |
114
b16a534f5302
Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
113
diff
changeset
|
91 int index; |
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
103
diff
changeset
|
92 } |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
93 |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
94 /** A "tab" widget: it doesn't display the tabs, but shows one of a number of widgets dependant on |
129
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
95 * an EnumContent. |
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
96 * |
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
97 * Sizability is set once (currently true if any widget is sizable). Size is kept when switching |
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
98 * widgets if allowed (if this is large enough and resizable). */ |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
99 class SwitchWidget : AParentWidget |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
100 { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
101 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
102 super (mgr, parent, id); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
103 content = cast(EnumContent) c; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
104 if (content is null || (subWidgets.length = content.list.length) == 0) |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
105 throw new ContentException (this); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
106 WDCheck (data, 1, subWidgets.length); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
107 |
130
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
108 foreach (i,sc; content.list) |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
109 subWidgets[i] = mgr.makeWidget (this, data.strings[i], sc); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
110 currentW = subWidgets[content()]; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
111 |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
112 content.addCallback (&switchWidget); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
113 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
114 |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
115 override bool setup (uint n, uint flags) { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
116 bool r = super.setup (n, flags); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
117 if (r) { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
118 mw = currentW.minWidth; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
119 mh = currentW.minHeight; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
120 w = currentW.width; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
121 h = currentW.height; |
130
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
122 static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE) |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
123 isWS = isHS = true; |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
124 foreach (i,sc; content.list) { |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
125 static if (SIZABILITY == SIZABILITY_ENUM.ANY_SUBWIDGETS) { |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
126 isWS |= subWidgets[i].isWSizable; |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
127 isHS |= subWidgets[i].isHSizable; |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
128 } else static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) { |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
129 isWS &= subWidgets[i].isWSizable; |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
130 isHS &= subWidgets[i].isHSizable; |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
131 } |
c5c38eaadb64
Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
129
diff
changeset
|
132 } |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
133 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
134 return r; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
135 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
136 |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
137 override void minWChange (IChildWidget widget, wdim nmw) { |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
138 if (widget !is currentW) return; |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
139 mw = nmw; |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
140 parent.minWChange (this, nmw); |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
141 } |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
142 override void minHChange (IChildWidget widget, wdim nmh) { |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
143 if (widget !is currentW) return; |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
144 mh = nmh; |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
145 parent.minHChange (this, nmh); |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
146 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
147 |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
148 override bool isWSizable () { |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
149 return isWS; |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
150 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
151 override bool isHSizable () { |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
152 return isHS; |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
153 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
154 |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
155 override void setWidth (wdim nw, int dir) { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
156 w = (nw >= mw ? nw : mw); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
157 currentW.setWidth (w, dir); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
158 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
159 override void setHeight (wdim nh, int dir) { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
160 h = (nh >= mh ? nh : mh); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
161 currentW.setHeight (h, dir); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
162 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
163 |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
164 override void setPosition (wdim nx, wdim ny) { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
165 x = nx; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
166 y = ny; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
167 currentW.setPosition (nx,ny); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
168 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
169 |
128
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
170 override IChildWidget getWidget (wdim cx, wdim cy) { |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
171 return currentW.getWidget (cx, cy); |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
172 } |
41582439a42b
Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
126
diff
changeset
|
173 |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
174 override void draw () { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
175 currentW.draw; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
176 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
177 |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
178 protected: |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
179 // callback on content |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
180 void switchWidget (Content) { |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
181 currentW = subWidgets[content()]; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
182 mw = currentW.minWidth; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
183 mh = currentW.minHeight; |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
184 parent.minWChange (this, mw); |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
185 parent.minHChange (this, mh); |
129
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
186 // If resizable and already large enough, don't resize; else do. |
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
187 if (isWS && w > mw) currentW.setWidth (w, -1); |
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
188 else w = currentW.width; |
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
189 if (isHS && h > mh) currentW.setHeight (h, -1); |
ad91de8867a0
Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
190 else h = currentW.height; |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
191 currentW.setPosition (x,y); |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
192 } |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
193 |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
194 IChildWidget currentW; |
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
195 EnumContent content; |
126
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
196 |
c9843fbaac88
Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
125
diff
changeset
|
197 bool isWS, isHS; // no infrastructure for changing sizability, so need to fix it. |
125
3e648bc53bde
Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
121
diff
changeset
|
198 } |