00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
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
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