Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / InfoBoxes / Panel / MacCreadySetup.cpp
blob695d3cd6bf5b1366dc2e2ac18ffae49124cfdd70
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 "MacCreadySetup.hpp"
25 #include "Screen/Layout.hpp"
26 #include "Widget/WindowWidget.hpp"
27 #include "Form/Button.hpp"
28 #include "Form/ActionListener.hpp"
29 #include "Interface.hpp"
30 #include "UIGlobals.hpp"
31 #include "Language/Language.hpp"
32 #include "Profile/Profile.hpp"
34 class WndButton;
36 class MacCreadySetupPanel : public WindowWidget,
37 private ActionListener {
38 public:
39 WndButton &GetButton() {
40 return *(WndButton *)GetWindow();
43 gcc_pure
44 static const TCHAR *GetCaption() {
45 return CommonInterface::GetComputerSettings().task.auto_mc
46 ? _("MANUAL")
47 : _("AUTO");
50 void UpdateCaption() {
51 GetButton().SetCaption(GetCaption());
54 /* virtual methods from class Widget */
55 virtual PixelSize GetMinimumSize() const override {
56 return PixelSize{Layout::Scale(80u), Layout::Scale(30u)};
59 virtual void Prepare(ContainerWindow &parent,
60 const PixelRect &rc) override;
62 virtual void Show(const PixelRect &rc) override;
64 /* virtual methods from class ActionListener */
65 virtual void OnAction(int id) override;
68 void
69 MacCreadySetupPanel::OnAction(int id)
71 TaskBehaviour &task_behaviour = CommonInterface::SetComputerSettings().task;
72 task_behaviour.auto_mc = !task_behaviour.auto_mc;
73 Profile::Set(ProfileKeys::AutoMc, task_behaviour.auto_mc);
75 UpdateCaption();
78 void
79 MacCreadySetupPanel::Prepare(ContainerWindow &parent, const PixelRect &rc)
81 ButtonWindowStyle style;
82 style.Hide();
83 style.TabStop();
85 SetWindow(new WndButton(parent, UIGlobals::GetDialogLook(), GetCaption(), rc,
86 style, *this, 1));
89 void
90 MacCreadySetupPanel::Show(const PixelRect &rc)
92 UpdateCaption();
93 WindowWidget::Show(rc);
96 Widget *
97 LoadMacCreadySetupPanel(unsigned id)
99 return new MacCreadySetupPanel();