MapView.h

Go to the documentation of this file.
00001 //**********************************************************************
00002 //
00003 //  REGCOM: Regimental Command
00004 //  Copyright (C) 2008 Randi J. Relander
00005 //    <rjrelander@users.sourceforge.net>
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 3
00010 //  of the License, or (at your option) any later version.
00011 //  
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //  
00017 //  You should have received a copy of the GNU General Public
00018 //  License along with this program.  If not, see 
00019 //  <http://www.gnu.org/licenses/>.
00020 //  
00021 //**********************************************************************
00022 
00023 #ifndef REGCOM_CLIENT_MAP_VIEW_H
00024 #define REGCOM_CLIENT_MAP_VIEW_H
00025 
00026 // PROJECT INCLUDES
00027 #include "regcom/client/TileInfo.h"
00028 
00029 #include "regcom/gui/ScrollView.h"
00030 #include "regcom/gui/Surface.h"
00031 #include "regcom/gui/Rect.h"
00032 
00033 #include "regcom/common/Map.h"
00034 
00035 // NAMESPACES
00036 namespace regcom {
00037 namespace client {
00038 
00039 // FORWARD REFERENCES
00040 class Console;
00041 
00042 #define MAPVIEW_MAXTILE 56
00043 #define MAPVIEW_LAYERS 5
00044 #define MAPVIEW_LOSLAYER 4
00045 
00047 //  CLASS: MapView
00053 class MapView : public gui::ScrollView
00054 {
00055 public:
00056 
00057     // PUBLIC METHODS
00058 
00060     MapView();
00061 
00063     virtual ~MapView();
00064 
00066     void SetConsole(Console* pConsole);
00067 
00069     void ScanMap(regcom::common::Map* pMap);
00070 
00072     void ZoomIn();
00073 
00075     void ZoomOut();
00076 
00078     void ToggleGrid();
00079 
00081     void WarpToTile(gui::Point point);
00082     
00084     gui::Point TileFromPoint(gui::Point point);
00085 
00087     virtual void OnMouseMove(gui::Point point);
00088 
00090     virtual void OnMouseDown(int n, gui::Point point);
00091 
00093     virtual void OnMouseUp(int n, gui::Point point);
00094 
00096     void ClearLOS();
00097 
00099     void MarkLOS(int x0, int y0, int x1, int y1);
00100 
00101 protected:
00102 
00103     // PROTECTED METHODS
00104 
00106     void SetDataSize(int x, int y);
00107 
00109     void UnloadTiles();
00110 
00112     void LoadTiles();
00113 
00115     void LoadTile(int n, gui::Surface* pTiles, int x, int y);
00116 
00118     void LoadUnitTile(int n, gui::Surface* pTiles, int x, int y);
00119 
00121     void RefreshTile(int x, int y);
00122 
00124     void SetTileIndex(int x, int y, int z, int n);
00125 
00127     int GetTileIndex(int x, int y, int z);
00128 
00130     void DrawTile(int n, int x, int y, gui::Surface* pSurface, gui::Rect clip);
00131 
00133     void DrawLayer(int n, gui::Rect rect, gui::Surface* pSurface, int x, int y);
00134 
00136     void ClipMargins(gui::Rect& rect, gui::Surface* pSurface, int& x, int& y);
00137 
00139     virtual void DrawImage(gui::Rect rect, gui::Surface* pSurface, int x, int y);
00140 
00142     virtual void ViewportChanged();
00143 
00145     void ImageSizeChanged();
00146 
00148     virtual int GetImageWidth() { return m_ImageWidth; }
00149 
00151     virtual int GetImageHeight() { return m_ImageHeight; }
00152 
00154     void SetZoomLevel(int n);
00155 
00157     gui::Point ArrayToHex(gui::Point p);
00158 
00160     gui::Point HexToArray(gui::Point p);
00161 
00162 private:
00163 
00164     // PRIVATE TYPES
00165 
00167     enum TILEBASE
00168     {
00169         TILEBASE_CLEAR          = 0,
00170         TILEBASE_WATER          = 8,
00171         TILEBASE_WOODS          = 16,
00172         TILEBASE_MARKERS        = 24,
00173 
00174         TILEBASE_UNIT1_BASE     = 32,
00175         TILEBASE_UNIT1_BODY     = 38,
00176         TILEBASE_UNIT2_BASE     = 44,
00177         TILEBASE_UNIT2_BODY     = 50
00178     };
00179 
00181     enum TILECOUNT
00182     {
00183         TILECOUNT_CLEAR         = 8,
00184         TILECOUNT_WATER         = 8,
00185         TILECOUNT_WOODS         = 8,
00186         TILECOUNT_MARKERS       = 8,
00187 
00188         TILECOUNT_UNIT1_BASE    = 6,
00189         TILECOUNT_UNIT1_BODY    = 6,
00190         TILECOUNT_UNIT2_BASE    = 6,
00191         TILECOUNT_UNIT2_BODY    = 6
00192     };
00193 
00195     enum TILEROW
00196     {
00197         TILEROW_CLEAR           = 0,
00198         TILEROW_CLEARGRID       = 1,
00199         TILEROW_WATER           = 2,
00200         TILEROW_WATERGRID       = 3,
00201         TILEROW_WOODS           = 4,
00202         TILEROW_MARKERS         = 5,
00203 
00204         TILEROW_UNIT1_BASE      = 0,
00205         TILEROW_UNIT1_BODY      = 1,
00206         TILEROW_UNIT2_BASE      = 2,
00207         TILEROW_UNIT2_BODY      = 3
00208     };
00209 
00210     // PRIVATE ATTRIBUTES
00211 
00213     int m_ZoomLevel;
00214 
00216     bool m_ShowGrid;
00217 
00219     Console* m_pConsole;
00220 
00222     unsigned char* m_pData[MAPVIEW_LAYERS];
00223 
00225     int m_DataWidth;
00226 
00228     int m_DataHeight;
00229 
00231     int m_ImageWidth;
00232 
00234     int m_ImageHeight;
00235 
00237     gui::Surface* m_pTile[MAPVIEW_MAXTILE];
00238 
00240     bool m_Dragging;
00241 
00243     gui::Point m_DragBegin;
00244 
00246     gui::Point m_DragEnd;
00247 
00249     int m_DebugRects;
00250 
00251     // PRIVATE STATIC ATTRIBUTES
00252 
00254     static const int ZOOM_LEVELS = 3;
00255 
00257     static const TileInfo s_TileInfo[ZOOM_LEVELS];
00258 };
00259 
00260 } // namespace client
00261 } // namespace regcom
00262 
00263 #endif