comparison mde/gui/widget/createWidget.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.createWidget;
18
19 // Widgets to create:
20 import mde.gui.widget.layout;
21 import mde.gui.widget.Widget;
22
23 import mde.gui.exception : WidgetDataException;
24
25 //BEGIN createWidget
26 /// Widget types. Start high so they can be reordered easily later.
27 enum WIDGET_TYPE : int {
28 BOX = 1001, GRID, BUTTON
29 }
30
31 /** Create a widget of type data[0] (see enum WIDGET_TYPES) for _window window, with initialisation
32 * data [1..$]. */
33 IWidget createWidget (IWindow window, IParentWidget parent, int[] data)
34 in {
35 assert (window !is null, "createWidget: window is null");
36 assert (parent !is null, "createWidget: parent is null");
37 } body {
38 if (data.length < 1) throw new WidgetDataException ("No widget data");
39 int type = data[0]; // type is first element of data
40 data = data[1..$]; // the rest is passed to the Widget
41
42 if (type == WIDGET_TYPE.BOX) return new BoxWidget (window, parent, data);
43 else if (type == WIDGET_TYPE.GRID) return new GridWidget (window, parent, data);
44 else if (type == WIDGET_TYPE.BUTTON) return new ButtonWidget (window, parent, data);
45 else throw new WidgetDataException ("Bad widget type");
46 }
47 //END createWidget