Mercurial > projects > mde
annotate mde/gui/WidgetManager.d @ 85:56c0ddd90193
Intermediate commit (not stable). Changes to init system.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 11 Sep 2008 11:33:51 +0100 |
parents | e0f1ec7fe73a |
children | 79d816b3e2d2 |
rev | line source |
---|---|
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
16 /************************************************************************************************* |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
17 * The gui manager class. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
18 * |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
19 * This is the module to use externally to create a graphical user interface (likely also with |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
20 * content modules). |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
21 *************************************************************************************************/ |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
22 module mde.gui.WidgetManager; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
24 import mde.gui.WidgetDataSet; |
34
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
25 import mde.gui.widget.Ifaces; |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
26 import mde.gui.renderer.createRenderer; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
27 |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
28 // For adding the input event callbacks and requesting redraws: |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
29 import imde = mde.imde; |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
30 import mde.input.Input; |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
31 import mde.scheduler.Scheduler; |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
32 import mde.setup.Screen; |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
33 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
34 import tango.core.sync.Mutex; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 import tango.util.log.Log : Log, Logger; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
37 private Logger logger; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
38 static this () { |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
39 logger = Log.getLogger ("mde.gui.WidgetManager"); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
42 /************************************************************************************************* |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
43 * The widget manager. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
44 * |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
45 * This is responsible for loading and saving an entire gui (although more than one may exist), |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
46 * controlling the rendering device (e.g. the screen or a texture), and providing user input. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
47 * |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
48 * Currently mouse coordinates are passed to widgets untranslated. It may make sense to translate |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
49 * them and possibly drop events for some uses, such as if the gui is drawn to a texture. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
50 * |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
51 * Aside from the IWidgetManager methods, this class should be thread-safe. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
52 *************************************************************************************************/ |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
53 class WidgetManager : WidgetLoader, Screen.Drawable { |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
54 /** Construct a new widget manager. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
55 * |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
56 * params: |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
57 * fileName = Name of file specifying the gui, excluding path and extension. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
58 */ |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
59 this (char[] file) { |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
60 super(file); |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
61 |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
62 Screen.addDrawable (this); |
84
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
63 } |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
64 |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
65 // NOTE - temporarily here to allow CTOR to run safely during static this |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
66 // called during init |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
67 void init () { |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
68 // Doesn't need a lock - cannot conflict with other class functions. |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
69 // Events we want to know about: |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
70 imde.input.addMouseClickCallback(&clickEvent); |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
71 imde.input.addMouseMotionCallback(&motionEvent); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
72 } |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
73 |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
74 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
75 /** Draw the gui. */ |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
76 void draw() { |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
77 debug logger.trace ("drawing; w,h = {},{}",w,h); |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
78 synchronized(mutex) |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
79 if (child) |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
80 child.draw; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
81 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
82 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
83 |
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
|
84 /** For mouse click events. |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
85 * |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
86 * Sends the event on to the relevant windows and all click callbacks. */ |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
87 void clickEvent (ushort cx, ushort cy, ubyte b, bool state) { |
43
1530d9c04d4d
Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
41
diff
changeset
|
88 debug scope (failure) |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
89 logger.warn ("clickEvent: failed!"); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
90 mutex.lock; |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
91 scope(exit) mutex.unlock; |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
92 if (child is null) return; |
58
d43523ed4b62
Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
93 |
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
|
94 // NOTE: buttons receive the up-event even when drag-callbacks are in place. |
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
|
95 foreach (dg; clickCallbacks) |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
96 // See IWidgetManager.addClickCallback's documentation: |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
97 if (dg (cast(wdabs)cx, cast(wdabs)cy, b, state)) return; |
34
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
98 |
76
65780e0e48e6
Re-enabled click event passing in the gui to make ButtonWidget work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
99 // NOTE: do we need to test if the click was on the gui (and thus child)? |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
100 // FIXME: yes, unless we can guarantee this! |
76
65780e0e48e6
Re-enabled click event passing in the gui to make ButtonWidget work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
101 IChildWidget widg = child.getWidget (cast(wdabs)cx,cast(wdabs)cy); |
65780e0e48e6
Re-enabled click event passing in the gui to make ButtonWidget work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
102 if (widg !is null) |
65780e0e48e6
Re-enabled click event passing in the gui to make ButtonWidget work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
103 widg.clickEvent (cast(wdabs)cx,cast(wdabs)cy,b,state); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
104 } |
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
|
105 |
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
106 /** For mouse motion events. |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
107 * |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
108 * Sends the event on to all motion callbacks. */ |
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
|
109 void motionEvent (ushort cx, ushort cy) { |
43
1530d9c04d4d
Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
41
diff
changeset
|
110 debug scope (failure) |
1530d9c04d4d
Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
41
diff
changeset
|
111 logger.warn ("motionEvent: failed!"); |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
112 mutex.lock; |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
113 scope(exit) mutex.unlock; |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
114 |
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
|
115 foreach (dg; motionCallbacks) |
58
d43523ed4b62
Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
116 dg (cast(wdabs)cx, cast(wdabs)cy); |
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
|
117 } |
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
|
118 |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
119 |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
120 void sizeEvent (int nw, int nh) { // Drawable function |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
121 mutex.lock; |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
122 scope(exit) mutex.unlock; |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
123 |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
124 w = cast(wdim) nw; |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
125 h = cast(wdim) nh; |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
126 |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
127 debug logger.trace ("Resize to: {},{}", nw, nh); |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
128 if (w < mw || h < mh) |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
129 logger.warn ("Minimal dimensions ({},{}) not met: ({},{}), but I cannot resize myself!",mw,mh,w,h); |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
130 |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
131 if (!child) return; // if not created yet. |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
132 child.setWidth (w, -1); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
133 child.setHeight (h, -1); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
134 child.setPosition (0,0); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
135 } |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
136 |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
137 //BEGIN IWidgetManager methods |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
138 // These methods are only intended for use within the gui package. They are not necessarily |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
139 // thread-safe. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
140 IRenderer renderer () { |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
141 assert (rend !is null, "WidgetManager.renderer: rend is null"); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
142 return rend; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
143 } |
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
|
144 |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
145 void requestRedraw () { |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
146 imde.mainSchedule.request(imde.SCHEDULE.DRAW); |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
147 } |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
35
diff
changeset
|
148 |
58
d43523ed4b62
Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
149 void addClickCallback (bool delegate(wdabs, wdabs, ubyte, bool) dg) { |
34
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
150 clickCallbacks[dg.ptr] = dg; |
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
151 } |
58
d43523ed4b62
Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
152 void addMotionCallback (void delegate(wdabs, wdabs) dg) { |
34
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
153 motionCallbacks[dg.ptr] = dg; |
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
154 } |
76
65780e0e48e6
Re-enabled click event passing in the gui to make ButtonWidget work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
155 void removeCallbacks (void* frame) { |
65780e0e48e6
Re-enabled click event passing in the gui to make ButtonWidget work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
156 clickCallbacks.remove(frame); |
65780e0e48e6
Re-enabled click event passing in the gui to make ButtonWidget work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
157 motionCallbacks.remove(frame); |
34
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
158 } |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
159 //END IWidgetManager methods |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
160 |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
161 protected: |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
162 /* Second stage of widget loading. |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
163 * Note: sizeEvent should be called with window size before this. */ |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
164 void createRootWidget () { |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
165 // The renderer needs to be created on the first load, but not after this. |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
166 if (rend is null) |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
167 rend = createRenderer (rendName); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
168 |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
169 child = makeWidget ("root"); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
170 |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
171 mw = child.minWidth; |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
172 mh = child.minHeight; |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
173 |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
174 if (w < mw || h < mh) |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
175 logger.warn ("Minimal dimensions ({},{}) not met: ({},{}), but I cannot resize myself!",mw,mh,w,h); |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
176 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
177 child.setWidth (w, -1); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
178 child.setHeight (h, -1); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
179 child.setPosition (0,0); |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
180 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
181 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
182 private: |
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
|
183 // callbacks indexed by their frame pointers: |
58
d43523ed4b62
Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
184 bool delegate(wdabs cx, wdabs cy, ubyte b, bool state) [void*] clickCallbacks; |
d43523ed4b62
Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
47
diff
changeset
|
185 void delegate(wdabs cx, wdabs cy) [void*] motionCallbacks; |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
186 IRenderer rend; |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
74
diff
changeset
|
187 wdim w,h; // area available to the widgets |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
188 wdim mw,mh; // minimal area available to the widgets |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
189 } |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
190 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
191 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
192 import mde.gui.exception; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
193 import mde.gui.widget.Ifaces; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
194 import mde.gui.widget.createWidget; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
195 |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
196 import mde.file.mergetag.Reader; |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
197 import mde.file.mergetag.Writer; |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
198 import mde.setup.paths; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
199 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
200 /************************************************************************************************* |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
201 * Contains the code for loading and saving the gui, but not the code for drawing it or handling |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
202 * user input. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
203 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
204 * This abstract class exists solely for separating out some of the functionality. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
205 *************************************************************************************************/ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
206 abstract scope class WidgetLoader : IWidgetManager |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
207 { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
208 /** Construct a new widget loader. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
209 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
210 * params: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
211 * fileName = Name of file specifying the gui, excluding path and extension. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
212 */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
213 protected this (char[] file) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
214 mutex = new Mutex; // Used on functions intended to be called from outside the gui package. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
215 fileName = file; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
216 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
217 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
218 /* Load the widgets' data from the file specified to the CTOR. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
219 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
220 * params: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
221 * allDesigns = Load all sections |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
222 */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
223 private void loadData (bool allDesigns = false) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
224 if (allLoaded || (defaultDesign !is null && allDesigns == false)) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
225 return; // test if already loaded |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
226 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
227 // Set up a reader |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
228 scope IReader reader; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
229 try { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
230 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_LOW, null, true); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
231 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
232 // Read from the HEADER: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
233 // Get the renderer |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
234 char[]* p = "Renderer" in reader.dataset.header._charA; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
235 if (p is null || *p is null) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
236 logger.warn ("No renderer specified: using \"Simple\""); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
237 rendName = "Simple"; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
238 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
239 else |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
240 rendName = *p; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
241 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
242 // Get which section to use |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
243 p = "Design" in reader.dataset.header._charA; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
244 if (p is null || *p is null) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
245 logger.warn ("No gui design specified: trying \"Default\""); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
246 defaultDesign = "Default"; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
247 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
248 else |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
249 defaultDesign = *p; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
250 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
251 // Read the body: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
252 // Load the chosen design |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
253 reader.dataSecCreator = delegate mt.IDataSection(mt.ID id) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
254 WidgetDataSet* p = id in data; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
255 if (p is null) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
256 data[id] = new WidgetDataSet; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
257 return *(id in data); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
258 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
259 return *p; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
260 }; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
261 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
262 if (allDesigns) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
263 reader.read; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
264 allLoaded = true; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
265 } else |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
266 reader.read([defaultDesign]); |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
267 } catch (NoFileException) { |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
268 logger.error ("Unable to load GUI: no config file!"); |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
269 // just return: not a fatal error (so long as the game can run without a GUI!) |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
270 } catch (Exception e) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
271 logger.error ("Unable to load GUI: errors parsing config file ("~confDir.getFileName(fileName,PRIORITY.HIGH_LOW)~"):"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
272 logger.error (e.msg); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
273 throw new GuiException ("Failure parsing config file"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
274 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
275 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
276 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
277 /** Load the gui from some design. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
278 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
279 * If a design was previously loaded, its changes are saved first. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
280 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
281 * Params: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
282 * name = Design to load. If null, the default will be loaded. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
283 */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
284 void loadDesign (char[] name = null) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
285 if (changes !is null) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
286 save; // own lock |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
287 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
288 mutex.lock; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
289 scope(exit) mutex.unlock; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
290 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
291 // Load data (loadData tests if it's already loaded first): |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
292 if (name is null) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
293 loadData (false); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
294 name = defaultDesign; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
295 } else |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
296 loadData (true); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
297 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
298 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
299 // Get data: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
300 auto p = name in data; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
301 while (p is null) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
302 if (name == defaultDesign) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
303 throw new GuiException ("Unable to load [specified or] default design"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
304 name = defaultDesign; // try again with the default |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
305 p = name in data; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
306 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
307 curData = *p; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
308 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
309 // Get/create a changes section: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
310 if (changesDS is null) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
311 changesDS = new mt.DataSet; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
312 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
313 mt.IDataSection* q = name in changesDS.sec; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
314 if (q && ((changes = cast(WidgetDataChanges) *q) !is null)) {} |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
315 else { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
316 changes = new WidgetDataChanges (curData); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
317 changesDS.sec[name] = changes; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
318 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
319 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
320 // Create the widgets: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
321 createRootWidget; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
322 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
323 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
324 /** Save changes, if any exist. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
325 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
326 * Is run when the manager is destroyed, but could be run at other times too. */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
327 void save () { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
328 mutex.lock; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
329 scope(exit) mutex.unlock; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
330 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
331 // Make all widgets save any changed data; return if no changes: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
332 if (!child.saveChanges ("root")) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
333 return; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
334 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
335 if (loadUserFile) { // merge entries from user file into current changes |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
336 try { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
337 scope IReader reader = confDir.makeMTReader ( |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
338 fileName, PRIORITY.HIGH_ONLY, changesDS, true); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
339 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
340 // Create if necessary, only corresponding to existing designs read: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
341 reader.dataSecCreator = delegate mt.IDataSection(mt.ID id) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
342 WidgetDataSet* p = id in data; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
343 if (p is null) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
344 throw new Exception ("File has changed since it was loaded!"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
345 return new WidgetDataChanges (*p); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
346 }; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
347 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
348 reader.read; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
349 } catch (NoFileException) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
350 // No user file exists; not an error. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
351 } catch (Exception e) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
352 logger.error ("Error reading "~confDir.getFileName(fileName,PRIORITY.HIGH_ONLY)~" prior to saving:"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
353 logger.error (e.msg); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
354 logger.error ("Overwriting the file."); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
355 // Continue... |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
356 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
357 loadUserFile = false; // don't need to do it again |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
358 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
359 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
360 try { // Save |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
361 IWriter writer; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
362 writer = confDir.makeMTWriter (fileName, changesDS); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
363 writer.write; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
364 } catch (Exception e) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
365 logger.error ("Saving to "~confDir.getFileName(fileName,PRIORITY.HIGH_ONLY)~" failed:"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
366 logger.error (e.msg); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
367 // No point in throwing since it doesn't affect anything else. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
368 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
369 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
370 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
371 /** Get the names of all designs available. */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
372 char[][] designs() { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
373 synchronized(mutex) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
374 loadData (true); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
375 return data.keys; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
376 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
377 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
378 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
379 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
380 /** Create a widget by ID. */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
381 IChildWidget makeWidget (widgetID id, IParentWidget parent = null) { |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
382 debug (mdeWidgets) logger.trace ("Creating widget \""~id~'"'); |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
383 return createWidget (this, curData[id], parent); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
384 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
385 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
386 /** For making changes. */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
387 void setData (widgetID id, WidgetData d) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
388 changes[id] = d; // also updates WidgetDataSet in data. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
389 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
390 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
391 /** Second stage of loading the widgets. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
392 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
393 * loadDesign handles the data; this method needs to: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
394 * --- |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
395 * // 1. Create the root widget: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
396 * child = makeWidget ("root"); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
397 * // 2. Set the setSize, e.g.: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
398 * child.setWidth (child.minWidth, 1); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
399 * child.setHeight (child.minHeight, 1); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
400 * --- |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
401 */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
402 void createRootWidget(); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
403 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
404 protected: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
405 final char[] fileName; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
406 char[] defaultDesign; // The design specified in the file header. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
407 char[] rendName; // Name of renderer; for saving and creating renderers |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
408 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
409 // Loaded data, indexed by design name. May not be loaded for all gui designs: |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
410 scope WidgetDataSet[char[]] data; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
411 private bool allLoaded = false; // applies to data |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
412 WidgetDataSet curData; // Current data |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
413 WidgetDataChanges changes; // Changes for the current design. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
414 scope mt.DataSet changesDS; // changes and sections from user file (used for saving) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
415 bool loadUserFile = true; // still need to load user file for saving? |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
416 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
417 scope IChildWidget child; // The primary widget. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
418 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
419 Mutex mutex; // lock on methods for use outside the package. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
76
diff
changeset
|
420 } |