Mercurial > projects > mde
view mde/gui/renderer/SimpleRenderer.d @ 108:c9fc2d303178
Added capability for border-less pop-up widgets. Simple pop-up menu.
Removed grid-layout spacing (may allow any widget to provide spacing later).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Wed, 03 Dec 2008 19:37:32 +0000 |
parents | 42e241e7be3e |
children | 2a1428ec5344 |
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 derelict.opengl.gl; 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.getDefault; } alias Border.BTYPE BTYPE; Border getBorder (BTYPE type, bool wS, bool hS) { Border border; with (border) { if (type & BTYPE.RESIZE) { if (wS) capability = RESIZE.X1 | RESIZE.X2; if (hS) capability |= RESIZE.Y1 | RESIZE.Y2; } if (type & BTYPE.LARGE) { y1 = 12; y2 = 6; } else if (type & BTYPE.SMALL) y1 = y2 = 4; x1 = x2 = y2; } return border; } wdim layoutSpacing () { return 0; } //FIXME - make these do something // They should restrict the drawing of floating widgets to the floating area, for instance, // although this isn't strictly necessary. void restrict (wdim x, wdim y, wdim w, wdim h) {} void relax () {} void drawWindow (Border* border, wdim x, wdim y, wdim w, wdim h) { glColor3f (0f, 0f, .8f); glRecti(x, y+h, x+w, y); if (border.capability != 0) { glColor3f (0f, 0f, .6f); glBegin (GL_TRIANGLES); wdim t = border.x1 + border.y1; glVertex2i (x, y); glVertex2i (x+t, y); glVertex2i (x, y+t); t = border.x2 + border.y1; glVertex2i (x+w, y); glVertex2i (x+w, y+t); glVertex2i (x+w-t, y); t = border.x2 + border.y2; glVertex2i (x+w, y+h); glVertex2i (x+w-t, y+h); glVertex2i (x+w, y+h-t); t = border.x1 + border.y2; glVertex2i (x, y+h); glVertex2i (x, y+h-t); glVertex2i (x+t, y+h); glEnd (); } glColor3f (0f, 0f, 0f); glRecti(x+border.x1, y+h-border.y2, x+w-border.x2, y+border.y1); } void drawWidgetBack (wdim x, wdim y, wdim w, wdim h) { debug { glColor3f (0f, .2f, .2f); glRecti (x,y+h, x+w,y); } } void drawBlank (wdim x, wdim y, wdim w, wdim h) { glColor3f (.4f, .4f, .4f); glRecti(x, y+h, x+w, y); } void drawButton (wdim x, wdim y, wdim w, wdim h, bool pushed) { if (pushed) glColor3f (1f, 0f, 1f); else glColor3f (.6f, 0f, .6f); glRecti(x, y+h, x+w, y); } 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) glColor3f (0f, c, 0f); else glColor3f (c, 0f, 0f); glRecti (x+2,y+14, x+14,y+2); } TextAdapter getAdapter (char[] text, int col) { TextAdapter a; a.font = defaultFont; a.content = text; a.colour_ = Colour (col); a.index_ = size_t.max; return a; } protected: FontStyle defaultFont; }