%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] % mode=step 

%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] \MPup    \framedwidth \interactioncolor \\
  \vskip10pt
  \but [nextsubpage]     \MPdown  \framedwidth \interactioncolor \\
  \vfill
  \but [PreviousJump]    \MPleft  \framedwidth {NoneColor}       \\
  \vskip-5pt
  \but [NextJump]        \MPright \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=540pt,
   height=10pt,
   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=\hsize,height=10pt,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] [\TitleGraphic]
\defineoverlay [NextPage]     [\NextPageButton]

\def\NextPageButton%
  {\button
     [width=\overlaywidth,height=\overlayheight,frame=off]
     {}[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=]

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

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

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

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

\def\MPright#1#2%
  {\startreusableMPgraphic{r:#1:#2}
     triangle (#1, 0, \MPcolor{#2} ) ;
   \stopreusableMPgraphic
   \reuseMPgraphic{r:#1:#2}}

\def\MPleft#1#2%
  {\startreusableMPgraphic{l:#1:#2}
     triangle (#1, 180, \MPcolor{#2} ) ;
   \stopreusableMPgraphic
   \reuseMPgraphic{l:#1:#2}}

\def\MPup#1#2%
  {\startreusableMPgraphic{u:#1:#2}
     triangle (#1, 90, \MPcolor{#2} ) ;
   \stopreusableMPgraphic
   \reuseMPgraphic{u:#1:#2}}

\def\MPdown#1#2%
  {\startreusableMPgraphic{d:#1:#2}
     triangle (#1, 270, \MPcolor{#2} ) ;
   \stopreusableMPgraphic
   \reuseMPgraphic{d:#1:#2}}

\def\TitleGraphic%
  {\startuseMPgraphic{title}
     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
   \useMPgraphic{title}}

\endinput
