guiscroller.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 GUISCROLLER_H
00023 #define GUISCROLLER_H
00024 
00025 #include "guidynamicbutton.h"
00026 #include "guibackground.h"
00027 
00039 class DECLSPEC GuiScroller : public GuiPictureBg  
00040 {
00041 public:
00042     enum direction {horizontal, vertikal};
00043 
00044     DECLSPEC GuiScroller( const SDL_Rect &r, GuiElement *p, const char *name, bool usetheme = true );
00051     DECLSPEC GuiScroller(TiXmlElement *el, GuiElement *p);
00052     virtual DECLSPEC ~GuiScroller();
00053 
00054     virtual const char *getClassName()  { return "GuiScroller"; }
00055     
00056     int getScrollPos() const    { return pos; }
00057     DECLSPEC int setScrollPos( int p );
00058     DECLSPEC int setMinMax( int mi, int ma );
00059     int getMax() const  { return max; }
00060     int getMin() const  { return min; }
00061     DECLSPEC void setDirection( direction d );
00062 
00063     void setChangeCallback( Callback c )    { cbChange.func = c; }
00064     void setCallbackData( BasicObject * d ) { cbChange.obj = d; }
00065 
00066     int tick;
00067     
00068     static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00069     {
00070         GuiElement *r = new GuiScroller((TiXmlElement*)xmldata, (GuiElement*)o);
00071         *(GuiElement**)presult = r;
00072     }
00073 protected:
00074     virtual DECLSPEC Uint32 onMouseDown( SDL_MouseButtonEvent *ev );
00075     virtual DECLSPEC Uint32 onMouseUp( SDL_MouseButtonEvent *ev );
00076     virtual DECLSPEC Uint32 onResize();
00077     virtual DECLSPEC void onInit();
00078     virtual DECLSPEC Uint32 onThemeChanged( UiTheme *t );
00079 
00080     GuiClickableBtn *buttonincrement;
00081     GuiClickableBtn *buttondecrement;
00082     GuiMoveableBtn *buttonmove;
00083 private:
00084     void updateitempos();
00085     void updateitemrange();
00086     void arrange();
00087     void increment();
00088     void decrement();
00089     void updatefromitem();
00090 
00091     FunctionData cbChange;
00092     direction dir;
00093     int pos;
00094     int min;
00095     int max;
00096     bool bThemeBtns;
00097 
00098     static inline void onButton( void* button, BasicObject * data, void* )
00099     {
00100         GuiScroller *scroller = (GuiScroller*)data;
00101         if( (GuiClickableBtn*)button == scroller->buttonincrement )
00102             scroller->increment();
00103         else if( (GuiClickableBtn*)button == scroller->buttondecrement )
00104             scroller->decrement();
00105         else if( (GuiClickableBtn*)button == scroller->buttonmove )
00106             scroller->updatefromitem();
00107     }
00108 
00109     static void setInfo();
00110     friend class guiinfo;
00111 };
00112 
00118 class DECLSPEC GuiScrollBg : public GuiElement
00119 {
00120 public:
00121     DECLSPEC GuiScrollBg( const SDL_Rect &r, GuiElement *el, const char *name, int minw, int minh, SdlSurface * bmp = NULL);
00128     DECLSPEC GuiScrollBg(TiXmlElement *el, GuiElement *p);
00129     virtual DECLSPEC ~GuiScrollBg();
00130 
00131     virtual const char *getClassName()  { return "GuiScrollBg"; }
00132     
00133     DECLSPEC void setMinSize( int w, int h );
00134     GuiFlowWindow *getwnd()             { return bg; }
00135     void setCallback( Callback c )      { cb.func = c; }
00136     void setCallbackData( BasicObject * d ) { cb.obj = d; }
00137 
00138     static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00139     {
00140         GuiElement *r = new GuiScrollBg((TiXmlElement*)xmldata, (GuiElement*)o);
00141         *(GuiElement**)presult = r;
00142     }
00143 protected:
00144     virtual DECLSPEC Uint32 onResize();
00145     virtual DECLSPEC void onInit();
00146 
00147 private:
00148     void arrange();
00149     void init(SdlSurface * bmp);
00150     
00151     int nMinWidth, nMinHeight;
00152     GuiScroller *scrolly;
00153     GuiScroller *scrollx;
00154     GuiFlowWindow *bg;
00155     GuiPictureBg *gpbCorner;
00156     FunctionData cb;
00157     void onScroll( GuiScroller * sender );
00158     static inline void onScroll( void * sender, BasicObject * data, void* )
00159     {
00160         ((GuiScrollBg*)data)->onScroll( (GuiScroller *)sender );
00161     };
00162 };
00163 
00164 #endif

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