Add documentation on placing tiles.
[Tsunagari.git] / src / viewport.h
blob0e71c3ca9ed26bea49198f1c730bea32b84e02a7
1 /*********************************
2 ** Tsunagari Tile Engine **
3 ** viewport.h **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
7 // **********
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // **********
27 #ifndef VIEWPORT_H
28 #define VIEWPORT_H
30 #include "entity.h"
32 class Area;
34 //! General control over where and how the map is rendered.
35 /*!
38 class Viewport
40 public:
41 Viewport(icoord vsize);
42 ~Viewport();
44 void tick(unsigned long dt);
45 void turn();
47 //! How far the map is scrolled in pixels, counting from the upper-left.
48 rvec2 getMapOffset() const;
50 //! Size of the letterbox matte bars in pixels.
51 rvec2 getLetterboxOffset() const;
53 //! Multiplier in X and Y dimensions to get from virtRes to physRes.
54 rvec2 getScale() const;
56 //! The resolution our game is actually being drawn at.
57 rvec2 getPhysRes() const;
59 //! The resolution our game thinks it is being drawn at. Chosen by a
60 //! world's creator. This allows graphics to look the same on any
61 //! setups of any resolution.
62 rvec2 getVirtRes() const;
64 // Immediatly center render offset. Stop any tracking.
65 void jumpToPt(ivec2 pt);
66 void jumpToPt(rvec2 pt);
67 void jumpToEntity(const Entity* e);
69 // Continuously follow.
70 void trackEntity(const Entity* e);
72 void setArea(const Area* a);
74 private:
75 void update();
77 void _jumpToEntity(const Entity* e);
79 //! Returns as a normalized vector the percentage of screen that should
80 //! be blanked to preserve the aspect ratio. It can also be thought of
81 //! as the correcting aspect ratio.
82 rvec2 getLetterbox() const;
84 rvec2 offsetForPt(rvec2 pt) const;
85 rvec2 centerOn(rvec2 pt) const;
86 rvec2 boundToArea(rvec2 pt) const;
87 double boundDimension(double window, double area, double pt,
88 bool loop) const;
89 rvec2 addLetterboxOffset(rvec2 pt) const;
91 enum TrackingMode
93 TM_MANUAL,
94 TM_FOLLOW_ENTITY
97 double aspectRatio;
98 rvec2 off;
99 rvec2 virtRes;
101 TrackingMode mode;
102 const Area* area;
103 const Entity* targete;
106 #endif