annotate mde/gui/widget/textContent.d @ 100:0ea4a3e651ae

There is now a position marker for text editing. Changed the way fonts are configured. Actually, not much of the new way exists yet.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 15 Nov 2008 17:39:14 +0000
parents 5de5810e3516
children 71f0f1f83620
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
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
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
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;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** Content widgets based on a text block. */
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 module textContent;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 import mde.gui.widget.Widget;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 import mde.gui.widget.TextWidget;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 import mde.gui.exception;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 import mde.gui.renderer.IRenderer;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import mde.gui.content.Content;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25
100
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
26 debug {
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
27 import tango.util.log.Log : Log, Logger;
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
28 private Logger logger;
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
29 static this () {
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
30 logger = Log.getLogger ("mde.gui.widget.textContent");
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
31 }
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
32 }
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
33
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 class TextContentWidget : ATextWidget
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 {
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 this (IWidgetManager mgr, widgetID id, WidgetData data, IContent c) {
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 WDCheck(data, 1);
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 content = cast(TextContent) c;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 if (!content) content = new TextContent (null, null);
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 //throw new ContentException ();
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 adapter = mgr.renderer.getAdapter (content.toString(0));
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 super (mgr, id, data);
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 /** On click, request keyboard input. */
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 int clickEvent (wdabs, wdabs, ubyte, bool state) {
100
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
48 adapter.setIndex = content.getEditIndex;
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
49 mgr.requestRedraw;
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 return 1; // get keyboard input via keyEvent
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 void keyEvent (ushort s, char[] i) {
100
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
54 adapter.setText = content.keyStroke (s, i);
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
55 adapter.setIndex = content.getEditIndex;
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
56 adapter.getDimensions (mw, mh); // NOTE: only passively change size: next resize will see new minimal size
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 mgr.requestRedraw;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 void keyFocusLost () {
100
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
60 adapter.setIndex;
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 content.endEdit; // update other users of content relying on callbacks
100
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
62 mgr.requestRedraw;
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 }
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 protected:
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 TextContent content;
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 }