Mercurial > projects > mde
annotate mde/content/AStringContent.d @ 105:08651e8a8c51
Quit button, big changes to content system.
Moved mde.gui.content to mde.content to reflect it's not only used by the gui.
Split Content module into Content and AStringContent.
New AContent and EventContent class.
Callbacks are now generic and implemented in AContent.
Renamed TextContent to StringContent and ValueContent to AStringContent.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 29 Nov 2008 12:36:39 +0000 |
parents | |
children | fe061009029d |
rev | line source |
---|---|
105
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
08651e8a8c51
Quit button, big changes to content system.
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 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
08651e8a8c51
Quit button, big changes to content system.
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; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /** The content system − string-based editable content. |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 module mde.content.AStringContent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
19 public import mde.content.Content; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 //FIXME: efficient conversions? Need to dup result when formatting a string anyway? |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 import Int = tango.text.convert.Integer; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 import Float = tango.text.convert.Float; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
24 import derelict.sdl.keysym; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
25 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 debug { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
27 import tango.util.log.Log : Log, Logger; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
28 private Logger logger; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
29 static this () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
30 logger = Log.getLogger ("mde.content.AStringContent"); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
33 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
34 // Used by Options |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 template ContentN(T) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 static if (is(T == bool)) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
37 const char[] ContentN = "BoolContent"; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
38 } else static if (is(T == int)) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
39 const char[] ContentN = "IntContent"; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 } else static if (is(T == double)) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 const char[] ContentN = "DoubleContent"; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
42 } else static if (is(T == char[])) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
43 const char[] ContentN = "StringContent"; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
44 } else |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
45 static assert (false, "No Content of type "~T.stringof); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
46 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
48 /** Base class for content containing a simple value editable as text. All content types used by |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
49 * Options extend this class. |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
50 * |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
51 * All derived classes should have the following functions: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
52 * --- |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 * void endEdit (); // Should convert sv and assign to self, then call endEvent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
54 * // Used by Options: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
55 * BoolContent changeCb (void delegate (char[] symbol,T value) cb); // The callback used by Options |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
56 * void assignNoCb (T val); // assign val, but without calling callbacks |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
57 * --- |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
58 * On any assignation (by this, assignNoCb, opAssign) the value should be converted to a string and |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
59 * assigned to sv, and pos should be clamped to [0,sv.length] (i.e. enforce pos <= sv.length). */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
60 abstract class AStringContent : AContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
61 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
62 protected this (char[] symbol) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
63 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
64 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
65 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
66 /// Get the text. |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
67 char[] toString (uint i) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
68 return i == 0 ? sv |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
69 : i == 1 ? name_ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
70 : i == 2 ? desc_ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
71 : null; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
72 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
73 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
74 /** Acts on a keystroke and returns the new value. |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
75 * |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
76 * Supports one-line editing: left/right, home/end, backspace/delete. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
77 char[] keyStroke (ushort sym, char[] i) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
78 debug assert (i.length, "StringContent.keyStroke: no value (??)"); // impossible? |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
79 char k = *i; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
80 if (k > 0x20) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
81 if (k == 0x7f) { // delete |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
82 size_t p = pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
83 if (p < sv.length) ++p; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
84 while (p < sv.length && (sv[p] & 0x80) && !(sv[p] & 0x40)) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
85 ++p; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
86 sv = sv[0..pos] ~ sv[p..$]; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
87 } else { // insert character |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
88 char[] tail = sv[pos..$]; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
89 sv.length = sv.length + i.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
90 size_t npos = pos+i.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
91 if (tail) sv[npos..$] = tail.dup; // cannot assign with overlapping ranges |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
92 sv[pos..npos] = i; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
93 pos = npos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
94 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
95 } else { // use sym; many keys output 0 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
96 if (sym == SDLK_BACKSPACE) { // backspace; k == 0x8 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
97 char[] tail = sv[pos..$]; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
98 if (pos) --pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
99 while (pos && (sv[pos] & 0x80) && !(sv[pos] & 0x40)) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
100 --pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
101 sv = sv[0..pos] ~ tail; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
102 } else if (sym == SDLK_LEFT) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
103 if (pos) --pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
104 while (pos && (sv[pos] & 0x80) && !(sv[pos] & 0x40)) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
105 --pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
106 } else if (sym == SDLK_RIGHT) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
107 if (pos < sv.length) ++pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
108 while (pos < sv.length && (sv[pos] & 0x80) && !(sv[pos] & 0x40)) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
109 ++pos; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
110 } else if (sym == SDLK_HOME || sym == SDLK_UP) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
111 pos = 0; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
112 } else if (sym == SDLK_END || sym == SDLK_DOWN) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
113 pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
114 } else |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
115 debug logger.trace ("Unhandled symbol: {}", sym); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
116 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
117 return sv; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
118 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
119 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
120 /// Get the character the edit cursor is in front of |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
121 size_t editIndex () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
122 size_t i = 0; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
123 for (size_t p = 0; p < pos; ++p) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
124 if (!(sv[p] & 0x80) || sv[p] & 0x40) |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
125 ++i; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
126 return i; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
127 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
128 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
129 /// Call after editing a string |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
130 void endEdit (); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
131 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
132 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
133 char[] sv; // string of value; updated on assignment for displaying and editing |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
134 size_t pos; // editing position; used by keyStroke |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
135 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
136 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
137 class BoolContent : AStringContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
138 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
139 /** Create a content with _symbol name symbol. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
140 this (char[] symbol, bool val = false) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
141 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
142 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
143 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
144 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
145 void assignNoCb (bool val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
146 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
147 sv = v ? "true" : "false"; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
148 if (pos > sv.length) pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
149 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
150 void opAssign (bool val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
151 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
152 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
153 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
154 bool opCall () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
155 return v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
156 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
157 alias opCall opCast; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
158 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
159 override void endEdit () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
160 v = sv && (sv[0] == 't' || sv[0] == 'T' || sv[0] == '1'); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
161 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
162 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
163 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
164 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
165 bool v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
166 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
167 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
168 /** Text content. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
169 class StringContent : AStringContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
170 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
171 this (char[] symbol, char[] val = null) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
172 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
173 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
174 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
175 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
176 void assignNoCb (char[] val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
177 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
178 if (pos > sv.length) pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
179 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
180 void opAssign (char[] val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
181 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
182 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
183 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
184 char[] opCall () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
185 return v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
186 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
187 alias opCall opCast; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
188 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
189 override void endEdit () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
190 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
191 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
192 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
193 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
194 alias sv v; // don't need separate v and sv in this case |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
195 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
196 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
197 /** Integer content. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
198 class IntContent : AStringContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
199 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
200 /** Create a content with _symbol name symbol. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
201 this (char[] symbol, int val = 0) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
202 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
203 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
204 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
205 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
206 void assignNoCb (int val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
207 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
208 sv = Int.toString (v); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
209 if (pos > sv.length) pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
210 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
211 void opAssign (int val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
212 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
213 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
214 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
215 int opCall () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
216 return v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
217 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
218 alias opCall opCast; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
219 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
220 override void endEdit () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
221 v = Int.toInt (sv); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
222 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
223 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
224 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
225 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
226 int v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
227 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
228 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
229 /** Double content. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
230 class DoubleContent : AStringContent |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
231 { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
232 /** Create a content with _symbol name symbol. */ |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
233 this (char[] symbol, double val = 0) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
234 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
235 super (symbol); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
236 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
237 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
238 void assignNoCb (double val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
239 v = val; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
240 sv = Float.toString (v); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
241 if (pos > sv.length) pos = sv.length; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
242 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
243 void opAssign (double val) { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
244 assignNoCb (val); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
245 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
246 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
247 double opCall () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
248 return v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
249 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
250 alias opCall opCast; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
251 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
252 override void endEdit () { |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
253 v = Float.toFloat (sv); |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
254 endEvent; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
255 } |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
256 |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
257 protected: |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
258 double v; |
08651e8a8c51
Quit button, big changes to content system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
259 } |