annotate mde/gui/WidgetManager.d @ 169:bc1cf73dc835

Context menu refinements: right button click-drag-release use and closing via buttons.
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 29 Jun 2009 18:55:50 +0200
parents da8d3091fdaf
children e45226d3deae
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
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
16 /******************************************************************************
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
17 * The gui manager class base.
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
18 *
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
19 * This contains most of the code required by a window manager, but does not
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
20 * interact with a screen or get user input. Rendering is handled separately by
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
21 * the renderer anyway.
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
22 *
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
23 * Public non IWidget* methods should be thread-safe.
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
24 *****************************************************************************/
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
25 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
26
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
27 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
28 import mde.gui.widget.Ifaces;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
30 import imde = mde.imde;
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
31 import mde.content.Content;
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
32 import mde.content.ServiceContent;
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
33 debug import mde.content.miscContent; // Debug menu
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
34 debug import mde.content.Debug;
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
35
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
36 // Widgets to create:
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
37 import mde.gui.widget.layout;
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
38 import mde.gui.widget.miscWidgets;
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
39 import mde.gui.widget.TextWidget;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
40 import mde.gui.widget.contentFunctions;
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
41 import mde.gui.widget.miscContent;
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
42 import mde.gui.widget.Floating;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 138
diff changeset
43 import mde.gui.widget.ParentContent;
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
44
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
45 public 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
46 import tango.util.log.Log : Log, Logger;
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
47 import tango.util.container.SortedMap;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 private Logger logger;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 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
51 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
52 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
54 /******************************************************************************
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
55 * Contains the code for loading and saving an entire gui (more than one may
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
56 * exist), but not the code for drawing it or handling user input.
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
57 *
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
58 * Methods in this class are only intended for use within the gui package,
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
59 * either by widgets (the IXXXWidget methods implementing from an interface in
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
60 * widgets.Ifaces.d) or by a derived class (back-end methods doing widget
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
61 * work). None of these methods are intended to be thread-safe when called
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
62 * concurrently on the same WidgetManager instance, but they should be thread-
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
63 * safe for calling on separate instances.
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
64 *
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
65 * This abstract class exists solely for separating out some of the functionality.
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
66 *****************************************************************************/
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 abstract scope class AWidgetManager : IWidgetManager
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
68 {
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
69 /** Construct a new widget manager.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
70 *
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
71 * Params:
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
72 * name = The file name of the config for this GUI (to identify multiple GUIs). */
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
73 protected this (char[] name) {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
74 auto p = "MiscOptions.l10n" in Content.allContent;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
75 assert (p, "MiscOptions.l10n not created!");
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
76 p.addCallback (&reloadStrings);
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
77
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
78 serviceContent = cast (IServiceContent) Content.get ("menus.services");
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
79 assert (Content.get ("menus.services"));
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
80 assert (serviceContent !is null, "Content service menu doesn't exist or has wrong type");
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
81
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
82 debug { // add a debug-mode menu
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
83 auto lWS = new EventContent ("menus.debug."~name~".logWidgetSize");
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
84 lWS.addCallback (&logWidgetSize);
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
85 }
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
86 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
87
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
88 public:
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
89 //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
90 // If call reaches the widget manager there isn't any recursion.
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
91 //NOTE: should be override
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
92 final void recursionCheck (widgetID, IContent) {}
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
93
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
94 override void minWChange (IChildWidget widget, wdim nmw) {
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
95 if (widget !is child) // Usually because widget is a floating widget
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
96 // This may get called from a CTOR, hence we can't check widget is one of popupContext, etc.
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
97 return;
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
98 mw = nmw;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
99 if (w < nmw) {
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
100 child.setWidth (nmw, -1);
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
101 w = nmw;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
102 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
103 child.setPosition (0,0);
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
104 requestRedraw;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
105 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
106 override void minHChange (IChildWidget widget, wdim nmh) {
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
107 if (widget !is child)
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
108 return;
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
109 mh = nmh;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
110 if (h < nmh) {
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
111 child.setHeight (nmh, -1);
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
112 h = nmh;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
113 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
114 child.setPosition (0,0);
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
115 requestRedraw;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
116 }
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 160
diff changeset
117
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 160
diff changeset
118 override bool dropContent (IContent content) {
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 160
diff changeset
119 return false;
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 160
diff changeset
120 }
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
121 //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
122
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
123 //BEGIN IPopupParentWidget methods
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
124 override IPopupParentWidget getParentIPPW () {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
125 return this;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
126 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
127
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
128 override void addChildIPPW (IPopupParentWidget ippw) {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
129 if (childIPPW)
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
130 childIPPW.removedIPPW;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
131 childIPPW = ippw;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
132 requestRedraw;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
133 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
134 override bool removeChildIPPW (IPopupParentWidget ippw) {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
135 if (childIPPW !is ippw) return false;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
136 childIPPW.removedIPPW;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
137 childIPPW = null;
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
138 mAIPPW = MenuPosition.INACTIVE;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
139 requestRedraw;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
140 return false;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
141 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
142
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
143 override void menuActive (MenuPosition mA) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
144 mAIPPW = mA;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
145 if (childIPPW)
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
146 childIPPW.menuActive = mA;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
147 }
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
148 override MenuPosition menuActive () {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
149 return mAIPPW;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
150 }
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
151 override MenuPosition parentMenuActive () {
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
152 return MenuPosition.INACTIVE;
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
153 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
154
169
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
155 override void menuDone () {
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
156 // close context menu, but not childIPPW
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
157 if (childIPPW is null)
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
158 menuActive = MenuPosition.INACTIVE;
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
159 popupContext = null;
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
160 requestRedraw;
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
161 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
162
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
163 override IChildWidget getPopupWidget (wdabs cx, wdabs cy, bool closePopup) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
164 if (popupContext) {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
165 if (popupContext.onSelf (cx, cy))
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
166 return popupContext.getWidget (cx, cy);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
167 if (closePopup) {
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
168 if (childIPPW is null)
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
169 menuActive = MenuPosition.INACTIVE;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
170 popupContext = null;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
171 requestRedraw;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
172 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
173 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
174 if (childIPPW) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
175 IChildWidget ret =
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
176 childIPPW.getPopupWidget (cx, cy, closePopup);
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
177 if (ret) return ret;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
178 if (closePopup) {
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
179 menuActive = MenuPosition.INACTIVE;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
180 removeChildIPPW (childIPPW);
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
181 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
182 }
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
183 return null;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
184 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
185
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
186 override void drawPopup () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
187 if (popupContext)
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
188 popupContext.draw();
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
189 if (dragContentDisplay)
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
190 dragContentDisplay.draw();
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
191 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
192
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
193 debug protected override bool isChild (IPopupParentWidget ippw) {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
194 return ippw is childIPPW;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
195 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
196
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
197 override void removedIPPW () {} // irrelevant
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
198 //END IPopupParentWidget methods
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
199
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
200 //BEGIN IWidgetManager 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
201 override IChildWidget makeWidget (IParentWidget parent, widgetID id, IContent content = null)
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
202 {
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
203 debug assert (parent, "makeWidget: parent is null (code error)");
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
204 debug scope (failure)
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
205 logger.warn ("Creating widget \""~id~"\" failed.");
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
206
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
207 WidgetData data = curData[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
208 if (data.ints.length < 1) {
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
209 logger.error ("No int data; creating a debug 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
210 data.ints = [WIDGET_TYPE.Debug];
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
211 }
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 int type = data.ints[0]; // type is first element of 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
213
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 try {
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
215 // Statically programmed binary search on type, returning a new widget or calling 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
216 // function:
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
217 //pragma (msg, binarySearch ("type", 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
218 mixin (binarySearch ("type", 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
219 // Not returned a new 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
220 logger.error ("Bad widget type: {}; creating a debug widget instead",type);
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
221 } catch (Exception e) {
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
222 logger.error ("Error creating widget: {}; creating a debug widget instead.", e.msg);
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
223 }
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
224
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
225 return new DebugWidget (this, parent, id, data, content);
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
226 }
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
227
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
228 override WidgetData widgetData (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
229 return curData[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 }
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
231 override void widgetData (widgetID id, WidgetData d) {
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
232 changes[id] = d; // also updates WidgetDataSet in 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
233 }
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
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 override wdims dimData (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
236 return curData.dims (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
237 }
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
238 override void dimData (widgetID id, wdims d) {
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
239 changes.setDims(id, d); // also updates WidgetDataSet in 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
240 }
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
241
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
242 IRenderer renderer () {
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
243 assert (rend !is null, "WidgetManager.renderer: rend is null");
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
244 return rend;
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
245 }
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
246
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
247 MenuPosition positionPopup (IChildWidget parent, IChildWidget popup, MenuPosition position = MenuPosition.INACTIVE) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
248 debug assert (parent && popup, "positionPopup: null widget");
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
249 wdim w = popup.width,
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
250 h = popup.height,
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
251 x, y;
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
252 if (position & MenuPosition.ACTIVE) {
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
253 y = parent.yPos; // height flush with top
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
254 if (y+h > this.h) y += parent.height - h; // or bottom
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
255 if (position & MenuPosition.LEFT) { // previously left
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
256 x = parent.xPos - w; // on left
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
257 if (x < 0) {
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
258 x = parent.xPos + parent.width; // on right
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
259 position = MenuPosition.RIGHT;
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
260 }
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
261 } else { // previously right or above/below
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
262 x = parent.xPos + parent.width; // on right
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
263 position = MenuPosition.RIGHT;
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
264 if (x+w > this.w) {
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
265 x = parent.xPos - w; // or left
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
266 position = MenuPosition.LEFT;
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
267 }
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
268 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
269 } else {
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
270 wdim pw = parent.width;
165
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
271 if (popup.minWidth <= pw)
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
272 popup.setWidth (pw, -1); // neatness
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
273 x = parent.xPos; // align on left edge
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
274 if (x+w > this.w) x += pw - w; // align on right edge
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
275 y = parent.yPos + parent.height; // place below
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
276 if (y+h > this.h) y = parent.yPos - h; // or above
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
277 position = MenuPosition.ACTIVE;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
278 }
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
279 if (x < 0) x = 0; // may be placed partially off-screen
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
280 if (y < 0) y = 0;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
281 popup.setPosition (x, y);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
282 //debug logger.trace ("placed popup at {},{}; size: {},{}", x,y, w,h);
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
283 return position;
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
284 }
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
285
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
286 void requestRedraw () {
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
287 imde.mainSchedule.request(imde.SCHEDULE.DRAW);
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
288 }
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
289 //END IWidgetManager 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
290
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
291 debug void logWidgetSize (Content) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
292 logger.trace ("size: {,4},{,4}; minimal: {,4},{,4} - WidgetManager", w,h, mw,mh);
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
293 child.logWidgetSize;
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
294 }
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
295
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
296 protected:
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
297 // These methods are called by derived classes to do the widget-management work
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
298 //BEGIN WidgetManagement methods
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
299 /** Draw all widgets */
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
300 void wmDrawWidgets() {
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
301 if (child)
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
302 child.draw;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
303 if (childIPPW)
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
304 childIPPW.drawPopup;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
305 drawPopup;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
306 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
307
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
308 /** For mouse click events.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
309 *
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
310 * Sends the event on to the relevant windows and all click callbacks. */
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
311 void wmMouseClick (wdabs cx, wdabs cy, ubyte b, bool state) {
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
312 if (child is null) return;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
313
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
314 // Update underMouse to get the widget clicked on
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
315 updateUnderMouse (cx, cy, state);
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
316
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
317 // end of a drag?
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
318 if (dragStart !is null && b == dragButton && state == false) {
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
319 IChildWidget dS = dragStart;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
320 dragStart = null;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
321 dragContentDisplay = null;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
322 requestRedraw;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
323 if (dS.dragRelease (cx, cy, underMouse))
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
324 return;
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
325 }
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
326
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
327 // Disable keyboard input if on another widget:
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
328 if (keyFocus && keyFocus !is underMouse) {
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
329 keyFocus.keyFocusLost;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
330 keyFocus = null;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
331 setLetterCallback (null);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
332 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
333
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
334 // Finally, post the actual event:
169
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
335 if (b == 3 && state) { // right click - open context menu
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
336 if (popupContext !is null) return;
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
337 Content contextContent = cast(Content)underMouse.content;
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
338 if (contextContent is null) return;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
339 // NOTE: Creates new widgets every time; not optimal
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
340 serviceContent.setContent (contextContent);
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
341 popupContext = makeWidget (this, "context", contextContent);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
342 popupContext.setup (0, 3);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
343 positionPopup (underMouse, popupContext);
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
344 menuActive = MenuPosition.ACTIVE;
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
345 requestRedraw;
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
346 } else { // post other button presses to clickEvent
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
347 int ret = underMouse.clickEvent (cast(wdabs)cx,cast(wdabs)cy,b,state);
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
348 if (ret & 1) { // keyboard input requested
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
349 keyFocus = underMouse;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
350 setLetterCallback (&underMouse.keyEvent);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
351 }
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
352 if (ret & 2 && dragStart is null) { // drag events requested
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
353 dragStart = underMouse;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
354 dragButton = b; // currently we allow any button to be used for a drag, but.. ?
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
355 if (ret & 4) {
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
356 IContent c = underMouse.content();
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
357 if (c) { // NOTE: creates a new widget, not optimal
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
358 dragContentDisplay = new DisplayContentWidget (this, this, "dragContentDisplay", WidgetData ([0], []), c);
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
359 dragContentDisplay.setup (0, 3);
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
360 dragX = underMouse.xPos - cx;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
361 dragY = underMouse.yPos - cy;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
362 dragContentDisplay.setPosition (cx + dragX, cy + dragY);
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
363 }
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
364 }
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
365 }
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
366 }
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
367 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
368
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
369 /** For mouse motion events.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
370 *
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
371 * Lock on mutex before calling. Pass new mouse coordinates. */
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
372 void wmMouseMotion (wdabs cx, wdabs cy) {
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
373 updateUnderMouse (cx, cy, false);
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
374
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
375 if (dragStart !is null) {
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
376 dragStart.dragMotion (cx, cy, underMouse);
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
377 if (dragContentDisplay !is null) {
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
378 dragContentDisplay.setPosition (cx + dragX, cy + dragY);
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
379 requestRedraw;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
380 }
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
381 }
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
382 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
383
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
384
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
385 /** A change callback on MiscOptions.l10n content to update widgets.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
386 *
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
387 * Relies on another callback reloading translations to content first! */
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
388 void reloadStrings (Content) {
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
389 synchronized(mutex) {
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
390 if (child is null) return;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
391 child.setup (++setupN, 2);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
392 child.setWidth (w, -1);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
393 child.setHeight (h, -1);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
394 child.setPosition (0,0);
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
395 popupContext.setup (setupN, 2);
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
396 //NOTE: does popupContext need to be re-scaled?
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
397 requestRedraw;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
398 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
399 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
400 // for internal use
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
401 void updateUnderMouse (wdabs cx, wdabs cy, bool closePopup) {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
402 auto oUM = underMouse;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
403 underMouse = getPopupWidget (cx, cy, closePopup);
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
404 if (underMouse is null) {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
405 debug assert (child.onSelf (cx, cy), "WidgetManager: child doesn't cover whole area");
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
406 underMouse = child.getWidget (cx, cy);
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
407 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
408 if (underMouse !is oUM) {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
409 debug assert (oUM && underMouse, "no widget under mouse: error");
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
410 oUM.underMouse (false);
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
411 underMouse.underMouse (true);
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
412 debug if (Debug.logUnderMouse())
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
413 logger.trace ("Widget under mouse: {}", underMouse);
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
414 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
415 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
416
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
417 /// This should be overloaded to set a callback receiving keyboard input.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
418 abstract void setLetterCallback(void delegate(ushort, char[]));
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
419 //END WidgetManagement methods
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: 97
diff changeset
420
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
421 public:
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
422 //BEGIN makeWidget metacode
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
423 private static {
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
424 /// Widget types. Items match widget names without the "Widget" suffix.
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
425 enum WIDGET_TYPE : int {
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
426 FUNCTION = 0x2000, // Function called instead of widget created (no "Widget" appended to fct name)
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
427 TAKES_CONTENT = 0x4000, // Flag indicates widget's this should be passed an IContent reference.
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
428
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
429 // Use widget names rather than usual capitals convention
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
430 Unnamed = 0x0, // Only for use by widgets not created with createWidget
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
431
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
432 // blank: 0x1
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
433 FixedBlank = 0x1,
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
434 SizableBlank = 0x2,
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
435 Debug = TAKES_CONTENT | 0xF,
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
436
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
437 // popup widgets: 0x10
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
438 PopupMenu = TAKES_CONTENT | 0x11,
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
439
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
440 // labels: 0x20
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
441 TextLabel = 0x21,
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
442
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
443 // content functions: 0x30
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
444 editContent = FUNCTION | TAKES_CONTENT | 0x30,
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
445 addContent = FUNCTION | 0x31,
132
264028f4115a Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
446 popupListContent = FUNCTION | TAKES_CONTENT | 0x33,
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
447
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
448 // content widgets: 0x40
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
449 DisplayContent = TAKES_CONTENT | 0x40,
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
450 BoolContent = TAKES_CONTENT | 0x41,
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
451 AStringContent = TAKES_CONTENT | 0x42,
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
452 ButtonContent = TAKES_CONTENT | 0x43,
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 138
diff changeset
453 SliderContent = TAKES_CONTENT | 0x44,
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
454
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
455 GridLayout = TAKES_CONTENT | 0x100,
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
456 ContentList = TAKES_CONTENT | 0x110,
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
457
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
458 FloatingArea = TAKES_CONTENT | 0x200,
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
459 Border = TAKES_CONTENT | 0x204,
125
3e648bc53bde Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
460 Switch = TAKES_CONTENT | 0x210,
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
461 Collapsible = TAKES_CONTENT | 0x214,
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
462 }
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
463
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
464 // Only used for binarySearch algorithm generation; must be ordered by numerical values.
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
465 const char[][] 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
466 "FixedBlank",
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
467 "SizableBlank",
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
468 "TextLabel",
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
469 "addContent",
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
470 "Debug",
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
471 "PopupMenu",
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
472 "DisplayContent",
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
473 "BoolContent",
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
474 "AStringContent",
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
475 "ButtonContent",
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 138
diff changeset
476 "SliderContent",
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
477 "GridLayout",
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
478 "ContentList",
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
479 "FloatingArea",
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
480 "Border",
125
3e648bc53bde Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
481 "Switch",
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
482 "Collapsible",
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
483 "editContent",
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
484 "popupListContent"];
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
485
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
486 /* Generates a binary search algorithm for makeWidget. */
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
487 char[] binarySearch (char[] var, char[][] consts) {
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
488 if (consts.length > 3) {
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
489 return `if (`~var~` <= WIDGET_TYPE.`~consts[$/2 - 1]~`) {` ~
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
490 binarySearch (var, consts[0 .. $/2]) ~
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
491 `} else {` ~
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
492 binarySearch (var, consts[$/2 .. $]) ~
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
493 `}`;
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
494 } else {
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
495 char[] ret;
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
496 foreach (c; consts) {
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
497 ret ~= `if (` ~ var ~ ` == WIDGET_TYPE.` ~ c ~ `) {
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
498 debug (mdeWidgets) logger.trace ("Creating new `~c~`.");
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
499 parent.recursionCheck (id, content);
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
500 static if (WIDGET_TYPE.`~c~` & WIDGET_TYPE.FUNCTION)
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
501 return `~c~` (this, parent, id, data, content);
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
502 else static if (WIDGET_TYPE.`~c~` & WIDGET_TYPE.TAKES_CONTENT)
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
503 return new `~c~`Widget (this, parent, id, data, content);
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
504 else
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
505 return new `~c~`Widget (this, parent, id, 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
506 } else `;
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
507 }
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
508 ret = ret[0..$-6]; // remove last else
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
509 return ret;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
510 }
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
511 }
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
512
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
513 debug { // check items in WIDGETS are listed in order
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
514 char[] WIDGETS_check () {
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
515 char[] ret;
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
516 for (int i = WIDGETS.length-2; i > 0; --i) {
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
517 ret ~= "WIDGET_TYPE."~WIDGETS[i] ~" >= WIDGET_TYPE."~ WIDGETS[i+1];
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
518 if (i>1) ret ~= " || ";
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
519 }
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
520 return ret;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
521 }
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
522 mixin ("static if ("~WIDGETS_check~")
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
523 static assert (false, \"WIDGETS is not in order!\");");
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
524 }
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
525 }
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
526 //END makeWidget metacode
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
527
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: 97
diff changeset
528 protected:
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
529 WidgetDataSet curData; // Current data
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
530 WidgetDataChanges changes; // Changes for the current design.
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
531
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
532 char[] rendName; // Name of renderer; for saving and creating renderers
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
533 IRenderer rend;
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
534
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
535 // Widgets:
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
536 wdim w,h; // current widget size; should be at least (mw,mh) even if not displayable
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
537 wdim mw,mh; // minimal area required by widgets
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: 97
diff changeset
538 scope IChildWidget child; // The primary widget.
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
539 uint setupN; // n to pass to IChildWidget.setup
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: 97
diff changeset
540
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
541 MenuPosition mAIPPW; // IPPW variable
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
542 IPopupParentWidget childIPPW; // child IPPW, if any active
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
543
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
544 // Popup(s) handled directly by AWidgetManager:
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
545 IChildWidget popupContext; // context menu (active if not null)
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
546 IServiceContent serviceContent; // context menu content tree
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
547 IChildWidget dragContentDisplay; // displays dragged content; no interaction
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
548
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
549 IChildWidget dragStart; // if non-null, this widget should receive motion and click-release events
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
550 int dragButton; // index of button in use for drag
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
551 wdrel dragX, dragY; // coordinates of dragged content relative to mouse
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
552
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
553 IChildWidget keyFocus; // widget receiving keyboard input
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
554 IChildWidget underMouse; // widget under the mouse pointer
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
555
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: 97
diff changeset
556 Mutex mutex; // lock on methods for use outside the package.
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
557 }