annotate mde/gui/widget/Window.d @ 39:5132301e9ed7

Implemented widget saving. Widget creation data saving (sub-widgets, etc:) code there but not used. Widget mutable data saving & loading: window size/position, row/column dimensions saved (still needs a fix in GridWidget.setSize()). committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 07 May 2008 13:07:03 +0100
parents 8c4c96f04e7f
children b28d7adc786b
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
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** The Window class. Hopefully eventually this will become a widget to make things a bit more
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 * generic. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 module mde.gui.widget.Window;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 import mde.gui.widget.Ifaces;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 import mde.gui.widget.createWidget;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import mde.gui.IGui;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import mde.gui.exception;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 import mt = mde.mergetag.DataSet;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import tango.scrapple.text.convert.parseTo : parseTo;
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
28 import tango.scrapple.text.convert.parseFrom : parseFrom;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29
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
30 import tango.util.log.Log : Log, Logger;
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
31
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
32 private Logger logger;
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
33 static this () {
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
34 logger = Log.getLogger ("mde.gui.widget.Window");
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
35 }
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
36
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 /** GUI Window class
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 * A window class instance does two things: (1) specify a region of the screen upon which the window
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 * and its associated widgets are drawn, and (2) load, save, and generally manage all its widgets.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 * Let the window load a table of widget data, of type int[][widgetID]. Each widget will, when
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 * created, be given its int[] of data, which this() must confirm is valid (or throw).
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 class Window : mt.IDataSection, IWindow
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 //BEGIN Methods for GUI
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
48 this (char[] id) {
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
49 name = id;
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
50 }
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
51
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 /** Call after loading is finished to setup the window and confirm that it's valid.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 *
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
54 * Throws: WindowLoadException (or possibly other exceptions). Do not use the instance if an
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
55 * exception occurs! */
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
56 void finalise (IGui gui)
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
57 in {
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
58 assert (gui !is null, "Window.finalise ("~name~"): gui is null");
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
59 } body {
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 // Check data was loaded:
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
61 if (widgetData is null || mutableData is null)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
62 throw new WindowLoadException ("No widget/mutable data");
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63
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
64 gui_ = gui;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 rend = gui.renderer;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
67 // Get border sizes
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
68 border = rend.getBorder (BORDER_TYPES.WINDOW_TOTAL);
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
69 resize = rend.getBorder (BORDER_TYPES.WINDOW_RESIZE);
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
70
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
71 // Create the primary widget (and indirectly all sub-widgets), throwing on error:
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
72 widget = makeWidget (0); // primary widget always has ID 0.
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
73 widgetData = null; // data is no longer needed: allow GC to collect (cannot safely delete)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
74
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
75 widget.adjust (mutableData); // adjust/set size, etc.
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
76 mutableData = null; // no longer needed
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
77
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
78 widget.getCurrentSize (w,h); // and get this size
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
79 w += border.l + border.r; // Adjust for border
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
80 h += border.t + border.b;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
82 widgetX = x + border.l; // widget position
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
83 widgetY = y + border.t; // must be updated if the window is moved
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
84 widget.setPosition (widgetX, widgetY);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 xw = x+w;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87 yh = y+h;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 //BEGIN Mergetag code
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 void addTag (char[] tp, mt.ID id, char[] dt) {
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
91 // Priority is HIGH_LOW, so don't overwrite data which has already been loaded.
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
92 if (tp == INTAA) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
93 if (id == WDGD && widgetData == null) {
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 widgetData = cast(int[][widgetID]) parseTo!(int[][int]) (dt);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 }
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
96 } else if (tp == INTA) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
97 if (id == MD && mutableData == null) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
98 mutableData = parseTo!(int[]) (dt);
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
99 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
100 } else if (tp == INT) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
101 if (id == X && x == -1) {
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102 x = parseTo!(int) (dt);
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
103 } else if (id == Y && y == -1) {
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
104 y = parseTo!(int) (dt);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
105 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
106 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 }
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
108 void writeAll (ItemDelg dlg)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
109 in {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
110 assert (widgetData is null, "Window.writeAll: widgetData !is null");
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
111 } body {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
112 /+ NOTE: currently editing is impossible...
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
113 if (edited) { // only save the widget creation data if it's been adjusted:
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
114 addSaveData (widget); // generate widget save data
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
115 dlg (INTAA, WDGD, parseFrom!(int[][int]) (widgetData));
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
116 }+/
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
117 // Save mutable data:
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
118 dlg (INTA, MD, parseFrom!(int[]) (widget.getMutableData));
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
119 // Save the window position:
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
120 dlg (INT, X, parseFrom!(int) (x));
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
121 dlg (INT, Y, parseFrom!(int) (y));
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
122 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
123 private static const {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
124 auto INTAA = "int[][int]";
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
125 auto INTA = "int[]";
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
126 auto INT = "int";
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
127 auto WDGD = "widgetData";
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
128 auto MD = "mutableData";
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
129 auto X = "x";
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
130 auto Y = "y";
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
131 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
132 //END Mergetag code
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
133 //END Methods for GUI
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
134
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
135 //BEGIN IWindow methods
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
136 /** Get/create a widget by ID.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
137 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
138 * Should $(I only) be called internally and by sub-widgets! */
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
139 IWidget makeWidget (widgetID i)
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
140 in {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
141 // widgetData is normally left to be garbage collected after widgets have been created:
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
142 assert (widgetData !is null, "Window.makeWidget ("~name~"): widgetData is null");
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
143 } body {
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
144 /* Each widget returned should be a unique object; if multiple widgets are requested with
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
145 * the same ID, a new widget is created each time. */
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
146
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
147 int[]* d = i in widgetData;
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
148 if (d is null)
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
149 throw new WindowLoadException ("Window.makeWidget ("~name~"): Widget not found");
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
150
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
151 // Throws WidgetDataException (a WindowLoadException) if bad data:
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
152 return createWidget (this, *d);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
155 /** Add this widget's data to that to be saved, returning it's widgetID. */
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
156 widgetID addCreationData (IWidget widget)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
157 {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
158 widgetID i;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
159 if (widgetData is null)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
160 i = 0;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
161 else
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
162 i = widgetData.keys[$-1] + 1;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
163
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
164 widgetData[i] = null; // Make sure the same ID doesn't get used by a recursive call
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
165 widgetData[i] = widget.getCreationData;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
166
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
167 return i;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
168 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
169
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
170 IGui gui () {
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
171 return gui_;
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
172 }
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
173
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 IRenderer renderer () {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175 return rend;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
177 //END IWindow methods
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178
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
179 //BEGIN IWidget methods
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
180 //FIXME: how many of these methods are actually needed/used?
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
181 int[] adjust (int[]) { // simply not relevant (never used)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
182 return [];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
183 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
184 int[] getCreationData () { // simply not relevant (never used)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
185 return [];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
186 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
187 int[] getMutableData () { // simply not relevant (never used)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
188 return [];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
189 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
190
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
191 bool isWSizable () {
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
192 return widget.isWSizable;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
193 }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
194 bool isHSizable () {
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
195 return widget.isHSizable;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
196 }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
197
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
198 void getMinimalSize (out int wM, out int hM) {
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
199 if (mh < 0) { // calculate if necessary
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
200 widget.getMinimalSize (mw, mh);
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
201 mw += border.l + border.r;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
202 mh += border.t + border.b;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
203 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
204 wM = mw;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
205 hM = mh;
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
206 }
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
207 void getCurrentSize (out int cw, out int ch) {
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
208 cw = w;
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
209 ch = h;
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
210 }
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
211
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
212 void setSize (int nw, int nh) {
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
213 getMinimalSize (w,h);
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
214 if (nw > w) w = nw; // expand if new size is larger, but don't go smaller
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
215 if (nh > h) h = nh;
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
216
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
217 xw = x+w;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
218 yh = y+h;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
219
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
220 widget.setSize (w - border.l - border.r, h - border.t - border.b);
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
221
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
222 gui_.requestRedraw (); // obviously necessary whenever the window's size is changed
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
223 }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
224
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
225 void setPosition (int nx, int ny) {
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
226 x = nx;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
227 y = ny;
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
228
35
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
229 xw = x+w;
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
230 yh = y+h;
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
231
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
232 widgetX = x + border.l;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
233 widgetY = y + border.t;
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
234
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
235 widget.setPosition (widgetX, widgetY);
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
236
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
237 gui_.requestRedraw (); // obviously necessary whenever the window is moved
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
238 }
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
239
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
240 IWidget getWidget (int cx, int cy) {
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
241 if (cx < x || cx >= xw || cy < y || cy >= yh) // not over window
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 return null;
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
243 if (cx >= widgetX && cx < xw-border.r && cy >= widgetY && cy < yh-border.b)
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
244 // over the widget
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 return widget.getWidget (cx, cy);
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 else // over the window border
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
247 return this;
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
248 }
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
249 void clickEvent (ushort cx, ushort cy, ubyte b, bool state) {
35
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
250 if (b == 1 && state == true) {
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
251 if (cx < x + resize.l || cx >= xw - resize.r ||
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
252 cy < y + resize.t || cy >= yh - resize.b) { // window is being resized
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
253 /* check for resizes (different to above; use whole border giving larger area for
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
254 * diagonal resizes). */
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
255 resizeType = RESIZE.NONE;
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
256
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
257 if (isWSizable) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
258 if (cx < x + border.l) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
259 xDrag = w + cx;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
260 resizeType = RESIZE.L;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
261 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
262 else if (cx >= xw - border.r) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
263 xDrag = w - cx;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
264 resizeType = RESIZE.R;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
265 }
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
266 }
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
267 if (isHSizable) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
268 if (cy < y + border.t) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
269 yDrag = h + cy;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
270 resizeType |= RESIZE.T;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
271 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
272 else if (cy >= yh - border.b) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
273 yDrag = h - cy;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
274 resizeType |= RESIZE.B;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
275 }
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
276 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
277
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
278 if (resizeType != RESIZE.NONE) { // only if some valid size is being done
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
279 gui_.addClickCallback (&endCallback);
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
280 gui_.addMotionCallback (&resizeCallback);
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
281 }
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
282 } else { // window is being moved
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
283 xDrag = cx - x;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
284 yDrag = cy - y;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
285
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
286 gui_.addClickCallback (&endCallback);
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
287 gui_.addMotionCallback (&moveCallback);
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
288 }
35
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
289 }
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
290 }
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
291
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
292 void draw () {
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
293 // background
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
294 rend.drawWindow (x,y, w,h);
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
295
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
296 // Tell the widget to draw itself:
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
297 widget.draw();
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
298 }
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
299 //END IWidget methods
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
300
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
301 private:
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
302 alias IRenderer.BorderDimensions BorderDimensions;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
303 alias IRenderer.BORDER_TYPES BORDER_TYPES;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
304
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
305 //BEGIN Window moving and resizing
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
306 void moveCallback (ushort cx, ushort cy) {
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
307 setPosition (cx-xDrag, cy-yDrag);
35
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
308 }
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
309 void resizeCallback (ushort cx, ushort cy) {
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
310 if (resizeType & RESIZE.L) {
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
311 int mw, nw;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
312 getMinimalSize (mw, nw); // (only want mw)
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
313 nw = xDrag - cx;
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
314 if (nw < mw) nw = mw; // clamp
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
315 mw = x + w - nw; // reuse
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
316 setSize (nw, h);
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
317 setPosition (mw, y);
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
318 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
319 else if (resizeType & RESIZE.R) {
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
320 setSize (xDrag + cx, h);
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
321 setPosition (x, y);
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
322 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
323 if (resizeType & RESIZE.T) {
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
324 int mh, nh;
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
325 getMinimalSize (nh, mh);
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
326 nh = yDrag - cy;
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
327 if (nh < mh) nh = mh;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
328 mh = y + h - nh;
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
329 setSize (w, nh);
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
330 setPosition (x, mh);
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
331 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
332 else if (resizeType & RESIZE.B) {
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
333 setSize (w, yDrag + cy);
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
334 setPosition (x, y);
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
335 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
336 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
337 void endCallback (ushort cx, ushort cy, ubyte b, bool state) {
35
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
338 if (b == 1 && state == false) {
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
339 // The mouse shouldn't have moved since the motion callback
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
340 // was last called, so there's nothing else to do now.
35
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
341 gui_.removeCallbacks (cast(void*) this);
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
342 }
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
343 }
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
344 int xDrag, yDrag; // where a drag starts relative to x and y
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
345 enum RESIZE : ubyte {
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
346 NONE = 0x0, L = 0x1, R = 0x2, T = 0x4, B = 0x8
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
347 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
348 RESIZE resizeType; // Type of current resize
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
349 //END Window moving and resizing
35
928db3c75ed3 Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
350
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
351 // Load/save data:
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
352 public char[] name; // The window's name (id from config file)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
353 //bool edited = false; // True if any widgets have been edited (excluding scaling)
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
354 // Data used for saving and loading (null in between):
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
355 int[][widgetID] widgetData = null;// Data for all widgets under this window
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
356 int[] mutableData = null; // Widget's mutable data (adjusted sizes, etc.)
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
357
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
358 IGui gui_; // The gui managing this window
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
359 IRenderer rend; // The window's renderer
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
360
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
361 IWidget widget; // The primary widget in this window.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
362
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 38
diff changeset
363 int x = -1, y = -1; // Window position
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
364 int w,h; // Window size (calculated from Widgets)
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
365 int xw, yh; // x+w, y+h (frequent use by clickEvent)
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
366 int widgetX, widgetY; // Widget position (= window position plus BORDER_WIDTH)
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
367 int mw = -1, mh = -1; // minimal size
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
368
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
369 BorderDimensions border; // Total border size (move plus resize)
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
370 BorderDimensions resize; // The outer resize part of the border
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
371 }