Mercurial > projects > mde
annotate mde/gui/widget/Floating.d @ 103:42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Some tidy-up.
Some name changes, to increase uniformity.
Bug-fix: floating widgets of fixed size could previously be made larger than intended from config dimdata.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 25 Nov 2008 18:01:44 +0000 |
parents | 5de5810e3516 |
children | 1655693702fc |
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 |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
16 /** The Window class. Becoming a widget. */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
17 module mde.gui.widget.Floating; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
19 import mde.gui.widget.Widget; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
20 import mde.gui.exception; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 |
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
|
22 import tango.util.log.Log : Log, Logger; |
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
23 |
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
|
24 private Logger logger; |
6b4116e6355c
Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
25 static this () { |
82
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
26 logger = Log.getLogger ("mde.gui.widget.Floating"); |
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
|
27 } |
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 |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
29 /** An area to contain floating widgets. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
30 * |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
31 * The position of each sub-widget is set from dimension data, but not the size. |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
32 * Rationale: parents' need to set subwidgets' positions when its position is set, so it needs to |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
33 * know their positions. |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
34 * |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
35 * Data: Each string item is interpreted as a subwidget widgetID. |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
36 * Ints supplied may consist of just the widget type or |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
37 * additionally an (x,y) coordinate for each subwidget (all x coords first, then all y coords). |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
38 */ |
95
2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
92
diff
changeset
|
39 class FloatingAreaWidget : AParentWidget |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 { |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
41 this (IWidgetManager mgr, widgetID id, WidgetData data) { |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
42 if (data.ints.length != 1 + data.strings.length) |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
43 throw new WidgetDataException (this); |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
44 |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
45 subWidgets.length = data.strings.length; // widgets created from string data |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
46 sWOrder.length = subWidgets.length; |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
47 sWData.length = subWidgets.length; |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
48 foreach (i,s; data.strings) { |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
49 subWidgets[i] = mgr.makeWidget (s); |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
50 sWOrder[i] = i; |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
51 sWData[i].borderType = cast(BTYPE) data.ints[i+1]; |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
52 } |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
53 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
54 wdim[] dd = mgr.dimData (id); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
55 if (dd.length == subWidgets.length * 4) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
56 foreach (i, ref d; sWData) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
57 (&d.x)[0..4] = dd[i*4..i*4+4]; |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
58 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
59 |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
60 super (mgr, id, data); |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
61 } |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
62 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
63 void finalize () { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
64 foreach (i, ref d; sWData) with (d) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
65 auto widg = subWidgets[i]; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
66 d.border = mgr.renderer.getBorder (borderType, widg.isWSizable, widg.isHSizable); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
67 mw = widg.minWidth + border.x1 + border.x2; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
68 mh = widg.minHeight + border.y1 + border.y2; |
103
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
99
diff
changeset
|
69 if (w < mw || !widg.isWSizable) w = mw; |
42e241e7be3e
ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
99
diff
changeset
|
70 if (h < mh || !widg.isHSizable) h = mh; |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
71 widg.setWidth (w - border.x1 - border.x2, -1); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
72 widg.setHeight (h - border.y1 - border.y2, -1); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
73 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
74 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
75 |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
76 bool saveChanges () { |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
77 wdim[] dd = new wdim[sWData.length*4]; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
78 foreach (i, ref d; sWData) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
79 subWidgets[i].saveChanges (); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
80 dd[4*i..4*i+4] = (&d.x)[0..4]; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
81 } |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
82 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
83 mgr.setDimData (id, dd); // save positions |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
84 return true; |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
85 } |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
86 |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
87 void setWidth (wdim nw, int) { |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
88 w = nw; |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
89 // check all floating widgets are visible |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
90 foreach (i, ref d; sWData) with (d) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
91 if (x + w > this.w) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
92 x = (w > this.w) ? 0 : this.w - w; |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
93 } |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
94 } |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
95 void setHeight (wdim nh, int) { |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
96 h = nh; |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
97 foreach (i, ref d; sWData) with (d) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
98 if (y + h > this.h) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
99 y = (h > this.h) ? 0 : this.h - h; |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
100 } |
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
|
101 } |
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
|
102 |
92
085f2ca31914
Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
103 bool isWSizable () { return true; } |
085f2ca31914
Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
104 bool isHSizable () { return true; } |
085f2ca31914
Shared alignments supported in more complex cases.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
105 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
106 void setPosition (wdim nx, wdim ny) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
107 x = nx; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
108 y = ny; |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
109 |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
110 size_t n = subWidgets.length; |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
111 foreach (i, ref d; sWData) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
112 subWidgets[i].setPosition (x + d.x + d.border.x1, y + d.y + d.border.y1); |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
113 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
114 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
115 void draw () { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
116 super.draw; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
117 |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
118 mgr.renderer.restrict (x,y, w,h); |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
119 foreach (i; sWOrder) |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
120 with (sWData[i]) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
121 mgr.renderer.drawWindow (&border, this.x + x, this.y + y, w, h); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
122 subWidgets[i].draw; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
123 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
124 mgr.renderer.relax; |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
125 } |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
126 |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
127 IChildWidget getWidget (wdim cx, wdim cy) { |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
128 debug scope (failure) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
129 logger.warn ("getWidget: failure; values: click, pos, width - {}, {}, {} - {}, {}, {}", cx, x, w, cy, y, h); |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
130 debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)"); |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
131 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
132 foreach_reverse (j,i; sWOrder) with (sWData[i]) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
133 wdim lx = cx - (this.x + x); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
134 wdim ly = cy - (this.y + y); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
135 if (lx >= 0 && lx < w && |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
136 ly >= 0 && ly < h) |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
137 { |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
138 sWOrder[j..$-1] = sWOrder[j+1..$].dup; |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
139 sWOrder[$-1] = i; |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
140 mgr.requestRedraw; |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
141 if (lx >= border.x1 && lx < w-border.x2 && |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
142 ly >= border.y1 && ly < h-border.y2) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
143 return subWidgets[i].getWidget (cx,cy); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
144 event = i; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
145 return this; |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
146 } |
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
147 } |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
148 event = size_t.max; |
96
dbf332403c6e
Improvements to FloatingAreaWidget: positioning, passing click events and draw order.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
95
diff
changeset
|
149 return this; // no match |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
150 } |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
151 |
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
|
152 int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) { |
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
|
153 if (event > subWidgets.length) return 0; |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
154 if (b == 1 && state == true) { |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
155 active = event; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
156 with (sWData[active]) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
157 resizeType = border.getResize (cx - this.x - x, cy - this.y - y, w,h); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
158 alias border.RESIZE RESIZE; |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
159 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
160 if (resizeType != RESIZE.NONE) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
161 // Set x/yDrag (unfortunately these need to be different for each edge) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
162 if (resizeType & RESIZE.X1) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
163 xDrag = w + cx; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
164 else if (resizeType & RESIZE.X2) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
165 xDrag = w - cx; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
166 |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
167 if (resizeType & RESIZE.Y1) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
168 yDrag = h + cy; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
169 else if (resizeType & RESIZE.Y2) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
170 yDrag = h - cy; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
171 |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
172 mgr.addClickCallback (&endCallback); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
173 mgr.addMotionCallback (&resizeCallback); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
174 } else if (borderType & BTYPE.MOVE) { // window is being moved |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
175 xDrag = cx - x; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
176 yDrag = cy - y; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
177 |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
178 mgr.addClickCallback (&endCallback); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
179 mgr.addMotionCallback (&moveCallback); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
180 } |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
181 } |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
182 } |
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
|
183 return 0; |
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
|
184 } |
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
|
185 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
186 protected: |
58
d43523ed4b62
Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
46
diff
changeset
|
187 void moveCallback (wdabs cx, wdabs cy) { |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
188 with (sWData[active]) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
189 x = cx-xDrag; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
190 y = cy-yDrag; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
191 |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
192 if (x < 0) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
193 x = 0; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
194 else if (x + w > this.w) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
195 x = (w > this.w) ? 0 : this.w - w; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
196 if (y < 0) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
197 y = 0; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
198 else if (y + h > this.h) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
199 y = (h > this.h) ? 0 : this.h - h; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
200 |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
201 subWidgets[active].setPosition (this.x + x + border.x1, this.y + y + border.y1); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
202 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
203 mgr.requestRedraw; |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
204 } |
58
d43523ed4b62
Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
46
diff
changeset
|
205 void resizeCallback (wdabs cx, wdabs cy) { |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
206 with (sWData[active]) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
207 if (resizeType & RESIZE.X1) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
208 wdim ow = w; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
209 w = xDrag - cx; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
210 if (w < mw) w = mw; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
211 x += ow - w; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
212 subWidgets[active].setWidth (w - border.x1 - border.x2, 1); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
213 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
214 else if (resizeType & RESIZE.X2) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
215 w = xDrag + cx; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
216 if (w < mw) w = mw; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
217 subWidgets[active].setWidth (w - border.x1 - border.x2, -1); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
218 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
219 if (resizeType & RESIZE.Y1) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
220 wdim oh = h; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
221 h = yDrag - cy; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
222 if (h < mh) h = mh; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
223 y += oh - h; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
224 subWidgets[active].setHeight (h - border.y1 - border.y2, 1); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
225 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
226 else if (resizeType & RESIZE.Y2) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
227 h = yDrag + cy; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
228 if (h < mh) h = mh; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
229 subWidgets[active].setHeight (h - border.y1 - border.y2, -1); |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
230 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
231 // Reposition widget and sub-widgets: |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
232 subWidgets[active].setPosition (this.x + x + border.x1, this.y + y + border.y1); |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
233 } |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
234 mgr.requestRedraw; |
38
8c4c96f04e7f
Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
37
diff
changeset
|
235 } |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
236 bool endCallback (wdabs, wdabs, ubyte b, bool state) { |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
237 if (b == 1 && state == false) { // end of a move/resize |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
238 mgr.removeCallbacks (cast(void*) this); |
41
b3a6ca4516b4
The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
40
diff
changeset
|
239 return true; // we've handled the up-click |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
240 } |
41
b3a6ca4516b4
The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
40
diff
changeset
|
241 return false; // we haven't handled it |
35
928db3c75ed3
Windows can now be moved.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
242 } |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
38
diff
changeset
|
243 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
244 struct SWData { // NOTE: x,y,w,h must be first elements; search (&d.x) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
245 wdim x,y; // position (corner of border) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
246 wdim w,h; // size (including border) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
247 wdim mw,mh; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
248 BTYPE borderType; // what type of border to put around the widget |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
249 IRenderer.Border border; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
250 } |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
251 static assert (SWData.alignof == 4); // assumptions for optimization; search (&d.x) |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
252 SWData[] sWData; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
253 size_t[] sWOrder; // indexes for draw order (top widget at end of list) |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
254 |
97
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
255 // Click/drag information: |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
256 alias IRenderer.Border.BTYPE BTYPE; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
257 alias IRenderer.Border.RESIZE RESIZE; |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
258 size_t event = size_t.max; // Border with last click/release: size_t.max: main area (no subwidget), i: subwidget[i] |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
259 size_t active = size_t.max; // Like event, but refers to widget being moved/resized |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
260 wdim xDrag, yDrag; // where a drag starts relative to x and y |
30470bc19ca4
Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
96
diff
changeset
|
261 RESIZE resizeType; // Type of current resize |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
262 } |