Mercurial > projects > mde
comparison mde/gui/widget/miscWidgets.d @ 45:0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Moved the implementable widgets from mde.gui.widget.Widget to miscWidgets, leaving base widgets in Widget.
Rewrote some of GridLayoutWidget's implementation. Made many operations general to work for either columns or rows. Some optimisations were intended but ended up being removed due to problems.
Allowed layout's to resize from either direction (only with window resizes).
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 22 May 2008 11:34:09 +0100 |
parents | |
children | a98ffb64f066 |
comparison
equal
deleted
inserted
replaced
44:07bd1a09e161 | 45:0fd51d2c6c8a |
---|---|
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 /** Some GUI Miscelaneas widgets. */ | |
17 module mde.gui.widget.miscWidgets; | |
18 | |
19 import mde.gui.widget.Widget; | |
20 import mde.gui.exception; | |
21 import mde.gui.renderer.IRenderer; | |
22 | |
23 import mde.resource.font; | |
24 | |
25 import tango.io.Stdout; | |
26 | |
27 | |
28 /// A fixed-size blank widget. | |
29 class FixedBlankWidget : FixedWidget | |
30 { | |
31 this (IWindow wind, int[] data) { | |
32 if (data.length != 3) throw new WidgetDataException; | |
33 super (wind, data); | |
34 } | |
35 | |
36 void draw () { | |
37 super.draw; | |
38 | |
39 window.renderer.drawBlank (x,y, w,h); | |
40 } | |
41 } | |
42 | |
43 /// A completely resizable blank widget (initial size zero). | |
44 class SizableBlankWidget : SizableWidget | |
45 { | |
46 this (IWindow wind, int[] data) { | |
47 if (data.length != 1) throw new WidgetDataException; | |
48 super (wind, data); | |
49 } | |
50 | |
51 void draw () { | |
52 super.draw; | |
53 | |
54 window.renderer.drawBlank (x,y, w,h); | |
55 } | |
56 } | |
57 | |
58 /// First interactible widget | |
59 class ButtonWidget : FixedWidget | |
60 { | |
61 bool pushed = false; // true if button is pushed in (visually) | |
62 // pushed is not the same as the button being clicked but not yet released. | |
63 // it is whether the mouse is over the button after being clicked. | |
64 | |
65 this (IWindow wind, int[] data) { | |
66 if (data.length != 3) throw new WidgetDataException; | |
67 super (wind, data); | |
68 } | |
69 | |
70 void draw () { | |
71 window.renderer.drawButton (x,y, w,h, pushed); | |
72 } | |
73 | |
74 void clickEvent (ushort, ushort, ubyte b, bool state) { | |
75 if (b == 1 && state == true) { | |
76 pushed = true; | |
77 window.requestRedraw; | |
78 window.gui.addClickCallback (&clickWhileHeld); | |
79 window.gui.addMotionCallback (&motionWhileHeld); | |
80 } | |
81 } | |
82 // Called when a mouse motion/click event occurs while (held == true) | |
83 bool clickWhileHeld (ushort cx, ushort cy, ubyte b, bool state) { | |
84 if (b == 1 && state == false) { | |
85 if (cx >= x && cx < x+w && cy >= y && cy < y+h) // button event | |
86 Stdout ("Button clicked!").newline; | |
87 | |
88 pushed = false; | |
89 window.requestRedraw; | |
90 window.gui.removeCallbacks (cast(void*) this); | |
91 | |
92 return true; | |
93 } | |
94 return false; | |
95 } | |
96 void motionWhileHeld (ushort cx, ushort cy) { | |
97 bool oldPushed = pushed; | |
98 if (cx >= x && cx < x+w && cy >= y && cy < y+h) pushed = true; | |
99 else pushed = false; | |
100 if (oldPushed != pushed) | |
101 window.requestRedraw; | |
102 } | |
103 } | |
104 | |
105 /// Basic text widget | |
106 class TextWidget : Widget | |
107 { | |
108 this (IWindow wind, int[] data) { | |
109 if (data.length != 1) throw new WidgetDataException; | |
110 mw = 100; //FIXME: set properly | |
111 mh = 50; | |
112 super (wind,data); | |
113 } | |
114 | |
115 void draw () { | |
116 super.draw(); | |
117 if (font is null) font = Font.get("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"); | |
118 font.drawStr (x,y, "Text Widget"); | |
119 } | |
120 | |
121 protected: | |
122 static Font font; | |
123 } |