Mercurial > projects > mde
annotate mde/gui/widget/Window.d @ 40:b28d7adc786b
Made GUI more robust to mutable data changes and improved much of GridLayoutWidget's code.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 08 May 2008 16:05:51 +0100 |
parents | 5132301e9ed7 |
children | b3a6ca4516b4 |
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: |
40
b28d7adc786b
Made GUI more robust to mutable data changes and improved much of GridLayoutWidget's code.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
39
diff
changeset
|
61 if (widgetData is null) |
b28d7adc786b
Made GUI more robust to mutable data changes and improved much of GridLayoutWidget's code.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
39
diff
changeset
|
62 throw new WindowLoadException ("No widget creation 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 |
40
b28d7adc786b
Made GUI more robust to mutable data changes and improved much of GridLayoutWidget's code.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
39
diff
changeset
|
75 // Note: this should return an empty array, but nothing much should happen if it's not empty: |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
76 widget.adjust (mutableData); // adjust/set size, etc. |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
77 mutableData = null; // no longer needed |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
78 |
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
|
79 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
|
80 w += border.l + border.r; // Adjust for border |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
81 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
|
82 |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
83 widgetX = x + border.l; // widget position |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
84 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
|
85 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
|
86 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
87 xw = x+w; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
88 yh = y+h; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
89 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
90 //BEGIN Mergetag code |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
91 void addTag (char[] tp, mt.ID id, char[] dt) { |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
92 // 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
|
93 if (tp == INTAA) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
94 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
|
95 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
|
96 } |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
97 } else if (tp == INTA) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
98 if (id == MD && mutableData == null) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
99 mutableData = parseTo!(int[]) (dt); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
100 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
101 } else if (tp == INT) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
102 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
|
103 x = parseTo!(int) (dt); |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
104 } 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
|
105 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
|
106 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
107 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
108 } |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
109 void writeAll (ItemDelg dlg) |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
110 in { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
111 assert (widgetData is null, "Window.writeAll: widgetData !is null"); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
112 } body { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
113 /+ NOTE: currently editing is impossible... |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
114 if (edited) { // only save the widget creation data if it's been adjusted: |
40
b28d7adc786b
Made GUI more robust to mutable data changes and improved much of GridLayoutWidget's code.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
39
diff
changeset
|
115 addCreationData (widget); // generate widget save data |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
116 dlg (INTAA, WDGD, parseFrom!(int[][int]) (widgetData)); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
117 }+/ |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
118 // Save mutable data: |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
119 dlg (INTA, MD, parseFrom!(int[]) (widget.getMutableData)); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
120 // Save the window position: |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
121 dlg (INT, X, parseFrom!(int) (x)); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
122 dlg (INT, Y, parseFrom!(int) (y)); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
123 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
124 private static const { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
125 auto INTAA = "int[][int]"; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
126 auto INTA = "int[]"; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
127 auto INT = "int"; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
128 auto WDGD = "widgetData"; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
129 auto MD = "mutableData"; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
130 auto X = "x"; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
131 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
|
132 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
133 //END Mergetag code |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
134 //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
|
135 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
136 //BEGIN IWindow methods |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
137 /** 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
|
138 * |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
139 * 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
|
140 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
|
141 in { |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
142 // 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
|
143 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
|
144 } body { |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
145 /* 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
|
146 * 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
|
147 |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
152 // Throws WidgetDataException (a WindowLoadException) if bad data: |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
153 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
|
154 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
155 |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
156 /** 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
|
157 widgetID addCreationData (IWidget widget) |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
158 { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
159 widgetID i; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
160 if (widgetData is null) |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
161 i = 0; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
162 else |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
163 i = widgetData.keys[$-1] + 1; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
164 |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
165 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
|
166 widgetData[i] = widget.getCreationData; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
167 |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
168 return i; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
169 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
170 |
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
|
171 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
|
172 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
|
173 } |
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
|
174 |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
175 IRenderer renderer () { |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
176 return rend; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
177 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
178 //END IWindow methods |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
179 |
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
|
180 //BEGIN IWidget methods |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
181 //FIXME: how many of these methods are actually needed/used? |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
182 int[] adjust (int[]) { // simply not relevant (never used) |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
183 return []; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
184 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
185 int[] getCreationData () { // simply not relevant (never used) |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
186 return []; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
187 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
188 int[] getMutableData () { // simply not relevant (never used) |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
189 return []; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
190 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
191 |
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
|
192 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
|
193 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
|
194 } |
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 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
|
196 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
|
197 } |
052df9b2fe07
Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
198 |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
199 void getMinimalSize (out int wM, out int hM) { |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
200 if (mh < 0) { // calculate if necessary |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
201 widget.getMinimalSize (mw, mh); |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
202 mw += border.l + border.r; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
203 mh += border.t + border.b; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
204 } |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
205 wM = mw; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
206 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
|
207 } |
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 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
|
209 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
|
210 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
|
211 } |
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
|
212 |
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
|
213 void setSize (int nw, int nh) { |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
214 getMinimalSize (w,h); |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
215 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
|
216 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
|
217 |
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 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
|
219 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
|
220 |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
221 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
|
222 |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
223 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
|
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 |
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 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
|
227 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
|
228 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
|
229 |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
230 xw = x+w; |
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
231 yh = y+h; |
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
232 |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
233 widgetX = x + border.l; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
234 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
|
235 |
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
|
236 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
|
237 |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
238 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
|
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 |
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 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
|
242 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
|
243 return null; |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
244 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
|
245 // 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
|
246 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
|
247 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
|
248 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
|
249 } |
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
250 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
|
251 if (b == 1 && state == true) { |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
252 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
|
253 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
|
254 /* 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
|
255 * diagonal resizes). */ |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
256 resizeType = RESIZE.NONE; |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
257 |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
258 if (isWSizable) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
259 if (cx < x + border.l) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
260 xDrag = w + cx; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
261 resizeType = RESIZE.L; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
262 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
263 else if (cx >= xw - border.r) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
264 xDrag = w - cx; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
265 resizeType = RESIZE.R; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
266 } |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
267 } |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
268 if (isHSizable) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
269 if (cy < y + border.t) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
270 yDrag = h + cy; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
271 resizeType |= RESIZE.T; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
272 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
273 else if (cy >= yh - border.b) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
274 yDrag = h - cy; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
275 resizeType |= RESIZE.B; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
276 } |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
277 } |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
278 |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
279 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
|
280 gui_.addClickCallback (&endCallback); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
281 gui_.addMotionCallback (&resizeCallback); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
282 } |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
283 } else { // window is being moved |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
284 xDrag = cx - x; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
285 yDrag = cy - y; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
286 |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
287 gui_.addClickCallback (&endCallback); |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
288 gui_.addMotionCallback (&moveCallback); |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
289 } |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
290 } |
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
|
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 |
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 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
|
294 // 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
|
295 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
|
296 |
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 // 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
|
298 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
|
299 } |
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
|
300 //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
|
301 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
302 private: |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
303 alias IRenderer.BorderDimensions BorderDimensions; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
304 alias IRenderer.BORDER_TYPES BORDER_TYPES; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
305 |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
306 //BEGIN Window moving and resizing |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
307 void moveCallback (ushort cx, ushort cy) { |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
308 setPosition (cx-xDrag, cy-yDrag); |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
309 } |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
310 void resizeCallback (ushort cx, ushort cy) { |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
311 if (resizeType & RESIZE.L) { |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
312 int mw, nw; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
313 getMinimalSize (mw, nw); // (only want mw) |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
314 nw = xDrag - cx; |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
315 if (nw < mw) nw = mw; // clamp |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
316 mw = x + w - nw; // reuse |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
317 setSize (nw, h); |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
318 setPosition (mw, y); |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
319 } |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
320 else if (resizeType & RESIZE.R) { |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
321 setSize (xDrag + cx, h); |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
322 setPosition (x, y); |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
323 } |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
324 if (resizeType & RESIZE.T) { |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
325 int mh, nh; |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
326 getMinimalSize (nh, mh); |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
327 nh = yDrag - cy; |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
328 if (nh < mh) nh = mh; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
329 mh = y + h - nh; |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
330 setSize (w, nh); |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
331 setPosition (x, mh); |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
332 } |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
333 else if (resizeType & RESIZE.B) { |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
334 setSize (w, yDrag + cy); |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
335 setPosition (x, y); |
38
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 } |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
338 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
|
339 if (b == 1 && state == false) { |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
340 // 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
|
341 // 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
|
342 gui_.removeCallbacks (cast(void*) this); |
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
343 } |
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
344 } |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
345 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
|
346 enum RESIZE : ubyte { |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
347 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
|
348 } |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
349 RESIZE resizeType; // Type of current resize |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
350 //END Window moving and resizing |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
351 |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
352 // Load/save data: |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
353 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
|
354 //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
|
355 // Data used for saving and loading (null in between): |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
356 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
|
357 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
|
358 |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
359 IGui gui_; // The gui managing this window |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
360 IRenderer rend; // The window's renderer |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
361 |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
362 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
|
363 |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 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
|
368 int mw = -1, mh = -1; // minimal size |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
369 |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
370 BorderDimensions border; // Total border size (move plus resize) |
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
371 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
|
372 } |