annotate mde/gui/widget/Widget.d @ 41:b3a6ca4516b4

The renderer now controls which parts of the window border allow resizing. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 13 May 2008 12:02:36 +0100
parents 5132301e9ed7
children 1530d9c04d4d
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
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /// GUI Widget module.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 module mde.gui.widget.Widget;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 public import mde.gui.widget.Ifaces;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 import mde.gui.exception;
41
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 39
diff changeset
21 import mde.gui.renderer.IRenderer;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import tango.io.Stdout;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
25 /** An abstract base widget class.
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 *
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
27 * This abstract class, and the more concrete FixedWidget and ScalableWidget classes provides a
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
28 * useful basic implementation for widgets. Widgets need not inherit these (they only need implement
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
29 * IWidget); they are simply provided for convenience and to promote code reuse. */
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
30 abstract class Widget : IWidget
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 {
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
32 // Base this(); all widgets must at least check data.length is correct.
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
33 this (IWindow wind, int[] data) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
34 window = wind;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
35 widgetType = data[0];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
36 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
37
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
38 // Most widgets don't need to do adjustments based on mutable data, however they usually do
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
39 // still need to set their size.
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
40 int[] adjust (int[] data) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
41 setSize (0,0);
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
42 return data;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
43 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
44
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
45 // Widget type should always be the first value.
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
46 int[] getCreationData () {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
47 return [widgetType];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
48 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
49 // Most widgets don't use mutable data.
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
50 int[] getMutableData () {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
51 return [];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
52 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
53
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
54 void getCurrentSize (out int cw, out int ch) {
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
55 cw = w;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
56 ch = h;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
59 void setPosition (int nx, int ny) {
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
60 x = nx;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
61 y = ny;
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
62 }
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
63
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
64 /* Return self, since we don't have child widgets and the method wouldn't have been called
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
65 * unless the location was over us. Valid for all widgets without children. */
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
66 IWidget getWidget (int,int) {
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
67 return this;
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
68 }
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
69
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
70 /* Dummy event method (widget doesn't respond to events) */
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
71 void clickEvent (ushort cx, ushort cy, ubyte b, bool state) {}
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
72
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
73 /* Basic draw method: draw the background (all widgets should do this) */
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
74 void draw () {
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
75 window.renderer.drawWidgetBack (x,y, w,h);
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
76 }
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
77
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 protected:
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
79 final int widgetType; // the type (stored for saving)
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 IWindow window; // the enclosing window
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
81 int x, y; // position
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
82 int w, h; // size
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 }
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
84 /** A base for fixed-size widgets. */
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
85 class FixedWidget : Widget {
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
86 this (IWindow wind, int[] data) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
87 super (wind, data);
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
88 w = wF = data[1];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
89 h = hF = data[2];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
90 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
91
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
92 int[] getCreationData () {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
93 return [widgetType, wF, hF];
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
94 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
95
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
96 bool isWSizable () { return false; }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
97 bool isHSizable () { return false; }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
98
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
99 /* Not resizable, so return current size. */
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
100 void getMinimalSize (out int mw, out int mh) {
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
101 mw = wF;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
102 mh = hF;
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
103 }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
104
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
105 /* Ignore: a fixed size widget. */
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
106 void setSize (int nw, int nh) {
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
107 w = (nw >= wF ? nw : wF);
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
108 h = (nh >= hF ? nh : hF);
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
109 }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
110
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
111 protected:
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
112 int wF, hF; // The "fixed" size, i.e. the preferred & minimal size
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
113 }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
114 /** A base for resizable widgets. */
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
115 class SizableWidget : Widget {
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
116 this (IWindow wind, int[] data) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
117 super (wind, data);
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
118 }
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
119
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
120 bool isWSizable () { return true; }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
121 bool isHSizable () { return true; }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
122
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
123 /* Return zero. */
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
124 void getMinimalSize (out int mw, out int mh) {}
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
125
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
126 /* Set size: a fully resizable widget. */
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
127 void setSize (int nw, int nh) {
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
128 w = (nw >= 0 ? nw : 0);
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
129 h = (nh >= 0 ? nh : 0);
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
130 }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
131 }
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
132
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
133 //BEGIN Widgets
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
134 /// A fixed-size blank widget.
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
135 class FixedBlankWidget : FixedWidget
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
136 {
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
137 this (IWindow wind, int[] data) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
138 if (data.length != 3) throw new WidgetDataException;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
139 super (wind, data);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
140 }
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
141 }
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
142
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
143 /// A completely resizable blank widget (initial size zero).
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
144 class SizableBlankWidget : SizableWidget
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
145 {
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
146 this (IWindow wind, int[] data) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
147 if (data.length != 1) throw new WidgetDataException;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
148 super (wind, data);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 /// First interactible widget
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
153 class ButtonWidget : FixedWidget
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 {
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
155 bool pushed = false; // true if button is pushed in (visually)
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
156 // pushed is not the same as the button being clicked but not yet released.
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
157 // it is whether the mouse is over the button after being clicked.
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158
39
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
159 this (IWindow wind, int[] data) {
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
160 if (data.length != 3) throw new WidgetDataException;
5132301e9ed7 Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
161 super (wind, data);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
162 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
163
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
164 void draw () {
37
052df9b2fe07 Allowed widget resizing, changed widget IDs and made Input catch any callback exceptions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 36
diff changeset
165 window.renderer.drawButton (x,y, w,h, pushed);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 void clickEvent (ushort, ushort, ubyte b, bool state) {
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
169 if (b == 1 && state == true) {
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
170 pushed = true;
41
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 39
diff changeset
171 window.requestRedraw;
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
172 window.gui.addClickCallback (&clickWhileHeld);
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
173 window.gui.addMotionCallback (&motionWhileHeld);
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
174 }
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
175 }
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
176 // Called when a mouse motion/click event occurs while (held == true)
41
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 39
diff changeset
177 bool clickWhileHeld (ushort cx, ushort cy, ubyte b, bool state) {
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 39
diff changeset
178 //NOTE: which button? test
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
179 if (cx >= x && cx < x+w && cy >= y && cy < y+h) // button event
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
180 Stdout ("Button clicked!").newline;
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
181
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
182 pushed = false;
41
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 39
diff changeset
183 window.requestRedraw;
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 window.gui.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: 39
diff changeset
185
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 39
diff changeset
186 return false;
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
187 }
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
188 void motionWhileHeld (ushort cx, ushort cy) {
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
189 bool oldPushed = pushed;
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
190 if (cx >= x && cx < x+w && cy >= y && cy < y+h) pushed = true;
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
191 else pushed = false;
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 34
diff changeset
192 if (oldPushed != pushed)
41
b3a6ca4516b4 The renderer now controls which parts of the window border allow resizing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 39
diff changeset
193 window.requestRedraw;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
194 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
195 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
196 //END Widgets