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 "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
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
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
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