annotate mde/gui/widget/Ifaces.d @ 36:57d000574d75

Enabled drawing on demand, and made the polling interval configurable. Renamed mde.global to mde.imde. Enabled drawing on demand. Allowed options to take double values. Made the main loop's polling interval (sleep duration) settable from config files. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 02 May 2008 17:38:43 +0100
parents 6b4116e6355c
children 052df9b2fe07
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 /** Window and widget interfaces. */
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.widget.Ifaces;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 public import mde.gui.renderer.IRenderer;
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
20 import mde.gui.IGui;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 /** Interface for Window, allowing widgets to call some of Window's methods.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 * Contains the methods in Window available for widgets to call on their root. */
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
25 interface IWindow : IWidget
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 {
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 /** Widget ID type. Each ID is unique under this window.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 * Type is int since this is the widget data type. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 alias int widgetID;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 /** Get a widget by ID.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 * Returns the widget with the given ID from the Window's widget list. If the widget hasn't yet
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
35 * been created, creates it using the Window's widget creation data.
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
36 *
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
37 * Widgets should never be used more than once (must have a unique parent and position!), and
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
38 * this function is only intended for widgets to get child-widgets, hence a warning is logged
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
39 * if a widget is asked for more than once. */
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
40 //NOTE: possibly revise: parent isn't actually used any more
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
41 IWidget makeWidget (widgetID i, IWidget parent);
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
42
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
43 /** Get the managing Gui. */
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
44 IGui gui ();
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 /** Get the window's renderer.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 * Normally specific to the GUI, but widgets have no direct contact with the GUI and this
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 * provides the possibility of per-window renderers (if desired). */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 IRenderer renderer ();
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 /** Interface for widgets.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 * Note that Window also implements this interface so that widgets can interact with their parent in
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 * a uniform way.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 * A widget is a region of a GUI window which handles rendering and user-interaction for itself
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 * and is able to communicate with it's window and parent/child widgets as necessary.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 * A widget's constructor should have this prototype:
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 * ----------------------------------
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
63 * this (IWindow window, IWidget parent, int[] data);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 * ----------------------------------
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 * Where window is the root window (the window to which the widget belongs), parent is the parent
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 * widget, and data is an array of initialisation data. The method should throw a
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 * WidgetDataException (created without parameters) if the data has wrong length or is otherwise
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 * invalid. */
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
69 interface IWidget
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 {
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
71 /** Calculate the minimum size the widget could be shrunk to, taking into account
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
72 * child-widgets. */
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
73 void getMinimumSize (out int w, out int h);
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
74
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
75 /** Get the current size of the widget.
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 *
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
77 * On the first call (during loading), this may be a value saved as part of the config or
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
78 * something else (e.g. revert to getMinimumSize). */
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
79 void getCurrentSize (out int w, out int h);
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
80
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
81 /** Set the current position (i.e. called on init and move). */
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
82 void setPosition (int x, int y);
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
83
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
84 /** Recursively scan the widget tree to find the widget under (x,y).
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
85 *
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
86 * If called on a widget, that widget should assume the location is over itself, and so should
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
87 * either return itself or the result of calling getWidget on the appropriate child widget.
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
88 *
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
89 * In the case of Window this may not be the case; it should check and return null if not under
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
90 * (x,y).
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
91 *
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
92 * Note: use global coordinates (x,y) not coordinates relative to the widget. */
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
93 IWidget getWidget (int x, int y);
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 /** Receive a mouse click event.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 * See mde.input.input.Input.MouseClickCallback for parameters. However, cx and cy are adjusted
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98 * to the Widget's local coordinates.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 *
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 * Widget may assume coordinates are on the widget (caller must check). */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 void clickEvent (ushort cx, ushort cy, ubyte b, bool state);
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
103 /** Draw, using the stored values of x and y.
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
104 *
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
105 * Maybe later enforce clipping of all sub-widget drawing, particularly for cases where only
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
106 * part of the widget is visible: scroll bars or a hidden window. */
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
107 void draw ();
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 }