guilist.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 1999, 2000, 2005 by Tobias Nadler und Georg Schnattinger      */
00005 /*                                                                              */
00006 /*  This library is free software; you can redistribute it and/or               */
00007 /*  modify it under the terms of the GNU Lesser General Public                  */
00008 /*  License as published by the Free Software Foundation; either                */
00009 /*  version 2.1 of the License, or (at your option) any later version.          */
00010 /*                                                                              */
00011 /*  This library is distributed in the hope that it will be useful,             */
00012 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of              */
00013 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
00014 /*  Lesser General Public License for more details.                             */
00015 /*                                                                              */
00016 /*  You should have received a copy of the GNU Lesser General Public            */
00017 /*  License along with this library; if not, write to the Free Software         */
00018 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */
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

Generated on Wed May 9 17:35:55 2007 for netrinjo by  doxygen 1.5.1