Advanced Strategic Command
guiiconhandler.h
Go to the documentation of this file.
1 // $Id: guiiconhandler.h,v 1.10 2009-07-12 13:53:47 mbickel Exp $
2 //
3 /*
4  This file is part of Advanced Strategic Command; http://www.asc-hq.de
5  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; see the file COPYING. If not, write to the
19  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  Boston, MA 02111-1307 USA
21 */
22 
23 #if defined(karteneditor) && !defined(pbpeditor)
24 #error the mapeditor is not supposed to use the gui icons !
25 #endif
26 
27 
28 #ifndef guiiconhandlerH
29 #define guiiconhandlerH
30 
31 #include "loki/Functor.h"
32 #include "loki/Typelist.h"
33 #include "graphics/surface.h"
34 
35 #include "paradialog.h"
36 #include "typen.h"
37 #include "containerbase.h"
38 #include "dashboard.h"
39 
40 #include "actions/command.h"
41 
42 extern const int smallGuiIconSizeX;
43 extern const int smallGuiIconSizeY;
44 
45 
46 class GuiFunction {
47 
48  public:
49  virtual bool available( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
50  virtual bool checkForKey( const SDL_KeyboardEvent* key, int modifier, int num ) { return false; };
51  virtual void execute( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
52  virtual Surface& getImage( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
53  virtual ASCString getName( const MapCoordinate& pos, ContainerBase* subject, int num ) = 0;
54  virtual ~GuiFunction() {};
55 };
56 
57 /*
58 class GenericGuiFunction : public GuiFunction {
59  ASCString name;
60  Surface icon;
61  public:
62  typedef Loki::Functor<bool, LOKI_TYPELIST_1(const MapCoordinate&)> Availability;
63  typedef Loki::Functor<void, LOKI_TYPELIST_1(const MapCoordinate&)> Execution;
64  protected:
65  Availability avail;
66  Execution exec;
67  public:
68 
69  GenericGuiFunction( Surface icon_, Availability availability, Execution execution, const ASCString& iconName )
70  : name(iconName), icon(icon_), avail(availability), exec(execution) {};
71 
72  bool available( const MapCoordinate& pos, int num ) { return avail(pos); };
73  void execute( const MapCoordinate& pos, int num ) { exec(pos); };
74  Surface& getImage( const MapCoordinate& pos, int num ) { return icon; };
75  ASCString getName( const MapCoordinate& pos, int num ) { return name; };
76 };
77 */
78 
79 class GuiButton : public PG_Button {
80  GuiFunction* func;
81  MapCoordinate pos;
82  ContainerBase* subject;
83  int id;
84  friend class SmallGuiButton;
85  protected:
86  void eventMouseEnter();
87  void eventMouseLeave();
88  void callFunc( const MapCoordinate& pos, ContainerBase* subject, int num );
89  public:
90  GuiButton( PG_Widget *parent, const PG_Rect &r );
91  void registerFunc( GuiFunction* f, const MapCoordinate& position, ContainerBase* subject, int id );
92  bool checkForKey( const SDL_KeyboardEvent* key, int modifier );
93  void unregisterFunc();
94  bool exec();
95  bool ready() { return func; };
96  void showInfoText();
97 };
98 
99 class NewGuiHost;
100 
101 
102 class SmallGuiButton : public PG_Button {
103  GuiButton* referenceButton;
104  SDL_Surface* smallIcon;
105  protected:
106  void eventMouseEnter();
107  void eventMouseLeave();
108  public:
109  SmallGuiButton( PG_Widget *parent, const PG_Rect &r, GuiButton* guiButton, NewGuiHost* host );
110  void updateIcon();
111  void press();
112  void showInfoText();
113  ~SmallGuiButton();
114 };
115 
116 
117 
119 
120  typedef list<GuiFunction*> Functions;
121  Functions functions;
122 
123 
124 
125  friend class NewGuiHost;
126  void registerHost( NewGuiHost* guiIconHost ) { host = guiIconHost; };
127  protected:
128  NewGuiHost* host;
129 
130  public:
131  GuiIconHandler() : host(NULL) {};
132 
135  void registerUserFunction( GuiFunction* function );
136 
137  virtual bool checkForKey( const SDL_KeyboardEvent* key, int modifier );
138 
140  // virtual void eval();
141 
142  virtual void eval( const MapCoordinate& pos, ContainerBase* subject );
143  virtual ~GuiIconHandler();
144 };
145 
146 class MapDisplayPG;
147 class MainScreenWidget;
148 class SmallButtonHolder;
149 
150 class NewGuiHost : public DashboardPanel {
151  GuiIconHandler* handler;
152  static NewGuiHost* theGuiHost;
153  list<GuiIconHandler*> iconHandlerStack;
154  MapDisplayPG* mapDisplay;
155  bool enterKeyPressed;
156  int keyPressedButton;
157 
158  void lockOptionsChanged( int options );
159 
160  void mapDeleted( GameMap& map );
161 
162  bool eventKeyDownSignal(const PG_MessageObject* o, const SDL_KeyboardEvent* key);
163  bool eventKeyUpSignal(const PG_MessageObject* o, const SDL_KeyboardEvent* key);
164 
165 
166  protected:
167  bool mapIconProcessing( const MapCoordinate& pos, const SPoint& mousePos, bool cursorChanged, int button, int prio );
168 
169  typedef vector<GuiButton*> Buttons;
171 
172  typedef vector<SmallGuiButton*> SmallButtons;
174 
175  SmallGuiButton* getSmallButton( int i );
176  int gapSize(int num );
177  void reflowSmallIcons(const SPoint& pos, int count);
178 
179 
180 
182 
183 
184  bool eventKeyDown(const SDL_KeyboardEvent* key);
185  bool eventKeyUp(const SDL_KeyboardEvent* key);
186 
188  bool setNewButtonPressed( int i );
189 
190  void evalCursor();
191 
192  public:
193  NewGuiHost (MainScreenWidget *parent, MapDisplayPG* mapDisplay, const PG_Rect &r ) ;
194 
195  static void pushIconHandler( GuiIconHandler* iconHandler );
196  static GuiIconHandler* getIconHandler( );
197  static void popIconHandler();
198 
199  void eval( const MapCoordinate& pos, ContainerBase* subject );
200 
201  bool showSmallIcons( PG_Widget* parent, const SPoint& pos, bool cursorChanged );
202  bool clearSmallIcons();
203 
204  GuiButton* getButton( int i );
205 
207  void disableButtons( int i );
208 
209  bool ProcessEvent (const SDL_Event *event, bool bModal);
210 
212 
213  ~NewGuiHost();
214 
215 };
216 
217 extern void resetActiveGuiAction( GameMap* map );
218 
219 
220 #endif
221 
virtual ~GuiFunction()
virtual bool checkForKey(const SDL_KeyboardEvent *key, int modifier)
The base class for buildings and vehicles.
virtual void eval(const MapCoordinate &pos, ContainerBase *subject)
checks evaluates the field on which the cursor resides
void disableButtons(int i)
disables all button from i onward
virtual bool checkForKey(const SDL_KeyboardEvent *key, int modifier, int num)
bool eventKeyUp(const SDL_KeyboardEvent *key)
GuiButton * getButton(int i)
bool ready()
void registerUserFunction(GuiFunction *function)
registers a user function.
void eventMouseLeave()
int gapSize(int num)
void resetActiveGuiAction(GameMap *map)
bool mapIconProcessing(const MapCoordinate &pos, const SPoint &mousePos, bool cursorChanged, int button, int prio)
static Command * pendingCommand
void showInfoText()
A Command is an action that the player initiates.
Definition: command.h:114
const int smallGuiIconSizeY
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool clearSmallIcons()
static void popIconHandler()
virtual bool available(const MapCoordinate &pos, ContainerBase *subject, int num)=0
bool eventKeyDown(const SDL_KeyboardEvent *key)
GuiButton(PG_Widget *parent, const PG_Rect &r)
static GuiIconHandler * getIconHandler()
bool checkForKey(const SDL_KeyboardEvent *key, int modifier)
virtual ASCString getName(const MapCoordinate &pos, ContainerBase *subject, int num)=0
Coordinate on the twodimensional map.
Definition: typen.h:202
Dialog classes based on the Paragui library.
SmallGuiButton * getSmallButton(int i)
virtual ~GuiIconHandler()
void callFunc(const MapCoordinate &pos, ContainerBase *subject, int num)
vector< GuiButton * > Buttons
void reflowSmallIcons(const SPoint &pos, int count)
NewGuiHost(MainScreenWidget *parent, MapDisplayPG *mapDisplay, const PG_Rect &r)
vector< SmallGuiButton * > SmallButtons
SDLmm::SPoint SPoint
Definition: surface.h:27
Buttons buttons
void registerFunc(GuiFunction *f, const MapCoordinate &position, ContainerBase *subject, int id)
const int smallGuiIconSizeX
bool showSmallIcons(PG_Widget *parent, const SPoint &pos, bool cursorChanged)
bool setNewButtonPressed(int i)
when operated by keyboard, set a new button as the pressed one
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
bool ProcessEvent(const SDL_Event *event, bool bModal)
SmallButtons smallButtons
static SmallButtonHolder * smallButtonHolder
SmallGuiButton(PG_Widget *parent, const PG_Rect &r, GuiButton *guiButton, NewGuiHost *host)
void eventMouseEnter()
void unregisterFunc()
NewGuiHost * host
virtual Surface & getImage(const MapCoordinate &pos, ContainerBase *subject, int num)=0
The box displaying unit information.
virtual void execute(const MapCoordinate &pos, ContainerBase *subject, int num)=0
static void pushIconHandler(GuiIconHandler *iconHandler)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182