%D \module
%D   [      file=s-present-random,
%D        version=2008.08.05, % updated 2016.10.20
%D          title=\CONTEXT\ Style File,
%D       subtitle=Presentation Environment Random,
%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.

\startmodule[present-random]

%D Unfortunately there are not that many viewers that support javascript
%D control over layers.

% \enablemode[numbers]
% \enablemode[paper]
% \usemodule[present-stepwise]

\registerctxluafile{s-present-random}{}

\setupinteraction
  [state=start,
   click=off]

\definepapersize
  [wide]
  [width=900pt,
   height=600pt]

\setuppapersize
  [wide]
  [wide]

\setuplayout
  [page]

\setupsorting
  [logo]
  [style=]

\startnotmode[paper]

    \setupbackgrounds
      [page]
      [background=color,
       backgroundcolor=black]

\stopnotmode

\definelayer
  [page]
  [width=\paperwidth,
   height=\paperheight]

\definecolor[TopicColor-1][r=.3,g=.4,b=.5]
\definecolor[TopicColor-2][r=.3,g=.5,b=.4]
\definecolor[TopicColor-3][r=.4,g=.3,b=.5]
\definecolor[TopicColor-4][r=.4,g=.5,b=.3]
\definecolor[TopicColor-5][r=.5,g=.3,b=.4]
\definecolor[TopicColor-6][r=.5,g=.4,b=.3]
\definecolor[TopicColor-7][r=.35,g=.35,b=.6]
\definecolor[TopicColor-8][r=.6,g=.35,b=.35]
\definecolor[TopicColor-9][r=.35,g=.6,b=.35]

\definecolor[TopicColor-0][t=.5,a=1,s=.5]
\definecolor[TopicColor]  [s=1]

\setupcolors
  [textcolor=TopicColor]

\starttexdefinition unexpanded StartTopics
    \doifelsemode {paper} {
        \disablemode[stepper]
        \enablemode[onepagestepper]
    } {
        \doifelsedefined {NextStep} {
            \enablemode[stepper]
            \disablemode[onepagestepper]
        } {
            \disablemode[stepper]
            \disablemode[onepagestepper]
        }
    }
    \doifelsemode {onepagestepper} {
        \startstandardmakeup[top=,bottom=\vfill]
    } {
        \setuplayer[state=repeat]
        \resetlayer[page]
    }
    \ctxlua{moduledata.steps.reset_locations()}
    \doifmode {interactivestepper} {
        \StartLocalSteps
    }
\stoptexdefinition

\starttexdefinition unexpanded StopTopics
    \doifmode {interactivestepper} {
        \StopLocalSteps
    }
    \doifelsemode {onepagestepper} {
        \flushlayer[page]
        \stopstandardmakeup
    } {
        \resetlayer[page]
    }
\stoptexdefinition

\starttexdefinition unexpanded StartTopic
    \dosingleempty\doStartTopic
\stoptexdefinition

\starttexdefinition unexpanded doStartTopic [#1]
    \doifmode {interactivestepper} {
        \NextStep
    }
    \ctxlua{moduledata.steps.next_location("#1")}
    \doifmode {paper} {
        \doifnothing {#1} {
            \ifcase\ctxlua{moduledata.steps.previous_n()}\else
                \setlayer
                    [page]
                    [preset=\ctxlua{moduledata.steps.previous_location()}]
                \bgroup
                    \doifmode {interactivestepper} {
                        \startviewerlayer[\StepLayer]
                    }
                    \framed
                        [offset=20pt,
                         strut=no,
                         align=normal,
                         frame=off,
                         height=\dimexpr\paperheight/3\relax,
                         width=\dimexpr\paperwidth/3\relax,
                         background=color,
                         backgroundcolor=TopicColor-0]
                        {}
                    \doifmode {interactivestepper} {
                        \stopviewerlayer
                    }
             \egroup
         \fi
        }
    }
    \setlayer
        [page]
        [preset=\ctxlua{moduledata.steps.current_location()}]
        \bgroup
            \doifmode {interactivestepper} {
                \startviewerlayer[\StepLayer]
            }
            \framed
                [offset=20pt,
                 strut=no,
                 align=\expdoifelse{#1}{}{normal}{middle,lohi},
                 align=\expdoifelse{#1}{}{flushleft,verytolerant}{middle,lohi},
                 frame=off,
                 height=\dimexpr\paperheight/3\relax,
                 width=\dimexpr\paperwidth/3\relax,
                 background=color,
                 backgroundcolor=TopicColor-\ctxlua{moduledata.steps.current_n()}]
                \bgroup
                    \ignorespaces
\stoptexdefinition

\starttexdefinition unexpanded StopTopic
                    \removeunwantedspaces
                \egroup
            \doifmode {interactivestepper} {
                \stopviewerlayer
            }
        \egroup
    \doifmode {numbers} {
        \setlayerframed
            [page]
            [preset=\ctxlua{moduledata.steps.current_location()}]
            [height=\dimexpr\paperheight/3\relax,
             width=\dimexpr\paperwidth/3\relax,
             frame=off,
             foregroundstyle=\bfa,
             align={flushright,low}]
           \bgroup
                \doifmode {interactivestepper} {
                    \startviewerlayer[\StepLayer]
                }
                \ctxlua{moduledata.steps.step()}\kern\strutdepth
                \doifmode {interactivestepper} {
                    \stopviewerlayer
                }
            \egroup
    }
    \doifnotmode {onepagestepper} {
        \startstandardmakeup[top=,bottom=\vfill]
            \flushlayer[page]
        \stopstandardmakeup
    }
\stoptexdefinition

\definefont[TitleFont][SansBold*default at 60pt]
\definefont[TempFont] [SansBold*default at 12pt]

\let\StartText\starttext % for old times sake
\let\StopText \stoptext  % for old times sake

\stopmodule

\continueifinputfile{s-present-random.mkiv}

\usemodule[present-common]

\inputpresentationfile{examples/present-random-001.tex}

