00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef GUIBACKGROUND_H
00023 #define GUIBACKGROUND_H
00024
00025 #include <list>
00026 #include "guielement.h"
00027 #include "definitions.h"
00028
00029 class GuiRadioBtn;
00030 class SdlSurfaceContainer;
00031 class SdlSurface;
00032
00033 using namespace std;
00034
00049 class DECLSPEC GuiBackground : public GuiElement
00050 {
00051 public:
00062 DECLSPEC GuiBackground(const SDL_Rect &r, GuiElement *p, const char *name, Uint32 c = CLR_STANDARD);
00070 DECLSPEC GuiBackground(TiXmlElement *el, GuiElement *p);
00071 virtual DECLSPEC ~GuiBackground();
00072
00073 virtual const char *getClassName() { return "GuiBackground"; }
00074
00076 Uint32 bgcolor;
00077
00078 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00079 {
00080 GuiElement *r = new GuiBackground((TiXmlElement*)xmldata, (GuiElement*)o);
00081 *(GuiElement**)presult = r;
00082 }
00083 protected:
00084 virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00085 virtual DECLSPEC void onInit();
00086 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00094 virtual DECLSPEC void paintBg( SdlSurface *dst );
00095
00096 private:
00097 Uint32 changeTheme( UiTheme *t, const char *classname );
00098 bool bThemeColor;
00099 };
00100
00109 class DECLSPEC GuiFrame : public GuiBackground
00110 {
00111 public:
00121 DECLSPEC GuiFrame(const SDL_Rect &r, GuiElement *p, const char *name, Uint32 c_out = CLR_INVALID, Uint32 c_over = CLR_INVALID);
00128 DECLSPEC GuiFrame(TiXmlElement *el, GuiElement *p);
00129 virtual DECLSPEC ~GuiFrame();
00130
00131 virtual const char *getClassName() { return "GuiFrame"; }
00132
00134 Uint32 color1;
00136 Uint32 color2;
00137
00138 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00139 {
00140 GuiElement *r = new GuiFrame((TiXmlElement*)xmldata, (GuiElement*)o);
00141 *(GuiElement**)presult = r;
00142 }
00143 protected:
00144 virtual DECLSPEC Uint32 onMouseOver();
00145 virtual DECLSPEC Uint32 onMouseOut();
00146 virtual DECLSPEC void onInit();
00147 private:
00148 };
00149
00162 class GuiBorder : public GuiElement
00163 {
00164 public:
00183 DECLSPEC GuiBorder( const SDL_Rect &r, GuiElement *p, const char *name, SdlSurfaceContainer * bmps = 0, bool themestyle = true );
00192 DECLSPEC GuiBorder(TiXmlElement *el, GuiElement *p);
00193 virtual DECLSPEC ~GuiBorder();
00194
00195 virtual const char *getClassName() { return "GuiBorder"; }
00201 DECLSPEC void setBmps( SdlSurfaceContainer * sc );
00203 SdlSurfaceContainer * getBmps() { return bmps; }
00208 bool invert, neutral;
00210 bool left, right, top, bottom;
00211
00212 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00213 {
00214 GuiElement *r = new GuiBorder((TiXmlElement*)xmldata, (GuiElement*)o);
00215 *(GuiElement**)presult = r;
00216 }
00217
00218 protected:
00219 virtual DECLSPEC Uint32 onResize();
00220 virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00221 virtual DECLSPEC void onInit();
00222 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00223
00225 bool bCanNeutral,
00227 bShowBorder;
00228
00230 int nCornerWidth, nCornerHeight,
00232 nBmpWidth,
00234 nBmpHeight;
00235
00236 private:
00237 Uint32 changeTheme( UiTheme *t, const char *classname );
00238
00239 int brd_height, brd_width;
00240 SdlSurfaceContainer *bmps;
00241 bool bThemeBmps, bThemeStyle;
00242 };
00243
00249 class DECLSPEC GuiRadioContainer : public GuiBackground
00250 {
00251 public:
00252 DECLSPEC GuiRadioContainer(const SDL_Rect &r, GuiElement *p, const char *name, Uint32 c = CLR_INVALID);
00260 DECLSPEC GuiRadioContainer(TiXmlElement *el, GuiElement *p);
00261 virtual DECLSPEC ~GuiRadioContainer();
00262
00263 virtual const char *getClassName() { return "GuiRadioContainer"; }
00264
00266 DECLSPEC void setIndex(int i);
00268 DECLSPEC int getIndex();
00270 DECLSPEC GuiRadioBtn * getSelectedItem();
00272 DECLSPEC GuiRadioBtn * getItem(int i);
00274 DECLSPEC GuiRadioBtn * getLast() { return buttons.size() != 0 ? buttons.back() : NULL; }
00279 DECLSPEC void setCallback(FunctionData d) {cb = d;}
00281 DECLSPEC void setAllowNoCheck( bool allow );
00282
00283 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00284 {
00285 GuiElement *r = new GuiRadioContainer((TiXmlElement*)xmldata, (GuiElement*)o);
00286 *(GuiElement**)presult = r;
00287 }
00288 protected:
00289 virtual DECLSPEC void onInit();
00294 virtual DECLSPEC void onSelect( int i );
00295
00296 private:
00297 typedef list<GuiRadioBtn*> button_list;
00298 typedef button_list::iterator button_iter;
00299 button_iter addButton(GuiRadioBtn *b);
00300 void removeButton(button_iter iter);
00301 void onCheck(button_iter iter);
00302
00303 int index;
00304 bool allownocheck;
00305 FunctionData cb;
00306
00307 button_iter checked;
00308 button_list buttons;
00309
00310 bool bChanging;
00311
00312 friend class GuiRadioBtn;
00313 };
00314
00320 class DECLSPEC GuiPictureBg: public GuiBackground
00321 {
00322 public:
00323 DECLSPEC GuiPictureBg(const SDL_Rect &r, GuiElement * el, const char *name, Uint32 color = CLR_STANDARD, SdlSurface * backbmp = NULL);
00331 DECLSPEC GuiPictureBg(TiXmlElement *el, GuiElement *p);
00332 virtual DECLSPEC ~GuiPictureBg();
00333
00334 virtual const char *getClassName() { return "GuiPictureBg"; }
00335
00336 DECLSPEC void setBmp(SdlSurface * backbmp);
00337
00338
00339 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00340 {
00341 GuiElement *r = new GuiPictureBg((TiXmlElement*)xmldata, (GuiElement*)o);
00342 *(GuiElement**)presult = r;
00343 }
00344 protected:
00345 virtual DECLSPEC void paintBg( SdlSurface *dst );
00346 virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00347 virtual DECLSPEC void onInit();
00348 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00349
00350 private:
00351 Uint32 changeTheme( UiTheme *t, const char *classname );
00352
00353
00354 SdlSurface * bmp;
00355 int nBmpWidth, nBmpHeight;
00356
00357 bool bThemeBmp;
00358 };
00359
00365 class DECLSPEC GuiFlowWindow : public GuiPictureBg
00366 {
00367 public:
00368 enum FlyStyles{sinus, cosinus, constant, powsin, sin_2, theme_std} eFlyStyle;
00369
00370 DECLSPEC GuiFlowWindow( const SDL_Rect &r, GuiElement *el, const char *name, Uint32 color = CLR_STANDARD, SdlSurface * backbmp = 0, FlyStyles style = theme_std );
00379 DECLSPEC GuiFlowWindow(TiXmlElement *el, GuiElement *p);
00380 virtual DECLSPEC ~GuiFlowWindow();
00381
00382 virtual const char *getClassName() { return "GuiFlowWindow"; }
00383
00390 DECLSPEC void flyTo( const SDL_Rect &r, Uint32 t );
00392 DECLSPEC void start();
00394 DECLSPEC void stop();
00396 void swapSrcDest() {SDL_Rect r=src;src=rDestination;rDestination=r;}
00401 void setPosReachedCallback(Callback c, BasicObject *aim) {cb.func = c; cb.obj = aim;}
00402
00403 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00404 {
00405 GuiElement *r = new GuiFlowWindow((TiXmlElement*)xmldata, (GuiElement*)o);
00406 *(GuiElement**)presult = r;
00407 }
00408 static void startflight(void *sender, BasicObject *aim, void *time)
00409 {
00410 ((GuiFlowWindow*)aim)->start();
00411 }
00413 SDL_Rect rDestination;
00415 Uint32 nTime;
00416
00417 protected:
00418 virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00425 virtual DECLSPEC Uint32 onPosReached();
00426 virtual DECLSPEC void onInit();
00427 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00428
00429 private:
00430 Uint32 changeTheme( UiTheme *t, const char *classname );
00431
00432 static SDL_Rect keyFrame( const SDL_Rect &s, const SDL_Rect &d, float t );
00433
00434
00435 bool bFly;
00436
00437 SDL_Rect src;
00438
00439 Uint32 elapsed;
00440
00441 bool bThemeStyle;
00442 BasicObject::FunctionData cb;
00443 };
00444
00450 class DECLSPEC GuiPageControl : public GuiPictureBg
00451 {
00452 public:
00453 typedef list<GuiElement*> page_list;
00454 typedef page_list::iterator page_iter;
00455 enum SIDE{top, bottom, left, right};
00456
00457 DECLSPEC GuiPageControl( const SDL_Rect &r, GuiElement *el, const char *name, Uint32 c = CLR_INVALID, SdlSurfaceContainer *res = 0 );
00465 DECLSPEC GuiPageControl(TiXmlElement *el, GuiElement *p);
00466 virtual DECLSPEC ~GuiPageControl();
00467
00468 virtual const char *getClassName() { return "GuiPageControl"; }
00469
00470 DECLSPEC page_iter addPage( GuiElement *pg, const char *t = 0, SdlSurfaceContainer *res = 0, Uint32 w = 0 );
00471 DECLSPEC void setButton( Uint32 w, Uint32 h, SdlSurfaceContainer *res = 0 );
00472 DECLSPEC void setSide( SIDE s );
00473
00474 DECLSPEC bool removePage( page_iter i );
00475 DECLSPEC bool removePage( GuiElement *el );
00476
00477 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00478 {
00479 GuiElement *r = new GuiPageControl((TiXmlElement*)xmldata, (GuiElement*)o);
00480 *(GuiElement**)presult = r;
00481 }
00482 protected:
00483 virtual DECLSPEC Uint32 onResize();
00484 virtual DECLSPEC void onChange( GuiRadioContainer *sender );
00485 virtual DECLSPEC void onInit();
00486 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00487
00488 private:
00489 Uint32 changeTheme( UiTheme *t, const char *classname );
00490 void arrange();
00491
00492 SIDE side;
00493 int nBtnWidth, nBtnHeight;
00494 page_list pages;
00495 GuiRadioContainer *radios;
00496 SdlSurfaceContainer *btnBmps;
00497 SDL_Rect pagerect;
00498 int count;
00499
00500 bool bUseTheme;
00501
00502 static inline void onRadio( void *sender, BasicObject * data, void * )
00503 {
00504 ((GuiPageControl*)data)->onChange( (GuiRadioContainer *)sender );
00505 }
00506 };
00507
00508 #endif