xref: /haiku/headers/libs/agg/agg_conv_concat.h (revision 2ae568931fcac7deb9f1e6ff4e47213fbfe4029b)
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 #ifndef AGG_CONV_CONCAT_INCLUDED
17 #define AGG_CONV_CONCAT_INCLUDED
18 
19 #include "agg_basics.h"
20 #include "agg_vertex_iterator.h"
21 
22 namespace agg
23 {
24     //=============================================================conv_concat
25     // Concatenation of two paths. Usually used to combine lines or curves
26     // with markers such as arrowheads
27     template<class VS1, class VS2> class conv_concat
28     {
29     public:
30         conv_concat(VS1& source1, VS2& source2) :
31             m_source1(&source1), m_source2(&source2), m_status(2) {}
32 
33         void set_source1(VS1& source) { m_source1 = &source; }
34         void set_source2(VS2& source) { m_source2 = &source; }
35 
36 
37         void rewind(unsigned id)
38         {
39             m_source1->rewind(id);
40             m_source2->rewind(0);
41             m_status = 0;
42         }
43 
44         unsigned vertex(double* x, double* y)
45         {
46             unsigned cmd;
47             if(m_status == 0)
48             {
49                 cmd = m_source1->vertex(x, y);
50                 if(!is_stop(cmd)) return cmd;
51                 m_status = 1;
52             }
53             if(m_status == 1)
54             {
55                 cmd = m_source2->vertex(x, y);
56                 if(!is_stop(cmd)) return cmd;
57                 m_status = 2;
58             }
59             return path_cmd_stop;
60         }
61 
62         typedef conv_concat<VS1, VS2> source_type;
63         typedef vertex_iterator<source_type> iterator;
64         iterator begin(unsigned id) { return iterator(*this, id); }
65         iterator end() { return iterator(path_cmd_stop); }
66 
67     private:
68         conv_concat(const conv_concat<VS1, VS2>&);
69         const conv_concat<VS1, VS2>&
70             operator = (const conv_concat<VS1, VS2>&);
71 
72         VS1* m_source1;
73         VS2* m_source2;
74         int  m_status;
75 
76     };
77 }
78 
79 
80 #endif
81