annotate mde/gui/gui.d @ 30:467c74d4804d

Major changes to the scheduler, previously only used by the main loop. Revamped Scheduler. Functions can be removed, have multiple schedules, have their scheduling changed, etc. Scheduler has a unittest. Checked all pass. Main loop scheduler moved to mde. Draw-on-demand currently disabled, simplifying this. Made mtunitest.d remove the temporary file it uses afterwards. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 28 Apr 2008 10:59:47 +0100
parents f985c28c0ec9
children baa87e68d7dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /// Base GUI module.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 module mde.gui.gui;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18
28
b5fadd8d930b Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
19 import mde.gui.IWindow;
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 import mde.gui.Widget;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 import mde.gui.exception;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import mt = mde.mergetag.DataSet;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import mt = mde.mergetag.exception;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25 import mde.mergetag.Reader;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import mde.resource.paths;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 import mde.scheduler.InitFunctions;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 import tango.scrapple.text.convert.parseTo : parseTo;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 import tango.scrapple.text.convert.parseFrom : parseFrom;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
33 import tango.util.log.Log : Log, Logger;
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
34
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 private Logger logger;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 static this () {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 logger = Log.getLogger ("mde.gui.gui");
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
39 init.addFunc (&loadGUI, "loadGUI");
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
42 GUI gui; // Currently just one instance; handle differently later.
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
43 // Wrap gui.load, since init doesn't handle delegates
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
44 // (do it this way since GUI handling will eventually be changed)
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
45 void loadGUI () {
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
46 gui.load();
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
47 }
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
48
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
49 /** A GUI handles a bunch of windows, all to be drawn to the same device. */
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 struct GUI {
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
51 /** Load all windows from the file gui. */
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 void load() {
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
53 static const fileName = "gui";
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 if (!confDir.exists (fileName)) {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 logger.error ("Unable to load GUI: no config file!");
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 return; // not a fatal error (so long as the game can run without a GUI!)
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 IReader reader;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 try {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_ONLY);
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 reader.dataSecCreator = delegate mt.IDataSection(mt.ID) {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 return new Window;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 };
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 reader.read;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 } catch (mt.MTException e) {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 logger.error ("Loading GUI aborted:");
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 logger.error (e.msg);
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 return;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 // get list
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74 windows.length = reader.dataset.sec.length; // pre-allocate
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 windows.length = 0;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 foreach (sec; reader.dataset.sec) {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 Window w = cast(Window) sec;
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
78 debug if (w is null) {
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
79 logger.error (__FILE__ ~ "(GUI.load): code error (w is null)");
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
80 continue;
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
81 }
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
82 try {
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
83 //logger.trace ("1");
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
84 int x;
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
85 w.finalise();
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
86 x = 6;
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
87 windows ~= w; // only add if load successful
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
88 } catch (WindowLoadException e) {
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
89 logger.error ("Window failed to load: " ~ e.msg);
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
94 /** Draw each window.
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
95 *
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
96 * Currently no concept of how to draw overlapping windows, or how to not bother drawing windows
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
97 * which don't need redrawing. */
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
98 void draw() {
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
99 foreach (w; windows)
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
100 w.draw();
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
101 }
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
102
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
103 private:
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
104 Window[] windows;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
105 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
106
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 package: // Nothing else here is for external use.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 /** GUI Window class
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
110 *
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
111 * A window class instance does two things: (1) specify a region of the screen upon which the window
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112 * and its associated widgets are drawn, and (2) load, save, and generally manage all its widgets.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113 *
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
114 * Let the window load a table of widget data, of type int[][widgetID]. Each widget will, when
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
115 * created, be given its int[] of data, which this() must confirm is valid (or throw).
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
116 */
28
b5fadd8d930b Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 27
diff changeset
117 class Window : mt.IDataSection, IWindow
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
118 {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
119 alias int widgetID; // Widget ID type. Each ID is unique under this window. Type is int since this is the widget data type.
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
120
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
121 /** Call after loading is finished to setup the window and confirm that it's valid.
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
122 *
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
123 * Throws: WindowLoadException. Do not use the instance in this case! */
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124 void finalise () {
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
125 // Check data was loaded:
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
126 if (widgetData is null) throw new WindowLoadException ("No widget data");
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
127
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
128 // Create the primary widget (and indirectly all sub-widgets), throwing on error:
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
129 widget = getWidget (0); // primary widget always has ID 0.
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
130
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
131 widgetData = null; // data is no longer needed: allow GC to collect (cannot safely delete)
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
132
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
133 widget.getCurrentSize (w,h);// Find the initial size
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
134 w += BORDER_WIDTH * 2; // Adjust for border
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
135 h += BORDER_WIDTH * 2;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
136 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
137
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
138 /** Get/create a widget by ID.
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
139 *
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
140 * Should $(I only) be called internally and by sub-widgets! */
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
141 IWidget getWidget (widgetID i)
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
142 in {
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
143 // widgetData is normally left to be garbage collected after widgets have been created:
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
144 assert (widgetData !is null, "getWidget: widgetData is null");
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
145 } body {
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 // See if it's already been created:
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
147 IWidget* p = i in widgets;
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 if (p !is null) return *p; // yes
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149 else { // no
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 int[]* d = i in widgetData;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151 if (d is null) throw new WindowLoadException ("Widget not found");
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153 // Throws WidgetDataException (a WindowLoadException) if bad data:
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
154 IWidget w = createWidget (this, *d);
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155 widgets[i] = w;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
156 return w;
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
157 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
160 void requestRedraw () {
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
161 //FIXME
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
162 }
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
163
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 void draw () {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 //BEGIN Window border/back
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166 gl.setColor (0.0f, 0.0f, 0.5f);
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 gl.drawBox (x,x+w, y,y+h);
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 //END Window border/back
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
170 // Tell the widget to draw itself:
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
171 widget.draw(x + BORDER_WIDTH, y + BORDER_WIDTH);
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
173
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 //BEGIN Mergetag code
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175 void addTag (char[] tp, mt.ID id, char[] dt) {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 if (tp == "int[][int]") {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
177 if (id == "widgetData") {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178 widgetData = cast(int[][widgetID]) parseTo!(int[][int]) (dt);
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
180 } else if (tp == "int") {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
181 if (id == "x") {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
182 x = parseTo!(int) (dt);
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
183 } else if (id == "y") {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
184 y = parseTo!(int) (dt);
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
186 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
187 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188 void writeAll (ItemDelg dlg) {
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
189 }
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
190 //END Mergetag code
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
191
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
192 private:
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
193 int[][widgetID] widgetData; // Data for all widgets under this window (deleted after loading)
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
194 IWidget[widgetID] widgets; // List of all widgets under this window (created on demand).
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
195
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
196 IWidget widget; // The primary widget in this window.
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
197 int x,y; // Window position
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
198 int w,h; // Window size (calculated from Widgets)
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
199
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
200 const BORDER_WIDTH = 8; // Temporary way to handle window decorations
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
201
27
0aa621b3e070 Some GUI work, plus a small fix in the paths module.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
202 }