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 "PageActions.hpp"
25 #include "UIActions.hpp"
26 #include "UIState.hpp"
27 #include "Interface.hpp"
28 #include "ActionInterface.hpp"
29 #include "MainWindow.hpp"
30 #include "CrossSection/CrossSectionWidget.hpp"
31 #include "InfoBoxes/InfoBoxSettings.hpp"
33 #include "UIGlobals.hpp"
34 #include "MapWindow/GlueMapWindow.hpp"
36 #if defined(ENABLE_SDL) && defined(main)
37 /* on some platforms, SDL wraps the main() function and clutters our
38 namespace with a macro called "main" */
42 namespace PageActions
{
44 * Call this when we're about to leave the current page. This
45 * function checks if settings need to be remembered.
47 static void LeavePage();
50 * Restore the map zoom afte switching to a configured page.
52 static void RestoreMapZoom();
55 * Loads the layout without updating current page information in
58 static void LoadLayout(const PageLayout
&layout
);
62 PageActions::LeavePage()
64 PagesState
&state
= CommonInterface::SetUIState().pages
;
66 if (state
.special_page
.IsDefined())
69 PageState
&page
= state
.pages
[state
.current_index
];
71 const GlueMapWindow
*map
= UIGlobals::GetMapIfActive();
73 page
.map_scale
= map
->VisibleProjection().GetMapScale();
77 PageActions::RestoreMapZoom()
79 const PagesState
&state
= CommonInterface::SetUIState().pages
;
80 if (state
.special_page
.IsDefined())
83 const PageState
&page
= state
.pages
[state
.current_index
];
84 const PageSettings
&settings
= CommonInterface::GetUISettings().pages
;
86 if (settings
.distinct_zoom
&& positive(page
.map_scale
)) {
87 GlueMapWindow
*map
= UIGlobals::GetMapIfActive();
89 map
->SetMapScale(page
.map_scale
);
95 static const PageLayout
&
98 const PageSettings
&settings
= CommonInterface::GetUISettings().pages
;
99 const PagesState
&state
= CommonInterface::GetUIState().pages
;
101 return settings
.pages
[state
.current_index
];
105 PageActions::GetCurrentLayout()
107 const PagesState
&state
= CommonInterface::GetUIState().pages
;
109 return state
.special_page
.IsDefined()
111 : GetConfiguredLayout();
115 PageActions::Update()
117 LoadLayout(GetCurrentLayout());
122 PageActions::NextIndex()
124 const PageSettings
&settings
= CommonInterface::GetUISettings().pages
;
125 const PagesState
&state
= CommonInterface::GetUIState().pages
;
127 if (state
.special_page
.IsDefined())
128 /* if a "special" page is active, any page switch will return to
129 the last configured page */
130 return state
.current_index
;
132 return (state
.current_index
+ 1) % settings
.n_pages
;
141 PagesState
&state
= CommonInterface::SetUIState().pages
;
143 state
.current_index
= NextIndex();
144 state
.special_page
.SetUndefined();
151 PageActions::PrevIndex()
153 const PageSettings
&settings
= CommonInterface::GetUISettings().pages
;
154 const PagesState
&state
= CommonInterface::GetUIState().pages
;
156 if (state
.special_page
.IsDefined())
157 /* if a "special" page is active, any page switch will return to
158 the last configured page */
159 return state
.current_index
;
161 return (state
.current_index
+ settings
.n_pages
- 1)
171 PagesState
&state
= CommonInterface::SetUIState().pages
;
173 state
.current_index
= PrevIndex();
174 state
.special_page
.SetUndefined();
181 PageActions::LoadLayout(const PageLayout
&layout
)
183 UIState
&ui_state
= CommonInterface::SetUIState();
190 if (!layout
.infobox_config
.enabled
) {
191 CommonInterface::main_window
->SetFullScreen(true);
192 ui_state
.auxiliary_enabled
= false;
194 if (!layout
.infobox_config
.auto_switch
&&
195 layout
.infobox_config
.panel
< InfoBoxSettings::MAX_PANELS
) {
196 CommonInterface::main_window
->SetFullScreen(false);
197 ui_state
.auxiliary_enabled
= true;
198 ui_state
.auxiliary_index
= layout
.infobox_config
.panel
;
201 CommonInterface::main_window
->SetFullScreen(false);
202 ui_state
.auxiliary_enabled
= false;
206 switch (layout
.bottom
) {
207 case PageLayout::Bottom::NOTHING
:
208 CommonInterface::main_window
->SetBottomWidget(nullptr);
211 case PageLayout::Bottom::CROSS_SECTION
:
212 CommonInterface::main_window
->SetBottomWidget(new CrossSectionWidget());
215 case PageLayout::Bottom::MAX
:
219 switch (layout
.main
) {
220 case PageLayout::Main::MAP
:
221 CommonInterface::main_window
->ActivateMap();
224 case PageLayout::Main::FLARM_RADAR
:
225 UIActions::ShowTrafficRadar();
228 case PageLayout::Main::THERMAL_ASSISTANT
:
229 UIActions::ShowThermalAssistant();
232 case PageLayout::Main::MAX
:
236 ActionInterface::UpdateDisplayMode();
237 ActionInterface::SendUIState();
241 PageActions::OpenLayout(const PageLayout
&layout
)
243 PagesState
&state
= CommonInterface::SetUIState().pages
;
244 state
.special_page
= layout
;
250 PageActions::Restore()
252 PageLayout
&special_page
= CommonInterface::SetUIState().pages
.special_page
;
253 if (!special_page
.IsDefined())
256 special_page
.SetUndefined();
258 LoadLayout(GetConfiguredLayout());
263 PageActions::DeferredRestore()
265 CommonInterface::main_window
->DeferredRestorePage();
269 PageActions::ShowMap()
271 PageLayout layout
= GetCurrentLayout();
272 if (layout
.main
!= PageLayout::Main::MAP
) {
273 /* not showing map currently: activate it */
275 if (GetConfiguredLayout().main
== PageLayout::Main::MAP
)
276 /* the configured page is a map page: restore it */
279 /* generate a "special" map page based on the current page */
280 layout
.main
= PageLayout::Main::MAP
;
285 return CommonInterface::main_window
->ActivateMap();
289 PageActions::ShowOnlyMap()
291 OpenLayout(PageLayout::FullScreen());
292 return CommonInterface::main_window
->ActivateMap();
296 PageActions::ShowTrafficRadar()
298 PageLayout layout
= GetCurrentLayout();
299 if (layout
.main
== PageLayout::Main::FLARM_RADAR
)
300 /* already showing the traffic radar */
303 if (GetConfiguredLayout().main
== PageLayout::Main::FLARM_RADAR
)
304 /* the configured page is a traffic radar page: restore it */
307 /* generate a "special" page based on the current page */
308 layout
.main
= PageLayout::Main::FLARM_RADAR
;
309 layout
.bottom
= PageLayout::Bottom::NOTHING
;
316 PageActions::ShowThermalAssistant()
318 PageLayout layout
= GetCurrentLayout();
319 if (layout
.main
== PageLayout::Main::THERMAL_ASSISTANT
)
320 /* already showing the traffic radar */
323 if (GetConfiguredLayout().main
== PageLayout::Main::THERMAL_ASSISTANT
)
324 /* the configured page is a traffic radar page: restore it */
327 /* generate a "special" page based on the current page */
328 layout
.main
= PageLayout::Main::THERMAL_ASSISTANT
;
329 layout
.bottom
= PageLayout::Bottom::NOTHING
;