Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

guiiconhandler.h

Go to the documentation of this file.
00001 //     $Id: guiiconhandler.h,v 1.5 2007-04-22 13:56:58 mbickel Exp $
00002 //
00003 /*
00004     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00005     Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; see the file COPYING. If not, write to the 
00019     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00020     Boston, MA  02111-1307  USA
00021 */
00022 
00023 #if defined(karteneditor) && !defined(pbpeditor)
00024 #error the mapeditor is not supposed to use the gui icons  !
00025 #endif
00026 
00027 
00028 #ifndef guiiconhandlerH
00029 #define guiiconhandlerH
00030 
00031 #include "libs/loki/Functor.h"
00032 #include "graphics/surface.h"
00033 
00034 #include "paradialog.h"
00035 #include "typen.h"
00036 #include "containerbase.h"
00037 #include "dashboard.h"
00038 
00039 extern const int smallGuiIconSizeX;
00040 extern const int smallGuiIconSizeY;
00041 
00042 
00043 class GuiFunction {
00044 
00045      public:
00046        virtual bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
00047        virtual bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) { return false; };
00048        virtual void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
00049        virtual Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
00050        virtual ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
00051        virtual ~GuiFunction() {};
00052 };
00053 
00054 /*
00055 class GenericGuiFunction : public GuiFunction {
00056         ASCString name;
00057         Surface icon;
00058      public:
00059         typedef Loki::Functor<bool, TYPELIST_1(const MapCoordinate&)> Availability;
00060         typedef Loki::Functor<void, TYPELIST_1(const MapCoordinate&)> Execution;
00061      protected:
00062         Availability avail;
00063         Execution exec;
00064      public:   
00065      
00066         GenericGuiFunction( Surface icon_, Availability availability, Execution execution, const ASCString& iconName ) 
00067                          : name(iconName), icon(icon_), avail(availability), exec(execution) {};
00068 
00069         bool available( const MapCoordinate& pos, int num ) { return avail(pos); };
00070         void execute( const MapCoordinate& pos, int num )   { exec(pos); };
00071         Surface& getImage( const MapCoordinate& pos, int num ) { return icon; };
00072         ASCString getName( const MapCoordinate& pos, int num ) { return name; };
00073 };
00074 */
00075 
00076 class GuiButton : public PG_Button {
00077           GuiFunction* func;
00078           MapCoordinate pos;
00079           ContainerBase* subject;
00080           int id;
00081           friend class SmallGuiButton;
00082        protected:
00083           void eventMouseEnter();
00084           void eventMouseLeave();
00085        public:
00086           GuiButton( PG_Widget *parent, const PG_Rect &r );
00087           void registerFunc( GuiFunction* f, const MapCoordinate& position, ContainerBase* subject, int id );
00088           bool checkForKey( const SDL_KeyboardEvent* key, int modifier );
00089           void unregisterFunc();
00090           bool exec();
00091           bool ready() { return func; };
00092           void showInfoText();
00093 };
00094 
00095 class NewGuiHost;
00096 
00097 
00098 class SmallGuiButton : public PG_Button {
00099           GuiButton* referenceButton;
00100           SDL_Surface* smallIcon;
00101        protected:
00102           void eventMouseEnter();
00103           void eventMouseLeave();
00104        public:
00105           SmallGuiButton( PG_Widget *parent, const PG_Rect &r, GuiButton* guiButton, NewGuiHost* host );
00106           void updateIcon();
00107           void press();
00108           void showInfoText();
00109           ~SmallGuiButton();
00110 };
00111 
00112 
00113 
00114 class GuiIconHandler {
00115 
00116        typedef list<GuiFunction*> Functions;
00117        Functions functions;
00118 
00119 
00120 
00121        friend class NewGuiHost;
00122        void registerHost( NewGuiHost* guiIconHost ) { host = guiIconHost; };
00123      protected:
00124         NewGuiHost* host;
00125 
00126      public:
00127        GuiIconHandler() : host(NULL) {};
00128 
00131        void registerUserFunction( GuiFunction* function );
00132 
00133        virtual bool checkForKey( const SDL_KeyboardEvent* key, int modifier );
00134 
00136        // virtual void eval();
00137        
00138        virtual void eval( const MapCoordinate& pos, ContainerBase* subject );
00139        virtual ~GuiIconHandler();
00140 };
00141 
00142 class MapDisplayPG;
00143 class MainScreenWidget;
00144 class SmallButtonHolder;
00145 
00146 class NewGuiHost : public DashboardPanel {
00147         GuiIconHandler* handler;
00148         static NewGuiHost* theGuiHost;
00149         list<GuiIconHandler*> iconHandlerStack;
00150         MapDisplayPG* mapDisplay;
00151         bool enterKeyPressed;
00152         int keyPressedButton;
00153         
00154         void lockOptionsChanged( int options );
00155 
00156         void mapDeleted( GameMap& map );
00157         
00158      protected:
00159         bool mapIconProcessing( const MapCoordinate& pos, const SPoint& mousePos, bool cursorChanged, int button, int prio );
00160 
00161         typedef vector<GuiButton*> Buttons;
00162         Buttons buttons;
00163 
00164         typedef vector<SmallGuiButton*> SmallButtons;
00165         SmallButtons smallButtons;
00166 
00167         SmallGuiButton* getSmallButton( int i );
00168         
00169         
00170         static SmallButtonHolder* smallButtonHolder;
00171 
00172 
00173         bool eventKeyDown(const SDL_KeyboardEvent* key);
00174         bool eventKeyUp(const SDL_KeyboardEvent* key);
00175 
00177         bool setNewButtonPressed( int i );
00178 
00179         void evalCursor();
00180         
00181      public:
00182         NewGuiHost (MainScreenWidget *parent, MapDisplayPG* mapDisplay, const PG_Rect &r ) ;
00183         
00184         static void pushIconHandler( GuiIconHandler* iconHandler );
00185         static GuiIconHandler* getIconHandler(  );
00186         static void popIconHandler();
00187         
00188         void eval( const MapCoordinate& pos, ContainerBase* subject );
00189 
00190         bool showSmallIcons( PG_Widget* parent, const SPoint& pos, bool cursorChanged );
00191         bool clearSmallIcons();
00192 
00193         GuiButton* getButton( int i );
00194 
00196         void disableButtons( int i );
00197 
00198         bool ProcessEvent (const SDL_Event *event, bool bModal);
00199 
00200         
00201         ~NewGuiHost();
00202 
00203 };
00204 
00205 
00206 
00207 #endif
00208 

Generated on Tue Jun 24 01:27:44 2008 for Advanced Strategic Command by  doxygen 1.4.2