summaryrefslogtreecommitdiff
path: root/agg/source/agg_arrowhead.cpp
blob: 694ed5ad887b930a7dd95aa6b91572bae11e2982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
//          mcseemagg@yahoo.com
//          http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Simple arrowhead/arrowtail generator
//
//----------------------------------------------------------------------------

#include "agg_arrowhead.h"

namespace agg
{

    //------------------------------------------------------------------------
    arrowhead::arrowhead() :
        m_head_d1(1.0),
        m_head_d2(1.0),
        m_head_d3(1.0),
        m_head_d4(0.0),
        m_tail_d1(1.0),
        m_tail_d2(1.0),
        m_tail_d3(1.0),
        m_tail_d4(0.0),
        m_head_flag(false),
        m_tail_flag(false),
        m_curr_id(0),
        m_curr_coord(0)
    {
    }



    //------------------------------------------------------------------------
    void arrowhead::rewind(unsigned id)
    {
        m_curr_id = id;
        m_curr_coord = 0;
        if(id == 0)
        {
            if(!m_tail_flag)
            {
                m_cmd[0] = path_cmd_stop;
                return;
            }
            m_coord[0]  =  m_tail_d1;             m_coord[1]  =  0.0;
            m_coord[2]  =  m_tail_d1 - m_tail_d4; m_coord[3]  =  m_tail_d3;
            m_coord[4]  = -m_tail_d2 - m_tail_d4; m_coord[5]  =  m_tail_d3;
            m_coord[6]  = -m_tail_d2;             m_coord[7]  =  0.0;
            m_coord[8]  = -m_tail_d2 - m_tail_d4; m_coord[9]  = -m_tail_d3;
            m_coord[10] =  m_tail_d1 - m_tail_d4; m_coord[11] = -m_tail_d3;

            m_cmd[0] = path_cmd_move_to;
            m_cmd[1] = path_cmd_line_to;
            m_cmd[2] = path_cmd_line_to;
            m_cmd[3] = path_cmd_line_to;
            m_cmd[4] = path_cmd_line_to;
            m_cmd[5] = path_cmd_line_to;
            m_cmd[7] = (unsigned)path_cmd_end_poly | (unsigned)path_flags_close | (unsigned)path_flags_ccw;
            m_cmd[6] = path_cmd_stop;
            return;
        }

        if(id == 1)
        {
            if(!m_head_flag)
            {
                m_cmd[0] = path_cmd_stop;
                return;
            }
            m_coord[0]  = -m_head_d1;            m_coord[1]  = 0.0;
            m_coord[2]  = m_head_d2 + m_head_d4; m_coord[3]  = -m_head_d3;
            m_coord[4]  = m_head_d2;             m_coord[5]  = 0.0;
            m_coord[6]  = m_head_d2 + m_head_d4; m_coord[7]  = m_head_d3;

            m_cmd[0] = path_cmd_move_to;
            m_cmd[1] = path_cmd_line_to;
            m_cmd[2] = path_cmd_line_to;
            m_cmd[3] = path_cmd_line_to;
            m_cmd[4] = (unsigned)path_cmd_end_poly | (unsigned)path_flags_close | (unsigned)path_flags_ccw;
            m_cmd[5] = path_cmd_stop;
            return;
        }
    }


    //------------------------------------------------------------------------
    unsigned arrowhead::vertex(double* x, double* y)
    {
        if(m_curr_id < 2)
        {
            unsigned curr_idx = m_curr_coord * 2;
            *x = m_coord[curr_idx];
            *y = m_coord[curr_idx + 1];
            return m_cmd[m_curr_coord++];
        }
        return path_cmd_stop;
    }

}