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 #include "MapWindow.hpp"
28 #include "Protection.hpp"
29 #include "Blackboard/DeviceBlackboard.hpp"
31 #include "Screen/WindowCanvas.hpp"
34 #include "Weather/Features.hpp"
37 MapWindow::OnResize(PixelSize new_size
)
39 DoubleBufferWindow::OnResize(new_size
);
44 // We only grow() the buffer here because resizing it everytime has
45 // a huge negative effect on the heap fragmentation
46 buffer_canvas
.Grow(new_size
);
48 if (!IsAncientHardware())
49 stencil_canvas
.Grow(new_size
);
52 visible_projection
.SetScreenSize(new_size
);
53 visible_projection
.UpdateScreenBounds();
59 DoubleBufferWindow::OnCreate();
62 WindowCanvas
canvas(*this);
63 buffer_canvas
.Create(canvas
);
65 if (!IsAncientHardware())
66 stencil_canvas
.Create(canvas
);
71 MapWindow::OnDestroy()
77 airspace_renderer
.Clear();
84 buffer_canvas
.Destroy();
86 if (!IsAncientHardware())
87 stencil_canvas
.Destroy();
90 DoubleBufferWindow::OnDestroy();
94 MapWindow::OnPaint(Canvas
&canvas
)
97 DoubleBufferWindow::OnPaint(canvas
);
98 #else /* !ENABLE_OPENGL */
99 if (buffer_generation
== ui_generation
)
100 DoubleBufferWindow::OnPaint(canvas
);
101 else if (scale_buffer
> 0) {
102 /* while zooming/panning, project the current buffer into the
107 /* do the projection */
109 const UPixelScalar buffer_width
= buffer_projection
.GetScreenWidth();
110 const UPixelScalar buffer_height
= buffer_projection
.GetScreenHeight();
112 const RasterPoint top_left
=
113 visible_projection
.GeoToScreen(buffer_projection
.ScreenToGeo(0, 0));
114 RasterPoint bottom_right
=
115 visible_projection
.GeoToScreen(buffer_projection
.ScreenToGeo(buffer_width
,
118 /* compensate for rounding errors in destination area */
120 if (abs(buffer_width
- (bottom_right
.x
- top_left
.x
)) < 5)
121 bottom_right
.x
= top_left
.x
+ buffer_width
;
123 if (abs(buffer_height
- (bottom_right
.y
- top_left
.y
)) < 5)
124 bottom_right
.y
= top_left
.y
+ buffer_height
;
126 if (top_left
.x
> bottom_right
.x
|| top_left
.y
> bottom_right
.y
) {
127 /* paranoid sanity check */
132 /* clear the areas around the buffer */
134 canvas
.SelectNullPen();
135 canvas
.SelectWhiteBrush();
138 canvas
.Rectangle(0, 0, top_left
.x
, canvas
.GetHeight());
140 if (bottom_right
.x
< (int)canvas
.GetWidth())
141 canvas
.Rectangle(bottom_right
.x
, 0,
142 canvas
.GetWidth(), canvas
.GetHeight());
145 canvas
.Rectangle(top_left
.x
, 0, bottom_right
.x
, top_left
.y
);
147 if (bottom_right
.y
< (int)canvas
.GetHeight())
148 canvas
.Rectangle(top_left
.x
, bottom_right
.y
,
149 bottom_right
.x
, canvas
.GetHeight());
151 /* now stretch the buffer into the window Canvas */
153 ScopeLock
protect(DoubleBufferWindow::mutex
);
154 const Canvas
&src
= GetVisibleCanvas();
155 canvas
.Stretch(top_left
.x
, top_left
.y
,
156 bottom_right
.x
- top_left
.x
, bottom_right
.y
- top_left
.y
,
157 src
, 0, 0, buffer_width
, buffer_height
);
159 /* the UI has changed since the last DrawThread iteration has
160 started: the buffer has invalid data, paint a white window
163 #endif /* !ENABLE_OPENGL */