%D \module
%D   [      file=s-present-tiles, % was s-pre-41
%D        version=2013.03.24,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Presentation Environment Tiles,
%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.

%D The Bacho\TeX\ 2013 style.

\setupbodyfont[pagella,14.4pt]

\setuppapersize[S6][S6]

\definecolor[primarycolor]  [.50(darkblue,darkgreen)]
\definecolor[secondarycolor][.25(darkblue,darkyellow)]
\definecolor[mixedcolor]    [s=.35]

\setupcolors
  [textcolor=white]

\setupalign
  [flushleft,nothyphenated]

\definemeasure[layoutunit][\dimexpr\paperheight/25]

\setuplayout
  [backspace=\measured{layoutunit},
   topspace=\measured{layoutunit},
   width=middle,
   height=middle,
   header=0pt,
   footer=0pt]

\definelayout
  [content]
  [backspace=.5\measured{layoutunit},
   topspace=.5\measured{layoutunit}]

\definemeasure [topiclistwidth] [
    (\textwidth+\backspace)/
    \ifcase\numexpr\structurelistsize\relax 1 %  0
    \or1\or1\or1\or2\or1\or3\or3\or3\or3      %  1 -  9
    \or3\or3\or3\or3\or3\or3\or4              % 10 - 16
    \or4\or4\or4\or4\or                       % 17 - 20
    \else5                                    % 21 - 25
    \fi
    -\backspace
]

\definemeasure [topiclistheight] [
    (\textheight+\topspace)/
    \ifcase\numexpr\structurelistsize\relax 1 %  0
    \or1\or2\or3\or2\or5\or2\or3\or3\or3      %  1 -  9
    \or4\or4\or4\or4\or4\or4\or4              % 10 - 16
    \or5\or5\or5\or5\or5                      % 17 - 20
    \else5                                    % 21 - 25
    \fi
    -\topspace
]

\definemeasure [topiclistfontsize] [
    \ifcase\numexpr\structurelistsize\relax 2.5            %  0
    \or1.4\or1.4\or1.4\or1.4\or1.4\or1.4\or1.4\or1.4\or1.4 %  1 -  9
    \or1.3\or1.3\or1.3\or1.3\or1.3\or1.3\or1.3             % 10 - 16
    \or1.2\or1.2\or1.2\or1.2\or1.2                         % 17 - 20
    \else1                                                 % 21 - 25
    \fi
    \bodyfontsize
]

\definemeasure [topiclistfont]  [\measured{topiclistfontsize}]
\definemeasure [topictitlefont] [1.2\measured{layoutunit}]
\definemeasure [titlepagefont]  [2\measured{layoutunit}]

\predefinefont[MyTopicTitleFont][SerifBold*default at \measure{topictitlefont}]
\predefinefont[MyTopicListFont] [SerifBold*default at \measure{topiclistfont}]

\defineframed
  [topiclistentry]
  [width=\measure{topiclistwidth},
   height=\measure{topiclistheight},
   background=color,
   frame=off,
   foregroundstyle=MyTopicListFont,
   backgroundcolor=primarycolor,
   foregroundcolor=white]

\setupwhitespace
  [big]

\setupblank
  [big]

\setupinteraction
 [state=start,
  color=,
  contrastcolor=,
  click=off]

\definemakeup
  [topic]
  [standard]
  [top=,bottom=]

\definemakeup
  [content]
  [standard]
  [top=,bottom=]

\startsetups[topic:start]
    \starttopicmakeup
\stopsetups

\startsetups[topic:stop]
    \vfill
    \stoptopicmakeup
\stopsetups

\definehead
  [topic]
  [chapter]
  [before=,
   style=MyTopicTitleFont,
   page=,
   number=off,
   interaction=list,
   beforesection=\directsetup{topic:start},
   aftersection=\directsetup{topic:stop}]

\setuplist
  [topic]
  [alternative=topic,
   interaction=all]

\definelistalternative
  [topic]
  [alternative=horizontal,
   renderingsetup=topic:list]

\startsetups[topic:list]
    \dontleavehmode
    \startcurrentlistentrywrapper
        \topiclistentry{\currentlistentrytitle}
    \stopcurrentlistentrywrapper
    \blankspace
\stopsetups

\defineoverlay[nextpage][\overlaybutton{nextpage}]
\defineoverlay[prevpage][\overlaybutton{prevpage}]
\defineoverlay[menupage][\overlaybutton{menupage}]
\defineoverlay[homepage][\overlaybutton{homepage}]

\setupbackgrounds
  [text]
  [backgroundoffset=.5\measured{layoutunit}]

% begin of buttons

\defineframed
  [bb]
  [width=\dimexpr\overlaywidth/10,
   height=\dimexpr\overlayheight/10,
   background=color,
   foregroundstyle=\bfa,
   frame=off]

\defineframed[nb] [bb] [empty=yes]
\defineframed[rb] [bb] [backgroundcolor=white,foregroundcolor=secondarycolor]
\defineframed[db] [bb] [backgroundcolor=mixedcolor,foregroundcolor=white]

\definepushbutton [prev]
\definepushbutton [next]
\definepushbutton [menu]
\definepushbutton [home]

\definepushsymbol [prev] [n] [\nb{prev}]
\definepushsymbol [prev] [r] [\rb{prev}]
\definepushsymbol [prev] [d] [\db{prev}]

\definepushsymbol [next] [n] [\nb{next}]
\definepushsymbol [next] [r] [\rb{next}]
\definepushsymbol [next] [d] [\db{next}]

\definepushsymbol [menu] [n] [\nb{menu}]
\definepushsymbol [menu] [r] [\rb{menu}]
\definepushsymbol [menu] [d] [\db{menu}]

\definepushsymbol [home] [n] [\nb{home}]
\definepushsymbol [home] [r] [\rb{home}]
\definepushsymbol [home] [d] [\db{home}]

\definelayer
  [buttons]
  [width=\dimexpr\textwidth+\measured{layoutunit}\relax,
   height=\dimexpr\textheight+\measured{layoutunit}\relax] % a setups

\startsetups [document:buttons]

    \setlayer
        [buttons]
        [preset=leftbottom,offset=-.25\measured{layoutunit}]
        {\pushbutton[prev][previouspage]}

    \setlayer
        [buttons]
        [preset=rightbottom,offset=-.25\measured{layoutunit}]
        {\pushbutton[next][nextpage]}

    \setlayer
        [buttons]
        [preset=lefttop,offset=-.25\measured{layoutunit}]
        {\pushbutton[home][homepage]}

    \setlayer
        [buttons]
        [preset=righttop,offset=-.25\measured{layoutunit}]
        {\pushbutton[menu][menupage]}

\stopsetups

\defineoverlay[setbuttons][\directsetup{document:buttons}]

% end of buttons

\defineframed
  [conclusion]
  [location=low,
   width=max,
   align={flushleft,lohi},
   background=color,
   backgroundcolor=white,
   foregroundcolor=secondarycolor]

\startsetups [document:titlepage]

    \definebodyfontenvironment
      [\measure{titlepagefont}]

    \setupbackgrounds
      [page]
      [background={color,menupage},
       backgroundcolor=secondarycolor]

    \setupbackgrounds
      [text]
      [background={color,menupage},
       backgroundcolor=secondarycolor]

    \starttopicmakeup[reference=homepage]

        \switchtobodyfont[\measure{titlepagefont}]

        \let\\=\crlf

        \startalignment[flushleft]
            \bf
            \setupinterlinespace
            \begstrut\getvariable{document}{title}\endstrut\par
        \stopalignment

        \vfill

        \startalignment[flushright]
            \bf
            \setupinterlinespace
            \begstrut\getvariable{document}{subtitle}\endstrut\par
        \stopalignment

    \stoptopicmakeup

    \setupbackgrounds
      [page]
      [background={color,homepage},
       backgroundcolor=secondarycolor]

    \setupbackgrounds
      [text]
      [background={color,menupage},
       backgroundcolor=secondarycolor]

    \startcontentmakeup[reference=menupage]

        \setupalign[tolerant,stretch,paragraph]
        \flexiblebaselines
        \placelist[topic][criterium=text]

    \stopcontentmakeup

    \setupbackgrounds
      [page]
    % [background={color,menupage},
      [background={color,invoke},
       backgroundcolor=primarycolor]

    \setupbackgrounds
      [text]
    % [background={color,nextpage,setbuttons,buttons},
      [background={color,setbuttons,buttons},
       backgroundcolor=secondarycolor]

\stopsetups

\setupdocument
  [before=\directsetup{document:titlepage}]

\continueifinputfile{s-present-tiles.mkiv}

\startdocument[title=Whatever We\\Want Here,subtitle=Whatever We\\Want There]

    \dorecurse{12}{\starttopic[title=Topic #1]\input tufte \stoptopic}

\stopdocument
