guiiconhandler.h

Go to the documentation of this file.
00001 //     $Id: guiiconhandler.h,v 1.10 2009-07-12 13:53:47 mbickel Exp $
00002 //
00003 /*
00004     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00005     Copyright (C) 1994-2010  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 "loki/Functor.h"
00032 #include "loki/Typelist.h"
00033 #include "graphics/surface.h"
00034 
00035 #include "paradialog.h"
00036 #include "typen.h"
00037 #include "containerbase.h"
00038 #include "dashboard.h"
00039 
00040 #include "actions/command.h"
00041 
00042 extern const int smallGuiIconSizeX;
00043 extern const int smallGuiIconSizeY;
00044 
00045 
00046 class GuiFunction {
00047 
00048      public:
00049        virtual bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
00050        virtual bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) { return false; };
00051        virtual void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
00052        virtual Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
00053        virtual ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
00054        virtual ~GuiFunction() {};
00055 };
00056 
00057 /*
00058 class GenericGuiFunction : public GuiFunction {
00059         ASCString name;
00060         Surface icon;
00061      public:
00062         typedef Loki::Functor<bool, LOKI_TYPELIST_1(const MapCoordinate&)> Availability;
00063         typedef Loki::Functor<void, LOKI_TYPELIST_1(const MapCoordinate&)> Execution;
00064      protected:
00065         Availability avail;
00066         Execution exec;
00067      public:   
00068      
00069         GenericGuiFunction( Surface icon_, Availability availability, Execution execution, const ASCString& iconName ) 
00070                          : name(iconName), icon(icon_), avail(availability), exec(execution) {};
00071 
00072         bool available( const MapCoordinate& pos, int num ) { return avail(pos); };
00073         void execute( const MapCoordinate& pos, int num )   { exec(pos); };
00074         Surface& getImage( const MapCoordinate& pos, int num ) { return icon; };
00075         ASCString getName( const MapCoordinate& pos, int num ) { return name; };
00076 };
00077 */
00078 
00079 class GuiButton : public PG_Button {
00080           GuiFunction* func;
00081           MapCoordinate pos;
00082           ContainerBase* subject;
00083           int id;
00084           friend class SmallGuiButton;
00085        protected:
00086           void eventMouseEnter();
00087           void eventMouseLeave();
00088           void callFunc( const MapCoordinate& pos, ContainerBase* subject, int num );
00089        public:
00090           GuiButton( PG_Widget *parent, const PG_Rect &r );
00091           void registerFunc( GuiFunction* f, const MapCoordinate& position, ContainerBase* subject, int id );
00092           bool checkForKey( const SDL_KeyboardEvent* key, int modifier );
00093           void unregisterFunc();
00094           bool exec();
00095           bool ready() { return func; };
00096           void showInfoText();
00097 };
00098 
00099 class NewGuiHost;
00100 
00101 
00102 class SmallGuiButton : public PG_Button {
00103           GuiButton* referenceButton;
00104           SDL_Surface* smallIcon;
00105        protected:
00106           void eventMouseEnter();
00107           void eventMouseLeave();
00108        public:
00109           SmallGuiButton( PG_Widget *parent, const PG_Rect &r, GuiButton* guiButton, NewGuiHost* host );
00110           void updateIcon();
00111           void press();
00112           void showInfoText();
00113           ~SmallGuiButton();
00114 };
00115 
00116 
00117 
00118 class GuiIconHandler {
00119 
00120        typedef list<GuiFunction*> Functions;
00121        Functions functions;
00122 
00123 
00124 
00125        friend class NewGuiHost;
00126        void registerHost( NewGuiHost* guiIconHost ) { host = guiIconHost; };
00127      protected:
00128         NewGuiHost* host;
00129 
00130      public:
00131        GuiIconHandler() : host(NULL) {};
00132 
00135        void registerUserFunction( GuiFunction* function );
00136 
00137        virtual bool checkForKey( const SDL_KeyboardEvent* key, int modifier );
00138 
00140        // virtual void eval();
00141        
00142        virtual void eval( const MapCoordinate& pos, ContainerBase* subject );
00143        virtual ~GuiIconHandler();
00144 };
00145 
00146 class MapDisplayPG;
00147 class MainScreenWidget;
00148 class SmallButtonHolder;
00149 
00150 class NewGuiHost : public DashboardPanel {
00151         GuiIconHandler* handler;
00152         static NewGuiHost* theGuiHost;
00153         list<GuiIconHandler*> iconHandlerStack;
00154         MapDisplayPG* mapDisplay;
00155         bool enterKeyPressed;
00156         int keyPressedButton;
00157         
00158         void lockOptionsChanged( int options );
00159 
00160         void mapDeleted( GameMap& map );
00161         
00162      protected:
00163         bool mapIconProcessing( const MapCoordinate& pos, const SPoint& mousePos, bool cursorChanged, int button, int prio );
00164 
00165         typedef vector<GuiButton*> Buttons;
00166         Buttons buttons;
00167 
00168         typedef vector<SmallGuiButton*> SmallButtons;
00169         SmallButtons smallButtons;
00170 
00171         SmallGuiButton* getSmallButton( int i );
00172         
00173         
00174         static SmallButtonHolder* smallButtonHolder;
00175 
00176 
00177         bool eventKeyDown(const SDL_KeyboardEvent* key);
00178         bool eventKeyUp(const SDL_KeyboardEvent* key);
00179 
00181         bool setNewButtonPressed( int i );
00182 
00183         void evalCursor();
00184         
00185      public:
00186         NewGuiHost (MainScreenWidget *parent, MapDisplayPG* mapDisplay, const PG_Rect &r ) ;
00187         
00188         static void pushIconHandler( GuiIconHandler* iconHandler );
00189         static GuiIconHandler* getIconHandler(  );
00190         static void popIconHandler();
00191         
00192         void eval( const MapCoordinate& pos, ContainerBase* subject );
00193 
00194         bool showSmallIcons( PG_Widget* parent, const SPoint& pos, bool cursorChanged );
00195         bool clearSmallIcons();
00196 
00197         GuiButton* getButton( int i );
00198 
00200         void disableButtons( int i );
00201 
00202         bool ProcessEvent (const SDL_Event *event, bool bModal);
00203 
00204         static Command* pendingCommand;
00205         
00206         ~NewGuiHost();
00207 
00208 };
00209 
00210 extern void resetActiveGuiAction( GameMap* map );
00211 
00212 
00213 #endif
00214 

Generated on Mon May 21 01:26:34 2012 for Advanced Strategic Command by  doxygen 1.5.1