dlgTextEntry_Keyboard: rename to TouchTextEntry
[xcsoar.git] / src / MapWindow / MapWindowEvents.cpp
blobb5de58e6e5add2c1be9bd2a41f206643e0dcf68a
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 #include "MapWindow.hpp"
25 #include "Asset.hpp"
27 #ifdef ENABLE_OPENGL
28 #include "Protection.hpp"
29 #include "Blackboard/DeviceBlackboard.hpp"
30 #else
31 #include "Screen/WindowCanvas.hpp"
32 #endif
34 #include "Weather/Features.hpp"
36 void
37 MapWindow::OnResize(PixelSize new_size)
39 DoubleBufferWindow::OnResize(new_size);
41 #ifndef ENABLE_OPENGL
42 ++ui_generation;
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);
50 #endif
52 visible_projection.SetScreenSize(new_size);
53 visible_projection.UpdateScreenBounds();
56 void
57 MapWindow::OnCreate()
59 DoubleBufferWindow::OnCreate();
61 #ifndef ENABLE_OPENGL
62 WindowCanvas canvas(*this);
63 buffer_canvas.Create(canvas);
65 if (!IsAncientHardware())
66 stencil_canvas.Create(canvas);
67 #endif
70 void
71 MapWindow::OnDestroy()
73 #ifdef HAVE_NOAA
74 SetNOAAStore(NULL);
75 #endif
76 SetMarks(NULL);
77 airspace_renderer.Clear();
78 SetWaypoints(NULL);
79 SetTopography(NULL);
80 SetTerrain(NULL);
81 SetWeather(NULL);
83 #ifndef ENABLE_OPENGL
84 buffer_canvas.Destroy();
86 if (!IsAncientHardware())
87 stencil_canvas.Destroy();
88 #endif
90 DoubleBufferWindow::OnDestroy();
93 void
94 MapWindow::OnPaint(Canvas &canvas)
96 #ifdef ENABLE_OPENGL
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
103 Canvas */
105 --scale_buffer;
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,
116 buffer_height));
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 */
128 canvas.ClearWhite();
129 return;
132 /* clear the areas around the buffer */
134 canvas.SelectNullPen();
135 canvas.SelectWhiteBrush();
137 if (top_left.x > 0)
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());
144 if (top_left.y > 0)
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);
158 } else
159 /* the UI has changed since the last DrawThread iteration has
160 started: the buffer has invalid data, paint a white window
161 instead */
162 canvas.ClearWhite();
163 #endif /* !ENABLE_OPENGL */