Advanced Strategic Command
mapdisplay.h
Go to the documentation of this file.
1 /***************************************************************************
2  mapdisplay.h - description
3  -------------------
4  begin : Wed Jan 24 2001
5  copyright : (C) 2001 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef mapdisplayH
19  #define mapdisplayH
20 
21 
22 #include <sigc++/sigc++.h>
23 #include "loki/Functor.h"
24 
25 
26 #include "typen.h"
27 #include "vehicle.h"
28 
29 
30 #include "paradialog.h"
31 #include "mapdisplayinterface.h"
32 
33 class MapLayer;
34 
35 class MapRenderer {
36 
37  struct Icons {
38  Surface mapBackground;
39  Surface notVisible;
40  Surface markField;
41  Surface markFieldDark;
42  };
43  static Icons icons;
44 
46  LayerRenderer layerRenderer;
47 
48  void readData();
49 
50  public:
52  public:
60  };
61 
62  protected:
63  MapRenderer();
64 
65  void paintUnitOntoField( const MapRenderer::FieldRenderInfo& fieldInfo, int binaryUnitHeight, const SPoint& pos, Vehicle* vehicle );
66 
67 
68  static const int surfaceBorder = 90;
69 
70  struct ViewPort {
71  ViewPort( int x1, int y1, int x2, int y2 );
72  ViewPort();
73  int x1,y1,x2,y2;
74  };
75 
76  // return the position of a field on the internal surface
77  int getFieldPosX( int x, int y ) {
78  if (y & 1 ) // even lines are shifted to the right
80  else
81  return surfaceBorder + x * fielddistx;
82  };
83 
84  // return the position of a field on the internal surface
85  int getFieldPosY( int x, int y ) {
86  return surfaceBorder + y * fielddisty;
87  };
88 
89  SPoint getFieldPos( int x, int y ) {
90  return SPoint( getFieldPosX(x,y), getFieldPosY(x,y));
91  };
93  return SPoint( getFieldPosX(pos.x,pos.y), getFieldPosY(pos.x,pos.y));
94  };
95 
96  void paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo, int layer, const SPoint& pos );
97  void paintTerrain( Surface& surf, GameMap* actmap, int playerView, const ViewPort& viewPort, const MapCoordinate& offset );
98  void paintBackground( Surface& surf, const ViewPort& viewPort );
99  void paintBackgroundField( Surface& surf, SPoint pos );
100 
101  int bitmappedHeight2pass( int height );
102 
103  sigc::signal<void,Surface&,int> additionalItemDisplayHook;
104 
105  void addMapLayer( MapLayer* mapLayer ) { layerRenderer.push_back( mapLayer ); };
106 
107 };
108 
109 
110 class MapLayer {
111  bool active;
112  protected:
113  MapLayer() : active(true) {};
114  public:
115  virtual bool onLayer( int layer ) = 0;
116  bool isActive() { return active; };
117  virtual void setActive( bool active ) { this->active = active; };
118  virtual void paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo, int layer, const SPoint& pos ) = 0;
119  virtual ~MapLayer() {};
120 };
121 
122 
123 
124 
125 class MainScreenWidget;
126 
127 
128 
129 
130 class MapDisplayPG: public PG_Widget, protected MapRenderer {
131 
132  typedef map<ASCString,MapLayer*> LayerMap;
133  LayerMap layerMap;
134 
135  struct Icons {
136  Surface cursor;
137  Surface fieldShape;
138  };
139  static Icons icons;
140 
141  void readData();
142 
143  static MapDisplayPG* theMapDisplay;
144 
145 
146  int zoom;
147  Surface* surface;
148 
149  GameMap* lastDisplayedMap;
150  void sigMapDeleted( GameMap& deletedMap );
151 
152  MapCoordinate offset;
153 
154  void setupFastBlitterCommands();
155  struct Field {
156  ViewPort viewPort;
157  int numx, numy;
158  } field;
159 
160 
161  void displayCursor( const PG_Rect& dst );
162  void displayCursor();
163 
164  enum Dirty { Nothing, Curs, Map } dirty;
165 
166  Vehicle* additionalUnit;
167 
168  void lockOptionsChanged( int options );
169 
170  protected:
171 
172  // Paragui stuff
173  void eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst);
174  // void eventDraw(SDL_Surface* surface, const PG_Rect& rect);
175 
176 
177  bool eventMouseButtonDown (const SDL_MouseButtonEvent *button);
178  bool eventMouseMotion (const SDL_MouseMotionEvent *button);
179  bool eventMouseButtonUp (const SDL_MouseButtonEvent *button);
180 
181  //
182 
183  void checkViewPosition( MapCoordinate& pos );
184 
185  void fillSurface( int playerView );
186  void paintBackground( );
187 
188 
189  public:
190  void changeZoom( int delta) { setNewZoom( getZoom() + delta); };
191  void setNewZoom( int zoom );
192  int getZoom() const { return zoom; };
193  sigc::signal<void, int> newZoom;
194 
195  MapCoordinate screenPos2mapPos( const SPoint& pos );
196  MapCoordinate widgetPos2mapPos( const SPoint& pos );
197 
200  SPoint internal2widget( const SPoint& pos );
201  SPoint widget2screen( const SPoint& pos );
202 
205 
206  bool fieldCompletelyInViewX( const MapCoordinate& pos );
207  bool fieldCompletelyInViewY( const MapCoordinate& pos );
208  bool fieldCompletelyInView( const MapCoordinate& pos );
209 
210  private:
211  SPoint upperLeftSourceBlitCorner;
212  protected:
213 
214 
215  void blitInternalSurface( SDL_Surface* dest, const SPoint& pnt, const PG_Rect& dstClip );
216 
217 
220 
221  struct MovementMask {
225 
226  void displayAddons( Surface& surf, int pass);
227 
228  struct Movement {
233  int toShadow;
237 
242 
243  static const int touchedFieldNum = 10;
245  struct {
249 
250  };
251 
252  void initMovementStructure();
254  void displayMovementStep( Movement& movement, int percentage );
255 
256  bool eventKeyDown(const SDL_KeyboardEvent* key)
257  {
258  return keyboardHandler( NULL, key );
259  };
260 
261  bool keyboardHandler( PG_MessageObject* o, const SDL_KeyboardEvent* keyEvent);
262 
264 
265  public:
266  void keyboadCursorMovement( bool enable ) { disableKeyboardCursorMovement = !enable; };
267 
268  void scrollMap( int dir );
269 
270  private:
271  void UpdateRect( const PG_Rect& rect );
272  void moveCursor( int dir, int step );
273  void redrawMapAtCursor ( const MapCoordinate& oldpos );
274 
275  public:
276 
277 
278 
279  MapDisplayPG ( MainScreenWidget *parent, const PG_Rect r );
280 
281  void displayUnitMovement( GameMap* actmap, Vehicle* veh, const MapCoordinate3D& from, const MapCoordinate3D& to, int duration );
282 
283  bool fieldInView(const MapCoordinate& mc );
284  bool centerOnField( const MapCoordinate& mc );
285 
286  void registerAdditionalUnit ( Vehicle* veh );
287 
289  void updateMap( bool force = false );
290 
292  void updateWidget();
293 
294  void addMapLayer( MapLayer* layer, const ASCString& name );
295  void activateMapLayer( const ASCString& name, bool active );
296  void toggleMapLayer( const ASCString& name );
297  bool layerActive( const ASCString& name );
298  sigc::signal<void, bool, const ASCString&> layerChanged;
299  void getActiveLayers( vector<ASCString>& list );
300 
301 
302  private:
303  int signalPrio;
304  public:
305  int setSignalPriority( int priority );
306 
314  sigc::signal<bool,const MapCoordinate&, const SPoint&, bool, int, int> mouseButtonOnField;
315 
322  sigc::signal<bool,const MapCoordinate&, const SPoint&, bool, int> mouseDraggedToField;
323 
324 
325  struct Cursor {
329  friend class MapDisplayPG;
330  friend class PG_MapDisplay;
331  MapCoordinate& pos();
332  public:
333  void goTo( const MapCoordinate& position );
334  void goTo( const MapCoordinate& cursorPosition, const MapCoordinate& upperLeftScreenCorner );
335  void intoView();
336  } cursor;
337 
338  class CursorHiding {
339  public:
340  CursorHiding();
341  ~CursorHiding();
342  };
343 
344  friend class CursorHiding;
345 
346  class LockDisplay {
347  private:
348  bool isDummy;
349  void raiseLock();
350  public:
351  LockDisplay( bool dummy = false );
352  ~LockDisplay();
353  };
354 
355  friend class LockDisplay;
356 
357 
358  ~MapDisplayPG ();
359  private:
360  int lock;
361 
362 };
363 
364 extern sigc::signal<void> lockMapdisplay;
365 extern sigc::signal<void> unlockMapdisplay;
366 
367 
369 
370 extern void benchMapDisplay();
371 
372 
373 #endif
SPoint mapGlobalPos2internalPos(const MapCoordinate &pos)
Definition: mapdisplay.cpp:898
void paintSingleField(const MapRenderer::FieldRenderInfo &fieldInfo, int layer, const SPoint &pos)
Definition: mapdisplay.cpp:436
MapDisplayPG * mapDisplay
Definition: mapdisplay.h:327
void paintBackground(Surface &surf, const ViewPort &viewPort)
Definition: mapdisplay.cpp:544
void displayMovementStep(Movement &movement, int percentage)
void getActiveLayers(vector< ASCString > &list)
int getFieldPosY(int x, int y)
Definition: mapdisplay.h:85
virtual void setActive(bool active)
Definition: mapdisplay.h:117
bool fieldInView(const MapCoordinate &mc)
void toggleMapLayer(const ASCString &name)
void paintTerrain(Surface &surf, GameMap *actmap, int playerView, const ViewPort &viewPort, const MapCoordinate &offset)
Definition: mapdisplay.cpp:558
MapCoordinate lowerRightCorner()
Definition: mapdisplay.cpp:952
bool fieldCompletelyInViewY(const MapCoordinate &pos)
void paintBackground()
Definition: mapdisplay.cpp:750
FieldRenderInfo(Surface &s, GameMap *actmap)
Definition: mapdisplay.h:53
Surface createMovementBufferSurface()
bool keyboardHandler(PG_MessageObject *o, const SDL_KeyboardEvent *keyEvent)
MapCoordinate & pos()
bool eventKeyDown(const SDL_KeyboardEvent *key)
Definition: mapdisplay.h:256
PG_Rect blitViewPortInternal
Definition: mapdisplay.h:238
bool disableKeyboardCursorMovement
Definition: mapdisplay.h:263
VisibilityStates
the different states that a player's view on a field can have
Definition: typen.h:403
SPoint getFieldPos2(const MapCoordinate &pos)
Definition: mapdisplay.h:92
sigc::signal< void > unlockMapdisplay
Definition: mapdisplay.cpp:68
sigc::signal< void, bool, const ASCString & > layerChanged
Definition: mapdisplay.h:298
sigc::signal< bool, const MapCoordinate &, const SPoint &, bool, int > mouseDraggedToField
Signal that is fired when the mouse is dragged onto a new field with mouse buttons pressed...
Definition: mapdisplay.h:322
static const int surfaceBorder
Definition: mapdisplay.h:68
static const int effectiveMovementSurfaceWidth
Definition: mapdisplay.h:218
virtual bool onLayer(int layer)=0
static const int effectiveMovementSurfaceHeight
Definition: mapdisplay.h:219
void fillSurface(int playerView)
Definition: mapdisplay.cpp:738
SPoint getFieldPos(int x, int y)
Definition: mapdisplay.h:89
void updateMap(bool force=false)
repaints to the internal surface, but does not blit this surface the screen
Definition: mapdisplay.cpp:785
void registerAdditionalUnit(Vehicle *veh)
a single field of the map
Definition: mapfield.h:26
struct MapDisplayPG::Cursor cursor
void setNewZoom(int zoom)
Definition: mapdisplay.cpp:703
void updateWidget()
update the internal surface and blits it to the screen
Definition: mapdisplay.cpp:794
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool layerActive(const ASCString &name)
sigc::signal< void, Surface &, int > additionalItemDisplayHook
Definition: mapdisplay.h:103
void displayUnitMovement(GameMap *actmap, Vehicle *veh, const MapCoordinate3D &from, const MapCoordinate3D &to, int duration)
const int sidenum
the number of sides that a field has; is now fixed at 6;
Definition: typen.h:438
#define fieldsizey
Definition: typen.h:441
void addMapLayer(MapLayer *mapLayer)
Definition: mapdisplay.h:105
int bitmappedHeight2pass(int height)
Definition: mapdisplay.cpp:422
#define fielddisthalfx
Definition: typen.h:435
virtual void paintSingleField(const MapRenderer::FieldRenderInfo &fieldInfo, int layer, const SPoint &pos)=0
struct MapDisplayPG::MovementMask movementMask[sidenum]
bool fieldCompletelyInViewX(const MapCoordinate &pos)
void benchMapDisplay()
Definition: mapdisplay.cpp:586
void paintUnitOntoField(const MapRenderer::FieldRenderInfo &fieldInfo, int binaryUnitHeight, const SPoint &pos, Vehicle *vehicle)
Definition: mapdisplay.cpp:428
Coordinate on the twodimensional map.
Definition: typen.h:202
MapCoordinate mapPos
Definition: mapdisplay.h:246
int setSignalPriority(int priority)
Definition: mapdisplay.cpp:989
LockDisplay(bool dummy=false)
int getFieldPosX(int x, int y)
Definition: mapdisplay.h:77
static const int touchedFieldNum
Definition: mapdisplay.h:243
struct MapDisplayPG::Movement::@18 touchedFields[touchedFieldNum]
Dialog classes based on the Paragui library.
SPoint mapViewPos2internalPos(const MapCoordinate &pos)
Definition: mapdisplay.cpp:903
MapDisplayPG::LockDisplay tlockdispspfld
Definition: mapdisplay.h:368
void scrollMap(int dir)
sigc::signal< void > lockMapdisplay
Definition: mapdisplay.cpp:67
void checkViewPosition(MapCoordinate &pos)
Definition: mapdisplay.cpp:758
int getZoom() const
Definition: mapdisplay.h:192
MapCoordinate upperLeftCorner()
Definition: mapdisplay.cpp:947
#define fieldsizex
Definition: typen.h:440
VisibilityStates visibility
Definition: mapdisplay.h:55
SDLmm::SPoint SPoint
Definition: surface.h:27
bool eventMouseButtonDown(const SDL_MouseButtonEvent *button)
void addMapLayer(MapLayer *layer, const ASCString &name)
void paintBackgroundField(Surface &surf, SPoint pos)
Definition: mapdisplay.cpp:551
#define fielddistx
Definition: typen.h:433
void blitInternalSurface(SDL_Surface *dest, const SPoint &pnt, const PG_Rect &dstClip)
Definition: mapdisplay.cpp:802
void eventBlit(SDL_Surface *srf, const PG_Rect &src, const PG_Rect &dst)
Definition: mapdisplay.cpp:879
void activateMapLayer(const ASCString &name, bool active)
sigc::signal< bool, const MapCoordinate &, const SPoint &, bool, int, int > mouseButtonOnField
Signal that is fired when the mouse is pressed on a valid field, after the cursor evaluation has been...
Definition: mapdisplay.h:314
MapCoordinate screenPos2mapPos(const SPoint &pos)
Definition: mapdisplay.cpp:921
MapCoordinate widgetPos2mapPos(const SPoint &pos)
Definition: mapdisplay.cpp:930
bool fieldCompletelyInView(const MapCoordinate &pos)
bool isActive()
Definition: mapdisplay.h:116
Coordinate on the map including height.
Definition: typen.h:238
void goTo(const MapCoordinate &position)
void changeZoom(int delta)
Definition: mapdisplay.h:190
GameMap * actmap
Definition: spfst.cpp:64
void displayAddons(Surface &surf, int pass)
bool eventMouseButtonUp(const SDL_MouseButtonEvent *button)
void initMovementStructure()
Cursor(MapDisplayPG *md)
Definition: mapdisplay.h:328
bool eventMouseMotion(const SDL_MouseMotionEvent *button)
sigc::signal< void, int > newZoom
Definition: mapdisplay.h:192
void keyboadCursorMovement(bool enable)
Definition: mapdisplay.h:266
bool centerOnField(const MapCoordinate &mc)
Definition: mapdisplay.cpp:958
virtual ~MapLayer()
Definition: mapdisplay.h:119
#define fielddisty
Definition: typen.h:434
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
SPoint widget2screen(const SPoint &pos)
Definition: mapdisplay.cpp:914
MapDisplayPG(MainScreenWidget *parent, const PG_Rect r)
Definition: mapdisplay.cpp:609
SPoint internal2widget(const SPoint &pos)
Definition: mapdisplay.cpp:909