TaskManager: remove GetStartState() and GetFinishState()
[xcsoar.git] / test / src / RunWindArrowRenderer.cpp
blob35122b659440782e93dd554a7dccba1851f3663c
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/WindArrowLook.hpp"
32 #include "Renderer/WindArrowRenderer.hpp"
33 #include "Geo/SpeedVector.hpp"
35 class WindWindow : public PaintWindow
37 WindArrowRenderer renderer;
38 SpeedVector wind;
40 public:
41 WindWindow(const WindArrowLook &look)
42 :renderer(look), wind(fixed(10), fixed(0)) {}
44 SpeedVector GetWind() const {
45 return wind;
48 void SetWind(const SpeedVector &_wind) {
49 wind = _wind;
50 Invalidate();
53 protected:
54 virtual void OnPaint(Canvas &canvas) override {
55 canvas.ClearWhite();
57 const PixelRect rc = canvas.GetRect();
59 RasterPoint pt = {
60 (PixelScalar)(rc.right / 2), (PixelScalar)(rc.bottom / 2)
63 canvas.SelectBlackPen();
64 canvas.SelectHollowBrush();
65 canvas.DrawCircle(pt.x, pt.y, 2);
67 renderer.Draw(canvas, Angle::Zero(), wind, pt, rc, WindArrowStyle::ARROW_HEAD);
71 class TestWindow : public SingleWindow
73 ButtonWindow close_button;
74 WindWindow wind;
76 WindowTimer timer;
78 enum {
79 ID_START = 100,
80 ID_CLOSE
83 public:
84 TestWindow(const WindArrowLook &look):wind(look), timer(*this)
86 timer.Schedule(250);
89 ~TestWindow() {
90 timer.Cancel();
93 void Create(PixelSize size) {
94 TopWindowStyle style;
95 style.Resizable();
97 SingleWindow::Create(_T("RunWindArrowRenderer"), size, style);
99 const PixelRect rc = GetClientRect();
101 WindowStyle with_border;
102 with_border.Border();
104 wind.Create(*this, rc, with_border);
106 PixelRect button_rc = rc;
107 button_rc.top = button_rc.bottom - 30;
108 close_button.Create(*this, _T("Close"), ID_CLOSE, button_rc);
111 protected:
112 virtual bool OnCommand(unsigned id, unsigned code) override {
113 switch (id) {
114 case ID_CLOSE:
115 Close();
116 return true;
119 return SingleWindow::OnCommand(id, code);
122 virtual bool OnTimer(WindowTimer &_timer) override {
123 if (_timer == timer) {
124 SpeedVector _wind = wind.GetWind();
126 _wind.bearing = (_wind.bearing + Angle::Degrees(5)).AsBearing();
127 _wind.norm += fixed(1);
128 if (_wind.norm > fixed(15))
129 _wind.norm = fixed(0);
131 wind.SetWind(_wind);
132 return true;
135 return SingleWindow::OnTimer(_timer);
138 virtual void OnResize(PixelSize new_size) override {
139 SingleWindow::OnResize(new_size);
140 if (wind.IsDefined())
141 wind.Resize(new_size);
145 static void
146 Main()
148 WindArrowLook wind_look;
149 wind_look.Initialise(bold_font);
151 TestWindow window(wind_look);
152 window.Create({160, 160});
154 window.Show();
155 window.RunEventLoop();