merge the formfield patch from ooo-build
[ooovba.git] / agg / source / agg_arrowhead.cpp
blob7f3a0272ce5c052d1ee6b830136bbaaffc5923f6
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 // Simple arrowhead/arrowtail generator
18 //----------------------------------------------------------------------------
20 #include "agg_arrowhead.h"
22 namespace agg
25 //------------------------------------------------------------------------
26 arrowhead::arrowhead() :
27 m_head_d1(1.0),
28 m_head_d2(1.0),
29 m_head_d3(1.0),
30 m_head_d4(0.0),
31 m_tail_d1(1.0),
32 m_tail_d2(1.0),
33 m_tail_d3(1.0),
34 m_tail_d4(0.0),
35 m_head_flag(false),
36 m_tail_flag(false),
37 m_curr_id(0),
38 m_curr_coord(0)
44 //------------------------------------------------------------------------
45 void arrowhead::rewind(unsigned id)
47 m_curr_id = id;
48 m_curr_coord = 0;
49 if(id == 0)
51 if(!m_tail_flag)
53 m_cmd[0] = path_cmd_stop;
54 return;
56 m_coord[0] = m_tail_d1; m_coord[1] = 0.0;
57 m_coord[2] = m_tail_d1 - m_tail_d4; m_coord[3] = m_tail_d3;
58 m_coord[4] = -m_tail_d2 - m_tail_d4; m_coord[5] = m_tail_d3;
59 m_coord[6] = -m_tail_d2; m_coord[7] = 0.0;
60 m_coord[8] = -m_tail_d2 - m_tail_d4; m_coord[9] = -m_tail_d3;
61 m_coord[10] = m_tail_d1 - m_tail_d4; m_coord[11] = -m_tail_d3;
63 m_cmd[0] = path_cmd_move_to;
64 m_cmd[1] = path_cmd_line_to;
65 m_cmd[2] = path_cmd_line_to;
66 m_cmd[3] = path_cmd_line_to;
67 m_cmd[4] = path_cmd_line_to;
68 m_cmd[5] = path_cmd_line_to;
69 m_cmd[7] = (unsigned)path_cmd_end_poly | (unsigned)path_flags_close | (unsigned)path_flags_ccw;
70 m_cmd[6] = path_cmd_stop;
71 return;
74 if(id == 1)
76 if(!m_head_flag)
78 m_cmd[0] = path_cmd_stop;
79 return;
81 m_coord[0] = -m_head_d1; m_coord[1] = 0.0;
82 m_coord[2] = m_head_d2 + m_head_d4; m_coord[3] = -m_head_d3;
83 m_coord[4] = m_head_d2; m_coord[5] = 0.0;
84 m_coord[6] = m_head_d2 + m_head_d4; m_coord[7] = m_head_d3;
86 m_cmd[0] = path_cmd_move_to;
87 m_cmd[1] = path_cmd_line_to;
88 m_cmd[2] = path_cmd_line_to;
89 m_cmd[3] = path_cmd_line_to;
90 m_cmd[4] = (unsigned)path_cmd_end_poly | (unsigned)path_flags_close | (unsigned)path_flags_ccw;
91 m_cmd[5] = path_cmd_stop;
92 return;
97 //------------------------------------------------------------------------
98 unsigned arrowhead::vertex(double* x, double* y)
100 if(m_curr_id < 2)
102 unsigned curr_idx = m_curr_coord * 2;
103 *x = m_coord[curr_idx];
104 *y = m_coord[curr_idx + 1];
105 return m_cmd[m_curr_coord++];
107 return path_cmd_stop;