TaskStats: remove unused attribute "Time"
[xcsoar.git] / test / src / RunFinalGlideBarRenderer.cpp
blobf7469cff3093c9ab98d479046edae1cb4502ce80
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 "Fonts.hpp"
32 #include "Look/TaskLook.hpp"
33 #include "Look/FinalGlideBarLook.hpp"
34 #include "Renderer/FinalGlideBarRenderer.hpp"
35 #include "NMEA/Derived.hpp"
36 #include "Geo/SpeedVector.hpp"
37 #include "Engine/GlideSolvers/GlideState.hpp"
38 #include "Engine/GlideSolvers/MacCready.hpp"
39 #include "Engine/GlideSolvers/GlideSettings.hpp"
40 #include "Engine/GlideSolvers/GlidePolar.hpp"
42 #ifdef USE_GDI
43 #include "ResourceLoader.hpp"
44 #endif
46 class FinalGlideBarWindow : public PaintWindow
48 FinalGlideBarRenderer renderer;
49 GlideState state;
50 GlidePolar glide_polar;
51 DerivedInfo calculated;
53 GlideSettings glide_settings;
55 public:
56 FinalGlideBarWindow(const FinalGlideBarLook &look, const TaskLook &task_look)
57 :renderer(look, task_look),
58 state(GeoVector(fixed(100), Angle::Zero()),
59 fixed(1000), fixed(1000),
60 SpeedVector(Angle::Zero(), fixed(0)))
62 glide_polar = GlidePolar(fixed(0));
64 calculated.task_stats.total.solution_remaining =
65 MacCready::Solve(glide_settings, glide_polar, state);
67 calculated.task_stats.total.solution_mc0 =
68 MacCready::Solve(glide_settings, glide_polar, state);
70 calculated.task_stats.task_valid = true;
73 fixed GetAltitudeDifference() {
74 return calculated.task_stats.total.solution_remaining.altitude_difference;
77 fixed GetAltitudeDifference0() {
78 return calculated.task_stats.total.solution_mc0.altitude_difference;
81 void SetAltitudeDifference(fixed altitude_difference) {
82 state.altitude_difference = altitude_difference;
84 calculated.task_stats.total.solution_remaining =
85 MacCready::Solve(glide_settings, glide_polar, state);
88 void SetAltitudeDifference0(fixed altitude_difference0) {
89 state.altitude_difference = altitude_difference0;
91 calculated.task_stats.total.solution_mc0 =
92 MacCready::Solve(glide_settings, glide_polar, state);
95 protected:
96 virtual void OnPaint(Canvas &canvas) override {
97 canvas.ClearWhite();
98 renderer.Draw(canvas, canvas.GetRect(), calculated, glide_settings, true);
102 class TestWindow : public SingleWindow
104 ButtonWindow close_button;
105 FinalGlideBarWindow final_glide;
106 fixed step;
107 fixed mc_mc0_step;
109 WindowTimer timer;
111 enum {
112 ID_START = 100,
113 ID_CLOSE
116 public:
117 TestWindow(const FinalGlideBarLook &look, const TaskLook &task_look)
118 :final_glide(look, task_look), step(fixed(10)), mc_mc0_step(fixed(100)), timer(*this)
120 timer.Schedule(100);
123 ~TestWindow() {
124 timer.Cancel();
128 void Create(PixelSize size) {
129 SingleWindow::Create(_T("RunFinalGlideBarRenderer"),
130 size);
132 const PixelRect rc = GetClientRect();
134 WindowStyle with_border;
135 with_border.Border();
137 final_glide.Create(*this, rc, with_border);
139 PixelRect button_rc = rc;
140 button_rc.top = button_rc.bottom - 30;
141 close_button.Create(*this, _T("Close"), ID_CLOSE, button_rc);
144 protected:
145 virtual bool OnCommand(unsigned id, unsigned code) override {
146 switch (id) {
147 case ID_CLOSE:
148 Close();
149 return true;
152 return SingleWindow::OnCommand(id, code);
155 virtual bool OnTimer(WindowTimer &_timer) override {
156 if (_timer == timer) {
157 fixed altitude_difference = final_glide.GetAltitudeDifference();
158 fixed altitude_difference0 = final_glide.GetAltitudeDifference0();
160 if (altitude_difference >= fixed(600) ) {
161 step = fixed(-10);
162 } else if (altitude_difference <= fixed(-600)) {
163 step = fixed(10);
165 if (altitude_difference0 > fixed(600)) {
166 mc_mc0_step = fixed(-100);
167 } else if (altitude_difference0 <= altitude_difference) {
168 mc_mc0_step = fixed(100);
171 altitude_difference0 += mc_mc0_step;
174 altitude_difference += step;
175 altitude_difference0 += step;
177 final_glide.SetAltitudeDifference(altitude_difference);
178 final_glide.SetAltitudeDifference0(altitude_difference0);
180 final_glide.Invalidate();
182 return true;
185 return SingleWindow::OnTimer(_timer);
189 static void
190 Main()
192 FinalGlideBarLook final_glide_look;
193 final_glide_look.Initialise(normal_font);
195 TaskLook task_look;
196 task_look.Initialise();
198 TestWindow window(final_glide_look, task_look);
199 window.Create({60, 320});
201 window.Show();
202 window.RunEventLoop();