Android release v6.7_preview1
[xcsoar.git] / src / Projection / WindowProjection.hpp
blobab84680e9d8c0ff55711095fb8a610902eef5abf
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_WINDOW_PROJECTION_HPP
25 #define XCSOAR_WINDOW_PROJECTION_HPP
27 #include "Screen/Point.hpp"
28 #include "Projection.hpp"
29 #include "Geo/GeoBounds.hpp"
30 #include "Util/DebugFlag.hpp"
32 #include <algorithm>
34 #include <assert.h>
36 class WindowProjection:
37 public Projection
39 DebugFlag screen_size_initialised;
41 unsigned screen_width, screen_height;
43 /**
44 * Geographical representation of the screen boundaries.
46 * This is a cached member that has to be updated manually by
47 * calling UpdateScreenBounds()
49 GeoBounds screenbounds_latlon;
51 public:
52 /**
53 * Converts a geographical location to a screen coordinate if the
54 * location is within the visible bounds
55 * @param loc Geographical location
56 * @param sc Screen coordinate (output)
57 * @return True if the location is within the bounds
59 bool GeoToScreenIfVisible(const GeoPoint &loc, RasterPoint &sc) const;
61 /**
62 * Checks whether a geographical location is within the visible bounds
63 * @param loc Geographical location
64 * @return True if the location is within the bounds
66 gcc_pure
67 bool GeoVisible(const GeoPoint &loc) const;
69 /**
70 * Checks whether a screen coordinate is within the visible bounds
71 * @param P Screen coordinate
72 * @return True if the screen coordinate is within the bounds
74 gcc_pure
75 bool ScreenVisible(const RasterPoint &P) const;
77 void SetScreenSize(PixelSize new_size) {
78 assert(new_size.cx > 0);
79 assert(new_size.cy > 0);
81 screen_width = new_size.cx;
82 screen_height = new_size.cy;
83 screen_size_initialised = true;
86 void SetMapRect(const PixelRect &rc) {
87 SetScreenSize(rc.GetSize());
90 gcc_pure
91 fixed GetMapScale() const;
93 /**
94 * Configure the scale so a centered circle with the specified
95 * radius is visible.
97 void SetScaleFromRadius(fixed radius);
99 /**
100 * Returns the width of the map area in pixels.
102 gcc_pure
103 unsigned GetScreenWidth() const {
104 assert(screen_size_initialised);
106 return screen_width;
110 * Returns the height of the map area in pixels.
112 gcc_pure
113 unsigned GetScreenHeight() const {
114 assert(screen_size_initialised);
116 return screen_height;
120 * Returns the raster coordinates at the center of the map.
122 gcc_pure
123 RasterPoint GetScreenCenter() const {
124 RasterPoint pt;
125 pt.x = GetScreenWidth() / 2;
126 pt.y = GetScreenHeight() / 2;
127 return pt;
131 * Returns the width of the map area in meters.
133 fixed GetScreenWidthMeters() const {
134 return DistancePixelsToMeters(GetScreenWidth());
138 * Returns the length of the larger edge of the map area in pixels.
140 unsigned GetScreenDistance() const
142 return std::max(GetScreenHeight(), GetScreenWidth());
146 * Returns the length of the smaller edge of the map area in pixels.
148 unsigned GetMinScreenDistance() const
150 return std::min(GetScreenHeight(), GetScreenWidth());
153 gcc_pure
154 fixed GetScreenDistanceMeters() const;
157 * Returns the GeoPoint at the center of the screen.
159 gcc_pure
160 GeoPoint GetGeoScreenCenter() const;
162 // used by terrain renderer, topography and airspace
163 gcc_pure
164 const GeoBounds &GetScreenBounds() const {
165 return screenbounds_latlon;
168 /** Updates the cached screenbounds_latlon member */
169 void UpdateScreenBounds();
171 protected:
172 gcc_pure
173 int GetMapResolutionFactor() const {
174 return GetMinScreenDistance() / 8;
178 #endif