Mercurial > projects > mde
annotate mde/gui/widget/TextWidget.d @ 93:08a4ae11454b
Widgets now save dimensions without preventing structural changes in the base config file from applying.
Widget dimensional data separated from other data in files, hence above change.
Moved TextAdapter from TextWidget to IRenderer.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 21 Oct 2008 11:35:15 +0100 |
parents | 4d5d53e4f881 |
children | 9520cc0448e5 |
rev | line source |
---|---|
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
672b6b162a36
Added very basic (and currently useless) content support.
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 |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
672b6b162a36
Added very basic (and currently useless) content support.
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; |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
62
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
16 /** Basic text widget and supporting code for widgets containing text. |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
17 * |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
18 * All content widgets have one (at least for basic content widgets) Content, from |
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
61
diff
changeset
|
19 * mde.gui.content.Items . */ |
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 module mde.gui.widget.TextWidget; |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 import mde.gui.widget.Widget; |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 import mde.gui.exception; |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
24 import mde.gui.renderer.IRenderer; |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
59
diff
changeset
|
25 import mde.gui.content.Content; |
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 |
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
27 /// Basic text widget |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
28 class TextLabelWidget : Widget |
59
672b6b162a36
Added very basic (and currently useless) content support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
29 { |
65
891211f034f2
Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
30 /** Constructor for a widget containing [fixed] content. |
891211f034f2
Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
31 * |
891211f034f2
Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
32 * Widget uses the initialisation data: |
891211f034f2
Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
33 * [widgetID, contentID, colour] |
891211f034f2
Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
34 * where contentID is an ID for the string ID of the contained content |
891211f034f2
Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
35 * and colour is an 8-bit-per-channel RGB colour of the form 0xRRGGBB. */ |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
36 this (IWidgetManager mgr, widgetID id, WidgetData data) { |
77
3dfd934100f7
Continuing widget data changes started in last commit: all previous widgets work again now (but lacking saving).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
37 WDCheck (data, 2, 1); |
93
08a4ae11454b
Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
38 adapter = mgr.renderer.getAdapter (data.strings[0], data.ints[1]); |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
39 adapter.getDimensions (mw, mh); |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
40 super (mgr, id, data); |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
41 } |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
42 |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
43 void draw () { |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
44 super.draw(); |
90
b525ff28774b
Widgets generated dynamically from a list can now be standard widgets selected from data files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
77
diff
changeset
|
45 adapter.draw (x,y); |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
46 } |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
47 |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
48 protected: |
93
08a4ae11454b
Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
49 IRenderer.TextAdapter adapter; |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
65
diff
changeset
|
50 } |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
51 |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
52 /// Basic widget displaying a label from a content. |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
53 class ContentLabelWidget : Widget |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
54 { |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
55 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) { |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
56 WDCheck (data, 3, 0); |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
57 content = c; |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
58 index = data.ints[1]; |
93
08a4ae11454b
Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
59 adapter = mgr.renderer.getAdapter (content.toString(index), data.ints[2]); |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
60 adapter.getDimensions (mw, mh); |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
61 super (mgr, id,data); |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
62 } |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
63 |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
64 void draw () { |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
65 super.draw(); |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
66 adapter.draw (x,y); |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
67 } |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
68 |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
69 protected: |
93
08a4ae11454b
Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
91
diff
changeset
|
70 IRenderer.TextAdapter adapter; |
91
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
71 IContent content; |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
72 int index; |
4d5d53e4f881
Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
90
diff
changeset
|
73 } |