Gel2D - The free/open source game creation suite

gelGUIWidget.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELGUIWIDGET_H__
00017 #define __GELGUIWIDGET_H__
00018 
00019 #include "gelObject.h"
00020 #include "gelText.h"
00021 
00022 namespace gel
00023 {
00026 
00027     class GelGUIWidget : public GelObject, public GelTextureObject
00028     {
00029         public:
00031             GelGUIWidget();
00032 
00034 
00035             void enable( bool benable ) { enabled = benable; }
00037 
00038                         bool isEnabled() { return enabled; }
00039 
00041 
00042                         void focus( bool bfocus ) { focused = bfocus; }
00044 
00045                         bool isFocused() { return focused; }
00046 
00048 
00049             GelColor getCol() { return col; }
00051 
00052             void setCol( GelColor color ) { col = color; }
00054 
00057             void setRGB( float r, float g, float b ) { col.setRGB(r, g, b); }
00059 
00060             float getAlpha() { return col.a; }
00062 
00064             void setAlpha( float alpha ) { col.a = alpha; }
00065 
00066                 protected:
00067             GelColor col;
00068 
00069                         bool enabled;
00070                         bool focused;
00071     };
00072 
00074     class GelGUIText : public GelGUIWidget
00075     {
00076         public:
00078             GelGUIText();
00079 
00081             GelGUIText( GelFont *fnt );
00082 
00084 
00087             GelGUIText( GelFont *fnt, const char *st, ... );
00088 
00090 
00091             GelFont *getFont() const { return font; }
00092 
00094 
00095             void setFont( GelFont *fnt );
00096 
00098 
00100             void setString( const char *st, ... );
00101 
00103 
00104             int getCharSpacing() const { return charSpacing; }
00105 
00107 
00108             void setCharSpacing( int dist ) { charSpacing = dist; }
00109 
00111 
00112             void setLineSpacing( int dist ) { lineSpacing = dist; }
00113 
00115 
00116             int getLineSpacing() const { return lineSpacing; }
00117 
00118             void setAlignment( int align ) { alignment = align; }
00119             int getAlignment() const { return alignment; }
00120 
00122 
00125             void setMaxLineLength( int len ) { maxLineLength = len; }
00126 
00128 
00129             int getMaxLineLength() const { return maxLineLength; }
00130 
00132 
00135             float getStringLength();
00136 
00138 
00139             void setTexture( GelTexture *tex );
00140 
00142             void render();
00143 
00144                 private:
00145             void _init();
00146                         float _getStringLength();
00147                         int _pointIntersect( float locx, float locy );
00148 
00149                 private:
00150             char string[1024];
00151 
00152             GelFont *font;
00153 
00154             int charSpacing;
00155             int lineSpacing;
00156             int alignment;
00157             int maxLineLength;
00158 
00159             GelFontChar fchar[256];
00160     };
00161 
00163     class GelGUIButton : public GelGUIWidget
00164     {
00165         public:
00167             GelGUIButton();
00168 
00169                         void press( bool bpress ) { pressed = bpress; }
00170                         bool isPressed() const { return pressed; }
00171 
00172                         void setSize( const Gel2dVec &size );
00173 
00174                         void mapRect( const Gel2dVec &pos, const Gel2dVec &size);
00175 
00177 
00178             void setTexture( GelTexture *tex );
00179 
00181             void render();
00182 
00183                 private:
00184                         int _pointIntersect( float locx, float locy );
00185 
00186                 private:
00187                         bool toggleable; // Is that even a word?
00188                         bool pressed;
00189 
00190                         GelVert v[4];
00191 
00192                         //GelGUIText label;
00193     };
00194 
00196     class GelGUICheckBox : public GelGUIWidget
00197     {
00198         public:
00200             GelGUICheckBox();
00201 
00203 
00207                         void check();
00208 
00210 
00211                         void check( bool bcheck );
00212 
00214 
00215                         bool isChecked() const;
00216 
00218 
00219                         void setCheckState( int state ) { checked = state; }
00220 
00222 
00224                         int getCheckState() const { return checked; }
00225 
00227 
00231                         void setTristate( bool state );
00232 
00234 
00235                         bool isTristate() const { return tristate; }
00236 
00237             void setLabel( const GelString &string ) { label.setString(string.toAscii()); }
00238 
00239                         void setSize( const Gel2dVec &size );
00240 
00241                         void mapRect( const Gel2dVec &pos, const Gel2dVec &size );
00242 
00244 
00245             void setTexture( GelTexture *tex );
00246 
00247                         void update();
00248 
00250             void render();
00251 
00252                 private:
00253                         int _pointIntersect( float locx, float locy );
00254 
00255                 private:
00256                         int checked;
00257                         bool tristate;
00258 
00259                         GelVert v[4];
00260 
00261                         GelGUIText label;
00262     };
00263 
00265     class GelGUIManager
00266     {
00267         public:
00269             GelGUIManager();
00270 
00271             static GelFont *getFont() { return font; }
00272 
00273                 private:
00274             static GelFont *font;
00275     };
00277 }
00278 
00279 #endif // __GELGUIWIDGET_H__