annotate mde/gui/renderer/IRenderer.d @ 179:1f9d00f392bd default tip

Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now. Optimised when ServiceContentList.opCall is called, I think without breaking anything.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 15 Sep 2009 20:09:59 +0200
parents 075705ad664a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
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
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
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;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** Interface for the renderer. This is planned to replace decoration.d */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 module mde.gui.renderer.IRenderer;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 75
diff changeset
19 public import mde.gui.types;
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
20 import mde.font.font;
58
d43523ed4b62 Included a wdim typedef for all variables to do with window position or size instead of just using int.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 43
diff changeset
21
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 /** Interface for renderers.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 *
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
24 * Renderers provide unified drawing methods for widget, e.g. to draw a window
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
25 * background, a frame, or a button.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
26 *
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
27 * A theme could be hard-coded into a renderer, or use a texture set and/or
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
28 * scripting with a more flexible renderer. There's currently no support for
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
29 * per-widget theming, although it shouldn't be too hard (e.g. if widgets get a
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
30 * renderer from their parent instead of the manager).
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
31 *
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
32 * The renderer interface could be improved by using more objects and interfaces
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
33 * (e.g. with a generic drawable interface for getting dimensions and drawing),
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
34 * but requiring more class objects seems excessive and structs don't support
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
35 * interfaces in D1. */
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 interface IRenderer
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 {
97
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
38 //BEGIN Types
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
39 /** For floating widget borders. Like TextAdapter above, could be more flexible. */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
40 struct Border {
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
41 /** Border type.
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
42 *
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
43 * No border, small non-functional border, movement only border, resize only border, or
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
44 * full border. */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
45 enum BTYPE : int {
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
46 NONE = 0, SMALL = 1, LARGE = 2, MOVE = 4, RESIZE = 8, BOTH = MOVE | RESIZE
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
47 }
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
48 /** Which edges of a window are being resized.
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
49 *
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
50 * E.g. X1 == left, X2 | Y1 == right and top. */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
51 enum RESIZE : int {
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
52 NONE = 0x0, X1 = 0x1, X2 = 0x2, Y1 = 0x4, Y2 = 0x8
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
53 }
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
54
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
55 wdim x1,x2; /// First and second (lef & right) horizontal borders
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
56 wdim y1,y2; /// First and second vertical borders
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
57 RESIZE capability; /// Which resizes are possible.
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
58
97
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
59 void opAddAssign (Border d) {
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
60 x1 += d.x1;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
61 x2 += d.x2;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
62 y1 += d.y1;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
63 y2 += d.y2;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
64 }
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
65
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
66 /** Used to tell if a click on a window's border is for resizing or moving.
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
67 *
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
68 * Depends on setSizable's parameters.
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
69 *
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
70 * Params:
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
71 * cx =
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
72 * cy = click coordinates relative to window border
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
73 * w =
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
74 * h = window size
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
75 *
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
76 * Returns:
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
77 * RESIZE = Describes whether the click resizes or moves the widget. */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
78 RESIZE getResize (wdim cx, wdim cy, wdim w, wdim h) {
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
79 RESIZE r = RESIZE.NONE;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
80 if (cx + cy < x1 + y1)
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
81 r = RESIZE.X1 | RESIZE.Y1;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
82 else if (cx + h - cy < x1 + y2)
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
83 r = RESIZE.X1 | RESIZE.Y2;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
84 else if (w - cx + cy < x2 + y1)
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
85 r = RESIZE.X2 | RESIZE.Y1;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
86 else if (w - cx + h - cy < x2 + y2)
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
87 r = RESIZE.X2 | RESIZE.Y2;
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
88 return r & capability;
38
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
89 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
90 }
8c4c96f04e7f Windows can now be resized!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 37
diff changeset
91
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
92 /** For drawing text - one instance per string.
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
93 *
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
94 * NOTE: currently inflexible. Could use (function) pointers, class interfaces or struct
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
95 * interfaces when available to allow flexibility. */
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
96 struct TextAdapter {
103
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
97 char[] text () {
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
98 return content;
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
99 }
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
100 void text (char[] str) {
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
101 content = str;
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: 97
diff changeset
102 textCache.cacheVer = -1; // force update
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
103 }
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: 97
diff changeset
104
103
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
105 void colour (int colour = 0xFFFFFF) {
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
106 colour_ = Colour (colour);
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: 97
diff changeset
107 }
100
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
108
103
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
109 /** If not size_t.max, an edit marker is drawn before character index. */
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
110 void index (size_t index = size_t.max) {
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
111 index_ = index;
100
0ea4a3e651ae There is now a position marker for text editing.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 99
diff changeset
112 }
119
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
113 /** Set the edit index for a click at x.
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
114 *
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
115 * TODO: this uses the left edge of the cached bitmap to compare against; it should
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
116 * probably use the glyph position. The font system needs some redesigning anyway. */
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
117 size_t setIndex (wdrel x) {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
118 foreach (i,ch; textCache.chars)
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
119 if (x < ch.xPos) {
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
120 index_ = i;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
121 goto gotIndex;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
122 }
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
123 index_ = textCache.chars.length;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
124 gotIndex:
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
125 return index_;
d28aea50c6da Basic edit cursor placement using the mouse.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 111
diff changeset
126 }
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
127
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
128 void getDimensions (out wdsize w, out wdsize h) {
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
129 font.updateBlock (content, textCache);
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
130 w = cast(wdim) textCache.w;
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
131 h = cast(wdim) textCache.h;
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
132 }
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
133
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
134 void draw (wdabs x, wdabs y) {
103
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
135 font.textBlock (x,y, content, textCache, colour_, index_);
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
136 }
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
137
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
138 char[] content;
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
139 TextBlock textCache;
103
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
140 size_t index_;
42e241e7be3e ContentList content type; getting content items/lists from Options generically via content.Items, and a new addContent widget function. Several improvements to generic handling of content. New button-with-text widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 100
diff changeset
141 Colour colour_;
93
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
142 FontStyle font;
08a4ae11454b Widgets now save dimensions without preventing structural changes in the base config file from applying.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 80
diff changeset
143 }
97
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
144 //END Types
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
145
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
146 //BEGIN Methods
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
147 /** Returns a Border containing dimensions.
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
148 *
123
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
149 * Params:
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
150 * type = Flags from BTYPE describing whether the border allows resizing and moving and
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
151 * its size. */
97
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
152 Border getBorder (Border.BTYPE type, bool wSizable, bool hSizable);
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
153
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
154 /** Return the renderer's between-widget spacing (for layout widgets). */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
155 wdim layoutSpacing ();
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
156
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
157 /** Restrict following draw operations to given box.
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
158 *
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
159 * Restrict "pushes" a restriction onto a stack; relax must be called afterwards to "pop" the
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
160 * restriction. */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
161 void restrict (wdim x, wdim y, wdim w, wdim h);
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
162 void relax (); /// ditto
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
163
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
164 /** Draw a border. */
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
165 void drawBorder (Border* border, wdim x, wdim y, wdim w, wdim h);
97
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
166
109
2a1428ec5344 Optional, visible spacing in grid layouts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
167 /** Draw vertical and horizontal spacers.
2a1428ec5344 Optional, visible spacing in grid layouts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
168 *
2a1428ec5344 Optional, visible spacing in grid layouts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
169 * x,y and w,h are the position and size of the grid containing spacers.
2a1428ec5344 Optional, visible spacing in grid layouts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
170 *
2a1428ec5344 Optional, visible spacing in grid layouts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
171 * For each col in cols, spacers should be drawn in the rectangle
2a1428ec5344 Optional, visible spacing in grid layouts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
172 * [x+col-layoutSpacing,x+col)*[y,y+h), and similarly for rows. */
2a1428ec5344 Optional, visible spacing in grid layouts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
173 void drawSpacers (wdabs x, wdabs y, wdsize w, wdsize h, wdims cols, wdims rows);
2a1428ec5344 Optional, visible spacing in grid layouts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
174
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 103
diff changeset
175 /** Draws a widget background. Usually doesn't do anything since backgrounds are transparent.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 103
diff changeset
176 *
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 103
diff changeset
177 * It used to be required for all widgets to do this, but I lapsed since mostly it's unused. */
97
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
178 void drawWidgetBack (wdim x, wdim y, wdim w, wdim h);
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
179
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
180 /** Draws a blank widget (temporary) */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
181 void drawBlank (wdim x, wdim y, wdim w, wdim h);
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
182
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
183 /** Draws a button frame, in if pushed == true. */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
184 void drawButton (wdim x, wdim y, wdim w, wdim h, bool pushed);
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
185
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
186 /** Toggle buttons.
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
187 *
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
188 * These have a fixed size which getToggleSize returns. */
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
189 wdimPair getToggleSize ();
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
190 void drawToggle (wdim x, wdim y, bool state, bool pushed); /// ditto
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
191
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
192 /** Slider / progress bar.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
193 *
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
194 * Width is resizable. */
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
195 wdimPair getSliderSize ();
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
196 void drawSlider (wdim x, wdim y, wdim w, double proportion);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
197
97
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
198 /** Get a TextAdapter to draw some text.
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
199 *
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
200 * If no colour is passes, a default is used (white). */
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 109
diff changeset
201 TextAdapter getAdapter (int colour = 0xFFFFFF);
97
30470bc19ca4 Floating widgets now work nicely: customizable borders added, resizing, moving.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
202 //END Methods
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
203 }