% File: hawkdraw-arrows.code.tex
% Copyright 2026 Jasper Habicht (mail(at)jasperhabicht.de).
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License version 1.3c,
% available at http://www.latex-project.org/lppl/.
%
% This file is part of the `hawkdraw' package (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% This work has the LPPL maintenance status `maintained'.
%
% BOF

\msg_new:nnn { hawkdraw } { arrow-unknown } {
    Arrow ~ tip ~ `#1` ~ unknown.
}

\clist_new:N \l_hawkdraw_arrow_start_keys_clist
\clist_new:N \l_hawkdraw_arrow_end_keys_clist

\keys_define:nn { hawkdraw / path } {
    arrow ~ start           .code:n         = {
        \tl_put_right:Nn \l_hawkdraw_path_postactions_tl {
            \fp_if_nan:nF { \g_hawkdraw_path_first_slope_fp } {
                \hawkdraw_put_arrow:nVVV {#1}
                    \g_hawkdraw_path_first_point_fp
                    \g_hawkdraw_path_first_slope_fp
                    \l_hawkdraw_arrow_start_keys_clist
            }
        }
    } ,
    arrow ~ start           .default:n      = { default } ,
    arrow ~ end             .code:n         = {
        \tl_put_right:Nn \l_hawkdraw_path_postactions_tl {
            \fp_if_nan:nF { \g_hawkdraw_path_last_slope_fp } {
                \hawkdraw_put_arrow:nVVV {#1}
                    \g_hawkdraw_path_last_point_fp
                    \g_hawkdraw_path_last_slope_fp
                    \l_hawkdraw_arrow_end_keys_clist
            }
        }
    } ,
    arrow ~ end             .default:n      = { default } ,
    arrow ~ start ~ style ~ set
                            .clist_set:N    = \l_hawkdraw_arrow_start_keys_clist ,
    arrow ~ end ~ style ~ set
                            .clist_set:N    = \l_hawkdraw_arrow_end_keys_clist ,
    arrow ~ start ~ style ~ add
                            .code:n         = {
        \clist_put_right:Nn \l_hawkdraw_arrow_start_keys_clist {#1}
    } ,
    arrow ~ end ~ style ~ add
                            .code:n         = {
        \clist_put_right:Nn \l_hawkdraw_arrow_end_keys_clist {#1}
    } ,
    arrow ~ style ~ set     .code:n         = {
        \clist_set:Nn \l_hawkdraw_arrow_start_keys_clist {#1}
        \clist_set:Nn \l_hawkdraw_arrow_end_keys_clist {#1}
    } ,
    arrow ~ style ~ set     .initial:n      = { fill } ,
    arrow ~ style ~ add     .code:n         = {
        \clist_put_right:Nn \l_hawkdraw_arrow_start_keys_clist {#1}
        \clist_put_right:Nn \l_hawkdraw_arrow_end_keys_clist {#1}
    } ,
}

\cs_new_protected:Npn \hawkdraw_put_arrow:nnnn #1#2#3#4 {
    \draw_scope_begin:
        \draw_transform_shift:n {#2}
        \draw_transform_rotate:n {#3}
        \clist_clear:N \l_hawkdraw_path_use_clist
        \keys_set:nn { hawkdraw / path } {#4}
        \hawkdraw_set_path_options:
        \cs_if_exist_use:cF { hawkdraw_arrow_ #1 : } {
            \msg_warning:nnn { hawkdraw } { arrow-unknown } {#1}
        }
        \draw_path_use_clear:e { \clist_use:N \l_hawkdraw_path_use_clist }
    \draw_scope_end:
}
\cs_generate_variant:Nn \hawkdraw_put_arrow:nnnn { nVVV }

% ===

\cs_new_protected:Npn \hawkdraw_arrow_none: { }

\cs_new_protected:Npn \hawkdraw_arrow_default: {
    \draw_path_moveto:n { -2.5 , -5 }
    \draw_path_curveto:nn { -1 , -3 } { 0 , 0 }
    \draw_path_curveto:nn { 1 , -3 } { 2.5 , -5 }
    \draw_path_close:
}

\cs_new_protected:Npn \hawkdraw_arrow_stealth: {
    \draw_path_moveto:n { 0 , 0 }
    \draw_path_lineto:n { -2.5 , -5 }
    \draw_path_lineto:n { 0 , -3.5 }
    \draw_path_lineto:n { 2.5 , -5 }
    \draw_path_close:
}

\cs_new_protected:Npn \hawkdraw_arrow_triangle: {
    \draw_path_moveto:n { 0 , 0 }
    \draw_path_lineto:n { -2.5 , -5 }
    \draw_path_lineto:n { 2.5 , -5 }
    \draw_path_close:
}

\cs_new_protected:Npn \hawkdraw_arrow_circle: {
    \draw_path_circle:nn { 0 , -2.5 } { 2.5 }
}

\cs_new_protected:Npn \hawkdraw_arrow_simple: {
    \draw_path_moveto:n { -3 , -3 }
    \draw_path_curveto:nn { -0.5 , -1.25 } { 0 , 0 }
    \draw_path_curveto:nn { 0.5 , -1.25 } { 3 , -3 }
}

\cs_new_protected:Npn \hawkdraw_arrow_straight: {
    \draw_path_moveto:n { -3 , -3 }
    \draw_path_lineto:n { 0 , 0 }
    \draw_path_lineto:n { 3 , -3 }
}

\cs_new_protected:Npn \hawkdraw_arrow_bar: {
    \draw_path_moveto:n { -3 , 0 }
    \draw_path_lineto:n { 3 , 0 }
}

% EOF
