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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
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 
85  void Set(const Vec2i &tilePos, const PixelDiff &offset);
87  void Center(const PixelPos &mapPixelPos);
88 
89  void SetClipping() const;
90 
92  void Draw() const;
93  void DrawBorder() const;
95  bool AnyMapAreaVisibleInViewport(const Vec2i &boxmin, const Vec2i &boxmax) const;
96 
97  bool Contains(const PixelPos &screenPos) const;
98 
99  void Restrict(int &screenPosX, int &screenPosY) const;
100 
101  PixelSize GetPixelSize() const;
102  const PixelPos &GetTopLeftPos() const { return TopLeftPos;}
103  const PixelPos &GetBottomRightPos() const { return BottomRightPos;}
104 private:
106  void Set(const PixelPos &mapPixelPos);
108  void DrawMapBackgroundInViewport() const;
110  void DrawMapFogOfWar() const;
111 
112 public:
113  //private:
116 
117 public:
120  int MapWidth;
121  int MapHeight;
122 
124 };
125 
127 
128 #endif // VIEWPORT_H
PixelPos TilePosToScreen_Center(const Vec2i &tilePos) const
convert tilepos coordonates into screen (take the center of the tile)
Definition: map_draw.cpp:146
bool AnyMapAreaVisibleInViewport(const Vec2i &boxmin, const Vec2i &boxmax) const
Check if any part of an area is visible in viewport.
Definition: map_draw.cpp:91
~CViewport()
Definition: map_draw.cpp:56
void Center(const PixelPos &mapPixelPos)
Center map on point in viewport.
Definition: map_draw.cpp:209
PixelPos ScreenToMapPixelPos(const PixelPos &screenPixelPos) const
Convert screen coordinates into map pixel coordinates.
Definition: map_draw.cpp:112
Vec2i ScreenToTilePos(const PixelPos &screenPixelPos) const
convert screen coordinate into tilepos
Definition: map_draw.cpp:129
int MapHeight
Width in map tiles.
Definition: viewport.h:121
bool Contains(const PixelPos &screenPos) const
Definition: map_draw.cpp:60
The big unit structure.
Definition: unit.h:119
PixelPos BottomRightPos
Screen pixel top-left corner.
Definition: viewport.h:115
PixelPos TilePosToScreen_TopLeft(const Vec2i &tilePos) const
convert tilepos coordonates into screen (take the top left of the tile)
Definition: map_draw.cpp:138
bool IsInsideMapArea(const PixelPos &screenPixelPos) const
Check if pos pixels are within map area.
Definition: map_draw.cpp:104
CViewport()
Definition: map_draw.cpp:48
PixelSize GetPixelSize() const
Definition: map_draw.cpp:73
Definition: viewport.h:63
Vec2i MapPos
Screen pixel bottom-right corner.
Definition: viewport.h:118
const PixelPos & GetTopLeftPos() const
Definition: viewport.h:102
PixelPos TopLeftPos
Definition: viewport.h:114
CUnit * Unit
Height in map tiles.
Definition: viewport.h:123
void SetClipping() const
Definition: map_draw.cpp:78
PixelPos MapToScreenPixelPos(const PixelPos &mapPixelPos) const
Definition: map_draw.cpp:121
PixelDiff Offset
Map tile left-upper corner.
Definition: viewport.h:119
void Draw() const
Draw the full Viewport.
Definition: map_draw.cpp:325
void DrawBorder() const
Definition: map_draw.cpp:446
void Restrict(int &screenPosX, int &screenPosY) const
Definition: map_draw.cpp:67
const PixelPos & GetBottomRightPos() const
Definition: viewport.h:103
int MapWidth
Offset within MapX, MapY.
Definition: viewport.h:120
void Set(const Vec2i &tilePos, const PixelDiff &offset)
Set the current map view to x,y(upper,left corner)
Definition: map_draw.cpp:197
(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.