update dev300-m57
[ooovba.git] / agg / inc / agg_conv_marker.h
blob52dceb3d93b9ecfe4b7db121077b5181a68ae559
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 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 //----------------------------------------------------------------------------
16 // conv_marker
18 //----------------------------------------------------------------------------
19 #ifndef AGG_CONV_MARKER_INCLUDED
20 #define AGG_CONV_MARKER_INCLUDED
22 #include "agg_basics.h"
23 #include "agg_trans_affine.h"
24 #include "agg_vertex_iterator.h"
26 namespace agg
28 //-------------------------------------------------------------conv_marker
29 template<class MarkerLocator, class MarkerShapes>
30 class conv_marker
32 public:
33 conv_marker(MarkerLocator& ml, MarkerShapes& ms);
35 trans_affine& transform() { return m_transform; }
36 const trans_affine& transform() const { return m_transform; }
38 void rewind(unsigned id);
39 unsigned vertex(double* x, double* y);
41 typedef conv_marker<MarkerLocator, MarkerShapes> source_type;
42 typedef vertex_iterator<source_type> iterator;
43 iterator begin(unsigned id) { return iterator(*this, id); }
44 iterator end() { return iterator(path_cmd_stop); }
46 private:
47 conv_marker(const conv_marker<MarkerLocator, MarkerShapes>&);
48 const conv_marker<MarkerLocator, MarkerShapes>&
49 operator = (const conv_marker<MarkerLocator, MarkerShapes>&);
51 enum status_e
53 initial,
54 markers,
55 polygon,
56 stop
59 MarkerLocator* m_marker_locator;
60 MarkerShapes* m_marker_shapes;
61 trans_affine m_transform;
62 trans_affine m_mtx;
63 status_e m_status;
64 unsigned m_marker;
65 unsigned m_num_markers;
69 //------------------------------------------------------------------------
70 template<class MarkerLocator, class MarkerShapes>
71 conv_marker<MarkerLocator, MarkerShapes>::conv_marker(MarkerLocator& ml, MarkerShapes& ms) :
72 m_marker_locator(&ml),
73 m_marker_shapes(&ms),
74 m_status(initial),
75 m_marker(0),
76 m_num_markers(1)
81 //------------------------------------------------------------------------
82 template<class MarkerLocator, class MarkerShapes>
83 void conv_marker<MarkerLocator, MarkerShapes>::rewind(unsigned)
85 m_status = initial;
86 m_marker = 0;
87 m_num_markers = 1;
91 //------------------------------------------------------------------------
92 template<class MarkerLocator, class MarkerShapes>
93 unsigned conv_marker<MarkerLocator, MarkerShapes>::vertex(double* x, double* y)
95 unsigned cmd = path_cmd_move_to;
96 double x1, y1, x2, y2;
98 while(!is_stop(cmd))
100 switch(m_status)
102 case initial:
103 if(m_num_markers == 0)
105 cmd = path_cmd_stop;
106 break;
108 m_marker_locator->rewind(m_marker);
109 ++m_marker;
110 m_num_markers = 0;
111 m_status = markers;
113 case markers:
114 if(is_stop(m_marker_locator->vertex(&x1, &y1)))
116 m_status = initial;
117 break;
119 if(is_stop(m_marker_locator->vertex(&x2, &y2)))
121 m_status = initial;
122 break;
124 ++m_num_markers;
125 m_mtx = m_transform;
126 m_mtx *= trans_affine_rotation(atan2(y2 - y1, x2 - x1));
127 m_mtx *= trans_affine_translation(x1, y1);
128 m_marker_shapes->rewind(m_marker - 1);
129 m_status = polygon;
131 case polygon:
132 cmd = m_marker_shapes->vertex(x, y);
133 if(is_stop(cmd))
135 cmd = path_cmd_move_to;
136 m_status = markers;
137 break;
139 m_mtx.transform(x, y);
140 return cmd;
142 case stop:
143 cmd = path_cmd_stop;
144 break;
147 return cmd;
153 #endif