guiflowmenu.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 2006 by Tobias Nadler                                         */
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 GUIFLOWMENU_H
00023 #define GUIFLOWMENU_H
00024 
00025 #include <map>
00026 #include "guibackground.h"
00027 
00034 class GuiFlowMenuItem;
00035 
00044 class GuiFlowMenu: public GuiFlowWindow
00045 {
00046 public:
00061     DECLSPEC GuiFlowMenu(TiXmlElement *el, GuiElement *p);
00062     virtual DECLSPEC ~GuiFlowMenu();
00063     
00064     virtual const char *getClassName()  { return "GuiFlowMenu"; }
00066     long getActiveItemID()  {return nID;}
00068     GuiFlowMenuItem *getActiveItem()    {return mapMenues[nID];}
00073     void setFlyTime(Uint32 t)   {nTime = t;}
00079     void setShowRect(const SDL_Rect &r) {rShow = r;}
00085     void setDisappearRect(const SDL_Rect &r)    {rDisappear = r;}
00087     DECLSPEC void appear();
00089     DECLSPEC void disappear();
00098     void setChooseNextCallback(const BasicObject::FunctionData &fd) {cbChooseNext = fd;}
00109     void setNoNextCallback(const BasicObject::FunctionData &fd) {cbNoNext = fd;}
00117     void setFlewInCallback(const BasicObject::FunctionData &fd) {cbFlewIn = fd;}
00123     void setBackCallback(const BasicObject::FunctionData &fd)   {cbBack = fd;}
00124     //BEGIN declaration of slots
00125     static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00126     {
00127         GuiElement *r = new GuiFlowMenu((TiXmlElement*)xmldata, (GuiElement*)o);
00128         *(GuiElement**)presult = r;
00129     }
00130     static void flyout_back(void *sender, BasicObject *aim, void *)
00131     {
00132         ((GuiFlowMenu*)aim)->fly('b');
00133     }
00134     static void flyout_next(void *sender, BasicObject *aim, void *)
00135     {
00136         ((GuiFlowMenu*)aim)->fly('n', sender);
00137     }
00138     static void flyout_disappear(void *sender, BasicObject *aim, void *)
00139     {
00140         ((GuiFlowMenu*)aim)->fly('d');
00141     }
00142     static void flyin(void *sender, BasicObject *aim, void *)
00143     {
00144         ((GuiFlowMenu*)aim)->fly('s');
00145     }
00146     //END declaration of slots
00148     static const long ID_INVALID;
00149         
00150 protected:
00151     virtual DECLSPEC void onInit();
00152     virtual DECLSPEC Uint32 onPosReached();
00153     
00154 private:
00162     DECLSPEC bool registerItem(long id, GuiFlowMenuItem * el);
00168     DECLSPEC void unregisterItem(long id);
00169     
00170     // param is not always required (requirement depends on where_to)
00171     DECLSPEC void fly(char where_to, void *param = NULL);
00172     void createItemsByFile();
00173     bool showItem(long id, bool savehistory);
00174     long getIDbySender( BasicObject *sender );
00175     
00176     char *strXmlFilename;
00177     TiXmlDocument xmlFile;
00178     BasicObject::FunctionData cbFlewIn, cbDisappear, cbBack,
00179         cbChooseNext,// called, when the next menu must be chosen (3rd param: &next_ID)
00180         cbNoNext;// called, when there is no valid next-ID (i.e. you can start the game from here)
00181     
00182     SDL_Rect rShow, rDisappear;
00183     
00184     std::map<long, GuiFlowMenuItem*> mapMenues;
00185     long nID, nIDnext;// currently active item-ID
00186     GuiFlowMenuItem *pCurr;
00187     
00188     std::list<long> lLastItemIDs;
00189     
00190     enum MenuState{sNone = '-', sShow = 's', sBack = 'b', sNext = 'n', sDisappeared = 'd'} state;
00191     
00192     friend class GuiFlowMenuItem;
00193 };
00194 
00199 class GuiFlowMenuItem : public GuiElement
00200 {
00201     public:
00208         GuiFlowMenuItem( TiXmlElement *el, GuiFlowMenu *parent );
00215         GuiFlowMenuItem( const SDL_Rect &r, GuiFlowMenu *parent, const char *name, long id );
00216         virtual ~GuiFlowMenuItem();
00218         long getID()    {return nID;}
00222         bool activatorCompare( BasicObject *obj );
00228         void setBackRect(const SDL_Rect &r) {rBack = r;}
00234         void setNextRect(const SDL_Rect &r) {rNext = r;}
00238         const SDL_Rect &getRectNext()   {return rNext;}
00242         const SDL_Rect &getRectBack()   {return rBack;}
00243         
00244         // the slot for creating
00245         static void newguiobject(void *presult, BasicObject *o, void *xmldata)
00246         {
00247             GuiElement *r = new GuiFlowMenuItem((TiXmlElement*)xmldata, (GuiFlowMenu*)o);
00248             *(GuiElement**)presult = r;
00249         }
00250         
00251     protected:
00252         virtual void onInit();
00253         
00254     private:
00255         long nID;
00256         bool bFailed;
00257         char *strActivator;
00258         SDL_Rect rNext, rBack;
00259 };
00260 
00261 
00262 #endif

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