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.
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
;
41 WindWindow(const WindArrowLook
&look
)
42 :renderer(look
), wind(fixed(10), fixed(0)) {}
44 SpeedVector
GetWind() const {
48 void SetWind(const SpeedVector
&_wind
) {
54 virtual void OnPaint(Canvas
&canvas
) override
{
57 const PixelRect rc
= canvas
.GetRect();
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
;
84 TestWindow(const WindArrowLook
&look
):wind(look
), timer(*this)
93 void Create(PixelSize size
) {
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
);
112 virtual bool OnCommand(unsigned id
, unsigned code
) override
{
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);
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
);
148 WindArrowLook wind_look
;
149 wind_look
.Initialise(bold_font
);
151 TestWindow
window(wind_look
);
152 window
.Create({160, 160});
155 window
.RunEventLoop();