%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 In this style the table of contents is a bunch of rectangular blobs. The layout
%D adapts itself upto 25 pages. This style was made for Bacho\TeX\ 2013.

\startmodule[present-tiles]

\setupbodyfont[pagella,14.4pt]

\setuppapersize[S6][S6]

\definecolor[maincolor] [.50(darkblue,darkgreen)]
\definecolor[othercolor][.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=maincolor,
   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=othercolor]
\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=othercolor]

\startsetups [document:titlepage]

    \definebodyfontenvironment
      [\measure{titlepagefont}]

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

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

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

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

    \startcontentmakeup[reference=menupage]

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

    \stopcontentmakeup

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

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

\stopsetups

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

\stopmodule

\continueifinputfile{s-present-tiles.mkiv}

\usemodule[present-common]

%inputpresentationfile{examples/present-tiles-001.tex}
%inputpresentationfile{context/2013/context-2013-speed.tex}
\inputpresentationfile{context/2013/context-2013-math.tex}
%inputpresentationfile{bachotex/2013/bachotex-2013-bits.tex}
%inputpresentationfile{bachotex/2013/bachotex-2013-bits.pdf}
%inputpresentationfile{bachotex/2013/bachotex-2013-luatex.tex}
%inputpresentationfile{bachotex/2013/bachotex-2013-luatex.pdf}
%inputpresentationfile{bachotex/2013/bachotex-2013-sense.tex}
%inputpresentationfile{bachotex/2013/bachotex-2013-sense.pdf}
%inputpresentationfile{bachotex/2013/bachotex-2013-speed.tex}
%inputpresentationfile{bachotex/2013/bachotex-2013-speed.pdf}
