comparison mde/gui/widget/Widget.d @ 32:316b0230a849

Lots more work on the GUI. Also renamed lots of files. Lots of changes to the GUI. Renderer is now used exclusively for rendering and WidgetDecoration is gone. Renamed lots of files to conform to case policies. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 30 Apr 2008 18:05:56 +0100
parents
children 6b4116e6355c
comparison
equal deleted inserted replaced
31:baa87e68d7dc 32:316b0230a849
1 /* LICENSE BLOCK
2 Part of mde: a Modular D game-oriented Engine
3 Copyright © 2007-2008 Diggory Hardy
4
5 This program is free software: you can redistribute it and/or modify it under the terms
6 of the GNU General Public License as published by the Free Software Foundation, either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16 /// GUI Widget module.
17 module mde.gui.widget.Widget;
18
19 public import mde.gui.widget.Ifaces;
20 import mde.gui.exception;
21
22 import gl = mde.gl.basic;
23
24 import tango.io.Stdout;
25
26 /** A base widget class. Widgets need not inherit this (they only need implement IWidget), but this
27 * class provides a useful basic implementation for widgets.
28 *
29 * Do not use directly (i.e. only for inheriting from).
30 */
31 class Widget : IWidget
32 {
33 /** Basic draw method: draw the background */
34 void draw (int x, int y) {
35 window.renderer.drawWidgetBack (x,y, w,h);
36 }
37
38 /** Dummy event method (ignore) */
39 void clickEvent (ushort cx, ushort cy, ubyte b, bool state) {}
40
41 /** Minimum size is zero. */
42 void getMinimumSize (out int w, out int h) {} // w,h initialised to 0
43 /** Current size. */
44 void getCurrentSize (out int w, out int h) {
45 w = this.w;
46 h = this.h;
47 }
48
49 protected:
50 IWindow window; // the enclosing window
51 int w, h; // size
52 }
53
54 //BEGIN Widgets
55 /// Draws a box. That's it.
56 class BoxWidget : Widget
57 {
58 this (IWindow wind, IParentWidget, int[] data) {
59 if (data.length != 2) throw new WidgetDataException;
60
61 window = wind;
62
63 w = data[0];
64 h = data[1];
65 }
66 void draw (int x, int y) {
67 gl.setColor(1f,0f,0f);
68 window.renderer.drawBox (x,y, w,h);
69 }
70 }
71
72 /// First interactible widget
73 class ButtonWidget : Widget
74 {
75 bool pushed = false;// true if button is pushed in
76
77 this (IWindow wind, IParentWidget, int[] data) {
78 if (data.length != 2) throw new WidgetDataException;
79
80 window = wind;
81
82 w = data[0];
83 h = data[1];
84 }
85
86 void draw (int x, int y) {
87 if (pushed)
88 gl.setColor (1f, 0f, 1f);
89 else
90 gl.setColor (.6f, 0f, .6f);
91 window.renderer.drawBox (x,y, w,h);
92 }
93
94 void getMinimumSize (out int w, out int h) {
95 w = this.w; // button is not resizable
96 h = this.h;
97 }
98
99 void clickEvent (ushort, ushort, ubyte b, bool state) {
100 if (b == 1) pushed = state; // very basic
101 }
102 }
103 //END Widgets