%D \module
%D   [      file=simpleslides-s-SideToc,
%D        version=2010.02.09,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Presentation Module --- SideToc style,
%D         author=Aditya Mahajan and Thomas A. Schmitz,
%D           date=\currentdate,
%D      copyright={Aditya Mahajan and Thomas A. Schmitz}]
%C
%C Copyright 2010 Aditya Mahajan and Thomas A. Schmitz
%C This file may be distributed under the GNU General Public License v. 2.0.

%D This file provides the \quotation{SideToc} style for the presentation
%D module. It is loaded at runtime. 

\writestatus{simpleslides}{loading Fuzzy Topic style}

\startmodule[simpleslides-s-FuzzyTopic]

\unprotect

%D We create different layouts for the title page, horizontal, and vertical
%D slides.

\setuplayout  [simpleslides:layout:vertical]
	      [leftmargin=0cm,
	      rightmargin=3cm,
              leftmargindistance=0cm,
              rightmargindistance=1.85cm,
              header=0.1cm, 
	      headerdistance=0cm,
              footer=0cm, 
              topspace=1cm, 
              backspace=8mm,
	      cutspace=5.5cm,
              bottomspace=0cm,
              bottom=0pt,
              location=middle]

\setuplayout  [simpleslides:layout:horizontal]
	      [leftmargin=0cm,
	      rightmargin=3cm,
              leftmargindistance=0cm,
              rightmargindistance=1.85cm,
              header=0.1cm, 
	      headerdistance=1.7cm,
              footer=0cm, 
              topspace=1cm, 
              backspace=8mm,
	      cutspace=5.5cm,
              bottomspace=0cm,
              bottom=0pt,
              location=middle]

\setuplayout  [simpleslides:layout:title]
	      [width=fit,
              leftmargin=0cm,
	      rightmargin=0cm,
              height=fit, 
              header=0cm, 
              footer=0cm, 
              topspace=1cm, 
              backspace=1cm,
              bottomspace=0cm,
              bottom=0pt,
              location=middle]

\setupcombinations[distance=0.75cm]

%D The interesting part of this presentation style is the "Topic" list which is
%D typeset in the left margin. It is inspired by something Hans did in
%D s-pre-19. The Difference is that I wanted the Topic to be independent from
%D SlideTitle macro. This way, several slides can be combined into one Topic.

% \definelayer
%   [Topiclayer]
%   [width=2.5cm,
%    height=\paperheight]
% 
% \defineoverlay
%   [simpleslides:background:ornament] 
%   [\setlayer[Topiclayer]{\completelist[MyTopic]}

% \startsetups tlayer
%  \setlayer[Topiclayer]{\completelist[MyTopics]}
%\stopsetups

%D These macros are used for placing figures/pictures:

\define\NormalHeight        {\textheight}
\define\NormalWidth         {.476\textwidth}
\define\PictureFrameHeight  {\textheight}
\define\PictureFrameWidth   {.476\textwidth}

\setuplayer
  [simpleslides:layer:slidetitle]
  [x=1cm,y=2mm]

%D We define our color scheme
\definecolor [simpleslides:contrastcolor]     [r=0.6,g=0,b=0]
\definecolor [simpleslides:backgroundcolor]   [s=0.9]
\definecolor [simpleslides:altcontrastcolor]  [s=0.92]
\definecolor [simpleslides:textcolor]         [s=0]
\definecolor [simpleslides:itemize:color]     [simpleslides:contrastcolor]

%D Here are the main macros for defining and typesetting the Topic list:

\define[3]\FancyEntry{%
  \doifelse \rawstructurelistfirst \MyMark%
  {\framed[width=3cm,height=1cm,frame=off,top=\vss,bottom=\vss,background=simpleslides:current,offset=1mm,align=center]{\switchtobodyfont[11pt]#1}}%
  {\framed[width=3cm,height=1cm,frame=off,top=\vss,bottom=\vss,offset=1mm,align=center]{\switchtobodyfont[11pt]#1}}}

\definelist[MyTopics][criterium=all]

\def\MyMark{}

\definemargindata [TopicMargin] [right] [style=small]

\def\Topic%
%{\relax}
  {\dosingleargument\doTopic}

\def\doTopic[#1]{%
  \gdef\MyMark{#1}%
  \writetolist[MyTopics][location=none]{#1}{}}%

%\def\Topic%
%  {\dosingleargument\doTopic}

%\def\doTopic[#1]{%
%  \gdef\MyMark{#1}%
%  \writetolist[MyTopics]{#1}{}%
%}

\setuplist[MyTopics]
          [pagenumber=no,
	   expansion=yes,
           alternative=command,
           command=\FancyEntry]

\setuptexttexts[margin][][\vbox{\placelist[MyTopics]}]

%D We use \METAPOST to draw the background.

\startuseMPgraphic{simpleslides:MP:title}
StartPage ;
def fuzzy (expr p,dx,dy) =
  (xpart p +dx-uniformdeviate dx,ypart p+dy-uniformdeviate dy)
enddef ;

save a, b, c ; a := 4.7cm ; b := 0.2cm ; c := 4.1cm ;
save dd ; dd := 7 ;
StartPage ;
save ll ; pair ll ; ll := (b, b) ;
save ul ; pair ul ; ul := (b, PaperHeight - b) ;
save ur ; pair ur ; ur := (PaperWidth - b, PaperHeight - b) ;
save lr ; pair lr ; lr := (PaperWidth - b, b) ;
save ple, pto, pri, pbo ; path ple, pto, pri, pbo ; 
fill Page withcolor black ;
pickup pencircle scaled 8pt ;
ple := ul.. for i=.1 step .1 until .9 : fuzzy (i[ul,ll],+dd,0).. endfor ll ; 
pbo := ll.. for i=.1 step .1 until .9 : fuzzy (i[ll,lr],0,+dd).. endfor lr ;
pri := lr.. for i=.1 step .1 until .9 : fuzzy (i[lr,ur],-dd,0).. endfor ur ; 
pto := ur.. for i=.1 step .1 until .9 : fuzzy (i[ur,ul],0,-dd).. endfor ul ;
fill ple & pbo & pri & pto -- cycle withcolor \MPcolor{simpleslides:backgroundcolor} ;
draw pri withcolor \MPcolor{simpleslides:contrastcolor} ;
draw pbo withcolor \MPcolor{simpleslides:contrastcolor} ;
draw pto withcolor \MPcolor{simpleslides:contrastcolor} ;
draw ple withcolor \MPcolor{simpleslides:contrastcolor} ;
StopPage ;
\stopuseMPgraphic

\startuseMPgraphic{simpleslides:MP:horizontal}
def fuzzy (expr p,dx,dy) =
  (xpart p +dx-uniformdeviate dx,ypart p+dy-uniformdeviate dy)
enddef ;

save a, b, c ; a := 4.7cm ; b := 0.2cm ; c := 4.1cm ;
save dd ; dd := 7 ;
StartPage ;
save ll ; pair ll ; ll := (b, b) ;
save ul ; pair ul ; ul := (b, PaperHeight - b) ;
save ur ; pair ur ; ur := (PaperWidth - a, PaperHeight - b) ;
save lr ; pair lr ; lr := (PaperWidth - a, b) ;
save tll ; pair tll ; tll := (PaperWidth - c, b) ;
save tlr ; pair tlr ; tlr := (PaperWidth - b, b) ;
save tul ; pair tul ; tul := (PaperWidth - c, PaperHeight - b) ;
save tur ; pair tur ; tur := (PaperWidth - b, PaperHeight - b) ;
save ple, pto, pri, pbo, sep ; path ple, pto, pri, pbo, sep ; 
save tle, tto, tri, tbo ; path tle, tto, tri, tbo ; 
fill Page withcolor black ;
pickup pencircle scaled 8pt ;
ple := ul.. for i=.1 step .1 until .9 : fuzzy (i[ul,ll],+dd,0).. endfor ll ; 
pbo := ll.. for i=.1 step .1 until .9 : fuzzy (i[ll,lr],0,+dd).. endfor lr ;
pri := lr.. for i=.1 step .1 until .9 : fuzzy (i[lr,ur],-dd,0).. endfor ur ; 
pto := ur.. for i=.1 step .1 until .9 : fuzzy (i[ur,ul],0,-dd).. endfor ul ;
tle := tul.. for i=.1 step .1 until .9 : fuzzy (i[tul,tll],+dd,0).. endfor tll ; 
tbo := tll.. for i=.1 step .2 until .9 : fuzzy (i[tll,tlr],0,+dd).. endfor tlr ;
tri := tlr.. for i=.1 step .1 until .9 : fuzzy (i[tlr,tur],-dd,0).. endfor tur ; 
tto := tur.. for i=.1 step .2 until .9 : fuzzy (i[tur,tul],0,-dd).. endfor tul ;
fill ple & pbo & pri & pto -- cycle withcolor \MPcolor{simpleslides:backgroundcolor} ;
fill tle & tbo & tri & tto -- cycle withcolor \MPcolor{simpleslides:backgroundcolor};
draw textext("\switchtobodyfont[55pt]\color[simpleslides:altcontrastcolor]{\pagenumber}") shifted (19cm, 1.5cm) ;
draw pri withcolor \MPcolor{simpleslides:contrastcolor} ;
draw pbo withcolor \MPcolor{simpleslides:contrastcolor} ;
draw pto withcolor \MPcolor{simpleslides:contrastcolor} ;
draw ple withcolor \MPcolor{simpleslides:contrastcolor} ;
draw tle withcolor \MPcolor{simpleslides:contrastcolor} ;
draw tbo withcolor \MPcolor{simpleslides:contrastcolor} ;
draw tri withcolor \MPcolor{simpleslides:contrastcolor} ;
draw tto withcolor \MPcolor{simpleslides:contrastcolor} ;
z[1] = point 0.14 along ple shifted (8mm, 0) ;
z[2] = point 0.86 along pri shifted (-8mm, 0) ;
sep := z[1].. for i=.1 step .1 until .9 : fuzzy (i[z[1],z[2]],0,+dd).. endfor z[2] ;
draw sep withcolor \MPcolor{simpleslides:contrastcolor} ;
StopPage ;
\stopuseMPgraphic

\startuseMPgraphic{simpleslides:MP:vertical}
def fuzzy (expr p,dx,dy) =
  (xpart p +dx-uniformdeviate dx,ypart p+dy-uniformdeviate dy)
enddef ;

save a, b, c ; a := 4.7cm ; b := 0.2cm ; c := 4.1cm ;
save dd ; dd := 7 ;
StartPage ;
save ll ; pair ll ; ll := (b, b) ;
save ul ; pair ul ; ul := (b, PaperHeight - b) ;
save ur ; pair ur ; ur := (PaperWidth - a, PaperHeight - b) ;
save lr ; pair lr ; lr := (PaperWidth - a, b) ;
save tll ; pair tll ; tll := (PaperWidth - c, b) ;
save tlr ; pair tlr ; tlr := (PaperWidth - b, b) ;
save tul ; pair tul ; tul := (PaperWidth - c, PaperHeight - b) ;
save tur ; pair tur ; tur := (PaperWidth - b, PaperHeight - b) ;
save ple, pto, pri, pbo, sep ; path ple, pto, pri, pbo, sep ; 
save tle, tto, tri, tbo ; path tle, tto, tri, tbo ; 
fill Page withcolor black ;
pickup pencircle scaled 8pt ;
ple := ul.. for i=.1 step .1 until .9 : fuzzy (i[ul,ll],+dd,0).. endfor ll ; 
pbo := ll.. for i=.1 step .1 until .9 : fuzzy (i[ll,lr],0,+dd).. endfor lr ;
pri := lr.. for i=.1 step .1 until .9 : fuzzy (i[lr,ur],-dd,0).. endfor ur ; 
pto := ur.. for i=.1 step .1 until .9 : fuzzy (i[ur,ul],0,-dd).. endfor ul ;
tle := tul.. for i=.1 step .1 until .9 : fuzzy (i[tul,tll],+dd,0).. endfor tll ; 
tbo := tll.. for i=.1 step .2 until .9 : fuzzy (i[tll,tlr],0,+dd).. endfor tlr ;
tri := tlr.. for i=.1 step .1 until .9 : fuzzy (i[tlr,tur],-dd,0).. endfor tur ; 
tto := tur.. for i=.1 step .2 until .9 : fuzzy (i[tur,tul],0,-dd).. endfor tul ;
fill ple & pbo & pri & pto -- cycle withcolor \MPcolor{simpleslides:backgroundcolor} ;
fill tle & tbo & tri & tto -- cycle withcolor \MPcolor{simpleslides:backgroundcolor} ;
draw textext("\switchtobodyfont[55pt]\color[simpleslides:altcontrastcolor]{\pagenumber}") shifted (19cm, 1.5cm) ;
draw pri withcolor \MPcolor{simpleslides:contrastcolor} ;
draw pbo withcolor \MPcolor{simpleslides:contrastcolor} ;
draw pto withcolor \MPcolor{simpleslides:contrastcolor} ;
draw ple withcolor \MPcolor{simpleslides:contrastcolor} ;
draw tle withcolor \MPcolor{simpleslides:contrastcolor} ;
draw tbo withcolor \MPcolor{simpleslides:contrastcolor} ;
draw tri withcolor \MPcolor{simpleslides:contrastcolor} ;
draw tto withcolor \MPcolor{simpleslides:contrastcolor} ;
z[1] = point 0.5 along pto shifted (0, -8mm) ;
z[2] = point 0.5 along pbo shifted (0, 8mm) ;
sep := z[1].. for i=.1 step .1 until .9 : fuzzy (i[z[1],z[2]],+dd,0).. endfor z[2] ;
draw sep withcolor \MPcolor{simpleslides:contrastcolor} ;
StopPage ;
\stopuseMPgraphic

\startuseMPgraphic{FancyFrame}
save p ; path p ;
z[1] = (0, 0) ;
z[2] = z[1] shifted (OverlayWidth, -3pt randomized 6pt) ; 
p := z[1].. for i=.1 step .1 until .8 : fuzzy (i[z[1],z[2]],+dd,0).. endfor z[2] ;
pickup pencircle scaled 5pt ;
draw p withcolor \MPcolor{simpleslides:contrastcolor} ;
setbounds currentpicture to boundingbox OverlayBox ;
\stopuseMPgraphic

\startuseMPgraphic{FancyFrame_2}
save p ; path p ;
z[0] = (0, OverlayHeight/2) ;
z[1] = z[0] shifted (-2.5mm randomized 5mm, -2.5mm randomized 5mm) ;
z[2] = (OverlayWidth/2, OverlayHeight) ;
z[3] = (OverlayWidth, OverlayHeight/2) ;
z[4] = (OverlayWidth/2, 0) ;
z[5] = z[0] shifted (-2.5mm randomized 5mm, -2.5mm randomized 5mm) ;
pickup pencircle scaled 5pt ;
draw z[1] .. z[2] .. z[3] .. z[4] .. z[5] withcolor \MPcolor{simpleslides:contrastcolor} ;
setbounds currentpicture to boundingbox OverlayBox ;
\stopuseMPgraphic

\startuseMPgraphic{FancyFrame_3}
w := OverlayWidth;  width  := 100;  wfactor := w/width;
h := OverlayHeight;  height := 100;  hfactor := h/height;
color lightred;  lightred  := (.90,.50,.50);
color lightgray; lightgray := (.95,.95,.95);
color gray;      gray      := (.50,.50,.50);
     %
def random_delta (expr d) =
  d-(uniformdeviate 2d)
enddef;
     %
z1 = (0,height);
z2 = (0,0);
z3 = (width,0);
z4 = (width,height);
%
z5 = (width+random_delta(.2width),height+random_delta(.2height));
z6 = (.5width+random_delta(.1width),height+random_delta(.1height));
%
pickup pencircle
  xscaled (15pt/wfactor)
  yscaled (15pt/(2*hfactor))
  rotated 30;
     %
draw z5..z1..z2..z3..z4..z6 withcolor \MPcolor{simpleslides:contrastcolor};
%
newwidth  := (xpart (urcorner currentpicture)) -
             (xpart (llcorner currentpicture));
newheight := (ypart (urcorner currentpicture)) -
             (ypart (llcorner currentpicture));
%
currentpicture := currentpicture
  xscaled (w/newwidth) yscaled (h/newheight);
\stopuseMPgraphic

%D We define these backgrounds as overlays:

\defineoverlay
  [simpleslides:background:horizontal]
  [\useMPgraphic{simpleslides:MP:horizontal}]

\defineoverlay
  [simpleslides:background:vertical]
  [\useMPgraphic{simpleslides:MP:vertical}]

\defineoverlay 
  [simpleslides:background:title] 
  [\useMPgraphic{simpleslides:MP:title}] 

\defineoverlay[simpleslides:current][\useMPgraphic{FancyFrame_3}]

%D We want the title to placed in color. 

\setupTitle
  [\c!title=,
   \c!author=,
   \c!date=\currentdate,
   \c!headstyle=,
   \c!headcolor={simpleslides:contrastcolor},
   \c!align=\v!middle,
   \c!before=\vfill,
   \c!after=\vfill,
   \c!title\c!style={\switchtobodyfont[\TitleSize]},
   \c!title\c!color=simpleslides:contrastcolor,
   \c!title\c!align=\v!middle,
   \c!author\c!style=,
   \c!author\c!color={simpleslides:contrastcolor},
   \c!author\c!align=\v!middle, 
   \c!date\c!style=,
   \c!date\c!color={simpleslides:contrastcolor},
   \c!date\c!align=\v!middle,
   \c!before\c!title=,
   \c!before\c!author=,
   \c!before\c!date=,
   \c!after\c!title={\blank[1*line]},
   \c!after\c!author={\blank[2*line]},
   \c!after\c!date=]

%D We want the slide title on the top

\setupSlideTitle
   [\c!after=,
    \c!alternative=layer,
    \c!width=\textwidth,
    \c!height=2.5cm,
    \c!color=black]

%D The symbol for the first level of itemizations. 

\definesymbol[1][\useMPgraphic{simpleslides:itemize:square}]
%\setupitemize[1][inmargin][color=simpleslides:backgroundcolor]

\protect
\stopmodule

\endinput

