1 // Crimson Fields -- a game of tactical warfare 2 // Copyright (C) 2000-2007 Jens Granseuer 3 // 4 // This program is free software; you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation; either version 2 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 // 18 19 /////////////////////////////////////////////////////////////// 20 // mapview.h 21 /////////////////////////////////////////////////////////////// 22 23 #ifndef _INCLUDE_MAPVIEW_H 24 #define _INCLUDE_MAPVIEW_H 25 26 #include "rect.h" 27 #include "map.h" 28 #include "surface.h" 29 30 // special hex graphics 31 #define IMG_CURSOR_IDLE 4 32 #define IMG_CURSOR_SELECT 3 33 #define IMG_CURSOR_ATTACK 5 34 #define IMG_CURSOR_SPECIAL 7 // e.g. pioneers, depot builders 35 #define IMG_CURSOR_HIGHLIGHT 0 36 #define IMG_RECESSED_HEX 2 37 #define IMG_NOT_AVAILABLE 6 38 39 40 #define MV_AUTOSCROLL 0x0001 // autoscroll when cursor reaches edge of viewport 41 #define MV_DISABLE 0x0002 // disable viewport entirely (don't update) 42 #define MV_DISABLE_FOG 0x0004 // don't show fog 43 #define MV_DISABLE_CURSOR 0x0008 // don't show cursor 44 #define MV_ENABLE_UNIT_STATS 0x0010 // overlay units with stats (health, xp) 45 #define MV_DIRTY 0x8000 // must be redrawn 46 47 class MapView : public Rect { 48 public: 49 MapView( Surface *display, const Rect &bounds, unsigned short flags ); ~MapView(void)50 ~MapView( void ) { delete [] shader_map; } 51 52 void Resize( const Rect &bounds ); 53 void SetMap( Map *map ); GetMap(void)54 Map *GetMap( void ) const { return map; } GetFogBuffer(void)55 signed char *GetFogBuffer( void ) const { return shader_map; } 56 57 void Enable( void ); Enabled(void)58 bool Enabled( void ) const { return !FlagSet(MV_DISABLE); } 59 void Disable( void ); EnableFog(void)60 void EnableFog( void ) { UnsetFlags(MV_DISABLE_FOG); } DisableFog(void)61 void DisableFog( void ) { SetFlags(MV_DISABLE_FOG); } FogEnabled(void)62 bool FogEnabled( void ) const { return !FlagSet(MV_DISABLE_FOG); } EnableCursor(void)63 void EnableCursor( void ) { UnsetFlags(MV_DISABLE_CURSOR); } DisableCursor(void)64 void DisableCursor( void ) { SetFlags(MV_DISABLE_CURSOR); } CursorEnabled(void)65 bool CursorEnabled( void ) const { return !FlagSet(MV_DISABLE_CURSOR); } EnableUnitStats(void)66 void EnableUnitStats( void ) { SetFlags(MV_ENABLE_UNIT_STATS); } DisableUnitStats(void)67 void DisableUnitStats( void ) { UnsetFlags(MV_ENABLE_UNIT_STATS); } UnitStatsEnabled(void)68 bool UnitStatsEnabled( void ) const { return FlagSet(MV_ENABLE_UNIT_STATS); } 69 SetFlags(unsigned short flags)70 void SetFlags( unsigned short flags ) { this->flags |= flags; } UnsetFlags(unsigned short flags)71 void UnsetFlags( unsigned short flags ) { this->flags &= (~flags); } FlagSet(unsigned short flag)72 bool FlagSet( unsigned short flag ) const { return (flags & flag) == flag; } 73 Draw(void)74 void Draw( void ) const { Draw( 0, 0, w, h ); } 75 void Draw( short x, short y, unsigned short w, unsigned short h ) const; 76 void DrawMap( short x, short y, unsigned short w, unsigned short h, 77 Surface *dest, short dx, short dy ) const; 78 DrawUnit(unsigned short n,Surface * dest,short px,short py,const Rect & clip)79 void DrawUnit( unsigned short n, Surface *dest, 80 short px, short py, const Rect &clip ) const 81 { map->GetUnitSet()->DrawTile( n, dest, px, py, clip ); } DrawTerrain(unsigned short n,Surface * dest,short px,short py,const Rect & clip)82 void DrawTerrain( unsigned short n, Surface *dest, 83 short px, short py, const Rect &clip ) const 84 { map->GetTerrainSet()->DrawTile( n, dest, px, py, clip ); } DrawFog(Surface * dest,short px,short py,const Rect & clip)85 void DrawFog( Surface *dest, short px, short py, const Rect &clip ) const 86 { map->GetTerrainSet()->DrawFog( dest, px, py, clip ); } 87 void DrawUnitHealth( unsigned char health, Surface *dest, 88 short px, short py, const Rect &clip ) const; 89 90 int Pixel2Hex( short px, short py, Point &hex ) const; 91 Point Hex2Pixel( const Point &hex ) const; 92 bool HexVisible( const Point &hex ) const; 93 void Scroll( short px, short py ); GetOffsets(void)94 Point GetOffsets( void ) const { return Point(curx,cury); } 95 96 Rect UpdateHex( const Point &hex ); 97 void CenterOnHex( const Point &hex ); 98 Rect SetCursor( const Point &hex ); Cursor(void)99 Point Cursor( void ) const { return cursor; } SetCursorImage(unsigned short cur)100 void SetCursorImage( unsigned short cur ) { cursor_image = cur; } GetCursorImage(void)101 unsigned short GetCursorImage( void ) const { return cursor_image; } 102 103 unsigned short MinXHex( short x ) const; 104 unsigned short MinYHex( short y ) const; 105 unsigned short MaxXHex( short x, unsigned short w ) const; 106 unsigned short MaxYHex( short y, unsigned short h ) const; 107 TileWidth(void)108 unsigned short TileWidth( void ) const { return map->GetTerrainSet()->TileWidth(); } TileHeight(void)109 unsigned short TileHeight( void ) const { return map->GetTerrainSet()->TileHeight(); } TileShiftX(void)110 unsigned short TileShiftX( void ) const { return map->GetTerrainSet()->TileShiftX(); } TileShiftY(void)111 unsigned short TileShiftY( void ) const { return map->GetTerrainSet()->TileShiftY(); } 112 113 private: 114 void InitOffsets( void ); 115 bool CheckScroll( void ); 116 117 Point cursor; 118 unsigned short cursor_image; 119 120 unsigned short curx; // current map offsets 121 unsigned short cury; 122 unsigned short maxx; // maximum map offsets 123 unsigned short maxy; 124 125 Map *map; 126 Surface *surface; 127 128 unsigned short flags; 129 signed char *shader_map; 130 }; 131 132 #endif /* _INCLUDE_MAPVIEW_H */ 133 134