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
),
38 ignore_single_click(false),
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
),
55 GlueMapWindow::Create(ContainerWindow
&parent
, const PixelRect
&rc
)
57 MapWindow::Create(parent
, rc
);
59 visible_projection
.SetScale(CommonInterface::GetMapSettings().cruise_scale
);
63 GlueMapWindow::SetMapSettings(const MapSettings
&new_value
)
65 AssertThreadOrUndefined();
68 ReadMapSettings(new_value
);
70 ScopeLock
protect(next_mutex
);
71 next_settings_map
= new_value
;
76 GlueMapWindow::SetComputerSettings(const ComputerSettings
&new_value
)
78 AssertThreadOrUndefined();
81 ReadComputerSettings(new_value
);
83 ScopeLock
protect(next_mutex
);
84 next_settings_computer
= new_value
;
89 GlueMapWindow::SetUIState(const UIState
&new_value
)
91 AssertThreadOrUndefined();
94 ReadUIState(new_value
);
96 ScopeLock
protect(next_mutex
);
97 next_ui_state
= new_value
;
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
112 ReadMapSettings(next_settings_map
);
113 ReadComputerSettings(next_settings_computer
);
114 ReadUIState(next_ui_state
);
120 GlueMapWindow::SuspendThreads()
122 #ifndef ENABLE_OPENGL
123 if (draw_thread
!= NULL
)
124 draw_thread
->Suspend();
129 GlueMapWindow::ResumeThreads()
131 #ifndef ENABLE_OPENGL
132 if (draw_thread
!= NULL
)
133 draw_thread
->Resume();
138 GlueMapWindow::FullRedraw()
148 draw_thread
->TriggerRedraw();
153 GlueMapWindow::QuickRedraw()
159 #ifndef ENABLE_OPENGL
160 /* update the Projection */
164 /* quickly stretch the existing buffer into the window */
171 #ifndef ENABLE_OPENGL
172 /* we suppose that the operation will need a full redraw later, so
174 draw_thread
->TriggerRedraw();
179 * This idle function allows progressive scanning of visibility etc
182 GlueMapWindow::Idle()
184 if (!render_projection
.IsValid())
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 */
194 if (!IsUserIdle(2500))
195 /* don't hold back the UI thread while the user is interacting */
202 bool topography_dirty
= true; /* scan topography in every Idle() call */
203 bool terrain_dirty
= true;
204 bool weather_dirty
= true;
207 idle_robin
= (idle_robin
+ 1) % 3;
208 switch (idle_robin
) {
210 topography_dirty
= UpdateTopography(1) > 0;
214 terrain_dirty
= UpdateTerrain();
218 weather_dirty
= UpdateWeather();
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() &&