Mercurial > projects > mde
view mde/gui/renderer/SimpleRenderer.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/>. */ /** A simple renderer. */ module mde.gui.renderer.SimpleRenderer; import mde.gui.renderer.IRenderer; import gl = mde.gl.basic; 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. */ class SimpleRenderer : IRenderer { this () { defaultFont = FontStyle.get("default"); } BorderDimensions setSizable (bool wS, bool hS) { wSizable = wS; hSizable = hS; // Set the border size based on the above with (border) { l = r = t = b = 14; } with (resize) { if (wSizable) l = r = 6; else l = r = 0; if (hSizable) { t = b = 6; } else t = b = 0; } border += resize; return border; } RESIZE_TYPE getResizeType (wdim cx, wdim cy, wdim w, wdim h) { RESIZE_TYPE resizeType = RESIZE_TYPE.NONE; if (cx < resize.l || cx >= w - resize.r || cy < resize.t || cy >= h - resize.b) { // window is being resized /* check for resizes (different to above; use whole border giving larger area for * diagonal resizes). */ if (wSizable) { if (cx < border.l) resizeType = RESIZE_TYPE.L; else if (cx >= w - border.r) resizeType = RESIZE_TYPE.R; } if (hSizable) { if (cy < border.t) resizeType |= RESIZE_TYPE.T; else if (cy >= h - border.b) resizeType |= RESIZE_TYPE.B; } } return resizeType; } wdim layoutSpacing () { return 4; } //FIXME - make these do something void restrict (wdim x, wdim y, wdim w, wdim h) {} void relax () {} void drawWindow (wdim x, wdim y, wdim w, wdim h) { gl.setColor (0f, 0f, .7f); gl.drawBox (x,y, w,h); gl.setColor (0f, 0f, 1f); gl.drawBox (x+resize.l, y+resize.t, w-resize.l-resize.r, h-resize.t-resize.b); gl.setColor (.3f, .3f, .3f); gl.drawBox (x+border.l, y+border.t, w-border.l-border.r, h-border.t-border.b); } void drawWidgetBack (wdim x, wdim y, wdim w, wdim h) { debug { gl.setColor (0f, .2f, .2f); gl.drawBox (x,y, w,h); } } void drawBlank (wdim x, wdim y, wdim w, wdim h) { gl.setColor (.4f, .4f, .4f); gl.drawBox (x,y, w,h); } void drawButton (wdim x, wdim y, wdim w, wdim h, bool pushed) { if (pushed) gl.setColor (1f, 0f, 1f); else gl.setColor (.6f, 0f, .6f); gl.drawBox (x,y, w,h); } wdimPair getToggleSize () { wdimPair r; r.x = 16; r.y = 16; return r; } void drawToggle (wdim x, wdim y, bool state, bool pushed) { float c = pushed ? .7f : .5f; if (state) gl.setColor (0f, c, 0f); else gl.setColor (c, 0f, 0f); gl.drawBox (x+2,y+2, 12,12); } TextAdapter getAdapter (char[] text, int col) { TextAdapter a; a.font = defaultFont; a.set (text, col); return a; } protected: bool wSizable, hSizable; BorderDimensions border; BorderDimensions resize; FontStyle defaultFont; }