Anti-Grain Geometry - AGG (libagg)  2.5
agg-2.5/include/agg_rasterizer_outline.h
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry (AGG) - Version 2.5
00003 // A high quality rendering engine for C++
00004 // Copyright (C) 2002-2006 Maxim Shemanarev
00005 // Contact: mcseem@antigrain.com
00006 //          mcseemagg@yahoo.com
00007 //          http://antigrain.com
00008 // 
00009 // AGG is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 // 
00014 // AGG is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU General Public License
00020 // along with AGG; if not, write to the Free Software
00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00022 // MA 02110-1301, USA.
00023 //----------------------------------------------------------------------------
00024 
00025 #ifndef AGG_RASTERIZER_OUTLINE_INCLUDED
00026 #define AGG_RASTERIZER_OUTLINE_INCLUDED
00027 
00028 #include "agg_basics.h"
00029 
00030 namespace agg
00031 {
00032     //======================================================rasterizer_outline
00033     template<class Renderer> class rasterizer_outline
00034     {
00035     public:
00036         explicit rasterizer_outline(Renderer& ren) : 
00037             m_ren(&ren), 
00038             m_start_x(0), 
00039             m_start_y(0), 
00040             m_vertices(0)
00041         {}
00042         void attach(Renderer& ren) { m_ren = &ren; }
00043 
00044 
00045         //--------------------------------------------------------------------
00046         void move_to(int x, int y)
00047         {
00048             m_vertices = 1;
00049             m_ren->move_to(m_start_x = x, m_start_y = y);
00050         }
00051 
00052         //--------------------------------------------------------------------
00053         void line_to(int x, int y)
00054         {
00055             ++m_vertices;
00056             m_ren->line_to(x, y);
00057         }
00058 
00059         //--------------------------------------------------------------------
00060         void move_to_d(double x, double y)
00061         {
00062             move_to(m_ren->coord(x), m_ren->coord(y));
00063         }
00064 
00065         //--------------------------------------------------------------------
00066         void line_to_d(double x, double y)
00067         {
00068             line_to(m_ren->coord(x), m_ren->coord(y));
00069         }
00070 
00071         //--------------------------------------------------------------------
00072         void close()
00073         {
00074             if(m_vertices > 2)
00075             {
00076                 line_to(m_start_x, m_start_y);
00077             }
00078             m_vertices = 0;
00079         }
00080 
00081         //--------------------------------------------------------------------
00082         void add_vertex(double x, double y, unsigned cmd)
00083         {
00084             if(is_move_to(cmd)) 
00085             {
00086                 move_to_d(x, y);
00087             }
00088             else 
00089             {
00090                 if(is_end_poly(cmd))
00091                 {
00092                     if(is_closed(cmd)) close();
00093                 }
00094                 else
00095                 {
00096                     line_to_d(x, y);
00097                 }
00098             }
00099         }
00100 
00101 
00102         //--------------------------------------------------------------------
00103         template<class VertexSource>
00104         void add_path(VertexSource& vs, unsigned path_id=0)
00105         {
00106             double x;
00107             double y;
00108 
00109             unsigned cmd;
00110             vs.rewind(path_id);
00111             while(!is_stop(cmd = vs.vertex(&x, &y)))
00112             {
00113                 add_vertex(x, y, cmd);
00114             }
00115         }
00116 
00117 
00118         //--------------------------------------------------------------------
00119         template<class VertexSource, class ColorStorage, class PathId>
00120         void render_all_paths(VertexSource& vs, 
00121                               const ColorStorage& colors, 
00122                               const PathId& path_id,
00123                               unsigned num_paths)
00124         {
00125             for(unsigned i = 0; i < num_paths; i++)
00126             {
00127                 m_ren->line_color(colors[i]);
00128                 add_path(vs, path_id[i]);
00129             }
00130         }
00131 
00132 
00133         //--------------------------------------------------------------------
00134         template<class Ctrl> void render_ctrl(Ctrl& c)
00135         {
00136             unsigned i;
00137             for(i = 0; i < c.num_paths(); i++)
00138             {
00139                 m_ren->line_color(c.color(i));
00140                 add_path(c, i);
00141             }
00142         }
00143 
00144 
00145     private:
00146         Renderer* m_ren;
00147         int       m_start_x;
00148         int       m_start_y;
00149         unsigned  m_vertices;
00150     };
00151 
00152 
00153 }
00154 
00155 
00156 #endif
00157 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines