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"
36 class WindowProjection
:
39 DebugFlag screen_size_initialised
;
41 unsigned screen_width
, screen_height
;
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
;
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;
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
67 bool GeoVisible(const GeoPoint
&loc
) const;
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
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());
91 fixed
GetMapScale() const;
94 * Configure the scale so a centered circle with the specified
97 void SetScaleFromRadius(fixed radius
);
100 * Returns the width of the map area in pixels.
103 unsigned GetScreenWidth() const {
104 assert(screen_size_initialised
);
110 * Returns the height of the map area in pixels.
113 unsigned GetScreenHeight() const {
114 assert(screen_size_initialised
);
116 return screen_height
;
120 * Returns the raster coordinates at the center of the map.
123 RasterPoint
GetScreenCenter() const {
125 pt
.x
= GetScreenWidth() / 2;
126 pt
.y
= GetScreenHeight() / 2;
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());
154 fixed
GetScreenDistanceMeters() const;
157 * Returns the GeoPoint at the center of the screen.
160 GeoPoint
GetGeoScreenCenter() const;
162 // used by terrain renderer, topography and airspace
164 const GeoBounds
&GetScreenBounds() const {
165 return screenbounds_latlon
;
168 /** Updates the cached screenbounds_latlon member */
169 void UpdateScreenBounds();
173 int GetMapResolutionFactor() const {
174 return GetMinScreenDistance() / 8;