00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef mapdisplayH
00019 #define mapdisplayH
00020
00021
00022 #include <sigc++/sigc++.h>
00023 #include "loki/Functor.h"
00024
00025
00026 #include "typen.h"
00027 #include "vehicle.h"
00028
00029
00030 #include "paradialog.h"
00031 #include "mapdisplayinterface.h"
00032
00033 class MapLayer;
00034
00035 class MapRenderer {
00036
00037 struct Icons {
00038 Surface mapBackground;
00039 Surface notVisible;
00040 Surface markField;
00041 Surface markFieldDark;
00042 };
00043 static Icons icons;
00044
00045 typedef deallocating_vector<MapLayer*> LayerRenderer;
00046 LayerRenderer layerRenderer;
00047
00048 void readData();
00049
00050 public:
00051 class FieldRenderInfo {
00052 public:
00053 FieldRenderInfo( Surface& s, GameMap* actmap) : surface(s), gamemap(actmap ) {};
00054 Surface& surface;
00055 VisibilityStates visibility;
00056 int playerView;
00057 MapField* fld;
00058 MapCoordinate pos;
00059 GameMap* gamemap;
00060 };
00061
00062 protected:
00063 MapRenderer();
00064
00065 static const int surfaceBorder = 90;
00066
00067 struct ViewPort {
00068 ViewPort( int x1, int y1, int x2, int y2 );
00069 ViewPort();
00070 int x1,y1,x2,y2;
00071 };
00072
00073
00074 int getFieldPosX( int x, int y ) {
00075 if (y & 1 )
00076 return surfaceBorder + fielddisthalfx + x * fielddistx;
00077 else
00078 return surfaceBorder + x * fielddistx;
00079 };
00080
00081
00082 int getFieldPosY( int x, int y ) {
00083 return surfaceBorder + y * fielddisty;
00084 };
00085
00086 SPoint getFieldPos( int x, int y ) {
00087 return SPoint( getFieldPosX(x,y), getFieldPosY(x,y));
00088 };
00089 SPoint getFieldPos2( const MapCoordinate& pos ) {
00090 return SPoint( getFieldPosX(pos.x,pos.y), getFieldPosY(pos.x,pos.y));
00091 };
00092
00093 void paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo, int layer, const SPoint& pos );
00094 void paintTerrain( Surface& surf, GameMap* actmap, int playerView, const ViewPort& viewPort, const MapCoordinate& offset );
00095 void paintBackground( Surface& surf, const ViewPort& viewPort );
00096 void paintBackgroundField( Surface& surf, SPoint pos );
00097
00098 int bitmappedHeight2pass( int height );
00099
00100 SigC::Signal2<void,Surface&,int> additionalItemDisplayHook;
00101
00102 void addMapLayer( MapLayer* mapLayer ) { layerRenderer.push_back( mapLayer ); };
00103
00104 };
00105
00106
00107 class MapLayer {
00108 bool active;
00109 protected:
00110 MapLayer() : active(true) {};
00111 public:
00112 virtual bool onLayer( int layer ) = 0;
00113 bool isActive() { return active; };
00114 virtual void setActive( bool active ) { this->active = active; };
00115 virtual void paintSingleField( const MapRenderer::FieldRenderInfo& fieldInfo, int layer, const SPoint& pos ) = 0;
00116 virtual ~MapLayer() {};
00117 };
00118
00119
00120
00121
00122 class MainScreenWidget;
00123
00124
00125
00126
00127 class MapDisplayPG: public PG_Widget, protected MapRenderer {
00128
00129 typedef map<ASCString,MapLayer*> LayerMap;
00130 LayerMap layerMap;
00131
00132 struct Icons {
00133 Surface cursor;
00134 Surface fieldShape;
00135 };
00136 static Icons icons;
00137
00138 void readData();
00139
00140 static MapDisplayPG* theMapDisplay;
00141
00142
00143 int zoom;
00144 Surface* surface;
00145
00146 GameMap* lastDisplayedMap;
00147 void sigMapDeleted( GameMap& deletedMap );
00148
00149 MapCoordinate offset;
00150
00151 void setupFastBlitterCommands();
00152 struct Field {
00153 ViewPort viewPort;
00154 int numx, numy;
00155 } field;
00156
00157
00158 void displayCursor( const PG_Rect& dst );
00159 void displayCursor();
00160
00161 enum Dirty { Nothing, Curs, Map } dirty;
00162
00163 Vehicle* additionalUnit;
00164
00165 void lockOptionsChanged( int options );
00166
00167 protected:
00168
00169
00170 void eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst);
00171
00172
00173
00174 bool eventMouseButtonDown (const SDL_MouseButtonEvent *button);
00175 bool eventMouseMotion (const SDL_MouseMotionEvent *button);
00176 bool eventMouseButtonUp (const SDL_MouseButtonEvent *button);
00177
00178
00179
00180 void checkViewPosition( MapCoordinate& pos );
00181
00182 void fillSurface( int playerView );
00183 void paintBackground( );
00184
00185
00186 public:
00187 void changeZoom( int delta) { setNewZoom( getZoom() + delta); };
00188 void setNewZoom( int zoom );
00189 int getZoom() const { return zoom; };
00190 SigC::Signal1<void, int> newZoom;
00191
00192 MapCoordinate screenPos2mapPos( const SPoint& pos );
00193 MapCoordinate widgetPos2mapPos( const SPoint& pos );
00194
00195 SPoint mapGlobalPos2internalPos ( const MapCoordinate& pos );
00196 SPoint mapViewPos2internalPos ( const MapCoordinate& pos );
00197 SPoint internal2widget( const SPoint& pos );
00198 SPoint widget2screen( const SPoint& pos );
00199
00200 MapCoordinate upperLeftCorner();
00201 MapCoordinate lowerRightCorner();
00202
00203 bool fieldCompletelyInViewX( const MapCoordinate& pos );
00204 bool fieldCompletelyInViewY( const MapCoordinate& pos );
00205 bool fieldCompletelyInView( const MapCoordinate& pos );
00206
00207 private:
00208 SPoint upperLeftSourceBlitCorner;
00209 protected:
00210
00211
00212 void blitInternalSurface( SDL_Surface* dest, const SPoint& pnt, const PG_Rect& dstClip );
00213
00214
00215 static const int effectiveMovementSurfaceWidth = 4 * fielddisthalfx + fieldsizex;
00216 static const int effectiveMovementSurfaceHeight = 4*fieldsizey;
00217
00218 struct MovementMask {
00219 Surface mask;
00220 SPoint startFieldPos;
00221 } movementMask[sidenum];
00222
00223 void displayAddons( Surface& surf, int pass);
00224
00225 struct Movement {
00226 Vehicle* veh;
00227 SPoint from;
00228 SPoint to;
00229 int fromShadow;
00230 int toShadow;
00231 GameMap* actmap;
00232 Surface* mask;
00233 int playerView;
00234
00235 PG_Rect blitViewPortInternal;
00236 PG_Rect blitViewPortScreen;
00237 SPoint maskPosition;
00238 SPoint targetBlitPos;
00239
00240 static const int touchedFieldNum = 10;
00241 int actualFieldNum;
00242 struct {
00243 MapCoordinate mapPos;
00244 SPoint surfPos;
00245 } touchedFields[touchedFieldNum];
00246
00247 };
00248
00249 void initMovementStructure();
00250 Surface createMovementBufferSurface();
00251 void displayMovementStep( Movement& movement, int percentage );
00252
00253 bool eventKeyDown(const SDL_KeyboardEvent* key)
00254 {
00255 return keyboardHandler( key );
00256 };
00257
00258 bool keyboardHandler( const SDL_KeyboardEvent* keyEvent);
00259
00260 bool disableKeyboardCursorMovement;
00261
00262 public:
00263 void keyboadCursorMovement( bool enable ) { disableKeyboardCursorMovement = !enable; };
00264
00265 void scrollMap( int dir );
00266
00267 private:
00268 void UpdateRect( const PG_Rect& rect );
00269 void moveCursor( int dir, int step );
00270 void redrawMapAtCursor ( const MapCoordinate& oldpos );
00271
00272 public:
00273
00274
00275
00276 MapDisplayPG ( MainScreenWidget *parent, const PG_Rect r );
00277
00278 void displayUnitMovement( GameMap* actmap, Vehicle* veh, const MapCoordinate3D& from, const MapCoordinate3D& to, int duration );
00279
00280 bool fieldInView(const MapCoordinate& mc );
00281 bool centerOnField( const MapCoordinate& mc );
00282
00283 void registerAdditionalUnit ( Vehicle* veh );
00284
00286 void updateMap( bool force = false );
00287
00289 void updateWidget();
00290
00291 void addMapLayer( MapLayer* layer, const ASCString& name );
00292 void activateMapLayer( const ASCString& name, bool active );
00293 void toggleMapLayer( const ASCString& name );
00294 bool layerActive( const ASCString& name );
00295 SigC::Signal2<void, bool, const ASCString&> layerChanged;
00296 void getActiveLayers( vector<ASCString>& list );
00297
00298
00299 private:
00300 int signalPrio;
00301 public:
00302 int setSignalPriority( int priority );
00303
00311 SigC::Signal5<bool,const MapCoordinate&, const SPoint&, bool, int, int> mouseButtonOnField;
00312
00319 SigC::Signal4<bool,const MapCoordinate&, const SPoint&, bool, int> mouseDraggedToField;
00320
00321
00322 struct Cursor {
00323 int invisible;
00324 MapDisplayPG* mapDisplay;
00325 Cursor( MapDisplayPG* md ) : invisible(0), mapDisplay(md) {};
00326 friend class MapDisplayPG;
00327 friend class PG_MapDisplay;
00328 MapCoordinate& pos();
00329 public:
00330 void goTo( const MapCoordinate& position );
00331 void goTo( const MapCoordinate& cursorPosition, const MapCoordinate& upperLeftScreenCorner );
00332 void intoView();
00333 } cursor;
00334
00335 class CursorHiding {
00336 public:
00337 CursorHiding();
00338 ~CursorHiding();
00339 };
00340
00341 friend class CursorHiding;
00342
00343 class LockDisplay {
00344 private:
00345 bool isDummy;
00346 void raiseLock();
00347 public:
00348 LockDisplay( bool dummy = false );
00349 ~LockDisplay();
00350 };
00351
00352 friend class LockDisplay;
00353
00354
00355 ~MapDisplayPG ();
00356 private:
00357 int lock;
00358
00359 };
00360
00361 extern SigC::Signal0<void> lockMapdisplay;
00362 extern SigC::Signal0<void> unlockMapdisplay;
00363
00364
00365 typedef MapDisplayPG::LockDisplay tlockdispspfld;
00366
00367 extern void benchMapDisplay();
00368
00369
00370 #endif