MainWindow: implement gestures
[xcsoar.git] / src / MainWindow.hpp
blob49afeebc165ec451abc50bf3c8de87c517da7e4b
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 #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"
35 #include <stdint.h>
36 #include <assert.h>
38 struct ComputerSettings;
39 struct MapSettings;
40 struct UIState;
41 struct Look;
42 class GlueMapWindow;
43 class Widget;
44 class StatusMessageList;
45 class RasterTerrain;
46 class TopographyStore;
47 class MapWindowProjection;
49 /**
50 * The XCSoar main window.
52 class MainWindow : public SingleWindow {
53 enum class Command: uint8_t {
54 /**
55 * Check the airspace_warning_pending flag and show the airspace
56 * warning dialog.
58 AIRSPACE_WARNING,
60 /**
61 * Called by the #MergeThread when new GPS data is available.
63 GPS_UPDATE,
65 /**
66 * Called by the calculation thread when new calculation results
67 * are available. This updates the map and the info boxes.
69 CALCULATED_UPDATE,
71 /**
72 * @see DeferredRestorePage()
74 RESTORE_PAGE,
77 static constexpr const TCHAR *title = _T("XCSoar");
79 Look *look;
81 GlueMapWindow *map;
83 /**
84 * A #Widget that is shown below the map.
86 Widget *bottom_widget;
88 /**
89 * A #Widget that is shown instead of the map. The #GlueMapWindow
90 * is hidden and the DrawThread is suspended while this attribute is
91 * non-NULL.
93 Widget *widget;
95 ManagedWidget vario;
97 ManagedWidget traffic_gauge;
98 bool suppress_traffic_gauge, force_traffic_gauge;
100 ManagedWidget thermal_assistant;
102 bool dragging;
103 GestureManager gestures;
105 public:
106 PopupMessage popup;
108 private:
109 WindowTimer timer;
111 BatteryTimer battery_timer;
113 PixelRect map_rect;
114 bool FullScreen;
116 #ifndef ENABLE_OPENGL
118 * This variable tracks whether the #DrawThread was suspended
119 * because the map was replaced by a #Widget.
121 bool draw_suspended;
122 #endif
124 bool restore_page_pending;
126 bool airspace_warning_pending;
128 public:
129 MainWindow(const StatusMessageList &status_messages);
130 virtual ~MainWindow();
132 #ifdef USE_GDI
133 static bool Find() {
134 return SingleWindow::Find(title);
136 #endif
138 protected:
140 * Is XCSoar already up and running?
142 bool IsRunning() {
143 /* it is safe enough to say that XCSoar initialization is complete
144 after the MapWindow has been created */
145 return map != NULL;
149 * Destroy the current Widget, but don't reactivate the map. The
150 * caller is responsible for reactivating the map or another Widget.
152 void KillWidget();
154 public:
155 void Create(PixelSize size, TopWindowStyle style=TopWindowStyle());
157 void Destroy();
159 void Initialise();
160 void InitialiseConfigured();
163 * Destroy the components of the main view (map, info boxes,
164 * gauges).
166 void Deinitialise();
168 private:
169 gcc_pure
170 const PixelRect &GetMainRect(const PixelRect &full_rc) const {
171 return FullScreen ? full_rc : map_rect;
174 gcc_pure
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);
185 * Adjust vario
187 void ReinitialiseLayout_vario(const InfoBoxLayout::Layout &layout);
189 void ReinitialiseLayoutTA(PixelRect rc, const InfoBoxLayout::Layout &layout);
191 public:
193 * Called by XCSoarInterface::Startup() after startup has been
194 * completed.
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
205 * position/size.
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
221 * MapWindow).
223 void SetDefaultFocus();
226 * Trigger a full redraw of the screen.
228 void FullRedraw();
230 bool GetFullScreen() const {
231 return FullScreen;
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);
260 return *look;
263 Look &SetLook() {
264 assert(look != NULL);
266 return *look;
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
275 * there is no map.
277 gcc_pure
278 GlueMapWindow *GetMap() {
279 return map;
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
291 * active.
293 gcc_pure
294 GlueMapWindow *GetMapIfActive();
297 * Activate the map and return a pointer to it. May return NULL if
298 * there is no map.
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
318 * Widget gets set.
320 void SetWidget(Widget *_widget);
323 * Returns the current #Widget, but only if the specified flavour is
324 * active.
326 * @see InputEvents::IsFlavour(), InputEvents::SetFlavour()
328 gcc_pure
329 Widget *GetFlavourWidget(const TCHAR *flavour);
331 void UpdateGaugeVisibility();
333 gcc_pure
334 const MapWindowProjection &GetProjection() const;
336 void ToggleSuppressFLARMRadar();
337 void ToggleForceFLARMRadar();
339 private:
340 void UpdateVarioGaugeVisibility();
341 void UpdateTrafficGaugeVisibility();
343 void StopDragging();
345 protected:
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;
364 #ifdef ANDROID
365 virtual void OnPause() override;
366 #endif
369 #endif