%D \module
%D   [       file=trac-riv,
%D        version=2023.08.15, % follow up
%D          title=\CONTEXT\ Tracing Macros,
%D       subtitle=Rivers,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Tracing Macros / Rivers}

\registerctxluafile{trac-riv}{autosuffix}

\unprotect

\permanent\tolerant\protected\def\startshowrivers[#1]#*%
  {\begingroup
   \letdummyparameter\c!margin\zeropoint
   \letdummyparameter\c!step\!!twopoint
   \setdummyparameter\c!height{.2\bodyfontsize}%
   \setdummyparameter\c!depth {.2\bodyfontsize}%
   \setdummyparameter\c!spaceinbetween{.1\lineheight}%
   \letdummyparameter\c!criterium\plusfour
   \letdummyparameter\c!option\empty
   \getdummyparameters[#1]%
   \setbox\scratchboxone\vbox\bgroup}

\permanent\tolerant\protected\def\stopshowrivers
  {\egroup
   \clf_getrivers
      box    \scratchboxone
      margin {\dummyparameter\c!margin}
      skip   {\dummyparameter\c!spaceinbetween}
      step   {\dummyparameter\c!step}
      height {\dummyparameter\c!height}
      depth  {\dummyparameter\c!depth}
   \relax
   \setbox\scratchboxtwo\hbox\bgroup
     \startMPcode
        lmt_showrivers (
           \tointeger{\dummyparameter\c!criterium},
           \todimension{\wd  \scratchboxone},
           \todimension{\htdp\scratchboxone},
           \ifcstok{\dummyparameter\c!option}\v!test true\else false\fi
        ) ;
     \stopMPcode
   \egroup
   \startoverlay
      {\box\scratchboxtwo}
      {\box\scratchboxone}
   \stopoverlay
   \endgroup}

\permanent\tolerant\protected\def\addriverstobox[#1]#2%
  {\begingroup
   \letdummyparameter\c!margin\zeropoint
   \letdummyparameter\c!step\!!twopoint
   \setdummyparameter\c!height{.2\bodyfontsize}%
   \setdummyparameter\c!depth {.2\bodyfontsize}%
   \setdummyparameter\c!spaceinbetween{.1\lineheight}%
   \getdummyparameters[#1]%
   \clf_addrivers
      box    {#2}%
      margin {\dummyparameter\c!margin}%
      skip   {\dummyparameter\c!spaceinbetween}%
      step   {\dummyparameter\c!step}%
      height {\dummyparameter\c!height}%
      depth  {\dummyparameter\c!depth}%
   \relax
   \endgroup}

% \def\page_one_show_rivers#1%
%   {\addriverstobox{#1}}
%
% \installtextracker
%   {typesetting.rivers}
%   {\let\page_one_hook_for_checks\page_one_show_rivers}
%   {\let\page_one_hook_for_checks\gobbleoneargument}

\permanent\tolerant\protected\def\showrivers[#1]%
  {\def\page_one_hook_for_checks##1{\addriverstobox[#1]{##1}}}

\protect \endinput
