Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

mapdisplay.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           mapdisplay.h  -  description
00003                              -------------------
00004     begin                : Wed Jan 24 2001
00005     copyright            : (C) 2001 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef mapdisplayH
00019  #define mapdisplayH
00020 
00021 
00022 #include <sigc++/sigc++.h>
00023 #include "libs/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                tfield* 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       // return the position of a field on the internal surface      
00074       int getFieldPosX( int x, int y ) { 
00075           if (y & 1 )   // even lines are shifted to the right
00076              return surfaceBorder + fielddisthalfx + x * fielddistx;
00077           else
00078              return surfaceBorder + x * fielddistx;
00079       };             
00080       
00081       // return the position of a field on the internal surface      
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 class MainScreenWidget;
00122 
00123 
00124 
00125 
00126 class MapDisplayPG: public PG_Widget, protected MapRenderer {
00127 
00128       typedef map<ASCString,MapLayer*> LayerMap;
00129       LayerMap layerMap;
00130       
00131       struct Icons {
00132          Surface cursor;
00133          Surface fieldShape;
00134       };
00135       static Icons icons;
00136 
00137       void readData();
00138 
00139       static MapDisplayPG* theMapDisplay;
00140       
00141             
00142       int zoom;
00143       Surface* surface;
00144       
00145       GameMap* lastDisplayedMap;
00146       void sigMapDeleted( GameMap& deletedMap );
00147       
00148       MapCoordinate offset;
00149      
00150       void setupFastBlitterCommands();
00151       struct Field {
00152          ViewPort viewPort;
00153          int numx, numy;
00154       } field;   
00155       
00156 
00157       void displayCursor( const PG_Rect& dst );
00158       void displayCursor();
00159       
00160       enum Dirty { Nothing, Curs, Map } dirty;
00161       
00162       Vehicle* additionalUnit;
00163        
00164       void lockOptionsChanged( int options );
00165       
00166    protected:
00167    
00168       // Paragui stuff
00169       void eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst);
00170       // void eventDraw(SDL_Surface* surface, const PG_Rect& rect);
00171 
00172 
00173       bool eventMouseButtonDown (const SDL_MouseButtonEvent *button);
00174       bool eventMouseMotion (const SDL_MouseMotionEvent *button);
00175       bool eventMouseButtonUp (const SDL_MouseButtonEvent *button);
00176       
00177       //
00178    
00179       void checkViewPosition( MapCoordinate& pos );
00180       
00181       void fillSurface( int playerView );
00182       void paintBackground( );
00183 
00184 
00185    public:
00186       void changeZoom( int delta) { setNewZoom( getZoom() + delta); };
00187       void setNewZoom( int zoom );
00188       int getZoom() const { return zoom; };
00189       SigC::Signal1<void, int> newZoom;
00190       
00191       MapCoordinate screenPos2mapPos( const SPoint& pos );
00192       MapCoordinate widgetPos2mapPos( const SPoint& pos );
00193 
00194       SPoint mapGlobalPos2internalPos ( const MapCoordinate& pos );
00195       SPoint mapViewPos2internalPos ( const MapCoordinate& pos );
00196       SPoint internal2widget( const SPoint& pos );
00197       SPoint widget2screen( const SPoint& pos );
00198       
00199       MapCoordinate upperLeftCorner();
00200       MapCoordinate lowerRightCorner();
00201       
00202       bool fieldCompletelyInViewX( const MapCoordinate& pos );
00203       bool fieldCompletelyInViewY( const MapCoordinate& pos );
00204       bool fieldCompletelyInView( const MapCoordinate& pos );
00205       
00206    private:
00207       SPoint upperLeftSourceBlitCorner;
00208    protected:
00209 
00210       
00211       void blitInternalSurface( SDL_Surface* dest, const SPoint& pnt, const PG_Rect& dstClip );
00212 
00213       
00214       static const int effectiveMovementSurfaceWidth = 4 * fielddisthalfx + fieldsizex;
00215       static const int effectiveMovementSurfaceHeight = 4*fieldsizey;
00216       
00217       struct MovementMask {
00218          Surface mask;
00219          SPoint  startFieldPos;
00220       } movementMask[sidenum];
00221 
00222       void displayAddons( Surface& surf, int pass);
00223       
00224       struct Movement {
00225          Vehicle* veh;
00226          SPoint from;
00227          SPoint to;
00228          int fromShadow;
00229          int toShadow;
00230          GameMap* actmap;
00231          Surface* mask;
00232          int playerView;
00233 
00234          PG_Rect blitViewPortInternal;
00235          PG_Rect blitViewPortScreen;
00236          SPoint maskPosition;
00237          SPoint targetBlitPos;
00238 
00239          static const int touchedFieldNum = 10;
00240          int actualFieldNum;
00241          struct {
00242             MapCoordinate mapPos;
00243             SPoint surfPos;
00244          } touchedFields[touchedFieldNum];
00245 
00246       };
00247 
00248       void initMovementStructure();
00249       Surface createMovementBufferSurface();
00250       void displayMovementStep( Movement& movement, int percentage );
00251 
00252       bool eventKeyDown(const SDL_KeyboardEvent* key)
00253       {
00254          return keyboardHandler( key );
00255       };
00256 
00257       bool keyboardHandler( const SDL_KeyboardEvent* keyEvent);
00258       
00259       bool disableKeyboardCursorMovement;
00260      
00261    public:   
00262       void keyboadCursorMovement( bool enable ) { disableKeyboardCursorMovement = !enable; }; 
00263       
00264       void scrollMap( int dir );
00265       
00266    private:
00267       void UpdateRect( const PG_Rect& rect );
00268       void moveCursor( int dir, int step );
00269       void redrawMapAtCursor ( const MapCoordinate& oldpos );
00270 
00271    public:
00272 
00273    
00274 
00275       MapDisplayPG ( MainScreenWidget *parent, const PG_Rect r );
00276 
00277       void displayUnitMovement( GameMap* actmap, Vehicle* veh, const MapCoordinate3D& from, const MapCoordinate3D& to );
00278 
00279       bool fieldInView(const MapCoordinate& mc );
00280       bool centerOnField( const MapCoordinate& mc );
00281 
00282       void registerAdditionalUnit ( Vehicle* veh );
00283 
00285       void updateMap( bool force = false );
00286 
00288       void updateWidget();
00289 
00290       void addMapLayer( MapLayer* layer, const ASCString& name );
00291       void activateMapLayer( const ASCString& name, bool active );
00292       void toggleMapLayer( const ASCString& name );
00293       bool layerActive( const ASCString& name );
00294       SigC::Signal2<void, bool, const ASCString&> layerChanged;
00295       void getActiveLayers( vector<ASCString>& list );
00296 
00297 
00298    private:
00299       int signalPrio;
00300    public:
00301       int setSignalPriority( int priority );
00302       
00310       SigC::Signal5<bool,const MapCoordinate&, const SPoint&, bool, int, int> mouseButtonOnField;
00311 
00318       SigC::Signal4<bool,const MapCoordinate&, const SPoint&, bool, int> mouseDraggedToField;
00319       
00320       
00321       struct Cursor {
00322             int invisible;
00323             MapDisplayPG* mapDisplay; 
00324             Cursor( MapDisplayPG* md ) : invisible(0), mapDisplay(md) {};
00325             friend class MapDisplayPG;
00326             friend class PG_MapDisplay;
00327             MapCoordinate& pos();
00328           public:
00329             void goTo( const MapCoordinate& position );
00330             void goTo( const MapCoordinate& cursorPosition, const MapCoordinate& upperLeftScreenCorner );
00331             void intoView();
00332       } cursor; 
00333             
00334       class CursorHiding {
00335          public:
00336             CursorHiding();
00337             ~CursorHiding();
00338       };
00339             
00340       friend class CursorHiding;
00341 
00342       class LockDisplay {
00343          private:
00344             bool isDummy;
00345             void raiseLock();
00346          public:
00347             LockDisplay( bool dummy = false );
00348             ~LockDisplay();
00349       };
00350 
00351       friend class LockDisplay;
00352 
00353       
00354       ~MapDisplayPG ();
00355    private:
00356       int lock;
00357            
00358 };
00359 
00360 extern SigC::Signal0<void> lockMapdisplay;
00361 extern SigC::Signal0<void> unlockMapdisplay;
00362 
00363 
00364 typedef MapDisplayPG::LockDisplay tlockdispspfld;
00365 
00366 extern void benchMapDisplay();
00367 
00368 
00369 #endif

Generated on Tue Jun 24 01:27:45 2008 for Advanced Strategic Command by  doxygen 1.4.2