comparison mde/gui/decoration.d @ 31:baa87e68d7dc

GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup. Removed some circular dependencies which slipped in. As a result, the OpenGL code got separated into different files. Enabled widgets to recieve events. New IParentWidget interface allowing widgets to interact with their parents. New Widget base class. New WidgetDecoration class. New ButtonWidget class responding to events (in a basic way). committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 29 Apr 2008 18:10:58 +0100
parents
children
comparison
equal deleted inserted replaced
30:467c74d4804d 31:baa87e68d7dc
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 /** Widget decoration / rendering code. */
17 module mde.gui.decoration;
18
19 import gl = mde.gl.basic;
20
21 enum TypeFlags
22 {
23 NONE = 0,
24 LAYOUT = 0x10,
25 BUTTON = 0x20
26 }
27
28 /** An attempt at unifying and generally improving apon the looks of Widgets.
29 *
30 * Probably only a stop-gap measure until something better turns up...
31 * Although this could be extended to do the actual rendering, etc.? */
32 class WidgetDecoration {
33 /** Create a decoration for a window. */
34 this () {
35 border = 20;
36 r = g = 0.0f;
37 b = 1.0f;
38 }
39
40 /** Create an appropriate decoration for a Widget. Pass parent. */
41 this (WidgetDecoration parent, TypeFlags flags = TypeFlags.NONE)
42 in {
43 assert (parent !is null, "WidgetDecoration: parent is null");
44 } body {
45 //depth = parent.depth + 1;
46
47 if (flags & TypeFlags.LAYOUT) {
48 if (!(parent.flags & TypeFlags.LAYOUT)) border = 4;
49 r = g = b = 1f;
50 } else if (flags & TypeFlags.BUTTON) {
51 r = b = .6f;
52 g = 0f;
53 } else {
54 r = 1.0f;
55 g = b = 0f; //cast(float) depth % 2;
56 }
57 this.flags = flags;
58 }
59
60 void setColor () {
61 gl.setColor (r,g,b);
62 }
63
64 final:
65 int border; // width of border
66 private:
67 float r,g,b; // colour
68 //int depth; // Window's WidgetDecoration has depth 0; each generation is one step deeper
69 TypeFlags flags;// used by children
70 }