00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #ifndef GUIUPDOWN_H
00023 #define GUIUPDOWN_H
00024 
00025 #include "guibackground.h"
00026 #include "guitext.h"
00027 #include "guidynamicbutton.h"
00028 
00040 class DECLSPEC GuiUpDown : public GuiPictureBg
00041 {
00042 public:
00043     DECLSPEC GuiUpDown( const SDL_Rect &r, GuiElement *el, const char *name, int val = 0, bool usetheme = true );
00052     DECLSPEC GuiUpDown(TiXmlElement *el, GuiElement *p);
00053     virtual DECLSPEC ~GuiUpDown();
00054 
00055     virtual const char *getClassName()  { return "GuiUpDown"; }
00056     
00057     void setCallback( Callback c )      { cb.func = c; }
00058     void setCallbackData( BasicObject* d )  { cb.obj = d; }
00059     DECLSPEC void setValue( int v );
00060     DECLSPEC void setMinMax( int min, int max );
00061     void chooseFont( GuiText::FontSize size, bool light )   { text->chooseFont( size, light ); }
00062     DECLSPEC int getValue();
00063 
00064     DECLSPEC int operator ++();
00065     DECLSPEC int operator --();
00066     DECLSPEC int operator +=(int i);
00067     DECLSPEC int operator -=(int i);
00068 
00069     int increment;
00070 
00071     static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00072     {
00073         GuiElement *r = new GuiUpDown((TiXmlElement*)xmldata, (GuiElement*)o);
00074         *(GuiElement**)presult = r;
00075     }
00076 protected:
00077     virtual DECLSPEC Uint32 onRelease();
00078     virtual DECLSPEC Uint32 onResize();
00079     virtual DECLSPEC void onInit();
00080     virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00081 
00082 private:
00083     void refresh();
00084     void arrange();
00085     void onButton( GuiClickableBtn * button );
00086 
00087     FunctionData cb;
00088     int value;
00089     int min, max;
00090     GuiClickableBtn * up;
00091     GuiClickableBtn * down;
00092     GuiTextInput * text;
00093 
00094     bool bThemeBtns;
00095 
00096     static inline void onUdBtn( void * btn, BasicObject *reciever, void * )
00097     {
00098         ((GuiUpDown*)reciever )->onButton( (GuiClickableBtn*)btn );
00099     }
00100     static inline void onText( void*, BasicObject *reciever, void * )
00101     {
00102         ((GuiUpDown*)reciever )->onRelease();
00103     }
00104 };
00105 
00106 #endif