view mde/gui/widget/Ifaces.d @ 32:316b0230a849

Lots more work on the GUI. Also renamed lots of files. Lots of changes to the GUI. Renderer is now used exclusively for rendering and WidgetDecoration is gone. Renamed lots of files to conform to case policies. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 30 Apr 2008 18:05:56 +0100
parents
children 6b4116e6355c
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;

/** 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 : IParentWidget
{
    /** 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 (throws on error; don't
    * catch the exception). */
    IWidget getWidget (widgetID i, IParentWidget parent);
    
    /+ Currently draw-on-event isn't used.
    /** Called by a sub-widget when a redraw is necessary (since drawing may sometimes be done on
    * event. */
    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 ();
}

/** Methods exposed by both Window and Widgets which widgets can call on a parent. */
interface IParentWidget
{
}

/** 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, IParentWidget parent, int[] data);
* ----------------------------------
* Where window is the root window (the window to which the widget belongs), parent is the parent
* widget, 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. */
interface IWidget : IParentWidget
{
    /** Draw, starting from given 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 (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);
    
    /** Calculate the minimum size the widget could be shrunk to, taking into account
     * child-widgets. */
    void getMinimumSize (out int w, out int h);
    
    /** Get the current size of the widget.
     *
     * On the first call (during loading), this may be a value saved as part of the config or
     * something else (e.g. revert to getMinimumSize). */
    void getCurrentSize (out int w, out int h);
}