guimenu.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 2007 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 GUIMENU_H
00023 #define GUIMENU_H
00024 
00025 #include "guidynamicbutton.h"
00026 
00033 class GuiMenuItem;
00034 class GuiMenuBar;
00035 
00042 class DECLSPEC GuiMenuBar : public GuiElement
00043 {
00044 public:
00045     DECLSPEC GuiMenuBar( const SDL_Rect &r, GuiElement *parent, const char *name, bool horizontal = true );
00046     virtual DECLSPEC ~GuiMenuBar();
00047     
00048     virtual const char * getClassName() { return "GuiMenuBar"; }
00049     
00051     DECLSPEC void hideSubmenus();
00056     DECLSPEC void showAt( const SDL_Rect &r );
00063     DECLSPEC void setCallback( const FunctionData &fd ) { fdSelect = fd; }
00064     
00065 protected:
00070     virtual DECLSPEC void onSelect( GuiMenuItem *selected );
00071     
00072 private:
00073     // refreshes the positions of it's items and it's visibility
00074     void refresh();
00075     // sets the positoion and adds it to lItems
00076     void add( GuiMenuItem *item );
00077     // true if the items are listed in a row; false if in a column
00078     bool bHorizontal;
00079     std::list<GuiMenuItem*> lItems;
00080     // pointer to an item that makes this menu appear, NULL if there is none
00081     GuiMenuItem *pActivator;
00082     
00083     FunctionData fdSelect;
00084     
00085     friend class GuiMenuItem;
00086 };
00087 
00088 
00095 class DECLSPEC GuiMenuItem: public GuiElement
00096 {
00097 public:
00098     enum TYPE {tCheckable, tClickable, tSubmenu};
00104     DECLSPEC GuiMenuItem( const SDL_Rect &r, GuiMenuBar *parent, const char *name, bool checkable = false,
00105                           const char *txt=0, SdlSurfaceContainer *b=0, SdlAudio *u=0, SdlAudio *d=0 );
00114     DECLSPEC GuiMenuItem( const SDL_Rect &r, GuiMenuBar *parent, const char *name, GuiMenuBar *submenu,
00115                           const char *txt=NULL, SdlSurfaceContainer *b=0, SdlAudio *u=0, SdlAudio *d=0 );
00116     virtual DECLSPEC ~GuiMenuItem();
00117     
00118     virtual const char * getClassName() { return "GuiMenuItem"; }
00119     
00121     int getItemID() { return nID; }
00126     void setItemID( int id )    { nID = id; }
00132     DECLSPEC void setSelectable( bool cansel );
00136     GuiMenuBar *getBar()    { return pSubmenu ? pSubmenu : gmbSubmenu; }
00142     void setButtonImages( SdlSurfaceContainer *b );
00143     
00144 private:
00145     static void OnClicked( void *sender, BasicObject *aim, void * )
00146     {
00147         ((GuiMenuItem*)aim)->onClicked();
00148     }
00149     void onClicked();
00150     // called only if type==tSubmenu and when the submenu is closed (hidden)
00151     void onSubClose( GuiMenuItem *selected );
00152     // hides other menus (necessary when the submenu appears)
00153     void hideSiblingMenus();
00154     
00155     GuiDynamicButton *gdbMain;
00156     // pointer to independent menu
00157     GuiMenuBar *pSubmenu;
00158     // pointer to self-created menu (will be destroyed with this)
00159     GuiMenuBar *gmbSubmenu;
00160     //GuiText *gtDescription;
00161     TYPE type;
00162     int nID;
00163     
00164     friend class GuiMenuBar;
00165 };
00166 
00167 
00168 #endif

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