1 //---------------------------------------------------------------------------- 2 // Anti-Grain Geometry - Version 2.2 3 // Copyright (C) 2002-2004 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 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 rasterizer_outline(Renderer& ren) : m_ren(&ren), m_start_x(0), m_start_y(0) 27 { 28 } 29 30 //-------------------------------------------------------------------- 31 void move_to(int x, int y) 32 { 33 m_ren->move_to(m_start_x = x, m_start_y = y); 34 } 35 36 //-------------------------------------------------------------------- 37 void line_to(int x, int y) 38 { 39 m_ren->line_to(x, y); 40 } 41 42 //-------------------------------------------------------------------- 43 void move_to_d(double x, double y) 44 { 45 move_to(m_ren->coord(x), m_ren->coord(y)); 46 } 47 48 //-------------------------------------------------------------------- 49 void line_to_d(double x, double y) 50 { 51 line_to(m_ren->coord(x), m_ren->coord(y)); 52 } 53 54 //-------------------------------------------------------------------- 55 void close() 56 { 57 line_to(m_start_x, m_start_y); 58 } 59 60 //-------------------------------------------------------------------- 61 void add_vertex(double x, double y, unsigned cmd) 62 { 63 if(is_move_to(cmd)) 64 { 65 move_to_d(x, y); 66 } 67 else 68 { 69 if(is_end_poly(cmd)) 70 { 71 if(is_closed(cmd)) close(); 72 } 73 else 74 { 75 line_to_d(x, y); 76 } 77 } 78 } 79 80 81 //-------------------------------------------------------------------- 82 template<class VertexSource> 83 void add_path(VertexSource& vs, unsigned id=0) 84 { 85 double x; 86 double y; 87 88 unsigned cmd; 89 vs.rewind(id); 90 while(!is_stop(cmd = vs.vertex(&x, &y))) 91 { 92 add_vertex(x, y, cmd); 93 } 94 } 95 96 97 //-------------------------------------------------------------------- 98 template<class VertexSource, class ColorStorage, class PathId> 99 void render_all_paths(VertexSource& vs, 100 const ColorStorage& colors, 101 const PathId& id, 102 unsigned num_paths) 103 { 104 for(unsigned i = 0; i < num_paths; i++) 105 { 106 m_ren->line_color(colors[i]); 107 add_path(vs, id[i]); 108 } 109 } 110 111 112 //-------------------------------------------------------------------- 113 template<class Ctrl> void render_ctrl(Ctrl& c) 114 { 115 unsigned i; 116 for(i = 0; i < c.num_paths(); i++) 117 { 118 m_ren->line_color(c.color(i)); 119 add_path(c, i); 120 } 121 } 122 123 124 private: 125 Renderer* m_ren; 126 int m_start_x; 127 int m_start_y; 128 }; 129 130 131 } 132 133 134 #endif 135 136