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_MAIN_WINDOW_HXX
25 #define XCSOAR_MAIN_WINDOW_HXX
27 #include "Screen/SingleWindow.hpp"
28 #include "Screen/Timer.hpp"
29 #include "InfoBoxes/InfoBoxLayout.hpp"
30 #include "PopupMessage.hpp"
31 #include "BatteryTimer.hpp"
32 #include "Widget/ManagedWidget.hpp"
33 #include "UIUtil/GestureManager.hpp"
38 struct ComputerSettings
;
44 class StatusMessageList
;
46 class TopographyStore
;
47 class MapWindowProjection
;
50 * The XCSoar main window.
52 class MainWindow
: public SingleWindow
{
53 enum class Command
: uint8_t {
55 * Check the airspace_warning_pending flag and show the airspace
61 * Called by the #MergeThread when new GPS data is available.
66 * Called by the calculation thread when new calculation results
67 * are available. This updates the map and the info boxes.
72 * @see DeferredRestorePage()
77 static constexpr const TCHAR
*title
= _T("XCSoar");
84 * A #Widget that is shown below the map.
86 Widget
*bottom_widget
;
89 * A #Widget that is shown instead of the map. The #GlueMapWindow
90 * is hidden and the DrawThread is suspended while this attribute is
97 ManagedWidget traffic_gauge
;
98 bool suppress_traffic_gauge
, force_traffic_gauge
;
100 ManagedWidget thermal_assistant
;
103 GestureManager gestures
;
111 BatteryTimer battery_timer
;
116 #ifndef ENABLE_OPENGL
118 * This variable tracks whether the #DrawThread was suspended
119 * because the map was replaced by a #Widget.
124 bool restore_page_pending
;
126 bool airspace_warning_pending
;
129 MainWindow(const StatusMessageList
&status_messages
);
130 virtual ~MainWindow();
134 return SingleWindow::Find(title
);
140 * Is XCSoar already up and running?
143 /* it is safe enough to say that XCSoar initialization is complete
144 after the MapWindow has been created */
149 * Destroy the current Widget, but don't reactivate the map. The
150 * caller is responsible for reactivating the map or another Widget.
155 * Destroy the current "bottom" Widget, but don't resize the main
156 * area. The caller is responsible for doing that or installing a
159 void KillBottomWidget();
162 void Create(PixelSize size
, TopWindowStyle style
=TopWindowStyle());
167 void InitialiseConfigured();
170 * Destroy the components of the main view (map, info boxes,
177 const PixelRect
&GetMainRect(const PixelRect
&full_rc
) const {
178 return FullScreen
? full_rc
: map_rect
;
182 PixelRect
GetMainRect() const {
183 return FullScreen
? GetClientRect() : map_rect
;
187 * Adjust the flarm radar position
189 void ReinitialiseLayout_flarm(PixelRect rc
, const InfoBoxLayout::Layout ib_layout
);
194 void ReinitialiseLayout_vario(const InfoBoxLayout::Layout
&layout
);
196 void ReinitialiseLayoutTA(PixelRect rc
, const InfoBoxLayout::Layout
&layout
);
200 * Called by XCSoarInterface::Startup() after startup has been
203 void FinishStartup();
206 * Called by XCSoarInterface::Shutdown() before shutdown begins.
208 void BeginShutdown();
211 * Destroy and re-create all info boxes, and adjust the map
214 void ReinitialiseLayout();
217 * Suspend threads that are owned by this object.
219 void SuspendThreads();
222 * Resumt threads that are owned by this object.
224 void ResumeThreads();
227 * Set the keyboard focus on the default element (i.e. the
230 void SetDefaultFocus();
233 * Trigger a full redraw of the screen.
237 bool GetFullScreen() const {
241 void SetFullScreen(bool _full_screen
);
244 * A new airspace warning was found. This method sends the
245 * Command::AIRSPACE_WARNING command to this window, which displays the
246 * airspace warning dialog.
248 void SendAirspaceWarning() {
249 airspace_warning_pending
= true;
250 SendUser((unsigned)Command::AIRSPACE_WARNING
);
253 void SendGPSUpdate() {
254 SendUser((unsigned)Command::GPS_UPDATE
);
257 void SendCalculatedUpdate() {
258 SendUser((unsigned)Command::CALCULATED_UPDATE
);
261 void SetTerrain(RasterTerrain
*terrain
);
262 void SetTopography(TopographyStore
*topography
);
264 const Look
&GetLook() const {
265 assert(look
!= NULL
);
271 assert(look
!= NULL
);
276 void SetComputerSettings(const ComputerSettings
&settings_computer
);
277 void SetMapSettings(const MapSettings
&settings_map
);
278 void SetUIState(const UIState
&ui_state
);
281 * Returns the map even if it is not active. May return NULL if
285 GlueMapWindow
*GetMap() {
290 * Is the map active, i.e. currently visible?
292 bool IsMapActive() const {
293 return widget
== NULL
;
297 * Returns the map if it is active, or NULL if the map is not
301 GlueMapWindow
*GetMapIfActive();
304 * Activate the map and return a pointer to it. May return NULL if
307 GlueMapWindow
*ActivateMap();
310 * Schedule a call to PageActions::Restore(). The function returns
311 * immediately, and there is no guarantee that it succeeds.
313 void DeferredRestorePage();
316 * Show this #Widget below the map. This replaces (deletes) the
317 * previous bottom widget, if any. To disable this feature, call
318 * this method with widget==nullptr.
320 void SetBottomWidget(Widget
*widget
);
323 * Replace the map with a #Widget. The Widget instance gets deleted
324 * when the map gets reactivated with ActivateMap() or if another
327 void SetWidget(Widget
*_widget
);
330 * Returns the current #Widget, but only if the specified flavour is
333 * @see InputEvents::IsFlavour(), InputEvents::SetFlavour()
336 Widget
*GetFlavourWidget(const TCHAR
*flavour
);
338 void UpdateGaugeVisibility();
341 const MapWindowProjection
&GetProjection() const;
343 void ToggleSuppressFLARMRadar();
344 void ToggleForceFLARMRadar();
347 void UpdateVarioGaugeVisibility();
348 void UpdateTrafficGaugeVisibility();
353 /* virtual methods from class Window */
354 virtual void OnDestroy() override
;
355 virtual void OnResize(PixelSize new_size
) override
;
356 virtual void OnSetFocus() override
;
357 virtual void OnCancelMode() override
;
358 virtual bool OnMouseDown(PixelScalar x
, PixelScalar y
) override
;
359 virtual bool OnMouseUp(PixelScalar x
, PixelScalar y
) override
;
360 virtual bool OnMouseMove(PixelScalar x
, PixelScalar y
,
361 unsigned keys
) override
;
362 virtual bool OnMouseDouble(PixelScalar x
, PixelScalar y
) override
;
363 virtual bool OnKeyDown(unsigned key_code
) override
;
364 virtual bool OnUser(unsigned id
) override
;
365 virtual bool OnTimer(WindowTimer
&timer
) override
;
367 /* virtual methods from class TopWindow */
368 virtual bool OnClose() override
;
369 virtual bool OnActivate() override
;
372 virtual void OnPause() override
;