_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

viewport.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 2012 by Joris Dauphin
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef VIEWPORT_H
31 #define VIEWPORT_H
32 
34 #include "fow.h"
35 #include "vec2i.h"
36 class CUnit;
37 
63 class CViewport
64 {
65 public:
66  CViewport();
67  ~CViewport();
68 
70  bool IsInsideMapArea(const PixelPos &screenPixelPos) const;
71 
73  PixelPos ScreenToMapPixelPos(const PixelPos &screenPixelPos) const;
74  // Convert map pixel coordinates into screen coordinates
75  PixelPos MapToScreenPixelPos(const PixelPos &mapPixelPos) const;
76 
78  Vec2i ScreenToTilePos(const PixelPos &screenPixelPos) const;
80  PixelPos TilePosToScreen_TopLeft(const Vec2i &tilePos) const;
82  PixelPos TilePosToScreen_Center(const Vec2i &tilePos) const;
83 
84  SDL_Surface* GetFogSurface() {
85  return this->FogSurface;
86  }
87 
89  void Set(const Vec2i &tilePos, const PixelDiff &offset);
91  void Center(const PixelPos &mapPixelPos);
92 
93  void SetClipping() const;
94 
96  void Draw();
97  void DrawBorder() const;
99  bool AnyMapAreaVisibleInViewport(const Vec2i &boxmin, const Vec2i &boxmax) const;
100 
101  bool Contains(const PixelPos &screenPos) const;
102 
103  void Restrict(int &screenPosX, int &screenPosY) const;
104  void Clean();
105 
106  static bool isGridEnabled()
107  {
108  return CViewport::ShowGrid;
109  }
110 
111  static void EnableGrid(const bool value)
112  {
113  CViewport::ShowGrid = value;
114  }
115 
116 
117  PixelSize GetPixelSize() const;
118  const PixelPos &GetTopLeftPos() const { return TopLeftPos;}
119  const PixelPos &GetBottomRightPos() const { return BottomRightPos;}
120 private:
122  void Set(const PixelPos &mapPixelPos);
124  void DrawMapGridInViewport() const;
126  void DrawMapBackgroundInViewport() const;
128  void DrawMapFogOfWar();
130  void AdjustFogSurface();
132  void CleanFog();
133 
134 public:
135  //private:
138 
139 public:
142  int MapWidth;
143  int MapHeight;
144 
146 private:
147  SDL_Surface *FogSurface { nullptr };
148  static bool ShowGrid;
149 
150 };
151 
152 
154 
155 #endif // VIEWPORT_H
CViewport::GetBottomRightPos
const PixelPos & GetBottomRightPos() const
Definition: viewport.h:119
CViewport::MapHeight
int MapHeight
Width in map tiles.
Definition: viewport.h:143
CViewport::Set
void Set(const Vec2i &tilePos, const PixelDiff &offset)
Set the current map view to x,y(upper,left corner)
Definition: map_draw.cpp:202
CViewport::BottomRightPos
PixelPos BottomRightPos
Screen pixel top-left corner.
Definition: viewport.h:137
CViewport::MapWidth
int MapWidth
Offset within MapX, MapY.
Definition: viewport.h:142
CViewport::CViewport
CViewport()
Definition: map_draw.cpp:52
CViewport::GetFogSurface
SDL_Surface * GetFogSurface()
Definition: viewport.h:84
CViewport::SetClipping
void SetClipping() const
Definition: map_draw.cpp:83
vec2i.h
CViewport::isGridEnabled
static bool isGridEnabled()
Definition: viewport.h:106
CViewport::IsInsideMapArea
bool IsInsideMapArea(const PixelPos &screenPixelPos) const
Check if pos pixels are within map area.
Definition: map_draw.cpp:109
CViewport::TilePosToScreen_TopLeft
PixelPos TilePosToScreen_TopLeft(const Vec2i &tilePos) const
convert tilepos coordonates into screen (take the top left of the tile)
Definition: map_draw.cpp:143
CViewport::Contains
bool Contains(const PixelPos &screenPos) const
Definition: map_draw.cpp:65
CViewport
Definition: viewport.h:63
fow.h
CViewport::AnyMapAreaVisibleInViewport
bool AnyMapAreaVisibleInViewport(const Vec2i &boxmin, const Vec2i &boxmax) const
Check if any part of an area is visible in viewport.
Definition: map_draw.cpp:96
CViewport::GetPixelSize
PixelSize GetPixelSize() const
Definition: map_draw.cpp:78
Vec2T< int >
CViewport::DrawBorder
void DrawBorder() const
Definition: map_draw.cpp:529
CViewport::Restrict
void Restrict(int &screenPosX, int &screenPosY) const
Definition: map_draw.cpp:72
CViewport::EnableGrid
static void EnableGrid(const bool value)
Definition: viewport.h:111
CViewport::TilePosToScreen_Center
PixelPos TilePosToScreen_Center(const Vec2i &tilePos) const
convert tilepos coordonates into screen (take the center of the tile)
Definition: map_draw.cpp:151
CViewport::ScreenToMapPixelPos
PixelPos ScreenToMapPixelPos(const PixelPos &screenPixelPos) const
Convert screen coordinates into map pixel coordinates.
Definition: map_draw.cpp:117
CViewport::Offset
PixelDiff Offset
Map tile left-upper corner.
Definition: viewport.h:141
CViewport::Unit
CUnit * Unit
Height in map tiles.
Definition: viewport.h:145
CViewport::MapToScreenPixelPos
PixelPos MapToScreenPixelPos(const PixelPos &mapPixelPos) const
Definition: map_draw.cpp:126
CViewport::Clean
void Clean()
Definition: map_fog.cpp:442
CViewport::MapPos
Vec2i MapPos
Screen pixel bottom-right corner.
Definition: viewport.h:140
CViewport::ScreenToTilePos
Vec2i ScreenToTilePos(const PixelPos &screenPixelPos) const
convert screen coordinate into tilepos
Definition: map_draw.cpp:134
CViewport::~CViewport
~CViewport()
Definition: map_draw.cpp:60
CViewport::Center
void Center(const PixelPos &mapPixelPos)
Center map on point in viewport.
Definition: map_draw.cpp:214
CViewport::TopLeftPos
PixelPos TopLeftPos
Definition: viewport.h:136
CUnit
The big unit structure.
Definition: unit.h:135
CViewport::Draw
void Draw()
Draw the full Viewport.
Definition: map_draw.cpp:382
CViewport::GetTopLeftPos
const PixelPos & GetTopLeftPos() const
Definition: viewport.h:118
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.