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 #ifndef SHAPE_RENDERER_HPP
25 #define SHAPE_RENDERER_HPP
27 #include "Screen/Pen.hpp"
28 #include "Screen/Point.hpp"
29 #include "Util/NonCopyable.hpp"
30 #include "Util/AllocatedArray.hpp"
31 #include "Screen/Canvas.hpp"
32 #include "Screen/Brush.hpp"
37 * A helper class optimized for doing bulk draws on OpenGL.
39 class ShapeRenderer
: private NonCopyable
{
40 AllocatedArray
<RasterPoint
> points
;
46 enum { NONE
, OUTLINE
, SOLID
} mode
;
49 void Configure(const Pen
*_pen
, const Brush
*_brush
) {
57 void Begin(unsigned n
) {
58 assert(num_points
== 0);
60 points
.GrowDiscard(((n
- 1) | 0x3ff) + 1);
63 void AddPoint(RasterPoint pt
) {
64 assert(num_points
< points
.size());
66 points
[num_points
++] = pt
;
70 * Adds the point only if it a few pixels distant from the previous
71 * one. Useful to reduce the complexity of small figures.
73 void AddPointIfDistant(RasterPoint pt
) {
74 assert(num_points
< points
.size());
76 if (num_points
== 0 || manhattan_distance(points
[num_points
- 1], pt
) >= 8)
80 void FinishPolyline(Canvas
&canvas
) {
81 if (mode
!= OUTLINE
) {
86 canvas
.DrawPolyline(points
.begin(), num_points
);
91 void FinishPolygon(Canvas
&canvas
) {
93 canvas
.SelectNullPen();
94 canvas
.Select(*brush
);
98 canvas
.DrawPolygon(points
.begin(), num_points
);
104 assert(num_points
== 0);