%D \module
%D   [      file=s-present-balls, % s-pre-15,
%D        version=1999.09.01,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Presentation Environment Balls,
%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-balls]

%D This is one of the styles I made for the presentation on the \NTS\ project at
%D Euro\TeX\ 1998. You need balls to let \TEX\ typeset graphics, but this style
%D demonstrates that it can be done.
%D
%D This presentation is meant for presentations that build up an idea stepwise.
%D
%D \starttyping
%D \TitlePage{Do you know \TEX ?}
%D
%D \StartIdea
%D   \StartItem We use \TEX\ for typesetting       \unknown \StopItem
%D   \StartItem mathematical text                  \unknown \StopItem
%D   \StartItem but also for text that has no math \unknown \StopItem
%D   \StartItem or presentations like this         \unknown \StopItem
%D   \StartItem and whatever you can come up with!          \StopItem
%D \StopIdea
%D \stoptyping
%D
%D The basic layout is rather simple and used as much of the screen as possible.

\setuppapersize
  [S6][S6]

\setuplayout
  [backspace=25pt,
   topspace=25pt,
   width=middle,
   height=middle,
   header=0pt,
   footer=0pt]

\setupinteraction
  [state=start,
   display=new,
   color=LineColor,
   contrastcolor=LineColor,
   click=no]

\setupinteractionscreen
  [option=max]

\startmode[asintended,atpragma] \setupbodyfont[lucidaot] \stopmode

\setupbodyfont[14.4pt]

%D We use a lot of color. You can remap them if you want different ones. The ideas
%D circulate over the colors.

\definecolor[TextColor][s=.8]
\definecolor[PageColor][s=.6]
\definecolor[LineColor][s=.4]

\definecolor[red]  [r=.4]        \definecolor[cyan]   [g=.4,b=.4]
\definecolor[green][g=.4]        \definecolor[magenta][r=.4,b=.4]
\definecolor[blue] [b=.4]        \definecolor[yellow] [r=.4,g=.4]

\definecolor[linecolor 1][red]   \definecolor[linecolor 5][cyan]
\definecolor[linecolor 2][green] \definecolor[linecolor 6][magenta]
\definecolor[linecolor 3][blue]  \definecolor[linecolor 4][yellow]

%D We use variables to make sure that the graphics are reused but unique.

\setupMPvariables[pageframe][pagecolor=PageColor,linecolor=LineColor]
\setupMPvariables[textframe][textcolor=TextColor,linecolor=LineColor]

\setupbackgrounds
  [page]
  [background={pageframe,nextpage}]

\defineoverlay [pageframe] [\uniqueMPgraphic{pageframe}]
\defineoverlay [textframe] [\uniqueMPgraphic{textframe}]
\defineoverlay [nextpage]  [\overlaybutton{forward}]

\startuniqueMPgraphic{pageframe}{pagecolor,linecolor}
    path p ; p := fullsquare xyscaled (OverlayWidth,OverlayHeight) ;
    pickup pencircle scaled 10pt ;
    fill p withcolor \MPvar{pagecolor} ;
    draw p withcolor \MPvar{linecolor} ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{textframe}{textcolor,linecolor}
    path p ; p := fullcircle xyscaled (OverlayWidth,OverlayHeight) ;
    pickup pencircle scaled 10pt ;
    fill p withcolor \MPvar{textcolor} ;
    draw p withcolor \MPvar{linecolor} ;
\stopuniqueMPgraphic

%D The rest of the file implements the nasty part: typesetting text embedded in a
%D graphic. The text is collected in a box so that we can reuse it.

\newbox  \CollectedIdeas
\newcount\CurrentTopic

\unexpanded\def\StartItem
  {\setbox\CollectedIdeas=\hbox\bgroup
     \ifdim\wd\CollectedIdeas>\zeropoint
        \unhbox\CollectedIdeas
        \hskip25pt
     \fi
     \setbox\scratchbox=\hbox\bgroup
       \framed
         [width=160pt,
          height=160pt,
          align=middle,
          frame=off,
          background=textframe,
          offset=15pt,
          top=\vfill,
          bottom=\vfill]
        \bgroup}

\unexpanded\def\StopItem
  {\egroup
   \egroup
   \setbox\scratchbox=\hbox{\lower.5\ht\scratchbox\box\scratchbox}%
   \ht\scratchbox=.5\ht\scratchbox
   \dp\scratchbox=  \ht\scratchbox
   \box\scratchbox
   \egroup
   \startstandardmakeup
     \dontcomplain
     \leftskip       0pt plus 50pt
     \rightskip      0pt plus 50pt
     \parfillskip    0pt
     \baselineskip 100pt
     \unhcopy\CollectedIdeas
   \stopstandardmakeup}

\unexpanded\def\StartIdea
  {\ifnum\CurrentTopic=6
     \global\CurrentTopic\plusone
   \else
     \global\advance\CurrentTopic\plusone
   \fi
   \definecolor[LineColor][linecolor \number\CurrentTopic]
   \setbox\CollectedIdeas\null}

\unexpanded\def\StopIdea
  {}

\unexpanded\def\StartTitlePage
  {\startstandardmakeup
   \setupalign[middle]
   \enforced\protected\def\\{\vfil\bfb\setupinterlinespace}
   \bfd\setupinterlinespace
   \vfil}

\unexpanded\def\StopTitlePage
  {\vfil\vfil
   \stopstandardmakeup}

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

\startsetups document:start
    \StartTitlePage
        \documentvariable{title}
        \doifsomething {\documentvariable{subtitle}} {
            \\
            \documentvariable{subtitle}
        }
        \doifsomething {\documentvariable{location}} {
            \\
            \documentvariable{location}
        }
    \StopTitlePage
\stopsetups

\startsetups document:stop
    %
\stopsetups

\stopmodule

\continueifinputfile{s-present-balls.mkiv}

\usemodule[present-common]

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