Mercurial > projects > mde
view mde/gui/widget/Ifaces.d @ 41:b3a6ca4516b4
The renderer now controls which parts of the window border allow resizing.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 13 May 2008 12:02:36 +0100 |
parents | b28d7adc786b |
children | 0fd51d2c6c8a |
line wrap: on
line source
/* LICENSE BLOCK Part of mde: a Modular D game-oriented Engine Copyright © 2007-2008 Diggory Hardy This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /** Window and widget interfaces. */ module mde.gui.widget.Ifaces; public import mde.gui.renderer.IRenderer; import mde.gui.IGui; /** Interface for Window, allowing widgets to call some of Window's methods. * * Contains the methods in Window available for widgets to call on their root. */ interface IWindow : IWidget { /** Widget ID type. Each ID is unique under this window. * * Type is int since this is the widget data type. */ alias int widgetID; /** Get a widget by ID. * * Returns the widget with the given ID from the Window's widget list. If the widget hasn't yet * been created, creates it using the Window's widget creation data. */ IWidget makeWidget (widgetID i); /** Add widget's saveData to the data to be saved, returning it's widgetID. */ widgetID addCreationData (IWidget widget); /** Returns the window's gui. */ //NOTE: was going to remove this, but it's used more than I thought IGui gui (); /** The widget/window needs redrawing. */ void requestRedraw (); /** Get the window's renderer. * * Normally specific to the GUI, but widgets have no direct contact with the GUI and this * provides the possibility of per-window renderers (if desired). */ IRenderer renderer (); } /** Interface for widgets. * * Note that Window also implements this interface so that widgets can interact with their parent * in a uniform way. * * A widget is a region of a GUI window which handles rendering and user-interaction for itself * and is able to communicate with it's window and parent/child widgets as necessary. * * A widget's constructor should have this prototype: * ---------------------------------- * this (IWindow window, int[] data); * ---------------------------------- * Where window is the root window (the window to which the widget belongs) and data is an array of * initialisation data. The method should throw a WidgetDataException (created without parameters) * if the data has wrong length or is otherwise invalid. * * The widget's size should be set either by it's this() method or by the first call to * setSize(). setSize() is called on all widgets immediately after their creation, and throwing an * exception at this point (but not on later calls to setSize) is an acceptible method of failure. */ //NOTE: add another this() without the data for default initialization, for the GUI editor? interface IWidget { //BEGIN Load and save /** Called after creating widgets to adjust size & other mutable attributes from saved data. * * As for setSize, setPosition should be called afterwards. * * Each widget should call adjust on each of its sub-widgets in turn with data, each time * replacing data by the return value of the call. It should then take its own mutable data * from the beginning of the array and return the remainder of the array. * * Adjust should handle errors gracefully by reverting to default values and not throwing. * This is because the creation data and the user's mutable data may be stored separately and * become out-of-sync during an update. */ int[] adjust (int[] data); /** Output data suitible for recreating the widget (data to be passed to this()). * * Creation data is data only changed when the gui is edited. */ int[] getCreationData (); /** Output data containing the widget's current adjustments (data to be passed to adjust()). * * Mutable data is data which can be changed during normal gui use, such as the size of * resizible widgets or current tab of a tab widget. * * Should be a concatenation of each sub-widget's mutable data and the widget's own. */ int[] getMutableData (); //END Load and save //BEGIN Size and position /** is the width / height resizable? * * If not, the widget has fixed dimensions equal the output of getMinimalSize. */ bool isWSizable (); bool isHSizable (); /// ditto /** Calculate the minimal size the widget could be shrunk to, taking into account * child-widgets. */ void getMinimalSize (out int w, out int h); /** Get the current size of the widget. */ void getCurrentSize (out int w, out int h); /** Used to adjust the size. * * setPosition should always be called after setSize (for layout widgets). Adding this * restriction appears to be the most efficient approach without a lot more tests. * * Implementation: * The size should be clamped to the widget's minimal size, i.e. the size set may be larger * than that given by the parameters. Conversely, the size should not be reduced to the * widget's maximal size (if any) but expanded as necessary (alignment to be implemented). * * If the actual size is needed, call getCurrentSize afterwards. */ void setSize (int w, int h); /** Set the current position (i.e. called on init and move). */ void setPosition (int x, int y); //END Size and position //BEGIN Events /** Recursively scan the widget tree to find the widget under (x,y). * * If called on a widget, that widget should assume the location is over itself, and so should * either return itself or the result of calling getWidget on the appropriate child widget. * * In the case of Window this may not be the case; it should check and return null if not under * (x,y). * * Note: use global coordinates (x,y) not coordinates relative to the widget. */ IWidget getWidget (int x, int y); /** Receive a mouse click event. * * See mde.input.input.Input.MouseClickCallback for parameters. However, cx and cy are adjusted * to the Widget's local coordinates. * * Widget may assume coordinates are on the widget (caller must check). */ void clickEvent (ushort cx, ushort cy, ubyte b, bool state); //END Events /** Draw, using the stored values of x and y. * * Maybe later enforce clipping of all sub-widget drawing, particularly for cases where only * part of the widget is visible: scroll bars or a hidden window. */ void draw (); }