TaskStats: remove unused attribute "Time"
[xcsoar.git] / test / src / RunHorizonRenderer.cpp
blob01d5c60584b34215fc2a4046bae8d4201fa81182
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 #define ENABLE_SCREEN
26 #include "Main.hpp"
27 #include "Screen/SingleWindow.hpp"
28 #include "Screen/ButtonWindow.hpp"
29 #include "Screen/Timer.hpp"
30 #include "Screen/Canvas.hpp"
31 #include "Look/HorizonLook.hpp"
32 #include "Renderer/HorizonRenderer.hpp"
33 #include "NMEA/Attitude.hpp"
35 class HorizonWindow : public PaintWindow
37 const HorizonLook &look;
38 AttitudeState attitude;
40 public:
41 HorizonWindow(const HorizonLook &_look)
42 :look(_look) {}
44 void SetAttitude(const AttitudeState &_attitude) {
45 attitude = _attitude;
46 Invalidate();
49 protected:
50 virtual void OnPaint(Canvas &canvas) override {
51 canvas.ClearWhite();
52 HorizonRenderer::Draw(canvas, canvas.GetRect(), look, attitude);
56 class TestWindow : public SingleWindow
58 ButtonWindow close_button;
59 HorizonWindow horizon;
61 WindowTimer timer;
63 enum {
64 ID_START = 100,
65 ID_CLOSE
68 public:
69 TestWindow(const HorizonLook &look):horizon(look), timer(*this)
71 timer.Schedule(250);
74 ~TestWindow() {
75 timer.Cancel();
78 void Create(PixelSize size) {
79 TopWindowStyle style;
80 style.Resizable();
82 SingleWindow::Create(_T("RunHorizonRenderer"), size, style);
84 const PixelRect rc = GetClientRect();
86 WindowStyle with_border;
87 with_border.Border();
89 horizon.Create(*this, rc, with_border);
91 PixelRect button_rc = rc;
92 button_rc.top = button_rc.bottom - 30;
93 close_button.Create(*this, _T("Close"), ID_CLOSE, button_rc);
96 protected:
97 virtual bool OnCommand(unsigned id, unsigned code) override {
98 switch (id) {
99 case ID_CLOSE:
100 Close();
101 return true;
104 return SingleWindow::OnCommand(id, code);
107 virtual bool OnTimer(WindowTimer &_timer) override {
108 if (_timer == timer) {
109 AttitudeState attitude;
110 attitude.bank_angle_available = true;
111 attitude.pitch_angle_available = true;
112 attitude.bank_angle = Angle::Zero();
113 attitude.pitch_angle = Angle::Zero();
115 horizon.SetAttitude(attitude);
116 return true;
119 return SingleWindow::OnTimer(_timer);
122 virtual void OnResize(PixelSize new_size) override {
123 SingleWindow::OnResize(new_size);
124 if (horizon.IsDefined())
125 horizon.Resize(new_size);
129 static void
130 Main()
132 HorizonLook horizon_look;
133 horizon_look.Initialise();
135 TestWindow window(horizon_look);
136 window.Create({160, 160});
138 window.Show();
139 window.RunEventLoop();