android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / src / Renderer / WindArrowRenderer.cpp
blob8ef10ce38a1b1fcc743c5b149fd9fd8f5ede0363
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 #include "WindArrowRenderer.hpp"
25 #include "TextInBox.hpp"
26 #include "Look/WindArrowLook.hpp"
27 #include "Screen/Canvas.hpp"
28 #include "Screen/Layout.hpp"
29 #include "Math/Angle.hpp"
30 #include "Math/Screen.hpp"
31 #include "NMEA/Derived.hpp"
32 #include "Units/Units.hpp"
33 #include "Util/Macros.hpp"
35 #include <tchar.h>
36 #include <cstdio>
38 void
39 WindArrowRenderer::DrawArrow(Canvas &canvas, RasterPoint pos, Angle angle,
40 PixelScalar length, WindArrowStyle arrow_style,
41 PixelScalar offset)
43 // Draw arrow
45 RasterPoint arrow[] = {
46 { 0, (PixelScalar)(-offset + 3) },
47 { -6, (PixelScalar)(-offset - 3 - length) },
48 { 0, (PixelScalar)(-offset + 3 - length) },
49 { 6, (PixelScalar)(-offset - 3 - length) },
52 // Rotate the arrow
53 PolygonRotateShift(arrow, ARRAY_SIZE(arrow), pos.x, pos.y, angle);
55 canvas.Select(look.arrow_pen);
56 canvas.Select(look.arrow_brush);
57 canvas.DrawPolygon(arrow, ARRAY_SIZE(arrow));
59 // Draw arrow tail
61 if (arrow_style == WindArrowStyle::FULL_ARROW) {
62 RasterPoint tail[] = {
63 { 0, (PixelScalar)(-offset + 3) },
64 { 0, -offset - 3 - std::min(PixelScalar(20), length) * 3 },
67 PolygonRotateShift(tail, ARRAY_SIZE(tail),
68 pos.x, pos.y, angle);
70 canvas.Select(look.tail_pen);
71 canvas.DrawLine(tail[0], tail[1]);
75 void
76 WindArrowRenderer::Draw(Canvas &canvas, const Angle screen_angle,
77 const SpeedVector wind, const RasterPoint pos,
78 const PixelRect rc, WindArrowStyle arrow_style)
80 // Draw arrow (and tail)
82 PixelScalar length = iround(4 * wind.norm);
83 DrawArrow(canvas, pos, wind.bearing - screen_angle, length, arrow_style);
85 // Draw wind speed label
87 StaticString<12> buffer;
88 buffer.Format(_T("%i"), iround(Units::ToUserWindSpeed(wind.norm)));
90 canvas.SetTextColor(COLOR_BLACK);
91 canvas.Select(*look.font);
93 PixelScalar offset = iround(fixed_sqrt_two * wind.norm);
94 RasterPoint label[] = {
95 { 18, (PixelScalar)(-26 - offset) },
97 PolygonRotateShift(label, ARRAY_SIZE(label),
98 pos.x, pos.y, wind.bearing - screen_angle);
100 TextInBoxMode style;
101 style.align = TextInBoxMode::Alignment::CENTER;
102 style.vertical_position = TextInBoxMode::VerticalPosition::CENTERED;
103 style.shape = LabelShape::OUTLINED;
105 TextInBox(canvas, buffer, label[0].x, label[0].y, style, rc);
108 void
109 WindArrowRenderer::Draw(Canvas &canvas, const Angle screen_angle,
110 const RasterPoint pos, const PixelRect rc,
111 const DerivedInfo &calculated,
112 const MapSettings &settings)
114 if (!calculated.wind_available ||
115 settings.wind_arrow_style == WindArrowStyle::NO_ARROW)
116 return;
118 // don't bother drawing it if not significant
119 if (calculated.wind.norm < fixed(1))
120 return;
122 WindArrowRenderer::Draw(canvas, screen_angle, calculated.wind, pos, rc,
123 settings.wind_arrow_style);