00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef GUILIST_H
00023 #define GUILIST_H
00024
00025 #include "guibackground.h"
00026 #include "guiscroller.h"
00027 #include <vector>
00028
00035 using namespace std;
00036
00042 class DECLSPEC GuiList : public GuiPictureBg
00043 {
00044 public:
00045 DECLSPEC GuiList( const SDL_Rect &r, GuiElement *p, const char *name );
00052 DECLSPEC GuiList(TiXmlElement *el, GuiElement *p);
00053 virtual DECLSPEC ~GuiList();
00054
00055 virtual const char *getClassName() { return "GuiList"; }
00056
00057 DECLSPEC int insertStr( const char* str, int pos = -1 );
00058 DECLSPEC bool clearStr( int pos = -1 );
00059 DECLSPEC void clearAll();
00060 DECLSPEC bool changeStr( const char *newstr, int pos );
00061 DECLSPEC const char *getStr( int pos ) const;
00062 DECLSPEC const char *getSelStr() const;
00063 DECLSPEC int getSelId() const;
00064 DECLSPEC int getCount() const;
00065
00066 void setSelChangeCallback( Callback c ) { cbSelchanged.func = c; }
00067 void setCallbackData( BasicObject * d ) { cbSelchanged.obj = d; }
00068 void setSelected( int i ) { selected = i; }
00069
00070 static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00071 {
00072 GuiElement *r = new GuiList((TiXmlElement*)xmldata, (GuiElement*)o);
00073 *(GuiElement**)presult = r;
00074 }
00075 protected:
00076 virtual DECLSPEC Uint32 onFrame( SdlSurface *dst );
00077 virtual DECLSPEC Uint32 onResize();
00078 virtual DECLSPEC Uint32 onMouseDown( SDL_MouseButtonEvent *ev );
00079 virtual DECLSPEC void onInit();
00080 virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00081 private:
00082 typedef vector<char*> strlist;
00083 typedef strlist::iterator strlist_iter;
00084
00085 void arrange();
00086 strlist_iter iterfrompos(int pos);
00087 void update();
00088 void updatefromscroller();
00089
00090 strlist strings;
00091 int selected;
00092 int topitem;
00093
00094 GuiScroller *scroller;
00095 Uint32 nMaxScroll;
00096 SdlFont *font, *fontSel;
00097
00098 FunctionData cbSelchanged;
00099
00100 static inline void ontopitemchanged(void*, BasicObject *data, void*)
00101 {
00102 GuiList *list = (GuiList*)data;
00103 list->updatefromscroller();
00104 }
00105 };
00106
00107 #endif