annotate mde/gui/widget/Widget.d @ 130:c5c38eaadb64

Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable. Ifaces.IParentWidget.SIZABILITY controlling parent sizability. TextWidget no longer vertically resizable (since multi-line editing is not supported).
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 17 Jan 2009 16:11:26 +0000
parents ad91de8867a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
77
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
16 /*************************************************************************************************
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
17 * GUI Widget module.
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
18 *
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
19 * This module contains some base widget classes suitable for widget classes to inherit. However,
77
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
20 * inheriting one of them is by no means necessary for a widget so long as the IWidget interface
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
21 * is implemented.
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
22 *
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
23 * Abstract widget classes have an 'A' prepended to the name, similar to the 'I' convention for
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
24 * interfaces.
77
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
25 *************************************************************************************************/
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 module mde.gui.widget.Widget;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 public import mde.gui.widget.Ifaces;
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 114
diff changeset
29 import mde.content.Content;
77
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
30 import mde.gui.exception;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
32 debug {
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
33 import tango.util.log.Log : Log, Logger;
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
34 private Logger logger;
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
35 static this () {
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
36 logger = Log.getLogger ("mde.gui.widget.Widget");
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
37 }
77
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
38 }
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
39
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
40
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
41 /*************************************************************************************************
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
42 * An abstract base widget class.
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
43 *
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
44 * This abstract class, and the more concrete FixedWidget and ScalableWidget classes provides a
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
45 * useful basic implementation for widgets. Widgets need not inherit these (they only need
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
46 * implement IWidget); they are simply provided for convenience and to promote code reuse.
3dfd934100f7 Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
47 *************************************************************************************************/
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
48 abstract class AWidget : IChildWidget
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 {
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
50 //BEGIN IParentWidget methods
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
51 // Don't override; use the WIDGET_TYPE.SAFE_RECURSION flag for safe widgets.
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
52 //NOTE: should be override (compiler bug)
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
53 final void recursionCheck (widgetID a) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
54 debug assert (id !is null && parent !is null, "recursionCheck called before parent and id set");
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
55 if (a is id)
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
56 throw new GuiException ("Infite recursion of "~a);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
57 parent.recursionCheck (a);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
58 }
123
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
59
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
60 // Parent widgets need to implement this.
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
61 override void minWChange (IChildWidget widget, wdim mw) {}
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
62 override void minHChange (IChildWidget widget, wdim mh) {}
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
63 //END IParentWidget methods
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
64
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
65 //BEGIN Load and save
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: 66
diff changeset
66 // Base this() for child Widgets.
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
67 protected this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
68 this.mgr = mgr;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
69 this.parent = parent;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
70 this.id = id;
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
71 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
72
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
73 // Widgets need to do their initialization either in this() or setup().
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
74 override bool setup (uint,uint) {
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
75 return false;
92
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
76 }
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
77
78
79a1809421aa Widget data saving reimplemented for the new data system. (Now grid layout widgets remember their row & column sizes.)
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
78 // Don't save any data: fine for many widgets.
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
79 override bool saveChanges () {
78
79a1809421aa Widget data saving reimplemented for the new data system. (Now grid layout widgets remember their row & column sizes.)
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
80 return false;
79a1809421aa Widget data saving reimplemented for the new data system. (Now grid layout widgets remember their row & column sizes.)
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
81 }
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
82 //END Load and save
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
83
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
84 //BEGIN Size and position
130
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
85 // default to not resizable
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
86 override bool isWSizable () {
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
87 return false;
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
88 }
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
89 override bool isHSizable () {
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
90 return false;
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
91 }
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
92
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
93 /* Return minimal/fixed size. */
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
94 override wdim minWidth () {
66
f54ae4fc2b2f Replaced IWidget.getMinimalSize(out w,out h) with minWidth() and minHeight().
Diggory Hardy <diggory.hardy@gmail.com>
parents: 65
diff changeset
95 return mw;
f54ae4fc2b2f Replaced IWidget.getMinimalSize(out w,out h) with minWidth() and minHeight().
Diggory Hardy <diggory.hardy@gmail.com>
parents: 65
diff changeset
96 }
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
97 override wdim minHeight () {
66
f54ae4fc2b2f Replaced IWidget.getMinimalSize(out w,out h) with minWidth() and minHeight().
Diggory Hardy <diggory.hardy@gmail.com>
parents: 65
diff changeset
98 return mh;
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
99 }
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
100
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
101 override wdim width () {
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
102 return w;
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
103 }
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
104 override wdim height() {
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
105 return h;
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
106 }
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
107
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
108 override wdabs xPos () {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
109 return x;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
110 }
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
111 override wdabs yPos () {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
112 return y;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
113 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
114
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
115 /* Set size: minimal size is (mw,mh). Note that both resizable and fixed widgets should allow
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
116 * enlarging, so in both cases this is a correct implementation. */
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
117 override void setWidth (wdim nw, int) {
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
118 debug if (nw < mw) logger.warn ("Widget width set below minimal size");
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
119 w = (nw >= mw ? nw : mw);
46
03fa79a48c48 Fixed resizing bugs in previous commit and made code cleaner and more efficient.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
120 }
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
121 override void setHeight (wdim nh, int) {
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
122 debug if (nh < mh) logger.warn ("Widget height set below minimal size");
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
123 h = (nh >= mh ? nh : mh);
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
124 }
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
125
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
126 override void setPosition (wdim nx, wdim ny) {
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
127 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
128 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
129 }
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
130 //END Size and position
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
131
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
132 //BEGIN Events
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
133 /* This method is only called when the location is over this widget; hence for all widgets
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
134 * without children this method is valid. */
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
135 override IChildWidget getWidget (wdim cx, wdim cy) {
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
136 debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)");
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
137 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
138 }
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
139
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
140 // Should be valid for any widget.
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
141 override bool onSelf (wdabs cx, wdabs cy) {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
142 return cx >= x && cx < x + w && cy >= y && cy < y + h;
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
143 }
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
144
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
145 /* Dummy event method (suitable for all widgets which don't respond to events). */
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
146 override int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) {
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 96
diff changeset
147 return 0;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 96
diff changeset
148 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 96
diff changeset
149
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 96
diff changeset
150 /* Dummy functions: suitable for widgets with no text input. */
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
151 override void keyEvent (ushort, char[]) {}
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
152 override void keyFocusLost () {}
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
153
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
154 // Currently only applies to popup widgets.
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
155 override void highlight (bool state) {}
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
156
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
157 // Only useful to widgets creating popups.
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
158 override void popupClose () {}
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
159 override bool popupParentClick () {
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
160 return true;
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
161 }
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
162 //END Events
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
163
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
164 /* Basic draw method: draw the background (all widgets should do this). */
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
165 override void draw () {
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: 66
diff changeset
166 mgr.renderer.drawWidgetBack (x,y, w,h);
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
167 }
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
168
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
169 // Debug function to print size info. Intended to be correct not optimal.
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
170 debug override void logWidgetSize () {
130
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
171 logger.trace ("Current size: {,4},{,4}; minimal: {,4},{,4}; sizable: {,5},{,5} - {,-50} {}", this.width, this.height, this.minWidth, this.minHeight, this.isWSizable, this.isHSizable, this, id);
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
172 }
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
173
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 protected:
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
175 /**********************************************************************************************
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
176 * Widgets may use W*Check as a utility to check for existance of data. Its use is encouraged,
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
177 * so that the checks can easily be updated should WidgetData be changed.
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
178 *
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
179 * Variants:
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
180 * WDCheck checks the exact length of integer and string data.
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
181 * WDCCheck checks data as WDCheck and that the content passed is valid.
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
182 * WDCMinCheck does the same as WDCCheck, but allows more data than required (used by some
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
183 * generic widgets).
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
184 *
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
185 * Params:
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
186 * data = the WidgetData to check lengths of
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
187 * n_ints = number of integers wanted
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
188 * n_strings= number of strings (default 0 since not all widgets use strings)
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
189 *********************************************************************************************/
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
190 void WDCheck (WidgetData data, size_t n_ints, size_t n_strings = 0) {
103
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
191 if (data.ints.length != n_ints ||
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
192 data.strings.length != n_strings)
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
193 throw new WidgetDataException (this);
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
194 }
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
195 /** ditto */
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
196 void WDCCheck (WidgetData data, size_t n_ints, size_t n_strings, IContent c) {
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
197 if (data.ints.length != n_ints ||
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
198 data.strings.length != n_strings)
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
199 throw new WidgetDataException (this);
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
200 if (c is null)
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
201 throw new ContentException (this);
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
202 }
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
203 /** ditto */
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
204 void WDCMinCheck (WidgetData data, size_t n_ints, size_t n_strings, IContent c) {
103
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
205 if (data.ints.length < n_ints ||
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
206 data.strings.length < n_strings)
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
207 throw new WidgetDataException (this);
112
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
208 if (c is null)
fe061009029d EnumContent; log level can be selected from a popup list.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
209 throw new ContentException (this);
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
210 }
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
211
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
212 IWidgetManager mgr; // the enclosing window
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
213 IParentWidget parent; // the parent widget
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
214 wdim x, y; // position
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 92
diff changeset
215 widgetID id; // The widget's ID, used for saving data
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: 46
diff changeset
216 wdim w, h; // size
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: 46
diff changeset
217 wdim mw = 0, mh = 0; // minimal or fixed size, depending on whether the widget is
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
218 // resizible; both types of widgets should actually be expandable.
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
219 }
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
220
92
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
221 /*************************************************************************************************
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
222 * Abstract base widget classes to facilitate parent widgets.
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
223 *
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
224 * Parent widgets probably need to overload these functions (from AWidget):
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
225 * setup, saveChanges, setPosition, getWidget, draw, setWidth and setHeight.
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
226 *************************************************************************************************/
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
227 abstract class AParentWidget : AWidget
92
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
228 {
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
229 this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
230 super (mgr, parent, id);
92
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
231 }
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
232
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
233 override bool setup (uint n, uint flags) {
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
234 debug (mdeWidgets) logger.trace ("AParentWidget.setup");
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
235 bool c = false;
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
236 foreach (w; subWidgets) {
130
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
237 debug assert (w, "AParentWidget: w is null");
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
238 c |= w.setup (n,flags);
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
239 }
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
240 return c;
92
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
241 }
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
242
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
243 override bool saveChanges () {
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 92
diff changeset
244 bool c = false;
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 92
diff changeset
245 foreach (w; subWidgets)
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 92
diff changeset
246 c |= w.saveChanges;
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 92
diff changeset
247 return c;
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 92
diff changeset
248 }
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 92
diff changeset
249
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
250 size_t getWidgetIndex (IChildWidget widg) {
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
251 foreach (i,w; subWidgets)
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
252 if (w is widg)
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
253 return i;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
254
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
255 throw new GuiException ("getWidgetIndex: widget not found (code error)");
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
256 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
257
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
258 debug override void logWidgetSize () {
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
259 super.logWidgetSize;
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
260 foreach (widg; subWidgets)
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
261 widg.logWidgetSize;
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
262 }
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
263
92
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
264 protected:
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
265 IChildWidget[] subWidgets;
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
266 }
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
267 /** ditto */
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
268 abstract class AParentSingleWidget : AWidget
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
269 {
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
270 this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
271 super (mgr, parent, id);
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
272 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
273
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
274 override bool setup (uint n, uint flags) {
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
275 debug (mdeWidgets) logger.trace ("AParentSingleWidget.setup");
130
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
276 debug assert (subWidget, "AParentSingleWidget: subWidget is null");
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
277 return subWidget.setup (n,flags);
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
278 }
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
279
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
280 override bool saveChanges () {
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
281 return subWidget.saveChanges;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
282 }
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
283
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
284 debug override void logWidgetSize () {
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
285 super.logWidgetSize;
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
286 subWidget.logWidgetSize;
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
287 }
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
288
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
289 protected:
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
290 IChildWidget subWidget;
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
291 }
92
085f2ca31914 Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 91
diff changeset
292
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
293 /** A base for fixed-size widgets taking their size from the creation data. */
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
294 class FixedWidget : AWidget {
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
295 // Check data.length is at least 3 before calling!
65
891211f034f2 Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 58
diff changeset
296 /** Constructor for a fixed-size [blank] widget.
891211f034f2 Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 58
diff changeset
297 *
891211f034f2 Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 58
diff changeset
298 * Widget uses the initialisation data:
891211f034f2 Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 58
diff changeset
299 * [widgetID, w, h]
891211f034f2 Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 58
diff changeset
300 * where w, h is the fixed size. */
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
301 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
302 super (mgr, parent, id);
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
303 w = mw = cast(wdim) data.ints[1];
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
304 h = mh = cast(wdim) data.ints[2];
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
305 }
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
306 }
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: 66
diff changeset
307
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
308 /** A base for resizable widgets. */
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
309 class SizableWidget : AWidget {
45
0fd51d2c6c8a Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 44
diff changeset
310 // Check data.length is at least 1 before calling!
65
891211f034f2 Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 58
diff changeset
311 /// Constructor for a completely resizable [blank] widget.
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
312 this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
313 super (mgr, parent, id);
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
314 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
315
130
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
316 override bool isWSizable () {
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
317 return true;
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
318 }
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
319 override bool isHSizable () {
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
320 return true;
c5c38eaadb64 Changed how sizability is set for parents: can require all sub-widgets resizable or only one to set parent resizable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
321 }
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
322 }
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
323
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
324 /** For pressable buttons.
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
325 *
96
dbf332403c6e Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
326 * Overriding classes should implement this() (setting the size), draw() and activated(). */
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
327 abstract class AButtonWidget : AWidget
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
328 {
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
329 protected this (IWidgetManager mgr, IParentWidget parent, widgetID id) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
330 super (mgr, parent, id);
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
331 }
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
332
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
333 /// May be over-ridden. Pushed is true if the button has been pushed and not released.
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
334 override void draw () {
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
335 mgr.renderer.drawButton (x,y, w,h, pushed);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
336 }
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
337
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
338 /// Handles the down-click
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
339 override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
340 if (b == 1 && state == true) {
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
341 pushed = true;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
342 mgr.requestRedraw;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
343 mgr.addClickCallback (&clickWhilePushed);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
344 mgr.addMotionCallback (&motionWhilePushed);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
345 }
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 96
diff changeset
346 return 0;
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
347 }
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
348
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
349 /// Called when a mouse click event occurs while held; handles up-click
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
350 bool clickWhilePushed (wdabs cx, wdabs cy, ubyte b, bool state) {
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
351 if (b == 1 && state == false) {
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
352 if (cx >= x && cx < x+w && cy >= y && cy < y+h) // button event
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
353 activated();
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
354
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
355 pushed = false;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
356 mgr.requestRedraw;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
357 mgr.removeCallbacks (cast(void*) this);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
358
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
359 return true;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
360 }
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
361 return false;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
362 }
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
363 /// Called when a mouse motion event occurs while held; handles pushing in/out on hover
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
364 void motionWhilePushed (wdabs cx, wdabs cy) {
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
365 bool oldPushed = pushed;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
366 if (cx >= x && cx < x+w && cy >= y && cy < y+h) pushed = true;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
367 else pushed = false;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
368 if (oldPushed != pushed)
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
369 mgr.requestRedraw;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
370 }
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
371
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
372 /// The action triggered when the button is clicked...
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
373 void activated ();
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
374
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
375 protected:
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
376 bool pushed = false; /// True if button is pushed in (visually)
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 93
diff changeset
377 }