guielement.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 1999-2006 by Tobias Nadler and 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 GUIELEMENT_H
00023 #define GUIELEMENT_H
00024 
00038 #include "SDL/SDL.h"
00039 #include "uiobject.h"
00040 
00047 class TiXmlElement;
00048 
00074 class DECLSPEC GuiElement : public UiObject
00075 {
00076 public:
00088     DECLSPEC GuiElement( const SDL_Rect &r, GuiElement *p, const char *name );
00096     DECLSPEC GuiElement( TiXmlElement *el, GuiElement *p );
00097     virtual DECLSPEC ~GuiElement();
00098 
00099     virtual const char *getClassName()  { return "GuiElement"; }
00101     virtual bool isGuiElement() const   { return true; }
00102 
00110     DECLSPEC void resizeTo( Uint32 w, Uint32 h );
00118     DECLSPEC void resizeBy( Sint32 dw, Sint32 dh );
00126     DECLSPEC void moveTo( Sint32 x, Sint32 y );
00134     DECLSPEC void moveRelCenterTo( Sint32 x, Sint32 y );
00142     DECLSPEC void moveBy( Sint32 x, Sint32 y );
00148     DECLSPEC void getWndSize( Uint32 &w, Uint32 &h ) const;
00153     DECLSPEC SDL_Rect getRelWindow() const;
00158     DECLSPEC void setRelWindow( const SDL_Rect &r );
00163     DECLSPEC SDL_Rect getAbsWindow();
00168     DECLSPEC void setAbsWindow( const SDL_Rect &r );
00175     DECLSPEC SDL_Rect getClientWindow() const;
00181     DECLSPEC SDL_Rect getDrawWindow();
00187     DECLSPEC void getRelCenterPoint( Sint32 &x, Sint32 &y );
00193     DECLSPEC void getAbsCenterPoint( Sint32 &x, Sint32 &y );
00200     DECLSPEC void getClientCenterPoint( Sint32 &x, Sint32 &y );
00206     DECLSPEC SDL_Rect getClip();
00207     /*
00208     Gets the rect of apperance on the surface where it is drawed.
00209     \returns the window's blitting rect
00210     * /
00211     DECLSPEC SDL_Rect getDrawWindow();*/
00215     DECLSPEC GuiElement *getParent() const;
00219     DECLSPEC GuiElement *getToplevel();
00225     DECLSPEC void setVisible( bool b );
00231     DECLSPEC bool isVisible() const;
00237     DECLSPEC void setEnabled( bool b );
00239     DECLSPEC bool isEnabled() const;
00244     DECLSPEC void setRedraw();
00246     bool getRedraw()    {return bRedraw;}
00252     virtual bool hasSurface() const { return false; }
00253 
00267     static GuiElement *create(TiXmlElement *el, GuiElement *parent = NULL);
00269     static GuiElement *createWithoutChildren(TiXmlElement *el, GuiElement *parent = NULL);
00270     
00271     // just for usage via BasicSlot
00272     static void newelement(void *presult, BasicObject *o, void *xmldata)
00273     {
00274         GuiElement *r = new GuiElement((TiXmlElement*)xmldata, (GuiElement*)o);
00275         *(GuiElement**)presult = r;
00276     }
00282     static void togglevisibility(void *sender, BasicObject *aim, void *)
00283     {
00284         ((GuiElement *)aim)->setVisible( !((GuiElement *)aim)->isVisible() );
00285     }
00286 
00287 protected:
00292     virtual DECLSPEC Uint32 onMouseOver();
00297     virtual DECLSPEC Uint32 onMouseOut();
00304     virtual Uint32 onMouseMove(Uint32 x, Uint32 y)  { return 0; }
00309     virtual Uint32 onResize()       { return 0; }
00319     virtual DECLSPEC Uint32 onFrame(SdlSurface * dest);
00320     virtual DECLSPEC void onInit();
00321     virtual DECLSPEC void onDestroy();
00322     virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00328     virtual DECLSPEC void onEnabledChanged( bool enabled );
00329 
00336     virtual void incRequireOnFrame()    {if(geParent) geParent->incRequireOnFrame();}
00338     virtual void decRequireOnFrame()    {if(geParent) geParent->decRequireOnFrame();}
00343     void setDrawRectDirty();
00344 
00345 private:
00346     void setWndDirty();
00347     GuiElement *elementFromPos( Sint32 x, Sint32 y );
00348 
00349     // the relative window rect
00350     SDL_Rect wnd;
00351     bool bVisible, bEnabled;
00352 // Optimization
00353     bool bClipdirty, bAbsdirty, bDrawdirty;
00354     SDL_Rect clip;
00355     SDL_Rect abswnd;
00356     SDL_Rect drawwnd;
00357 
00358     GuiElement *geParent;
00359 
00360     // whether repainting is necessary, see setRedraw()
00361     bool bRedraw;
00362 
00363     friend class GuiManager;
00364 };
00365 
00366 #endif

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