annotate mde/gui/WidgetManager.d @ 115:1b1e2297e2fc

Enums handled more generically now via either a popup list or flat list of BoolContentWidgets. EnumContent is an IContentList with BoolContent sub-contents. Content modules moved around (again). ContentListWidget can now list horizontally. Log-level setting callback.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 20 Dec 2008 17:57:05 +0000
parents b16a534f5302
children 5ee69b3ed9c9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
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
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
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;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
16 /*************************************************************************************************
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
17 * The gui manager class.
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
18 *
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
19 * This is the module to use externally to create a graphical user interface (likely also with
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
20 * content modules).
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
21 *************************************************************************************************/
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
22 module mde.gui.WidgetManager;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
24 import mde.gui.WidgetDataSet;
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
25 import mde.gui.widget.Ifaces;
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
26 import mde.gui.renderer.createRenderer;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
28 import imde = mde.imde;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
29 import mde.input.Input;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
30 import mde.scheduler.Scheduler;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
31 import mde.setup.Screen;
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
32 import Items = mde.content.Items; // loadTranslation
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
33 import mde.lookup.Options; // miscOpts.L10n callback
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
34
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
35 import tango.core.sync.Mutex;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 import tango.util.log.Log : Log, Logger;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
37 import tango.util.container.CircularList; // pop-up draw callbacks
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
38 import tango.util.container.SortedMap;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 private Logger logger;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 static this () {
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
42 logger = Log.getLogger ("mde.gui.WidgetManager");
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
45 /*************************************************************************************************
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
46 * The widget manager.
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
47 *
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
48 * This provides a layer on top of WidgetLoader, handling input and rendering. Other functionality
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
49 * is contained in the super class, to simplify supporting new input/graphics libraries.
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
50 *
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
51 * Currently mouse coordinates are passed to widgets untranslated. It may make sense to translate
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
52 * them and possibly drop events for some uses, such as if the gui is drawn to a texture.
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
53 *
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
54 * Aside from the IWidgetManager methods, this class should be thread-safe.
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
55 *************************************************************************************************/
86
79d816b3e2d2 New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 85
diff changeset
56 class WidgetManager : WidgetLoader, Screen.IDrawable {
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
57 /** Construct a new widget manager.
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
58 *
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
59 * params:
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
60 * fileName = Name of file specifying the gui, excluding path and extension.
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
61 */
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
62 this (char[] file) {
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
63 super(file);
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
64
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
65 Screen.addDrawable (this);
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
66 clickCallbacks = new typeof(clickCallbacks);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
67 motionCallbacks = new typeof(motionCallbacks);
84
e0f1ec7fe73a Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 81
diff changeset
68 }
e0f1ec7fe73a Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 81
diff changeset
69
92
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
70 // this() runs during static this(), when imde.input doesn't exist. init() runs later.
84
e0f1ec7fe73a Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 81
diff changeset
71 void init () {
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
72 // Doesn't need a lock - cannot conflict with other class functions.
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
73 // Events we want to know about:
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
74 imde.input.addMouseClickCallback(&clickEvent);
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
75 imde.input.addMouseMotionCallback(&motionEvent);
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
76
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
77 Items.loadTranslation ();
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
78 miscOpts.L10n.addCallback (&reloadStrings);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79 }
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
80
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
82 /** Draw the gui. */
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 void draw() {
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
84 synchronized(mutex) {
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
85 if (child)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
86 child.draw;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
87 foreach (popup; popups.iterator.reverse)
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
88 popup.widget.draw();
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
89 }
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
92
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
93 /** For mouse click events.
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
94 *
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
95 * Sends the event on to the relevant windows and all click callbacks. */
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 void clickEvent (ushort cx, ushort cy, ubyte b, bool state) {
43
1530d9c04d4d Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 41
diff changeset
97 debug scope (failure)
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
98 logger.warn ("clickEvent: failed!");
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
99 mutex.lock;
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
100 scope(exit) mutex.unlock;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
101 if (child is null) return;
58
d43523ed4b62 Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 47
diff changeset
102
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
103 // 1. Callbacks have the highest priority recieving events (e.g. a button release)
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
104 foreach (dg; clickCallbacks)
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
105 if (dg (cast(wdabs)cx, cast(wdabs)cy, b, state)) return;
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
106
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
107 // 2. Then pop-ups
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
108 static IChildWidget[] removedPopupParents;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
109 uint removedPopups = 0;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
110 IChildWidget widg; // widget clicked on
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
111 {
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
112 auto i = popups.iterator;
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
113 foreach (popup; i) with (popup) {
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
114 if (cx < x || cx >= x + w ||
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
115 cy < y || cy >= y + h) {
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
116 i.remove;
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
117 requestRedraw;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
118 if (removedPopupParents.length <= removedPopups)
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
119 removedPopupParents.length = removedPopupParents.length * 2 + 4;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
120 removedPopupParents[removedPopups++] = parent;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
121 } else {
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
122 widg = widget.getWidget (cast(wdabs)cx,cast(wdabs)cy);
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
123 break;
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
124 }
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
125 }
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 90
diff changeset
126 }
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
127
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
128 // 3. Then the main widget tree
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
129 debug assert (cx < child.width && cy < child.height, "WidgetManager: child doesn't cover whole area (code error)");
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
130 if (widg is null)
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
131 widg = child.getWidget (cast(wdabs)cx,cast(wdabs)cy);
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
132 if (keyFocus && keyFocus !is widg) {
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
133 keyFocus.keyFocusLost;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
134 keyFocus = null;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
135 imde.input.setLetterCallback (null);
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
136 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
137 if (widg !is null) {
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
138 if (widg.clickEvent (cast(wdabs)cx,cast(wdabs)cy,b,state) & 1) {
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
139 keyFocus = widg;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
140 imde.input.setLetterCallback (&widg.keyEvent);
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
141 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
142 }
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
143
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
144 // Tell parents their popups closed (needs to be after clickEvent for PopupMenuWidget)
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
145 while (removedPopups)
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
146 removedPopupParents[--removedPopups].popupRemoved;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147 }
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
148
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
149 /** For mouse motion events.
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
150 *
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
151 * Sends the event on to all motion callbacks. */
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
152 void motionEvent (ushort scx, ushort scy) {
43
1530d9c04d4d Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 41
diff changeset
153 debug scope (failure)
1530d9c04d4d Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 41
diff changeset
154 logger.warn ("motionEvent: failed!");
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
155 mutex.lock;
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
156 scope(exit) mutex.unlock;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
157 wdabs cx = cast(wdabs) scx, cy = cast(wdabs) scy;
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
158 foreach (dg; motionCallbacks)
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
159 dg (cx, cy);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
160
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
161 IChildWidget ohighlighted = highlighted;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
162 foreach (popup; popups) with (popup) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
163 if (cx >= x && cx < x+w && cy >= y && cy < y+h) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
164 highlighted = widget.getWidget (cx,cy);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
165 goto foundPopup;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
166 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
167 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
168 highlighted = null; // not over a popup
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
169 foundPopup:
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
170 if (ohighlighted != highlighted) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
171 if (ohighlighted)
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
172 ohighlighted.highlight (false);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
173 if (highlighted)
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
174 highlighted.highlight (true);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
175 requestRedraw;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
176 }
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
177 }
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
178
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179
86
79d816b3e2d2 New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 85
diff changeset
180 void sizeEvent (int nw, int nh) { // IDrawable function
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
181 mutex.lock;
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
182 scope(exit) mutex.unlock;
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
183
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
184 w = cast(wdim) nw;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
185 h = cast(wdim) nh;
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
186
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
187 if (w < mw || h < mh)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
188 logger.warn ("Minimal dimensions ({},{}) not met: ({},{}), but I cannot resize myself!",mw,mh,w,h);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
189
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
190 if (!child) return; // if not created yet.
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
191 child.setWidth (w, -1);
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
192 child.setHeight (h, -1);
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
193 child.setPosition (0,0);
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
194 }
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
195
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
196 //BEGIN IWidgetManager methods
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
197 // These methods are only intended for use within the gui package. They are not necessarily
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
198 // thread-safe.
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
199 IRenderer renderer () {
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
200 assert (rend !is null, "WidgetManager.renderer: rend is null");
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
201 return rend;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
202 }
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
203
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
204 /** Place a pop-up widget (widg) above or below parent.
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
205 *
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
206 * WidgetManager sets its position, draws it, passes it click events and removes it; other
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
207 * functionality should be handled by the widget's parent.
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
208 *
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
209 * Popups currently should not change their size while active. */
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
210 void addPopup (IChildWidget parent, IChildWidget widg) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
211 debug assert (parent && widg, "addPopup: null widget");
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
212 ActivePopup popup;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
213 popup.parent = parent;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
214 with (popup) {
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
215 widget = widg;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
216 w = widg.width;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
217 h = widg.height;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
218 x = parent.xPos; // align on left edge
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
219 if (x+w > this.w) x += parent.width - w; // align on right edge
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
220 y = parent.yPos + parent.height; // place below
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
221 if (y+h > this.h) y = parent.yPos - h; // place above
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
222 widget.setPosition (x, y);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
223 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
224 popups.prepend (popup);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
225 requestRedraw;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
226 }
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
227 /+ Not required but possibly useful later. Not optimal.
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
228 void removePopup (IChildWidget widg) {
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
229 auto i = popups.iterator;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
230 foreach (popup; i) {
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
231 if (popup.widget is widg)
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
232 i.remove;
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
233 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
234 requestRedraw;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
235 }+/
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
236
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
237 void requestRedraw () {
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
238 imde.mainSchedule.request(imde.SCHEDULE.DRAW);
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
239 }
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
240
58
d43523ed4b62 Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 47
diff changeset
241 void addClickCallback (bool delegate(wdabs, wdabs, ubyte, bool) dg) {
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
242 clickCallbacks[dg.ptr] = dg;
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
243 }
58
d43523ed4b62 Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 47
diff changeset
244 void addMotionCallback (void delegate(wdabs, wdabs) dg) {
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
245 motionCallbacks[dg.ptr] = dg;
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
246 }
76
65780e0e48e6 Re-enabled click event passing in the gui to make ButtonWidget work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 75
diff changeset
247 void removeCallbacks (void* frame) {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
248 clickCallbacks.removeKey(frame);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
249 motionCallbacks.removeKey(frame);
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
250 }
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
251 //END IWidgetManager methods
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
252
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
253 protected:
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
254 /* Second stage of widget loading.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
255 * Note: sizeEvent should be called with window size before this. */
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
256 final override void createRootWidget () {
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
257 // The renderer needs to be created on the first load, but not after this.
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
258 if (rend is null)
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
259 rend = createRenderer (rendName);
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
260 popups = new CircularList!(ActivePopup);
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
261
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
262 child = makeWidget ("root");
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
263 child.setup (0, 3);
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
264
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
265 mw = child.minWidth;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
266 mh = child.minHeight;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
267
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
268 if (w < mw || h < mh)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
269 logger.warn ("Minimal dimensions ({},{}) not met: ({},{}), but I cannot resize myself!",mw,mh,w,h);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 84
diff changeset
270
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
271 child.setWidth (w, -1);
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
272 child.setHeight (h, -1);
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
273 child.setPosition (0,0);
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
274 }
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
275
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
276 final override void preSave () {
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
277 if (keyFocus) {
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
278 keyFocus.keyFocusLost;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
279 keyFocus = null;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
280 imde.input.setLetterCallback (null);
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
281 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
282 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
283
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
284 private:
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
285 struct ActivePopup {
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
286 IChildWidget widget;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
287 IChildWidget parent;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
288 wdabs x,y;
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
289 wdsize w,h;
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
290 }
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
291 IRenderer rend;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
292 CircularList!(ActivePopup) popups;// Pop-up [menus] to draw. First element is top popup.
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
293 // callbacks indexed by their frame pointers. Must support removal of elements in foreach:
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
294 SortedMap!(void*,bool delegate(wdabs cx, wdabs cy, ubyte b, bool state)) clickCallbacks;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
295 SortedMap!(void*,void delegate(wdabs cx, wdabs cy)) motionCallbacks;
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
296 IChildWidget keyFocus; // widget receiving keyboard input when non-null
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
297 IChildWidget highlighted; // NOTE: in some ways should be same as keyFocus
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
298 }
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
299
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
300
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
301 import mde.gui.exception;
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
302 import mde.content.Content; // Content passed to a callback
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
303 import mde.gui.widget.createWidget;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
304
81
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
305 import mde.file.mergetag.Reader;
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
306 import mde.file.mergetag.Writer;
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
307 import mde.setup.paths;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
308
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
309 /*************************************************************************************************
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
310 * Contains the code for loading and saving an entire gui (more than one may exist), but not the
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
311 * code for drawing it or handling user input.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
312 *
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
313 * This abstract class exists solely for separating out some of the functionality.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
314 *************************************************************************************************/
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
315 abstract scope class WidgetLoader : IWidgetManager
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
316 {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
317 /** Construct a new widget loader.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
318 *
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
319 * params:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
320 * fileName = Name of file specifying the gui, excluding path and extension.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
321 */
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
322 protected this (char[] file) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
323 mutex = new Mutex; // Used on functions intended to be called from outside the gui package.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
324 fileName = file;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
325 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
326
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
327 /* Load the widgets' data from the file specified to the CTOR.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
328 *
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
329 * params:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
330 * allDesigns = Load all sections
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
331 */
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
332 private void loadData (bool allDesigns = false) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
333 if (allLoaded || (defaultDesign !is null && allDesigns == false))
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
334 return; // test if already loaded
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
335
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
336 // Set up a reader
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
337 scope IReader reader;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
338 try {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
339 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_LOW, null, true);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
340
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
341 // Read from the HEADER:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
342 // Get the renderer
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
343 char[]* p = "Renderer" in reader.dataset.header._charA;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
344 if (p is null || *p is null) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
345 logger.warn ("No renderer specified: using \"Simple\"");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
346 rendName = "Simple";
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
347 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
348 else
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
349 rendName = *p;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
350
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
351 // Get which section to use
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
352 p = "Design" in reader.dataset.header._charA;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
353 if (p is null || *p is null) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
354 logger.warn ("No gui design specified: trying \"Default\"");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
355 defaultDesign = "Default";
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
356 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
357 else
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
358 defaultDesign = *p;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
359
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
360 // Read the body:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
361 // Load the chosen design
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
362 reader.dataSecCreator = delegate mt.IDataSection(mt.ID id) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
363 WidgetDataSet* p = id in data;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
364 if (p is null) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
365 data[id] = new WidgetDataSet;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
366 return *(id in data);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
367 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
368 return *p;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
369 };
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
370
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
371 if (allDesigns) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
372 reader.read;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
373 allLoaded = true;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
374 } else
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
375 reader.read([defaultDesign]);
81
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
376 } catch (NoFileException) {
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
377 logger.error ("Unable to load GUI: no config file!");
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
378 // just return: not a fatal error (so long as the game can run without a GUI!)
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
379 } catch (Exception e) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
380 logger.error ("Unable to load GUI: errors parsing config file ("~confDir.getFileName(fileName,PRIORITY.HIGH_LOW)~"):");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
381 logger.error (e.msg);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
382 throw new GuiException ("Failure parsing config file");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
383 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
384 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
385
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
386 /** Load the gui from some design.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
387 *
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
388 * If a design was previously loaded, its changes are saved first.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
389 *
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
390 * Params:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
391 * name = Design to load. If null, the default will be loaded.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
392 */
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
393 void loadDesign (char[] name = null) {
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
394 if (changes !is null) // A design was previously loaded
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
395 save; // own lock
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
396
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
397 mutex.lock;
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
398 scope(exit) mutex.unlock;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
399
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
400 // Load data (loadData tests if it's already loaded first):
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
401 if (name is null) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
402 loadData (false);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
403 name = defaultDesign;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
404 } else
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
405 loadData (true);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
406
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
407
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
408 // Get data:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
409 auto p = name in data;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
410 while (p is null) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
411 if (name == defaultDesign)
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
412 throw new GuiException ("Unable to load [specified or] default design");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
413 name = defaultDesign; // try again with the default
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
414 p = name in data;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
415 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
416 curData = *p;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
417
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
418 // Get/create a changes section:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
419 if (changesDS is null)
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
420 changesDS = new mt.DataSet;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
421
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
422 mt.IDataSection* q = name in changesDS.sec;
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
423 if (!q || ((changes = cast(WidgetDataChanges) *q) is null)) {
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
424 changes = new WidgetDataChanges (curData);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
425 changesDS.sec[name] = changes;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
426 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
427
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
428 // Create the widgets:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
429 createRootWidget;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
430 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
431
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
432 /** Save changes, if any exist.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
433 *
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
434 * Is run when the manager is destroyed, but could be run at other times too. */
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
435 void save () {
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
436 preSave;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
437
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
438 mutex.lock;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
439 scope(exit) mutex.unlock;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
440
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
441 // Make all widgets save any changed data; return if no changes:
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 92
diff changeset
442 if (!child.saveChanges)
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
443 return;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
444
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
445 if (loadUserFile) { // merge entries from user file into current changes
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
446 try {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
447 scope IReader reader = confDir.makeMTReader (
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
448 fileName, PRIORITY.HIGH_ONLY, changesDS, true);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
449
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
450 // Create if necessary, only corresponding to existing designs read:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
451 reader.dataSecCreator = delegate mt.IDataSection(mt.ID id) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
452 WidgetDataSet* p = id in data;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
453 if (p is null)
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
454 throw new Exception ("File has changed since it was loaded!");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
455 return new WidgetDataChanges (*p);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
456 };
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
457
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
458 reader.read;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
459 } catch (NoFileException) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
460 // No user file exists; not an error.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
461 } catch (Exception e) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
462 logger.error ("Error reading "~confDir.getFileName(fileName,PRIORITY.HIGH_ONLY)~" prior to saving:");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
463 logger.error (e.msg);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
464 logger.error ("Overwriting the file.");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
465 // Continue...
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
466 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
467 loadUserFile = false; // don't need to do it again
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
468 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
469
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
470 try { // Save
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
471 IWriter writer;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
472 writer = confDir.makeMTWriter (fileName, changesDS);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
473 writer.write;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
474 } catch (Exception e) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
475 logger.error ("Saving to "~confDir.getFileName(fileName,PRIORITY.HIGH_ONLY)~" failed:");
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
476 logger.error (e.msg);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
477 // No point in throwing since it doesn't affect anything else.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
478 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
479 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
480
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
481 /** Get the names of all designs available. */
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
482 char[][] designs() {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
483 synchronized(mutex) {
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
484 loadData (true);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
485 return data.keys;
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
486 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
487 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
488
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
489 /** Called when translation strings have been reloaded. */
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
490 void reloadStrings (Content) {
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
491 Items.loadTranslation;
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
492 child.setup (++setupN, 2);
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
493 child.setWidth (w, -1);
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
494 child.setHeight (h, -1);
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
495 child.setPosition (0,0);
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
496 requestRedraw;
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
497 }
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
498
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
499 protected:
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
500 /** Second stage of loading the widgets.
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
501 *
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
502 * loadDesign handles the data; this method needs to:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
503 * ---
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
504 * // 1. Create the root widget:
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
505 * child = makeWidget ("root");
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
506 * child.setup (0, 3);
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
507 * // 2. Set the size:
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
508 * child.setWidth (child.minWidth, 1);
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
509 * child.setHeight (child.minHeight, 1);
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
510 * // 3. Set the position (necessary part of initialization):
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
511 * child.setPosition (0,0);
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
512 * ---
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
513 */
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
514 void createRootWidget();
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
515
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
516 /** Called before saving (usually when the GUI is about to be destroyed, although not
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
517 * necessarily). */
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
518 void preSave ();
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
519
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
520 public:
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
521 //BEGIN IWidgetManager methods
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
522 override IChildWidget makeWidget (widgetID id, IContent content = null) {
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
523 debug (mdeWidgets) logger.trace ("Creating widget \""~id~'"');
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
524 return createWidget (this, id, curData[id], content);
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
525 }
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
526 override IChildWidget makeWidget (widgetID id, WidgetData data, IContent content = null) {
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
527 debug (mdeWidgets) logger.trace ("Creating widget \""~id~'"');
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
528 return createWidget (this, id, data, content);
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
529 }
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
530
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
531 override wdims dimData (widgetID id) {
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
532 return curData.dims (id);
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
533 }
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
534 override void setData (widgetID id, WidgetData d) {
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
535 changes[id] = d; // also updates WidgetDataSet in data.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
536 }
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
537 override void setDimData (widgetID id, wdims d) {
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
538 changes.setDims(id, d); // also updates WidgetDataSet in data.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
539 }
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
540 //END IWidgetManager methods
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
541
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
542 protected:
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
543 final char[] fileName;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
544 char[] defaultDesign; // The design specified in the file header.
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
545 char[] rendName; // Name of renderer; for saving and creating renderers
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
546
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
547 // Loaded data, indexed by design name. May not be loaded for all gui designs:
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
548 scope WidgetDataSet[char[]] data;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
549 private bool allLoaded = false; // applies to data
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
550 WidgetDataSet curData; // Current data
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
551 WidgetDataChanges changes; // Changes for the current design.
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
552 scope mt.DataSet changesDS; // changes and sections from user file (used for saving)
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
553 bool loadUserFile = true; // still need to load user file for saving?
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
554
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
555 wdim w,h; // area available to the widgets
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
556 wdim mw,mh; // minimal area required by widgets (ideally for limiting w,h)
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
557 scope IChildWidget child; // The primary widget.
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
558 uint setupN; // n to pass to IChildWidget.setup
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
559
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
560 Mutex mutex; // lock on methods for use outside the package.
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
561 }