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

\usemodule[streams]

\setuppapersize
  [S6] [S6]

\setupbodyfont
  [12pt,tt]

\definemeasure[bleed][6pt]

\definecolor[maincolor-3][r=.5,g=.2,b=.2]
\definecolor[maincolor-1][r=.2,g=.5,b=.2]
\definecolor[maincolor-2][r=.2,g=.2,b=.5]

\definecolor[pagecolor]  [s=.5]
\definecolor[resultcolor][s=1,t=.85,a=1]
\definecolor[maincolor]  [maincolor-3]

\definecolorgroup
  [maingroup]
  [.5:.2:.2,
   .2:.5:.2,
   .2:.2:.5]

\definecolorgroup
  [resultgroup]
  [1:.85:.85,
   .85:1:.85,
   .85:.85:1]

\def\CurrentColor{1}

\definecolor[maincolor]  [maingroup:\CurrentColor]
\definecolor[resultcolor][resultgroup:\CurrentColor]

\def\NextColor{\ifnum\CurrentColor=3 \def\CurrentColor{1}\else\doglobal\increment\CurrentColor\fi}

\setuplayout
  [backspace=\measure{bleed},
   topspace=30pt,
   bottomdistance=\measure{bleed},
   bottom=\dimexpr30pt-\measure{bleed}\relax,
   header=0pt,
   footer=0pt,
   topdistance=\measure{bleed},
   top=\dimexpr30pt-\measure{bleed}\relax,
   width=middle,
   height=middle]

\setuptop
  [before=\vfill,
   after=\vfill,
   strut=yes]

\setupbackgrounds
  [text]
  [backgroundoffset=\measure{bleed},
   background=color,
   backgroundcolor=maincolor]

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

\setupcolors
  [state=start,
   textcolor=white]

\setuphead
  [chapter]
  [style=\ttd]

\setuphead
  [section]
  [style=\ttd]

\defineproperty
  [result]
  [layer]
  [state=stop]

\definelayer
  [result]

\setuplayer
  [result]
  [width=\textwidth,
   height=\textheight]

\setupbackgrounds
  [text]
  [background={color,toggle,foreground,result}]

\setupinteraction
  [state=start,
   click=no,
   menu=on,
   color=white,
   contrastcolor=white,
   closepageaction=HideLayer{result},
   openpageaction=HideLayer{result}]

% We add a dummy color switch so that each page has at least one
% transparency; else acrobat will render the pages differently
% bug in 6 and 7).

\startinteractionmenu[bottom]
%     \color[resultcolor]{ }%
    \hfill
    \got [content]             content \\
    \got [previouspage]        previous \\
    \got [nextpage]            next     \\
    \got [ToggleLayer{result}] result   \\
    \got [CloseDocument]       close    \\
\stopinteractionmenu

\setuphead
  [section]
  [placehead=no,
   incrementnumber=list]

\setuplist
  [section]
  [alternative=f]

\defineoverlay
  [toggle]
  [\overlaybutton{ToggleLayer{result}}]

\definestreamlayer
  [resultstream]

\startsetups streamlayer:resultstream:flush
  \setlayer
    [result]
    [preset=middlebottom,
     hoffset=\measure{bleed},
%      voffset=-\measure{bleed}]
     voffset=\measure{bleed}]
    {\startproperty[result]%
%      \framed
%        [offset=overlay,
%         frame=off,
%         background=color,
%         backgroundoffset=1\dimexpr\measure{bleed}\relax,
%         backgroundcolor=maincolor]
       {\framed
          [offset=overlay,
           frame=off,
           foregroundcolor=maincolor,
           background=color,
           backgroundoffset=1\dimexpr\measure{bleed}\relax,
           backgroundcolor=resultcolor]
          {\tightlayer[\currentstreamlayer]}}
     \stopproperty}
\stopsetups

\startsetups  show-definition
  \subject{definition}
  \typebuffer
  \getbuffer
  \page
\stopsetups

\startsetups show-result
  \startstreamlayer[resultstream]
    \subject{result}
    \getbuffer
  \stopstreamlayer
  \placestreamlayer[resultstream]
  \page
\stopsetups

\startsetups show-usage
  \subject{usage}
  \typebuffer
  \startstreamlayer[resultstream]
    \subject{result}
    \getbuffer
  \stopstreamlayer
  \placestreamlayer[resultstream]
  \page
\stopsetups

\startsetups show-usage-lines
  \subject{usage}
  \typebuffer
  \startstreamlayer[resultstream]
    \subject{result}
    \startlines
    \getbuffer
    \stoplines
  \stopstreamlayer
  \placestreamlayer[resultstream]
  \page
\stopsetups

\startsetups show-contents
    \startcolumns[n=3]
    \placelist[section][criterium=text]
    \stopcolumns
    \pagereference[content]
    \page
    \NextColor
\stopsetups

\def\TitlePage#1%
  {\title{#1}
   \setups{show-contents}}

\def\StartSample#1%
  {\starttext
   \page
   \section{#1}
   \setuptoptexts[][\processedfile\enspace:\enspace\lowercase{#1}]}

\def\StopSample
  {\page
   \setuptoptexts[][]
   \stoptext
   \NextColor}

\endinput

\usemodule[pre-30]

% \TitlePage{Howling to the moon}

\StartSample{Basics}

\startbuffer
\lua{a = 1.5 ; b = 1.8 ; c = a*b ; tex.print(c) ;}

\startlua
    a = 1
    b = 2
    c = a*b
    tex.print(c)
\stoplua
\stopbuffer

\setups{show-usage}

\StopSample
