%D \module
%D   [      file=s-pre-02,
%D        version=1998.04.21,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Presentation Environment 2,
%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. 

%D This environment can be used to typeset interactive
%D presentations. This module was first used at the 1998 
%D publishers conference of the European Portable Document 
%D Association (now merged into a graphics association).

\usemodule[pre-general]

%D \macros
%D   {setupbodyfont, switchtobodyfont, setuplayout}
%D
%D At \PRAGMA\ we prefer using the Lucida Bright fonts, but 
%D one can of course load another typeface. 

\startmode[asintended] \setupbodyfont[lbr] \stopmode

\setupbodyfont[14.4pt]

\setuplayout
  [style=smallbodyfont]

%D \macros
%D   {setuppapersize, setuplayout}
%D
%D The papersize suits the screen dimensions. The layout is 
%D rather simple. We use the whole width of the screen and only
%D have navigational tools at the bottom of the screen.

\setuppapersize
  [S6][S6]

\setuplayout
  [backspace=1cm,
   topspace=1cm,
   margin=0pt,
   header=0pt,
   footer=0pt,
   bottomdistance=.875cm,
   bottom=1cm,
   width=fit,
   height=fit]

%D \macros
%D   {setupwhitespace, setuptyping}
%D
%D We don't have much height, so we use a more cramped 
%D spacing. Verbatim text looks better when indented. 
%D

\setupwhitespace
  [medium]

\setuptyping
  [margin=standard]

%D \macros
%D   {definecolor, setupcolors}
%D
%D Of course we enable color. We define some logical colors,
%D of which most default to the same green shade. 

\definecolor [BackgroundColor]  [r=.8, g=.8, b=.8]
\definecolor [OrnamentColor]    [r= 0, g=.7, b=.4]

\setupcolors
  [state=start]

%D \macros
%D   {setupinteraction, setupinteractionscreen}
%D   
%D We still have to enable interaction mode. We go full 
%D screen!

\setupinteraction
  [state=start,
   color=OrnamentColor,
   contrastcolor=OrnamentColor]

\setupinteractionscreen
  [option=max,
   width=fit,
   height=fit]

%D \macros
%D   {setupitemize}
%D
%D And why not bring some color in itemizations too?

\setupitemize
  [color=OrnamentColor]

%D \macros
%D   {defineoverlay, setupbackgrounds}
%D 
%D The navigational elements and the backgrounds are 
%D provided by \METAPOST.
%D 
%D When \METAPOST\ is used, it makes sense to generate the
%D graphics at runtime. This is supported when one enables
%D system calls in the local \type {texmf.cnf} file and add the
%D switch \type {\runMPgraphicstrue} to the local file \type
%D {cont-sys.tex}. When direct processing is disabled or not 
%D supported, \TEXEXEC\ will take care of graphic generation. 

\startuniqueMPgraphic{PageBackground}
  fill unitsquare
    xyscaled(OverlayWidth,OverlayHeight) 
    withcolor OverlayColor ; 
  draw unitsquare
    xyscaled(OverlayWidth,OverlayHeight) 
    enlarged (-2*OverlayLineWidth)
    withpen pencircle scaled OverlayLineWidth
    withcolor OverlayLineColor ; 
\stopuniqueMPgraphic

\defineoverlay
  [PageBackground]
  [\uniqueMPgraphic{PageBackground}] 

\setupbackgrounds
  [page]
  [background=PageBackground,
   backgroundcolor=BackgroundColor,
   rulethickness=.125cm,
   framecolor=OrnamentColor]

%D \macros
%D   {setuptexttexts}
%D
%D By clicking on the text area, one goes to the next page. 
%D We hook this feature into the text backgrounds. 

\startuniqueMPgraphic{TextBackground}
  draw unitsquare
    xyscaled(OverlayWidth,OverlayHeight) 
    enlarged (4*OverlayLineWidth)
    withpen pencircle scaled OverlayLineWidth
    withcolor OverlayLineColor ;  
\stopuniqueMPgraphic

\defineoverlay
  [TextBackground]
  [\uniqueMPgraphic{TextBackground}]

\defineoverlay
  [NextPage]
  [\overlaybutton{nextpage}]

\setupbackgrounds
  [text]
  [background={TextBackground,NextPage},
   backgroundcolor=BackgroundColor,
   rulethickness=.0625cm,
   framecolor=OrnamentColor]

%D \macros
%D   {setupinteractionmenu,startinteractionmenu}
%D
%D At the bottom of the screen, we show three buttons. These
%D direct us to the previous or next jump or exit the document.

\setupMPvariables[RightArrow][height=\bottomheight]
\setupMPvariables[LeftArrow] [height=\bottomheight]
\setupMPvariables[Circle]    [height=\bottomheight]
\setupMPvariables[UpArrow]   [height=\bottomheight]

\startuniqueMPgraphic{RightArrow}{height}
  z1=(0,0) ; z2=(\MPvar{height},.5y3) ; z3=(0,\MPvar{height}) ;
  drawfill z1--z2--z3--cycle
    withpen pencircle scaled (\MPvar{height}/5)
    withcolor \MPcolor{OrnamentColor} ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{LeftArrow}{height}
  z1=(\MPvar{height},0) ; z2=(0,.5y3) ; z3=(\MPvar{height},\MPvar{height}) ;
  drawfill z1--z2--z3--cycle
    withpen pencircle scaled (\MPvar{height}/5)
    withcolor \MPcolor{OrnamentColor} ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{Circle}{height}
  drawfill fullcircle scaled \MPvar{height}
    withpen pencircle scaled (\MPvar{height}/5)
    withcolor \MPcolor{OrnamentColor} ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{UpArrow}{height}
  z1=(0,0) ; z2=(\MPvar{height},0) ; z3=(.5x2,\MPvar{height}) ;
  drawfill z1--z2--z3--cycle
    withpen pencircle scaled (\MPvar{height}/5)
    withcolor \MPcolor{OrnamentColor} ;
\stopuniqueMPgraphic

\setupinteractionmenu
  [bottom]
  [state=start,
   frame=off,
   width=.3\textwidth,
   height=\bottomheight]

\setupinteraction
  [menu=on]

\def\WhateverButton
  {\doifreferencefoundelse{Whatever} 
     {\raw [Whatever] \uniqueMPgraphic{UpArrow} \\}   
     {}}

\startinteractionmenu[bottom]
  \but [Topics]                                     \\ % secret button 
  \hfill
  \WhateverButton                                      % user specific 
  \kern2\bottomheight
  \raw [previouspage]  \uniqueMPgraphic{LeftArrow}  \\
  \kern.5\bottomheight
  \raw [CloseDocument] \uniqueMPgraphic{Circle}     \\
  \kern.5\bottomheight
  \raw [nextpage]      \uniqueMPgraphic{RightArrow} \\
  \kern.5\bottomheight
\stopinteractionmenu

%D \macros
%D   {TitlePage, Topics, Topic, Subject}
%D
%D A presentation after loading this module looks like:
%D
%D \starttyping
%D \TitlePage {About Whatever\\Topics}
%D
%D \Topics {Todays Talk}
%D
%D \Topic {Some topic}
%D
%D .....
%D
%D \Topic {Next Topic}
%D
%D .....
%D \stoptyping

%D \macros
%D  {StartTitlePage, TitlePage}
%D
%D The titlepage is rather simple and can be typeset in two 
%D ways: 
%D
%D \starttyping
%D \StartTitlePage
%D text \\ text \\ text 
%D \StopTitlepage
%D \stoptyping
%D
%D or as one||liner:
%D
%D \starttyping
%D \TitlePage{text\\text\\text} 
%D \stoptyping
%D 
%D The first alternative can be used for more complicated 
%D title pages.  

\def\StartTitlePage%
  {\startstandardmakeup
   \bfd\setupinterlinespace
   \setupalign[middle]
   \vfil
   \let\\=\vfil}

\def\StopTitlePage%
  {\vfil\vfil\vfil
   \stopstandardmakeup}

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

%D \macros
%D   {definehead}
%D
%D The commands \type{\Topic} and \type{\Subject} are defined
%D as copies of head. We use \type{\Nopic} for internal 
%D purposes. 

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

\definehead [Nopic]   [title]

%D \macros
%D   {setuphead}
%D
%D We use our own command for typesetting the titles. We hide
%D sectionnumbers from viewing. Each topic is followed by a
%D list of subjects that belong to the topic.

\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   {setuplist}
%D
%D When found, the subject list is automatically placed 
%D after the topic head. 

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

\setuplist
  [Topic]
  [criterium=all]

\def\Topics#1% 
  {\determinelistcharacteristics[Topic]
   \doifmode{*list}
     {\Nopic[Topics]{#1}
      \startcolumns
      \placelist[Topic]
      \stopcolumns}}

\setuplist
  [Subject]
  [criterium=Topic]

\def\Subjects% 
  {\determinelistcharacteristics[Subject]
   \doifmode{*list}
     {\placelist[Subject]}}

\setuphead
  [Topic]
  [after={\blank[3*medium]\Subjects}]

\endinput
