00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef GUIDYNAMICBUTTON_H
00023 #define GUIDYNAMICBUTTON_H
00024
00025 #include "guibackground.h"
00026 #include "basicapp.h"
00027 #include "sdlaudio.h"
00028
00035 class SdlSurfaceContainer;
00036 class SdlSurface;
00037 class SdlFont;
00038 class GuiDynamicButton;
00039 class GuiClickableBtn;
00040 class GuiCheckableBtn;
00041
00047 class DECLSPEC GuiDynamicButton : public GuiBorder
00048 {
00049 public:
00050 enum DynamicState{ds_none, ds_fast} eDynamic;
00051 enum StateType {normal = 0,pressed = 1,mouseover = 2};
00052
00053 DECLSPEC GuiDynamicButton( const SDL_Rect &r, GuiElement *p, const char *name, const char *t, SdlSurfaceContainer *b = 0, SdlAudio *u = 0, SdlAudio *d = 0 );
00061 DECLSPEC GuiDynamicButton(TiXmlElement *el, GuiElement *p);
00062 virtual DECLSPEC ~GuiDynamicButton();
00063
00064 virtual const char *getClassName() { return "GuiDynamicButton"; }
00065
00066 StateType getState() const { return eBtnState; }
00067 DECLSPEC void setBorderVisible( bool show );
00068 DECLSPEC void setSounds( SdlAudio *u, SdlAudio *d );
00069 DECLSPEC void setButtonBmps( SdlSurfaceContainer *b = 0 );
00070 DECLSPEC void setText( const char *t = 0 );
00071
00072 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00073 {
00074 GuiElement *r = new GuiDynamicButton((TiXmlElement*)xmldata, (GuiElement*)o);
00075 *(GuiElement**)presult = r;
00076 }
00077
00078 protected:
00079 DECLSPEC virtual Uint32 onFrame( SdlSurface *dst );
00080 DECLSPEC virtual Uint32 onButtonPress( Sint32 x, Sint32 y );
00081 DECLSPEC virtual Uint32 onButtonRelease( bool bInClient );
00082 DECLSPEC virtual Uint32 onThemeChanged( UiTheme *t );
00083 virtual DECLSPEC void onInit();
00084 DECLSPEC virtual Uint32 changeTheme( UiTheme *t, const char *classname );
00089 void setBtnState(StateType t) {if(t!=eBtnState) {eBtnState=t; setRedraw();}}
00091 StateType getBtnState() {return eBtnState;}
00092 private:
00093 StateType eBtnState;
00094 SdlSurfaceContainer *bmps;
00095 SdlAudio *up;
00096 SdlAudio *down;
00097 SdlFont *fNormal, *fHover;
00098 char *text;
00099
00100 bool bThemeBmps, bThemeAudios, bThemeFonts;
00101 };
00102
00107 class DECLSPEC GuiClickableBtn : public GuiDynamicButton
00108 {
00109 public:
00110 typedef void (*CallBack)( GuiClickableBtn*, void* );
00111
00112 DECLSPEC GuiClickableBtn( const SDL_Rect &r, GuiElement *p, const char *name, const char *t = 0, SdlSurfaceContainer *b = 0, SdlAudio *u = 0, SdlAudio *d = 0 );
00119 DECLSPEC GuiClickableBtn(TiXmlElement *el, GuiElement *p);
00120 virtual DECLSPEC ~GuiClickableBtn();
00121
00122 virtual const char *getClassName() { return "GuiClickableBtn"; }
00123
00124 void setClickCallback( Callback c ) { cbClicked.func = c; }
00125 void setCallbackData( BasicObject* d ) { cbClicked.obj = d; }
00126
00127 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00128 {
00129 GuiElement *r = new GuiClickableBtn((TiXmlElement*)xmldata, (GuiElement*)o);
00130 *(GuiElement**)presult = r;
00131 }
00132 protected:
00133 virtual DECLSPEC Uint32 onMouseOver();
00134 virtual DECLSPEC Uint32 onMouseOut();
00135 virtual DECLSPEC Uint32 onMouseDown( SDL_MouseButtonEvent *ev );
00136 virtual DECLSPEC Uint32 onMouseUp( SDL_MouseButtonEvent *ev );
00137 virtual DECLSPEC void onInit();
00138 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00139 virtual DECLSPEC void onEnabledChanged( bool enabled );
00140
00141 FunctionData cbClicked;
00142 private:
00143 };
00144
00150 class DECLSPEC GuiCheckableBtn : public GuiDynamicButton
00151 {
00152 public:
00153 DECLSPEC GuiCheckableBtn( const SDL_Rect &r, GuiElement *p, const char *name, const char *t = 0, SdlSurfaceContainer *b = 0, SdlAudio *u = 0, SdlAudio *d = 0 );
00160 DECLSPEC GuiCheckableBtn(TiXmlElement *el, GuiElement *p);
00161 virtual DECLSPEC ~GuiCheckableBtn();
00162
00163 virtual const char *getClassName() { return "GuiCheckableBtn"; }
00164
00165 DECLSPEC void setCheck( bool b );
00166 bool getCheck() const { return checked; }
00167 void setCheckCallback( Callback c ) { cbChecked.func = c; }
00168 void setCallbackData( BasicObject * d ) { cbChecked.obj = d; }
00169
00170 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00171 {
00172 GuiElement *r = new GuiCheckableBtn((TiXmlElement*)xmldata, (GuiElement*)o);
00173 *(GuiElement**)presult = r;
00174 }
00175 protected:
00176 virtual DECLSPEC Uint32 onMouseDown( SDL_MouseButtonEvent *ev );
00177 virtual DECLSPEC Uint32 onMouseUp( SDL_MouseButtonEvent *ev );
00178 virtual DECLSPEC void onInit();
00179 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00184 virtual DECLSPEC void onCheck( bool checked );
00185
00186 private:
00187 FunctionData cbChecked;
00188 bool checked;
00189 };
00190
00191
00197 class DECLSPEC GuiRadioBtn : public GuiCheckableBtn
00198 {
00199 public:
00200 DECLSPEC GuiRadioBtn(const SDL_Rect &r, GuiRadioContainer *p, const char *name,const char *t = 0, SdlSurfaceContainer *b = 0, SdlAudio *u = 0, SdlAudio *d = 0 );
00207 DECLSPEC GuiRadioBtn(TiXmlElement *el, GuiRadioContainer *p);
00208 virtual DECLSPEC ~GuiRadioBtn();
00209
00210 virtual const char *getClassName() { return "GuiRadioBtn"; }
00211
00212 GuiRadioContainer::button_iter getiter() {return iter;}
00213
00214 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00215 {
00216 GuiElement *r;
00217 if(strcmp(o->getClassName(), "GuiRadioContainer") == 0)
00218 r = new GuiRadioBtn((TiXmlElement*)xmldata, (GuiRadioContainer*)o);
00219 else {
00220 BasicApp::the->logLine("Error: GuiRadioBtn::newguiobject(): parent element's class must be GuiRadioContainer!");
00221 r = NULL;
00222 }
00223 *(GuiElement**)presult = r;
00224 }
00225
00226 protected:
00227 virtual DECLSPEC void onCheck( bool checked );
00228 virtual DECLSPEC void onInit();
00229 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00230
00231 private:
00232 GuiRadioContainer::button_iter iter;
00233 };
00234
00240 class DECLSPEC GuiMoveableBtn : public GuiClickableBtn
00241 {
00242 public:
00243 enum direction {horizontal, vertikal};
00244
00245 DECLSPEC GuiMoveableBtn( const SDL_Rect &r, GuiElement *p, const char *name, const char *t = 0, SdlSurfaceContainer *b = 0, SdlAudio *u = 0, SdlAudio *d = 0 );
00252 DECLSPEC GuiMoveableBtn(TiXmlElement *el, GuiElement *p);
00253 virtual DECLSPEC ~GuiMoveableBtn();
00254
00255 virtual const char *getClassName() { return "GuiMoveableBtn"; }
00256
00257 DECLSPEC bool setRange( Sint32 xStart, Sint32 yStart, Sint32 xEnd, Sint32 yEnd );
00258 DECLSPEC void setDirection( direction d );
00259 void setPosChangeCallback( Callback c, BasicObject *o ) { cbPoschanged.func = c; cbPoschanged.obj = o; }
00260 DECLSPEC void setPosToRange();
00261
00262 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00263 {
00264 GuiElement *r = new GuiMoveableBtn((TiXmlElement*)xmldata, (GuiElement*)o);
00265 *(GuiElement**)presult = r;
00266 }
00267 protected:
00268 virtual DECLSPEC Uint32 onResize();
00269 virtual DECLSPEC Uint32 onMouseMove( Uint32 x, Uint32 y );
00270 virtual DECLSPEC Uint32 onMouseUp( SDL_MouseButtonEvent *ev );
00271 virtual DECLSPEC Uint32 onButtonPress( Sint32 x, Sint32 y );
00272 virtual DECLSPEC Uint32 onButtonRelease( bool bInClient );
00273 virtual DECLSPEC void onInit();
00274 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00275
00276 direction dir;
00277 Sint32 xStart, yStart;
00278 Sint32 xEnd, yEnd;
00279 bool tracking;
00280 Sint32 xTrackingPoint, yTrackingPoint;
00281
00282 private:
00283 FunctionData cbPoschanged;
00284 };
00285
00286 #endif