00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00209
00210
00211
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
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
00350 SDL_Rect wnd;
00351 bool bVisible, bEnabled;
00352
00353 bool bClipdirty, bAbsdirty, bDrawdirty;
00354 SDL_Rect clip;
00355 SDL_Rect abswnd;
00356 SDL_Rect drawwnd;
00357
00358 GuiElement *geParent;
00359
00360
00361 bool bRedraw;
00362
00363 friend class GuiManager;
00364 };
00365
00366 #endif