view mde/gui/renderer/IRenderer.d @ 95:2a364c7d82c9

Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes. Fixed a minor bug where layouts with the same id but without shared alignments would be messed up. Tracked down the "nothing trawn until a resize" bug (see jobs.txt). If widgets throw during creation they're now replaced by debug widgets. Function pointers are converted to delegates using a safer method.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 06 Nov 2008 11:07:18 +0000
parents 08a4ae11454b
children 30470bc19ca4
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/>. */

/** Interface for the renderer. This is planned to replace decoration.d */
module mde.gui.renderer.IRenderer;

public import mde.gui.types;
import mde.font.font;

/** Interface for renderers.
*
* Renderers provide unified drawing methods for widget, e.g. to draw a window background, a frame,
* or a button. The renderer will effectively be synonymous with the theme, except that a scripted
* renderer may also be available.
*
* The renderer is intended to be per-GUI. */
interface IRenderer
{
    //BEGIN Get dimensions
    /// A container for the dimensions
    struct BorderDimensions {
        /// The dimensions: left, top, right, bottom
        wdim l, t, r, b;
        
        void opAddAssign (BorderDimensions d) {
            l += d.l;
            t += d.t;
            r += d.r;
            b += d.b;
        }
    }
    
    /** Use to set and reset these parameters, and to get the border size (which may depend on
     * them). */
    BorderDimensions setSizable (bool wSizable, bool hSizable);
    
    /// Which edges of a window are being resized
    enum RESIZE_TYPE : ubyte {
        NONE = 0x0, L = 0x1, R = 0x2, T = 0x4, B = 0x8
    }
    
    /** Used to tell if a click on a window's border is for resizing or moving.
    *
    * Depends on setSizable's parameters.
    *
    * Params:
    *   cx =
    *   cy = click coordinates relative to window border
    *   w  =
    *   h  = window size
    *
    * Returns:
    *   RESIZE_TYPE = NONE for a move, an or'd combination of L/R/T/B for resizing.
    */
    RESIZE_TYPE getResizeType (wdim cx, wdim cy, wdim w, wdim h);
    
    /** Return the renderer's between-widget spacing (for layout widgets). */
    wdim layoutSpacing ();
    //END Get dimensions
    
    //BEGIN draw routines
    /** Restrict following draw operations to given box.
     *
     * Restrict "pushes" a restriction onto a stack; relax must be called afterwards to "pop" the
     * restriction. */
    void restrict (wdim x, wdim y, wdim w, wdim h);
    void relax ();      /// ditto
    
    /** Draw a window border plus background. */
    void drawWindow (wdim x, wdim y, wdim w, wdim h);
    
    /** Draws a widget background. Usually doesn't do anything since backgrounds are transparent. */
    void drawWidgetBack (wdim x, wdim y, wdim w, wdim h);
    
    /** Draws a blank widget (temporary) */
    void drawBlank (wdim x, wdim y, wdim w, wdim h);
    
    /** Draws a button frame, in if pushed == true. */
    void drawButton (wdim x, wdim y, wdim w, wdim h, bool pushed);
    
    /** Toggle buttons.
     *
     * These have a fixed size which getToggleSize returns. */
    wdimPair getToggleSize ();
    void drawToggle (wdim x, wdim y, bool state, bool pushed);  /// ditto
    
    /** Get a TextAdapter to draw some text.
     *
     * If no colour is passes, a default is used (white). */
    TextAdapter getAdapter (char[] text, int colour = 0xFFFFFF);
    
    /** For drawing text - one instance per string.
     *
     * NOTE: currently inflexible. Could use (function) pointers, class interfaces or struct
     * interfaces when available to allow flexibility. */
    struct TextAdapter {
        void set (char[] c, int col) {
            content = c;
            colour = Colour (col);
        }
        
        void getDimensions (out wdsize w, out wdsize h) {
            font.updateBlock (content, textCache);
            w = cast(wdim) textCache.w;
            h = cast(wdim) textCache.h;
        }
        
        void draw (wdabs x, wdabs y) {
            font.textBlock (x,y, content, textCache, colour);
        }
        
        char[] content;
        TextBlock textCache;
        Colour colour;
        FontStyle font;
    }
    //END draw routines
}