PageSettings: split top_layout into two boolean flags
[xcsoar.git] / src / Pages.cpp
blob0ceaa615cad4d03016cf8d09b20b9ec6c1d738e7
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 #include "Pages.hpp"
25 #include "UIState.hpp"
26 #include "Interface.hpp"
27 #include "ActionInterface.hpp"
28 #include "MainWindow.hpp"
29 #include "CrossSection/CrossSectionWidget.hpp"
30 #include "InfoBoxes/InfoBoxManager.hpp"
31 #include "InfoBoxes/InfoBoxSettings.hpp"
32 #include "Language/Language.hpp"
34 #include <stdio.h>
36 namespace Pages
38 static unsigned current_page = 0;
41 void
42 Pages::Update()
44 const PageSettings &settings = CommonInterface::GetUISettings().pages;
46 if (!settings.pages[current_page].IsDefined())
47 current_page = NextIndex();
49 OpenLayout(settings.pages[current_page]);
53 unsigned
54 Pages::NextIndex()
56 const PageSettings &settings = CommonInterface::GetUISettings().pages;
58 unsigned i = current_page;
59 do {
60 i = (i + 1) % PageSettings::MAX_PAGES;
61 } while (!settings.pages[i].IsDefined());
62 return i;
66 void
67 Pages::Next()
69 current_page = NextIndex();
70 Update();
74 unsigned
75 Pages::PrevIndex()
77 const PageSettings &settings = CommonInterface::GetUISettings().pages;
79 unsigned i = current_page;
80 do {
81 i = (i == 0) ? PageSettings::MAX_PAGES - 1 : i - 1;
82 } while (!settings.pages[i].IsDefined());
83 return i;
87 void
88 Pages::Prev()
90 current_page = PrevIndex();
91 Update();
94 void
95 Pages::Open(unsigned page)
97 const PageSettings &settings = CommonInterface::GetUISettings().pages;
99 if (page >= PageSettings::MAX_PAGES)
100 return;
102 if (!settings.pages[page].IsDefined())
103 return;
105 current_page = page;
106 Update();
110 void
111 Pages::OpenLayout(const PageSettings::PageLayout &layout)
113 UIState &ui_state = CommonInterface::SetUIState();
115 if (!layout.valid)
116 return;
118 if (!layout.infobox_config.enabled) {
119 CommonInterface::main_window->SetFullScreen(true);
120 ui_state.auxiliary_enabled = false;
121 } else {
122 if (!layout.infobox_config.auto_switch &&
123 layout.infobox_config.panel < InfoBoxSettings::MAX_PANELS) {
124 CommonInterface::main_window->SetFullScreen(false);
125 ui_state.auxiliary_enabled = true;
126 ui_state.auxiliary_index = layout.infobox_config.panel;
128 else {
129 CommonInterface::main_window->SetFullScreen(false);
130 ui_state.auxiliary_enabled = false;
134 switch (layout.bottom) {
135 case PageSettings::PageLayout::Bottom::NOTHING:
136 CommonInterface::main_window->SetBottomWidget(nullptr);
137 break;
139 case PageSettings::PageLayout::Bottom::CROSS_SECTION:
140 CommonInterface::main_window->SetBottomWidget(new CrossSectionWidget());
141 break;
144 ActionInterface::UpdateDisplayMode();
145 ActionInterface::SendUIState();