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 "OffsetButtonsWidget.hpp"
25 #include "Form/Button.hpp"
26 #include "Util/Macros.hpp"
27 #include "Screen/Layout.hpp"
30 OffsetButtonsWidget::GetMinimumSize() const
32 return { 4u * Layout::GetMinimumControlHeight(),
33 Layout::GetMinimumControlHeight() };
37 OffsetButtonsWidget::GetMaximumSize() const
39 return { 4u * Layout::GetMaximumControlHeight(),
40 Layout::GetMaximumControlHeight() };
44 LayoutOffsetButtons(const PixelRect
&total_rc
, PixelRect buttons
[4])
46 const unsigned total_width
= total_rc
.right
- total_rc
.left
;
47 PixelRect rc
= { 0, total_rc
.top
, total_rc
.left
, total_rc
.bottom
};
49 for (unsigned i
= 0; i
< 4; ++i
) {
51 rc
.right
= total_rc
.left
+ (i
+ 1) * total_width
/ 4;
57 OffsetButtonsWidget::Prepare(ContainerWindow
&parent
,
58 const PixelRect
&total_rc
)
60 PixelRect rc
[ARRAY_SIZE(buttons
)];
61 LayoutOffsetButtons(total_rc
, rc
);
63 ButtonWindowStyle style
;
67 for (unsigned i
= 0; i
< ARRAY_SIZE(buttons
); ++i
) {
69 _stprintf(caption
, format
, (double)offsets
[i
]);
70 buttons
[i
] = new WndButton(parent
, look
, caption
, rc
[i
], style
,
76 OffsetButtonsWidget::Unprepare()
78 for (unsigned i
= 0; i
< ARRAY_SIZE(offsets
); ++i
)
83 OffsetButtonsWidget::Show(const PixelRect
&total_rc
)
85 PixelRect rc
[ARRAY_SIZE(buttons
)];
86 LayoutOffsetButtons(total_rc
, rc
);
88 for (unsigned i
= 0; i
< ARRAY_SIZE(buttons
); ++i
)
89 buttons
[i
]->MoveAndShow(rc
[i
]);
93 OffsetButtonsWidget::Hide()
95 for (unsigned i
= 0; i
< ARRAY_SIZE(buttons
); ++i
)
100 OffsetButtonsWidget::Move(const PixelRect
&total_rc
)
102 PixelRect rc
[ARRAY_SIZE(buttons
)];
103 LayoutOffsetButtons(total_rc
, rc
);
105 for (unsigned i
= 0; i
< ARRAY_SIZE(buttons
); ++i
)
106 buttons
[i
]->Move(rc
[i
]);
110 OffsetButtonsWidget::SetFocus()
112 buttons
[2]->SetFocus();
117 OffsetButtonsWidget::OnAction(int id
)
119 assert(unsigned(id
) < ARRAY_SIZE(offsets
));
121 OnOffset(offsets
[id
]);