%D \module
%D   [      file=s-pre-05,
%D        version=1998.12.12,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Presentation Environment 5,
%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] % mdode=step 

%D Yet undocumented, mostly copied from s-pre-04; much can be 
%D moved to s-pre-00!

\setupbodyfont
  [lbr,14.4pt]

\setupcolors [state=start]

\definecolor [FrameColor]      [r=.6,g=.7,b=.8]
\definecolor [BackgroundColor] [s=.95] 
\definecolor [GotoColor]       [FrameColor]
\definecolor [NoneColor]       [blank]

\setuppapersize
  [S6]

\setuplayout
  [width=430pt,
   height=400pt,
   header=0pt,
   footer=0pt,
   margin=0pt,
   backspace=25pt,
   topspace=25pt,
   rightedgedistance=20pt,
   rightedge=110pt]

\setupinteractionscreen
  [option=max,
   width=600pt,   % fit
   height=450pt]  % fit 

\setupbackgrounds
  [state=repeat]

\setupbackgrounds
  [text][text]
  [background={HashFrameA,NextPage},
   backgroundoffset=20pt]

\defineoverlay
  [HashFrameA]
  [\HashFrame\overlaywidth\overlayheight{15pt}]

\defineoverlay
  [HashFrameB]
  [\HashFrame\overlaywidth\overlayheight{5pt}]

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

\startinteractionmenu[right]
  \setupbuttons
    [background=HashFrameB,
     frame=off,
     offset=10pt,
     height=30pt,
     width=\rightedgewidth]
  \placelist
    [Topic]
    [criterium=all,
     alternative=e,  
     background=HashFrameB,
     frame=off,
     offset=10pt,
   % align=middle,                 % this is a nice alternative 
     width=\rightedgewidth,
     interaction=all,
     textcommand=\TopicLine,
     before=,
     after=]
  \vfill
  \button{Close}[CloseDocument]
\stopinteractionmenu

%D \macros
%D   {TitlePage}
%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\overlaywidth\overlayheight]
\defineoverlay [NextPage]     [\NextPageButton]

\def\NextPageButton%
  {\button
     [width=\overlaywidth,height=\overlayheight,frame=off]
     {}[forward]}

\def\StartTitlePage%
  {\setupbackgrounds[page][background={TitleGraphic,NextPage}]
   \setupbackgrounds[text][text][background=]
   \setupinteraction[menu=off]
   \setupinteractionbar[state=stop]
   \setuplayout[width=550pt,rightedge=0pt]
   \startstandardmakeup
   \switchtobodyfont[24pt]
   \bfd\stelinterliniein
   \setupalign[middle]
   \vfil
   \let\\=\vfil}

\def\StopTitlePage%
  {\vfil\vfil\vfil
   \stopstandardmakeup
   \setuplayout[width=430pt,rightedge=110pt]
   \setupinteraction[menu=on]
   \setupinteractionbar[state=start]
   \setupbackgrounds[page][background=]
   \setupbackgrounds[text][text][background={HashFrameA,NextPage}]}

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

%D \macros 
%D   {Topics}
%D
%D ...

\def\Topics#1{}

%D \macros
%D   {Topic, Nopic, Subject} 
%D
%D ...

\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]

\def\TopicLine#1%
  {\limitatetext{#1}{80pt}{...}}

\startMPinclusions
  input mp-tool ;
  
  def random_hash_frame (expr width, height, offset, linewidth ) =  

    def delta = ((uniformdeviate .5offset) + .25offset) enddef ;
    x1 := offset ; y1 := offset ; x2 := width-offset ; y2 := height-offset ;

    drawoptions(withpen pencircle scaled linewidth withcolor \MPcolor{BackgroundColor}) ; 
    fill z1--(x2,y1)--z2--(x1,y2)--cycle ;

    drawoptions(withpen pencircle scaled linewidth withcolor \MPcolor{FrameColor}) ; 
    draw (x1-delta,y1)--(x2+delta,y1) ;
    draw (x2,y1-delta)--(x2,y2+delta) ;
    draw (x2+delta,y2)--(x1-delta,y2) ;
    draw (x1,y2+delta)--(x1,y1-delta) ;

    setbounds currentpicture to unitsquare xscaled width yscaled height ;
  enddef ; 
\stopMPinclusions

\def\HashFrame#1#2#3%
  {\startuseMPgraphic{HashFrame}
     random_hash_frame(#1,#2,#3,2pt) ;
   \stopuseMPgraphic
   \useMPgraphic{HashFrame}}

\def\TitleGraphic#1#2%
  {\startuseMPgraphic{title}
     picture savedpicture ; 
     savedpicture := nullpicture ; 
     def MakeOne = 
       offset := uniformdeviate 10pt ; 
       width  := 2*offset + 30pt + uniformdeviate 30pt ; 
       height := 2*offset + 10pt + uniformdeviate 10pt ; 
       random_hash_frame(width,height,offset,1pt) ;
       addto savedpicture also (currentpicture shifted   
         (uniformdeviate #1, uniformdeviate #2)) ; 
       currentpicture := nullpicture ; 
     enddef ;
     for i=1 upto 300 : MakeOne ; endfor ;  
     currentpicture := savedpicture ; 
   \stopuseMPgraphic
   \useMPgraphic{title}}

\endinput
