Makefile: remove spurious tab
[xcsoar.git] / src / MapWindow / GlueMapWindow.cpp
bloba6dcc3b29c36a9d5578cf069c345a00f8ef573cf
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 "GlueMapWindow.hpp"
25 #include "Components.hpp"
26 #include "DrawThread.hpp"
27 #include "Blackboard/DeviceBlackboard.hpp"
28 #include "Look/Look.hpp"
29 #include "Interface.hpp"
30 #include "Time/PeriodClock.hpp"
31 #include "Event/Idle.hpp"
33 GlueMapWindow::GlueMapWindow(const Look &look)
34 :MapWindow(look.map, look.traffic),
35 logger(NULL),
36 idle_robin(-1),
37 drag_mode(DRAG_NONE),
38 ignore_single_click(false),
39 #ifdef ENABLE_OPENGL
40 kinetic_x(700),
41 kinetic_y(700),
42 kinetic_timer(*this),
43 #endif
44 arm_mapitem_list(false),
45 last_display_mode(DisplayMode::NONE),
46 thermal_band_renderer(look.thermal_band, look.chart),
47 final_glide_bar_renderer(look.final_glide_bar, look.map.task),
48 vario_bar_renderer(look.vario_bar),
49 gesture_look(look.gesture),
50 map_item_timer(*this)
54 void
55 GlueMapWindow::Create(ContainerWindow &parent, const PixelRect &rc)
57 MapWindow::Create(parent, rc);
59 visible_projection.SetScale(CommonInterface::GetMapSettings().cruise_scale);
62 void
63 GlueMapWindow::SetMapSettings(const MapSettings &new_value)
65 AssertThreadOrUndefined();
67 #ifdef ENABLE_OPENGL
68 ReadMapSettings(new_value);
69 #else
70 ScopeLock protect(next_mutex);
71 next_settings_map = new_value;
72 #endif
75 void
76 GlueMapWindow::SetComputerSettings(const ComputerSettings &new_value)
78 AssertThreadOrUndefined();
80 #ifdef ENABLE_OPENGL
81 ReadComputerSettings(new_value);
82 #else
83 ScopeLock protect(next_mutex);
84 next_settings_computer = new_value;
85 #endif
88 void
89 GlueMapWindow::SetUIState(const UIState &new_value)
91 AssertThreadOrUndefined();
93 #ifdef ENABLE_OPENGL
94 ReadUIState(new_value);
95 #else
96 ScopeLock protect(next_mutex);
97 next_ui_state = new_value;
98 #endif
101 void
102 GlueMapWindow::ExchangeBlackboard()
104 /* copy device_blackboard to MapWindow */
106 device_blackboard->mutex.Lock();
107 ReadBlackboard(device_blackboard->Basic(), device_blackboard->Calculated());
108 device_blackboard->mutex.Unlock();
110 #ifndef ENABLE_OPENGL
111 next_mutex.Lock();
112 ReadMapSettings(next_settings_map);
113 ReadComputerSettings(next_settings_computer);
114 ReadUIState(next_ui_state);
115 next_mutex.Unlock();
116 #endif
119 void
120 GlueMapWindow::SuspendThreads()
122 #ifndef ENABLE_OPENGL
123 if (draw_thread != NULL)
124 draw_thread->Suspend();
125 #endif
128 void
129 GlueMapWindow::ResumeThreads()
131 #ifndef ENABLE_OPENGL
132 if (draw_thread != NULL)
133 draw_thread->Resume();
134 #endif
137 void
138 GlueMapWindow::FullRedraw()
140 UpdateDisplayMode();
141 UpdateScreenAngle();
142 UpdateProjection();
143 UpdateMapScale();
145 #ifdef ENABLE_OPENGL
146 Invalidate();
147 #else
148 draw_thread->TriggerRedraw();
149 #endif
152 void
153 GlueMapWindow::QuickRedraw()
155 UpdateScreenAngle();
156 UpdateProjection();
157 UpdateMapScale();
159 #ifndef ENABLE_OPENGL
160 /* update the Projection */
162 ++ui_generation;
164 /* quickly stretch the existing buffer into the window */
166 scale_buffer = 2;
167 #endif
169 Invalidate();
171 #ifndef ENABLE_OPENGL
172 /* we suppose that the operation will need a full redraw later, so
173 trigger that now */
174 draw_thread->TriggerRedraw();
175 #endif
179 * This idle function allows progressive scanning of visibility etc
181 bool
182 GlueMapWindow::Idle()
184 if (!render_projection.IsValid())
185 return false;
187 if (idle_robin == unsigned(-1)) {
188 /* draw the first frame as quickly as possible, so the user can
189 start interacting with XCSoar immediately */
190 idle_robin = 2;
191 return true;
194 if (!IsUserIdle(2500))
195 /* don't hold back the UI thread while the user is interacting */
196 return true;
198 PeriodClock clock;
199 clock.Update();
201 bool still_dirty;
202 bool topography_dirty = true; /* scan topography in every Idle() call */
203 bool terrain_dirty = true;
204 bool weather_dirty = true;
206 do {
207 idle_robin = (idle_robin + 1) % 3;
208 switch (idle_robin) {
209 case 0:
210 topography_dirty = UpdateTopography(1) > 0;
211 break;
213 case 1:
214 terrain_dirty = UpdateTerrain();
215 break;
217 case 2:
218 weather_dirty = UpdateWeather();
219 break;
222 still_dirty = terrain_dirty || topography_dirty || weather_dirty;
223 } while (!clock.Check(700) && /* stop after 700ms */
224 #ifndef ENABLE_OPENGL
225 !draw_thread->IsTriggered() &&
226 #endif
227 IsUserIdle(2500) &&
228 still_dirty);
230 return still_dirty;