xref: /haiku/headers/libs/agg/agg_rasterizer_outline.h (revision e39da397f5ff79f2db9f9a3ddf1852b6710578af)
139241fe2SDarkWyrm //----------------------------------------------------------------------------
2*e39da397SStephan Aßmus // Anti-Grain Geometry - Version 2.4
3*e39da397SStephan Aßmus // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
439241fe2SDarkWyrm //
539241fe2SDarkWyrm // Permission to copy, use, modify, sell and distribute this software
639241fe2SDarkWyrm // is granted provided this copyright notice appears in all copies.
739241fe2SDarkWyrm // This software is provided "as is" without express or implied
839241fe2SDarkWyrm // warranty, and with no claim as to its suitability for any purpose.
939241fe2SDarkWyrm //
1039241fe2SDarkWyrm //----------------------------------------------------------------------------
1139241fe2SDarkWyrm // Contact: mcseem@antigrain.com
1239241fe2SDarkWyrm //          mcseemagg@yahoo.com
1339241fe2SDarkWyrm //          http://www.antigrain.com
1439241fe2SDarkWyrm //----------------------------------------------------------------------------
1539241fe2SDarkWyrm #ifndef AGG_RASTERIZER_OUTLINE_INCLUDED
1639241fe2SDarkWyrm #define AGG_RASTERIZER_OUTLINE_INCLUDED
1739241fe2SDarkWyrm 
1839241fe2SDarkWyrm #include "agg_basics.h"
1939241fe2SDarkWyrm 
2039241fe2SDarkWyrm namespace agg
2139241fe2SDarkWyrm {
2239241fe2SDarkWyrm     //======================================================rasterizer_outline
2339241fe2SDarkWyrm     template<class Renderer> class rasterizer_outline
2439241fe2SDarkWyrm     {
2539241fe2SDarkWyrm     public:
rasterizer_outline(Renderer & ren)26*e39da397SStephan Aßmus         rasterizer_outline(Renderer& ren) :
27*e39da397SStephan Aßmus             m_ren(&ren),
28*e39da397SStephan Aßmus             m_start_x(0),
29*e39da397SStephan Aßmus             m_start_y(0),
30*e39da397SStephan Aßmus             m_vertices(0)
31*e39da397SStephan Aßmus         {}
attach(Renderer & ren)32*e39da397SStephan Aßmus         void attach(Renderer& ren) { m_ren = &ren; }
33*e39da397SStephan Aßmus 
3439241fe2SDarkWyrm 
3539241fe2SDarkWyrm         //--------------------------------------------------------------------
move_to(int x,int y)3639241fe2SDarkWyrm         void move_to(int x, int y)
3739241fe2SDarkWyrm         {
38*e39da397SStephan Aßmus             m_vertices = 1;
3939241fe2SDarkWyrm             m_ren->move_to(m_start_x = x, m_start_y = y);
4039241fe2SDarkWyrm         }
4139241fe2SDarkWyrm 
4239241fe2SDarkWyrm         //--------------------------------------------------------------------
line_to(int x,int y)4339241fe2SDarkWyrm         void line_to(int x, int y)
4439241fe2SDarkWyrm         {
45*e39da397SStephan Aßmus             ++m_vertices;
4639241fe2SDarkWyrm             m_ren->line_to(x, y);
4739241fe2SDarkWyrm         }
4839241fe2SDarkWyrm 
4939241fe2SDarkWyrm         //--------------------------------------------------------------------
move_to_d(double x,double y)5039241fe2SDarkWyrm         void move_to_d(double x, double y)
5139241fe2SDarkWyrm         {
5239241fe2SDarkWyrm             move_to(m_ren->coord(x), m_ren->coord(y));
5339241fe2SDarkWyrm         }
5439241fe2SDarkWyrm 
5539241fe2SDarkWyrm         //--------------------------------------------------------------------
line_to_d(double x,double y)5639241fe2SDarkWyrm         void line_to_d(double x, double y)
5739241fe2SDarkWyrm         {
5839241fe2SDarkWyrm             line_to(m_ren->coord(x), m_ren->coord(y));
5939241fe2SDarkWyrm         }
6039241fe2SDarkWyrm 
6139241fe2SDarkWyrm         //--------------------------------------------------------------------
close()6239241fe2SDarkWyrm         void close()
6339241fe2SDarkWyrm         {
64*e39da397SStephan Aßmus             if(m_vertices > 2)
65*e39da397SStephan Aßmus             {
6639241fe2SDarkWyrm                 line_to(m_start_x, m_start_y);
6739241fe2SDarkWyrm             }
68*e39da397SStephan Aßmus             m_vertices = 0;
69*e39da397SStephan Aßmus         }
7039241fe2SDarkWyrm 
7139241fe2SDarkWyrm         //--------------------------------------------------------------------
add_vertex(double x,double y,unsigned cmd)7239241fe2SDarkWyrm         void add_vertex(double x, double y, unsigned cmd)
7339241fe2SDarkWyrm         {
7439241fe2SDarkWyrm             if(is_move_to(cmd))
7539241fe2SDarkWyrm             {
7639241fe2SDarkWyrm                 move_to_d(x, y);
7739241fe2SDarkWyrm             }
7839241fe2SDarkWyrm             else
7939241fe2SDarkWyrm             {
8039241fe2SDarkWyrm                 if(is_end_poly(cmd))
8139241fe2SDarkWyrm                 {
8239241fe2SDarkWyrm                     if(is_closed(cmd)) close();
8339241fe2SDarkWyrm                 }
8439241fe2SDarkWyrm                 else
8539241fe2SDarkWyrm                 {
8639241fe2SDarkWyrm                     line_to_d(x, y);
8739241fe2SDarkWyrm                 }
8839241fe2SDarkWyrm             }
8939241fe2SDarkWyrm         }
9039241fe2SDarkWyrm 
9139241fe2SDarkWyrm 
9239241fe2SDarkWyrm         //--------------------------------------------------------------------
9339241fe2SDarkWyrm         template<class VertexSource>
94*e39da397SStephan Aßmus         void add_path(VertexSource& vs, unsigned path_id=0)
9539241fe2SDarkWyrm         {
9639241fe2SDarkWyrm             double x;
9739241fe2SDarkWyrm             double y;
9839241fe2SDarkWyrm 
9939241fe2SDarkWyrm             unsigned cmd;
100*e39da397SStephan Aßmus             vs.rewind(path_id);
10139241fe2SDarkWyrm             while(!is_stop(cmd = vs.vertex(&x, &y)))
10239241fe2SDarkWyrm             {
10339241fe2SDarkWyrm                 add_vertex(x, y, cmd);
10439241fe2SDarkWyrm             }
10539241fe2SDarkWyrm         }
10639241fe2SDarkWyrm 
10739241fe2SDarkWyrm 
10839241fe2SDarkWyrm         //--------------------------------------------------------------------
10939241fe2SDarkWyrm         template<class VertexSource, class ColorStorage, class PathId>
render_all_paths(VertexSource & vs,const ColorStorage & colors,const PathId & path_id,unsigned num_paths)11039241fe2SDarkWyrm         void render_all_paths(VertexSource& vs,
11139241fe2SDarkWyrm                               const ColorStorage& colors,
112*e39da397SStephan Aßmus                               const PathId& path_id,
11339241fe2SDarkWyrm                               unsigned num_paths)
11439241fe2SDarkWyrm         {
11539241fe2SDarkWyrm             for(unsigned i = 0; i < num_paths; i++)
11639241fe2SDarkWyrm             {
11739241fe2SDarkWyrm                 m_ren->line_color(colors[i]);
118*e39da397SStephan Aßmus                 add_path(vs, path_id[i]);
11939241fe2SDarkWyrm             }
12039241fe2SDarkWyrm         }
12139241fe2SDarkWyrm 
12239241fe2SDarkWyrm 
12339241fe2SDarkWyrm         //--------------------------------------------------------------------
render_ctrl(Ctrl & c)12439241fe2SDarkWyrm         template<class Ctrl> void render_ctrl(Ctrl& c)
12539241fe2SDarkWyrm         {
12639241fe2SDarkWyrm             unsigned i;
12739241fe2SDarkWyrm             for(i = 0; i < c.num_paths(); i++)
12839241fe2SDarkWyrm             {
12939241fe2SDarkWyrm                 m_ren->line_color(c.color(i));
13039241fe2SDarkWyrm                 add_path(c, i);
13139241fe2SDarkWyrm             }
13239241fe2SDarkWyrm         }
13339241fe2SDarkWyrm 
13439241fe2SDarkWyrm 
13539241fe2SDarkWyrm     private:
13639241fe2SDarkWyrm         Renderer* m_ren;
13739241fe2SDarkWyrm         int       m_start_x;
13839241fe2SDarkWyrm         int       m_start_y;
139*e39da397SStephan Aßmus         unsigned  m_vertices;
14039241fe2SDarkWyrm     };
14139241fe2SDarkWyrm 
14239241fe2SDarkWyrm 
14339241fe2SDarkWyrm }
14439241fe2SDarkWyrm 
14539241fe2SDarkWyrm 
14639241fe2SDarkWyrm #endif
14739241fe2SDarkWyrm 
148