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