Mercurial > projects > mde
view mde/gui/decoration.d @ 31:baa87e68d7dc
GUI now supports basic interactible widgets, widget colour and border are more unified, and some code cleanup.
Removed some circular dependencies which slipped in. As a result, the OpenGL code got separated into different files.
Enabled widgets to recieve events.
New IParentWidget interface allowing widgets to interact with their parents.
New Widget base class.
New WidgetDecoration class.
New ButtonWidget class responding to events (in a basic way).
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 29 Apr 2008 18:10:58 +0100 |
parents | |
children |
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/>. */ /** Widget decoration / rendering code. */ module mde.gui.decoration; import gl = mde.gl.basic; enum TypeFlags { NONE = 0, LAYOUT = 0x10, BUTTON = 0x20 } /** An attempt at unifying and generally improving apon the looks of Widgets. * * Probably only a stop-gap measure until something better turns up... * Although this could be extended to do the actual rendering, etc.? */ class WidgetDecoration { /** Create a decoration for a window. */ this () { border = 20; r = g = 0.0f; b = 1.0f; } /** Create an appropriate decoration for a Widget. Pass parent. */ this (WidgetDecoration parent, TypeFlags flags = TypeFlags.NONE) in { assert (parent !is null, "WidgetDecoration: parent is null"); } body { //depth = parent.depth + 1; if (flags & TypeFlags.LAYOUT) { if (!(parent.flags & TypeFlags.LAYOUT)) border = 4; r = g = b = 1f; } else if (flags & TypeFlags.BUTTON) { r = b = .6f; g = 0f; } else { r = 1.0f; g = b = 0f; //cast(float) depth % 2; } this.flags = flags; } void setColor () { gl.setColor (r,g,b); } final: int border; // width of border private: float r,g,b; // colour //int depth; // Window's WidgetDecoration has depth 0; each generation is one step deeper TypeFlags flags;// used by children }