% 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

% v0.0.7 2026-05-25

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

\prop_new:N \g_hawkdraw_arrow_default_keys_prop
\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 ~ 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:ne { hawkdraw / path } {
            \prop_item:Nn \g_hawkdraw_arrow_default_keys_prop {#1}
        }
        \keys_set:nn { hawkdraw / path } {#4}
        \hawkdraw_set_path_options:
        \cs_if_exist_use:cF { hawkdraw_arrow_tip_ #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_create:nnn #1#2#3 {
    \prop_gput:Nnn \g_hawkdraw_arrow_default_keys_prop {#1} {#2}
    \cs_new_protected:cpn { hawkdraw_arrow_tip_ #1 : } {    
        #3
    }
}

% ===

\hawkdraw_arrow_create:nnn { none } { } { }

\hawkdraw_arrow_create:nnn { default } {
    fill
} {
    \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:
}

\hawkdraw_arrow_create:nnn { stealth } {
    fill
} {
    \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:
}

\hawkdraw_arrow_create:nnn { triangle } {
    fill
} {
    \draw_path_moveto:n { 0 , 0 }
    \draw_path_lineto:n { -2.5 , -5 }
    \draw_path_lineto:n { 2.5 , -5 }
    \draw_path_close:
}

\hawkdraw_arrow_create:nnn { circle } {
    fill
} {
    \draw_path_circle:nn { 0 , -2.5 } { 2.5 }
}

\hawkdraw_arrow_create:nnn { simple } {
    stroke ,
    line ~ cap = { round } ,
    line ~ join = { round }
} {
    \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 }
}

\hawkdraw_arrow_create:nnn { straight } {
    stroke
} {
    \draw_path_moveto:n { -3 , -3 }
    \draw_path_lineto:n { 0 , 0 }
    \draw_path_lineto:n { 3 , -3 }
}

\hawkdraw_arrow_create:nnn { bar } {
    stroke
} {
    \draw_path_moveto:n { -3 , 0 }
    \draw_path_lineto:n { 3 , 0 }
}

% EOF
