Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / Renderer / SymbolRenderer.cpp
blob86a363404a5f595ba4521d26f41814e7142ce1b5
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 "SymbolRenderer.hpp"
25 #include "Screen/Canvas.hpp"
27 #include <algorithm>
29 void
30 SymbolRenderer::DrawArrow(Canvas &canvas, PixelRect rc, Direction direction)
32 assert(direction == UP || direction == DOWN ||
33 direction == LEFT || direction == RIGHT);
35 PixelScalar size = std::min(rc.right - rc.left, rc.bottom - rc.top) / 5;
36 RasterPoint center = rc.GetCenter();
37 RasterPoint arrow[3];
39 if (direction == LEFT || direction == RIGHT) {
40 arrow[0].x = center.x + (direction == LEFT ? size : -size);
41 arrow[0].y = center.y + size;
42 arrow[1].x = center.x + (direction == LEFT ? -size : size);
43 arrow[1].y = center.y;
44 arrow[2].x = center.x + (direction == LEFT ? size : -size);
45 arrow[2].y = center.y - size;
46 } else if (direction == UP || direction == DOWN) {
47 arrow[0].x = center.x + size;
48 arrow[0].y = center.y + (direction == UP ? size : -size);
49 arrow[1].x = center.x;
50 arrow[1].y = center.y + (direction == UP ? -size : size);
51 arrow[2].x = center.x - size;
52 arrow[2].y = center.y + (direction == UP ? size : -size);
55 canvas.DrawTriangleFan(arrow, 3);
58 void
59 SymbolRenderer::DrawSign(Canvas &canvas, PixelRect rc, bool plus)
61 PixelScalar size = std::min(rc.right - rc.left, rc.bottom - rc.top) / 5;
62 RasterPoint center = rc.GetCenter();
64 // Draw horizontal bar
65 canvas.Rectangle(center.x - size, center.y - size / 3,
66 center.x + size, center.y + size / 3);
68 if (plus)
69 // Draw vertical bar
70 canvas.Rectangle(center.x - size / 3, center.y - size,
71 center.x + size / 3, center.y + size);