update dev300-m58
[ooovba.git] / agg / inc / agg_rasterizer_outline.h
blobdac917050456029e2bac9baca9fa44afd7a6a8b3
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 #ifndef AGG_RASTERIZER_OUTLINE_INCLUDED
16 #define AGG_RASTERIZER_OUTLINE_INCLUDED
18 #include "agg_basics.h"
20 namespace agg
22 //======================================================rasterizer_outline
23 template<class Renderer> class rasterizer_outline
25 public:
26 rasterizer_outline(Renderer& ren) :
27 m_ren(&ren),
28 m_start_x(0),
29 m_start_y(0),
30 m_vertices(0)
34 //--------------------------------------------------------------------
35 void move_to(int x, int y)
37 m_vertices = 1;
38 m_ren->move_to(m_start_x = x, m_start_y = y);
41 //--------------------------------------------------------------------
42 void line_to(int x, int y)
44 ++m_vertices;
45 m_ren->line_to(x, y);
48 //--------------------------------------------------------------------
49 void move_to_d(double x, double y)
51 move_to(m_ren->coord(x), m_ren->coord(y));
54 //--------------------------------------------------------------------
55 void line_to_d(double x, double y)
57 line_to(m_ren->coord(x), m_ren->coord(y));
60 //--------------------------------------------------------------------
61 void close()
63 if(m_vertices > 2)
65 line_to(m_start_x, m_start_y);
67 m_vertices = 0;
70 //--------------------------------------------------------------------
71 void add_vertex(double x, double y, unsigned cmd)
73 if(is_move_to(cmd))
75 move_to_d(x, y);
77 else
79 if(is_end_poly(cmd))
81 if(is_closed(cmd)) close();
83 else
85 line_to_d(x, y);
91 //--------------------------------------------------------------------
92 template<class VertexSource>
93 void add_path(VertexSource& vs, unsigned id=0)
95 double x;
96 double y;
98 unsigned cmd;
99 vs.rewind(id);
100 while(!is_stop(cmd = vs.vertex(&x, &y)))
102 add_vertex(x, y, cmd);
107 //--------------------------------------------------------------------
108 template<class VertexSource, class ColorStorage, class PathId>
109 void render_all_paths(VertexSource& vs,
110 const ColorStorage& colors,
111 const PathId& id,
112 unsigned num_paths)
114 for(unsigned i = 0; i < num_paths; i++)
116 m_ren->line_color(colors[i]);
117 add_path(vs, id[i]);
122 //--------------------------------------------------------------------
123 template<class Ctrl> void render_ctrl(Ctrl& c)
125 unsigned i;
126 for(i = 0; i < c.num_paths(); i++)
128 m_ren->line_color(c.color(i));
129 add_path(c, i);
134 private:
135 Renderer* m_ren;
136 int m_start_x;
137 int m_start_y;
138 unsigned m_vertices;
145 #endif