guitext.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 1999, 2000, 2005 by Tobias Nadler und Georg Schnattinger      */
00005 /*                                                                              */
00006 /*  This library is free software; you can redistribute it and/or               */
00007 /*  modify it under the terms of the GNU Lesser General Public                  */
00008 /*  License as published by the Free Software Foundation; either                */
00009 /*  version 2.1 of the License, or (at your option) any later version.          */
00010 /*                                                                              */
00011 /*  This library is distributed in the hope that it will be useful,             */
00012 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of              */
00013 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
00014 /*  Lesser General Public License for more details.                             */
00015 /*                                                                              */
00016 /*  You should have received a copy of the GNU Lesser General Public            */
00017 /*  License along with this library; if not, write to the Free Software         */
00018 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */
00019 /*                                                                              */
00020 /********************************************************************************/
00021 
00022 #ifndef GUITEXT_H
00023 #define GUITEXT_H
00024 
00025 #include "guibackground.h"
00026 #include "sdlfont.h"
00027 #include "frametimer.h"
00028 
00035 class GuiText;
00036 class GuiTextInput;
00037 
00044 class DECLSPEC GuiText : public GuiElement
00045 {
00046 public:
00048     typedef SdlFont::VAlign VAlign;
00050     typedef SdlFont::HAlign HAlign;
00059     enum FontSize{fs_theme = -1, fs_standard = 0, fs_text, fs_button, fs_heading};
00060 
00071     DECLSPEC GuiText( const SDL_Rect &r, GuiElement *p, const char *name, const char *t = 0, FontSize font = fs_theme, bool light = false, bool stdAlign = true );
00080     DECLSPEC GuiText(TiXmlElement *el, GuiElement *p);
00081     virtual DECLSPEC ~GuiText();
00082 
00083     virtual const char *getClassName()  { return "GuiText"; }
00088     DECLSPEC void setText( const char *t );
00093     DECLSPEC void addText( const char *t );
00098     DECLSPEC void addLine( const char *t );
00104     DECLSPEC bool clearLine( int l = 0 );
00106     DECLSPEC int numLines();
00112     void setAlign( VAlign v, HAlign h ) {eVAlign = v; eHAlign = h;}
00114     const char *getText() const { return pText ? pText : ""; }
00120     DECLSPEC void chooseFont( FontSize size, bool light );
00125     DECLSPEC void setFont( SdlFont *f );
00131     virtual void setWordWrap( bool active ) { bWordWrap = active; }
00132     
00139     static DECLSPEC FontSize strToSize( const char *s );
00148     static DECLSPEC SdlFont *fontSizeToFont( FontSize s, bool l, UiTheme *t );
00149 
00150     static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00151     {
00152         GuiElement *r = new GuiText((TiXmlElement*)xmldata, (GuiElement*)o);
00153         *(GuiElement**)presult = r;
00154     }
00157     static void settext(void *sender, BasicObject *aim, void *text)
00158     {
00159         ((GuiText*)aim)->setText( (const char*)text );
00160     }
00161 
00162 protected:
00163     virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00164     virtual DECLSPEC void onInit();
00165     virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00166 
00168     int nCharWidth, nCharHeight;
00170     int curpos;
00172     bool showcursor;
00174     bool bWordWrap;
00175 
00176 private:
00177     VAlign eVAlign;
00178     HAlign eHAlign;
00179     char *chBuffer, *pText;
00180     int nBufferSize;
00181     bool bLightFont;
00182     FontSize eFontSize;
00183     SdlFont *font;
00184 
00185     bool bThemeAlign, bThemeFont;
00186 };
00187 
00194 class DECLSPEC GuiTextInput : public GuiText
00195 {
00196 public:
00197     DECLSPEC GuiTextInput( const SDL_Rect &r, GuiElement *p, const char *name, const char *t = NULL, bool singleline = true);
00205     DECLSPEC GuiTextInput(TiXmlElement *el, GuiElement *p);
00206     virtual DECLSPEC ~GuiTextInput();
00207 
00208     virtual const char *getClassName()  { return "GuiTextInput"; }
00209     
00210     void setCallback( Callback c )  { cb.func = c; }
00211     void setCbData( BasicObject* d )    { cb.obj = d; }
00216     DECLSPEC void setMaxlen( int l );
00217 
00218     static Uint32 nBlinkIv;
00219     static char alpha[], ALPHA[], altAlpha[];
00220     static const unsigned int nKeys, nModKeys;
00221     static char MOD_LETTER;
00222 
00223     int bwActive, bwInactive;// if & 0x80000000 then
00224     Sint32 cActive, cInactive;// set by theme
00225 
00226     static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00227     {
00228         GuiElement *r = new GuiTextInput((TiXmlElement*)xmldata, (GuiElement*)o);
00229         *(GuiElement**)presult = r;
00230     }
00231 protected:
00232     virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00233     virtual DECLSPEC Uint32 onMouseDown( SDL_MouseButtonEvent *ev );
00234     virtual DECLSPEC Uint32 onKeyDown( SDL_KeyboardEvent *ev );
00235     virtual DECLSPEC Uint32 onKeyUp( SDL_KeyboardEvent *ev );
00236     virtual DECLSPEC Uint32 onFocus( FocusTypes gained );
00237     virtual DECLSPEC Uint32 onRelease(FocusTypes lost);
00238     virtual DECLSPEC void onInit();
00239     virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00240 
00241 private:
00242     static void refresh(void *, BasicObject *aim, void*)    {
00243         ((GuiTextInput*)aim)->showcursor = !((GuiTextInput*)aim)->showcursor;
00244         ((GuiTextInput*)aim)->setRedraw();
00245     }
00246     FunctionData cb;
00247     FrameTimer::CbInfo *blinkTimer;
00248 
00249     bool hasfocus;
00250     bool bSingleLine;
00251     int maxlen;
00252     static void setInfo();
00253     friend class guiinfo;
00254 };
00255 
00262 class DECLSPEC GuiKeyControl : public GuiText 
00263 {
00264 public:
00265     DECLSPEC GuiKeyControl(const SDL_Rect &r, GuiElement *p, const char *name);
00272     DECLSPEC GuiKeyControl(TiXmlElement *el, GuiElement *p);
00273     virtual DECLSPEC ~GuiKeyControl();
00274 
00275     virtual const char *getClassName()  { return "GuiKeyControl"; }
00276 
00277     SDL_keysym getKey() const   {return key;}
00278     DECLSPEC void setKey( const SDL_keysym &k );
00279     
00280     static DECLSPEC const char *alpha[];
00281     static DECLSPEC const SDLKey code[];
00282     static DECLSPEC const unsigned int count;
00283 
00284     static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00285     {
00286         GuiElement *r = new GuiKeyControl((TiXmlElement*)xmldata, (GuiElement*)o);
00287         *(GuiElement**)presult = r;
00288     }
00289     
00290 protected:
00291     virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00292     virtual DECLSPEC Uint32 onMouseDown( SDL_MouseButtonEvent *ev );
00293     virtual DECLSPEC Uint32 onKeyDown( SDL_KeyboardEvent *ev );
00294     virtual DECLSPEC Uint32 onFocus();
00295     virtual DECLSPEC Uint32 onRelease();
00296     virtual DECLSPEC void onInit();
00297     
00298 private:
00299     void update();
00300     bool hasfocus;
00301     SDL_keysym key;
00302 };
00303 
00311 class DECLSPEC GuiFrameCounter : public GuiText
00312 {
00313 public:
00314     DECLSPEC GuiFrameCounter(const SDL_Rect &r, GuiElement *p, const char *name);
00321     DECLSPEC GuiFrameCounter(TiXmlElement *el, GuiElement *p);
00322     virtual DECLSPEC ~GuiFrameCounter();
00323 
00324     virtual const char *getClassName()  { return "GuiFrameCounter"; }
00325 
00326     static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00327     {
00328         GuiElement *r = new GuiFrameCounter((TiXmlElement*)xmldata, (GuiElement*)o);
00329         *(GuiElement**)presult = r;
00330     }
00331 protected:
00332     virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00333     virtual DECLSPEC void onInit();
00334     
00335 private:
00336     long frame;
00337     Uint32 time;
00338 };
00339 
00340 #endif

Generated on Wed May 9 17:35:55 2007 for netrinjo by  doxygen 1.5.1