%D \module
%D   [      file=s-pre-04,
%D        version=1998.09.06,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Presentation Environment 4,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\usemodule[pre-general]

%D \macros
%D   {setupbodyfont}
%D
%D This is just another environment for typesetting interactive
%D presentations. I wrote this module on behalf of a course I
%D gave for the United Kingdom \TeX\ users group.

\setupbodyfont[ams,pos,14.4pt]

%D \macros
%D   {setupcolors,definecolor}
%D
%D I started using dark blue for the navigational elements. In
%D that context, dark red is a logical choice for the contrast
%D color. While playing around with the navigational elements
%D I decided to use the not so dominant color yellow for the
%D status bar.
%D
%D A few days before I wrote this style, the recent acquisition
%D of Mondriaans last painting by the Dutch governement was a
%D hot topic in the dutch news scenary. Therefore I decided to
%D replace the rather dull title page by something more
%D colorful, in mondriaan colors, but far more random than any
%D of his paintings. For consistence we remap the already
%D defined primary colors.

\setupcolors [state=start]

\definecolor [NoneColor] [s=.6]
\definecolor [GotoColor] [b=.6]        \definecolor[blue]  [GotoColor]
\definecolor [ExitColor] [r=.6]        \definecolor[red]   [ExitColor]
\definecolor [JumpColor] [s=.6]
\definecolor [UserColor] [g=.6]        \definecolor[green] [UserColor]
\definecolor [StepColor] [r=.6,g=.6]   \definecolor[yellow][StepColor]

\definecolor [PageColor] [s=.80]       \definecolor[gray]  [PageColor]
\definecolor [TextColor] [s=.90]

%D \macros
%D   {setuppapersize}
%D
%D As usual, we take a screen oriented paper size:

\setuppapersize
  [S6][S6]

%D \macros
%D   {setuplayout,setupinteractionscreen}
%D
%D The layout definition fits into this $600\times450$ point
%D area, but the dimensions are somewhat diffused by the text
%D background offset.

\setuplayout
  [width=530pt,
   height=400pt,
   header=0pt,
   footer=0pt,
   backspace=15pt,
   topspace=15pt,
   bottomdistance=15pt,
   bottom=10pt,
   margin=0pt,
   rightedgedistance=15pt,
   rightedge=30pt]

\setupinteractionscreen
  [option=max]

%D \macros
%D   {setupbackgrounds}
%D
%D Both the page and the text area have a gray background.
%D The \type {[text,text]} area also has an offset. Later we
%D will see that we have to compensate for that in the
%D navigational areas.

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

\setupbackgrounds
  [text][text]
  [background=color,
   backgroundcolor=TextColor,
   backgroundoffset=5pt]

%D \macros
%D   {setupinteraction}
%D
%D For convenient navigation, we turn on interaction.

\setupinteraction
  [state=start,
   menu=on,
   color=UserColor,
   contrastcolor=NoneColor]

%D \macros
%D   {setupsubpagenumber}
%D
%D When navigating the document, we keep the title page out
%D of sight, therefore we use sub page numbers.

\setupsubpagenumber
  [state=start,
   way=bytext]

%D \macros
%D   {setupinteractionmenu}
%D
%D There is only one interaction menu, located in the right
%D edge of the screen. Both offsets enlarge the edge by the
%D same amount as the text background offset.

\setupinteractionmenu
  [right]
  [state=start,
   frame=off,
   strut=no,
   offset=0pt,
   inbetween=,
   bottomoffset=-5pt,
   topoffset=-5pt]

%D \macros
%D   {startinteractionmenu}
%D
%D The menu itself is not that spectacular. We use the
%D start||stop alternative for setting the content. The macro
%D \type {\interactioncolor} expands into either the
%D interaction color or the contrast color, the latter only
%D when no jump is possible.

\startinteractionmenu[right]
  \setupinteraction[color=GotoColor]
  \but [previoussubpage] \Triangle {90}\framedwidth\interactioncolor \\
  \vskip10pt
  \but [nextsubpage]     \Triangle{270}\framedwidth\interactioncolor \\
  \vfill
  \but [PreviousJump]    \Triangle{180}\framedwidth{NoneColor}       \\
  \vskip-5pt
  \but [NextJump]        \Triangle  {0}\framedwidth{NoneColor}       \\
\stopinteractionmenu

%D \macros
%D   {setupinteractionbar}
%D
%D The interaction bar at the bottom is also larger than the
%D normal width of the bottom area.

\setupinteractionbar
  [alternative=f,
   width=\textwidth,
   height=\bottomheight,
   distance=10pt,
   color=NoneColor,
   contrastcolor=StepColor]

%D \macros
%D   {setupbottomtexts}
%D
%D The bar is centered in the middle.

\setupbottomtexts
  [\interactionbar]

%D We can exit viewing with a close button, located on the
%D rightmost bottom area.

\def\CloseButton
  {\button
     [width=\rightedgewidth,height=\bottomheight,offset=overlay,
      background=color,backgroundcolor=ExitColor,frame=off]
     {}%
     [CloseDocument]}

\setupbottomtexts
  [edge][][\CloseButton]

%D \macros
%D   {definesymbol,setupitemize}
%D
%D Because some prominent things are rectangular or triangular,
%D we prefer some different symbols in itemizations:

\definesymbol[1][$\blacktriangleright$]
\definesymbol[2][$\blacktriangledown$]
\definesymbol[3][$\blacktriangleright$]
\definesymbol[4][$\blacktriangledown$]

\setupitemize[each][color=NoneColor]

%D \macros
%D   {TitlePage,defineoverlay,button,setupalign,
%D    setupbackgrounds,setupinteraction,setupinteractionbar,
%D    startstandardmakeup,switchtobodyfont,setupinterlinespace}
%D
%D Now the main layout and navigational definitions are
%D done, it makes sense to define and tune some structuring
%D commands. First we build the titlepage.

\defineoverlay [TitleGraphic] [\useMPgraphic{title}]
\defineoverlay [NextPage]     [\overlaybutton{nextpage}]

\def\StartTitlePage
  {\setupbackgrounds[page][background={color,TitleGraphic,NextPage}]
   \setupbackgrounds[text][text][background=]
   \setupinteraction[menu=off]
   \setupinteractionbar[state=stop]
   \startstandardmakeup
   \switchtobodyfont[24pt]
   \bfd\setupinterlinespace
   \setupalign[middle]
   \vfil
   \let\\=\vfil}

\def\StopTitlePage
  {\vfil\vfil\vfil
   \stopstandardmakeup
   \setupinteraction[menu=on]
   \setupinteractionbar[state=start]
   \setupbackgrounds[page][background=color]
   \setupbackgrounds[text][text][background=color]
   \setupsubpagenumber[reset]}

\def\TitlePage#1%
  {\StartTitlePage#1\StopTitlePage}

%D \macros
%D   {Topic, Nopic, Subject,
%D    definehead, setuphead}
%D
%D We use \type {\Topic} and \type {\Subject} instead of
%D chapters and sections. The \type {\Nopic} alternative is
%D meant for internal use.

\definehead [Topic]   [chapter]
\definehead [Nopic]   [title]
\definehead [Subject] [section]

\setuphead
  [Topic, Nopic]
  [after={\blank[3*medium]},
   number=no,
   style=\tfb,
   page=yes,
   alternative=middle]

\setuphead
  [Subject]
  [after=\blank,
   number=no,
   page=yes,
   continue=no,
   style=\tfa]

%D \macros
%D   {Topics, Subjects,
%D    setuplist, placelist, startcolumns}
%D
%D This style is meant for the more large presentations, and
%D therefore provided for a list of topics as well as local
%D lists of subjects. When many topics are introduces, the
%D list is typeset in columns.

\setuplist
  [Topic,Subject]
  [alternative=g,
   interaction=all,
   before=,
   after=]

\setuplist
  [Topic]
  [criterium=all]

\def\Topics#1%
  {\determinelistcharacteristics[Topic]
   \ifnum\utilitylistlength>0
     \Nopic[Topics]{#1}
     \ifnum\utilitylistlength>12
       \startcolumns
       \placelist[Topic]
       \stopcolumns
     \else
       \placelist[Topic]
     \fi
   \fi}

\def\Subjects%
  {\placelist[Subject]}

%D Last we define the overlays. Look at the way colors are
%D linked into the macros.

\startMPinclusions
  def triangle (expr wid, rot, col) =
    x1 := x3 := y1 := 0 ; x2 := y3 := wid ; y2 := .5y3 ;
    fill (z1--z2--z3--cycle) rotated rot withcolor col ;
    currentpicture := currentpicture xysized (wid,wid) ;
  enddef ;
\stopMPinclusions

\setupMPvariables
  [triangle]
  [width=1cm,
   rotation=0,
   color=black]

\startuniqueMPgraphic{triangle}{width,rotation,color}
  triangle(\MPvar{width},\MPvar{rotation},\MPvar{color}) ;
\stopuniqueMPgraphic

\def\Triangle#1#2#3%
  {\uniqueMPgraphic{triangle}{rotation=#1,width=#2,color=#3}}

\startuseMPgraphic{title} % can be simplified with "randomized"
  color c ; path p ;
  for i=1 upto 250 :
    x0 := uniformdeviate \overlaywidth ;
    y0 := uniformdeviate \overlayheight ;
    sx := uniformdeviate 20 ;
    sy := uniformdeviate 20 ;
    cc := round(uniformdeviate 2) ;
    if cc=0 : c := \MPcolor{GotoColor} fi ;
    if cc=1 : c := \MPcolor{ExitColor} fi ;
    if cc=2 : c := \MPcolor{StepColor} fi ;
    qq := round(uniformdeviate 1) ;
    if qq=0 :
      p := unitsquare xscaled sx yscaled sy ;
    else :
      rr := round(uniformdeviate 3) * 90 ;
      x1 := x3 := y1 := 0 ; x2 := y3 := sx; y2 := .5y3 ;
      p := (z1--z2--z3--cycle) rotated rr ;
    fi ;
    fill p shifted z0 withcolor c ;
  endfor ;
\stopuseMPgraphic

\doifnotmode{demo}{\endinput}

%D The (rather silly) demo section.

\starttext

\TitlePage{Title Page\\pre-colorfull}

\Topics{Some Nice Quotes}

\Topic{A Few}

\Subject{Knuth} \input knuth
\Subject{Tufte} \input tufte

\Topic{Some More}

\Subject{Zapf}   \input zapf
\Subject{Bryson} \input bryson

\stoptext
