android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / src / Renderer / TaskProgressRenderer.cpp
blob084932e3479e6ebaf72a248443beb763be85055c
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 "TaskProgressRenderer.hpp"
25 #include "Look/TaskLook.hpp"
26 #include "Engine/Task/Stats/TaskSummary.hpp"
27 #include "Screen/Canvas.hpp"
28 #include "Screen/Layout.hpp"
29 #include "Screen/Icon.hpp"
31 #include <algorithm>
33 void
34 TaskProgressRenderer::Draw(const TaskSummary& summary, Canvas &canvas,
35 const PixelRect &rc, bool inverse)
37 const int radius = std::min(rc.right - rc.left, rc.bottom - rc.top) / 2 -
38 Layout::Scale(3);
39 RasterPoint center;
40 center.x = (rc.left + rc.right) / 2;
41 center.y = (rc.bottom + rc.top) / 2;
43 const fixed sweep = fixed_two_pi * fixed(0.9);
44 Pen pen_f(1, inverse ? COLOR_WHITE : COLOR_BLACK);
46 if (summary.p_remaining < fixed(0.99)) {
47 canvas.Select(look.hbGray);
48 canvas.SelectNullPen();
49 canvas.DrawSegment(center.x, center.y, radius, Angle::Zero(),
50 Angle::Radians(sweep * (fixed(1) - summary.p_remaining)));
53 canvas.Select(pen_f);
54 canvas.SelectHollowBrush();
55 canvas.DrawCircle(center.x, center.y, radius);
57 unsigned i = 0;
58 canvas.Select(pen_f);
59 for (auto it = summary.pts.begin(); it != summary.pts.end(); ++it, ++i) {
60 Angle a = Angle::Radians(it->p * sweep);
61 int x = center.x + (int)(radius * a.fastsine());
62 int y = center.y - (int)(radius * a.fastcosine());
63 int w;
64 if (i == summary.active) {
65 if (it->achieved)
66 canvas.Select(look.hbGreen);
67 else
68 canvas.Select(look.hbOrange);
70 w = Layout::Scale(3);
71 } else if (i < summary.active) {
72 if (it->achieved)
73 canvas.Select(look.hbGreen);
74 else
75 canvas.Select(look.hbNotReachableTerrain);
77 w = Layout::Scale(2);
78 } else {
79 if (it->achieved)
80 canvas.Select(look.hbGreen);
81 else
82 canvas.Select(look.hbLightGray);
84 w = Layout::Scale(1);
87 canvas.Rectangle(x - w, y - w, x + w, y + w);