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 void Create(PixelSize size
, TopWindowStyle style
=TopWindowStyle());
160 void InitialiseConfigured();
163 * Destroy the components of the main view (map, info boxes,
170 const PixelRect
&GetMainRect(const PixelRect
&full_rc
) const {
171 return FullScreen
? full_rc
: map_rect
;
175 PixelRect
GetMainRect() const {
176 return FullScreen
? GetClientRect() : map_rect
;
180 * Adjust the flarm radar position
182 void ReinitialiseLayout_flarm(PixelRect rc
, const InfoBoxLayout::Layout ib_layout
);
187 void ReinitialiseLayout_vario(const InfoBoxLayout::Layout
&layout
);
189 void ReinitialiseLayoutTA(PixelRect rc
, const InfoBoxLayout::Layout
&layout
);
193 * Called by XCSoarInterface::Startup() after startup has been
196 void FinishStartup();
199 * Called by XCSoarInterface::Shutdown() before shutdown begins.
201 void BeginShutdown();
204 * Destroy and re-create all info boxes, and adjust the map
207 void ReinitialiseLayout();
210 * Suspend threads that are owned by this object.
212 void SuspendThreads();
215 * Resumt threads that are owned by this object.
217 void ResumeThreads();
220 * Set the keyboard focus on the default element (i.e. the
223 void SetDefaultFocus();
226 * Trigger a full redraw of the screen.
230 bool GetFullScreen() const {
234 void SetFullScreen(bool _full_screen
);
237 * A new airspace warning was found. This method sends the
238 * Command::AIRSPACE_WARNING command to this window, which displays the
239 * airspace warning dialog.
241 void SendAirspaceWarning() {
242 airspace_warning_pending
= true;
243 SendUser((unsigned)Command::AIRSPACE_WARNING
);
246 void SendGPSUpdate() {
247 SendUser((unsigned)Command::GPS_UPDATE
);
250 void SendCalculatedUpdate() {
251 SendUser((unsigned)Command::CALCULATED_UPDATE
);
254 void SetTerrain(RasterTerrain
*terrain
);
255 void SetTopography(TopographyStore
*topography
);
257 const Look
&GetLook() const {
258 assert(look
!= NULL
);
264 assert(look
!= NULL
);
269 void SetComputerSettings(const ComputerSettings
&settings_computer
);
270 void SetMapSettings(const MapSettings
&settings_map
);
271 void SetUIState(const UIState
&ui_state
);
274 * Returns the map even if it is not active. May return NULL if
278 GlueMapWindow
*GetMap() {
283 * Is the map active, i.e. currently visible?
285 bool IsMapActive() const {
286 return widget
== NULL
;
290 * Returns the map if it is active, or NULL if the map is not
294 GlueMapWindow
*GetMapIfActive();
297 * Activate the map and return a pointer to it. May return NULL if
300 GlueMapWindow
*ActivateMap();
303 * Schedule a call to PageActions::Restore(). The function returns
304 * immediately, and there is no guarantee that it succeeds.
306 void DeferredRestorePage();
309 * Show this #Widget below the map. This replaces (deletes) the
310 * previous bottom widget, if any. To disable this feature, call
311 * this method with widget==nullptr.
313 void SetBottomWidget(Widget
*widget
);
316 * Replace the map with a #Widget. The Widget instance gets deleted
317 * when the map gets reactivated with ActivateMap() or if another
320 void SetWidget(Widget
*_widget
);
323 * Returns the current #Widget, but only if the specified flavour is
326 * @see InputEvents::IsFlavour(), InputEvents::SetFlavour()
329 Widget
*GetFlavourWidget(const TCHAR
*flavour
);
331 void UpdateGaugeVisibility();
334 const MapWindowProjection
&GetProjection() const;
336 void ToggleSuppressFLARMRadar();
337 void ToggleForceFLARMRadar();
340 void UpdateVarioGaugeVisibility();
341 void UpdateTrafficGaugeVisibility();
346 /* virtual methods from class Window */
347 virtual void OnDestroy() override
;
348 virtual void OnResize(PixelSize new_size
) override
;
349 virtual void OnSetFocus() override
;
350 virtual void OnCancelMode() override
;
351 virtual bool OnMouseDown(PixelScalar x
, PixelScalar y
) override
;
352 virtual bool OnMouseUp(PixelScalar x
, PixelScalar y
) override
;
353 virtual bool OnMouseMove(PixelScalar x
, PixelScalar y
,
354 unsigned keys
) override
;
355 virtual bool OnMouseDouble(PixelScalar x
, PixelScalar y
) override
;
356 virtual bool OnKeyDown(unsigned key_code
) override
;
357 virtual bool OnUser(unsigned id
) override
;
358 virtual bool OnTimer(WindowTimer
&timer
) override
;
360 /* virtual methods from class TopWindow */
361 virtual bool OnClose() override
;
362 virtual bool OnActivate() override
;
365 virtual void OnPause() override
;