Debian Codegraph @

extern/agg24-svn/include/agg_rasterizer_outline.h

raw
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
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: [email protected]
12 // [email protected]
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 #ifndef AGG_RASTERIZER_OUTLINE_INCLUDED
16 #define AGG_RASTERIZER_OUTLINE_INCLUDED
17
18 #include "agg_basics.h"
19
20 namespace agg
21 {
22 //======================================================rasterizer_outline
23 template<class Renderer> class rasterizer_outline
24 {
25 public:
26 explicit rasterizer_outline(Renderer& ren) :
27 m_ren(&ren),
28 m_start_x(0),
29 m_start_y(0),
30 m_vertices(0)
31 {}
32 void attach(Renderer& ren) { m_ren = &ren; }
33
34
35 //--------------------------------------------------------------------
36 void move_to(int x, int y)
37 {
38 m_vertices = 1;
39 m_ren->move_to(m_start_x = x, m_start_y = y);
40 }
41
42 //--------------------------------------------------------------------
43 void line_to(int x, int y)
44 {
45 ++m_vertices;
46 m_ren->line_to(x, y);
47 }
48
49 //--------------------------------------------------------------------
50 void move_to_d(double x, double y)
51 {
52 move_to(m_ren->coord(x), m_ren->coord(y));
53 }
54
55 //--------------------------------------------------------------------
56 void line_to_d(double x, double y)
57 {
58 line_to(m_ren->coord(x), m_ren->coord(y));
59 }
60
61 //--------------------------------------------------------------------
62 void close()
63 {
64 if(m_vertices > 2)
65 {
66 line_to(m_start_x, m_start_y);
67 }
68 m_vertices = 0;
69 }
70
71 //--------------------------------------------------------------------
72 void add_vertex(double x, double y, unsigned cmd)
73 {
74 if(is_move_to(cmd))
75 {
76 move_to_d(x, y);
77 }
78 else
79 {
80 if(is_end_poly(cmd))
81 {
82 if(is_closed(cmd)) close();
83 }
84 else
85 {
86 line_to_d(x, y);
87 }
88 }
89 }
90
91
92 //--------------------------------------------------------------------
93 template<class VertexSource>
94 void add_path(VertexSource& vs, unsigned path_id=0)
95 {
96 double x;
97 double y;
98
99 unsigned cmd;
100 vs.rewind(path_id);
101 while(!is_stop(cmd = vs.vertex(&x, &y)))
102 {
103 add_vertex(x, y, cmd);
104 }
105 }
106
107
108 //--------------------------------------------------------------------
109 template<class VertexSource, class ColorStorage, class PathId>
110 void render_all_paths(VertexSource& vs,
111 const ColorStorage& colors,
112 const PathId& path_id,
113 unsigned num_paths)
114 {
115 for(unsigned i = 0; i < num_paths; i++)
116 {
117 m_ren->line_color(colors[i]);
118 add_path(vs, path_id[i]);
119 }
120 }
121
122
123 //--------------------------------------------------------------------
124 template<class Ctrl> void render_ctrl(Ctrl& c)
125 {
126 unsigned i;
127 for(i = 0; i < c.num_paths(); i++)
128 {
129 m_ren->line_color(c.color(i));
130 add_path(c, i);
131 }
132 }
133
134
135 private:
136 Renderer* m_ren;
137 int m_start_x;
138 int m_start_y;
139 unsigned m_vertices;
140 };
141
142
143 }
144
145
146 #endif
147