xref: /haiku/headers/libs/agg/agg_vcgen_dash.h (revision aff60bb217827097c13d643275fdf1f1c66e7f17)
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 //
16 // Line dash generator
17 //
18 //----------------------------------------------------------------------------
19 #ifndef AGG_VCGEN_DASH_INCLUDED
20 #define AGG_VCGEN_DASH_INCLUDED
21 
22 #include "agg_basics.h"
23 #include "agg_vertex_sequence.h"
24 #include "agg_vertex_iterator.h"
25 
26 namespace agg
27 {
28 
29     //---------------------------------------------------------------vcgen_dash
30     //
31     // See Implementation agg_vcgen_dash.cpp
32     //
33     class vcgen_dash
34     {
35         enum
36         {
37             max_dashes = 32
38         };
39 
40         enum status_e
41         {
42             initial,
43             ready,
44             polyline,
45             stop
46         };
47 
48     public:
49         typedef vertex_sequence<vertex_dist, 6> vertex_storage;
50 
51         vcgen_dash();
52 
53         void remove_all_dashes();
54         void add_dash(double dash_len, double gap_len);
55         void dash_start(double ds);
56 
57         void shorten(double s) { m_shorten = s; }
58         double shorten() const { return m_shorten; }
59 
60         // Vertex Generator Interface
61         void remove_all();
62         void add_vertex(double x, double y, unsigned cmd);
63 
64         // Vertex Source Interface
65         void     rewind(unsigned id);
66         unsigned vertex(double* x, double* y);
67 
68         typedef vcgen_dash source_type;
69         typedef vertex_iterator<source_type> iterator;
70         iterator begin(unsigned id) { return iterator(*this, id); }
71         iterator end() { return iterator(path_cmd_stop); }
72 
73     private:
74         vcgen_dash(const vcgen_dash&);
75         const vcgen_dash& operator = (const vcgen_dash&);
76 
77         void calc_dash_start(double ds);
78 
79         double             m_dashes[max_dashes];
80         double             m_total_dash_len;
81         unsigned           m_num_dashes;
82         double             m_dash_start;
83         double             m_shorten;
84         double             m_curr_dash_start;
85         unsigned           m_curr_dash;
86         double             m_curr_rest;
87         const vertex_dist* m_v1;
88         const vertex_dist* m_v2;
89 
90         vertex_storage m_src_vertices;
91         unsigned       m_closed;
92         status_e       m_status;
93         unsigned       m_src_vertex;
94     };
95 
96 
97 }
98 
99 #endif
100