% -*- coding: utf-8 -*-

\ProvidesPackage{beamerthemeepyt}[2016/05/25 v1.0]

\makeatletter

%%% presentation mode

\mode<presentation>

\def\beamer@epyt@style{default}
\DeclareOptionBeamer{style}[default]{\def\beamer@epyt@style{#1}}
\ProcessOptionsBeamer

%% basic settings

\setlength{\parskip}{5pt plus 1pt minus 1pt}

\setbeamersize{text margin left=8mm,text margin right=8mm}
%\geometry{hmargin=1em,vmargin=0em}

%% -------------------- outer templates --------------------

% make "vertical shading" modifiable in the middle of the document
% see beamerbaseauxtemplates.sty for the original code

\define@key{epyt@backgroundshade}{bottom}{\def\epyt@bgsb{#1}}
\define@key{epyt@backgroundshade}{middle}{\def\epyt@bgsm{#1}}
\define@key{epyt@backgroundshade}{top}{\def\epyt@bgst{#1}}
\define@key{epyt@backgroundshade}{midpoint}{\def\epyt@bgsmp{#1}}

\defbeamertemplate{background canvas}{myshading}[1][]
{%
  \setkeys{epyt@backgroundshade}{middle={},midpoint=0.5}%
  \setkeys{epyt@backgroundshade}{#1}%
  \pgfdeclareverticalshading[\epyt@bgsb,\epyt@bgsm,\epyt@bgst]%
    {epyt@backgroundshading}{\the\paperwidth}%
    {color(0cm)=(\epyt@bgsb);
     color(\epyt@bgsmp\paperheight)=(\epyt@bgsm);
     color(\the\paperheight)=(\epyt@bgst)}%
  \pgfuseshading{epyt@backgroundshading}%
}

\defbeamertemplate{frametitle}{simple}
{%
  \begingroup\offinterlineskip
  \begin{beamercolorbox}[wd=\paperwidth,leftskip=\beamer@leftmargin]{frametitle}
    \vskip6pt
    \noindent\usebeamerfont{frametitle}\strut\insertframetitle\strut\par
    \vskip4pt
  \end{beamercolorbox}
  \endgroup
}

\defbeamertemplate{footline}{simple}
{
  \hbox{%
  \begin{beamercolorbox}[wd=.2\paperwidth,ht=2.25ex,dp=1ex,left]{footline}%
    \usebeamerfont{footline}\hspace*{\beamer@leftmargin}%
    \Acrobatmenu{GoToPage}{\insertframenumber{}/\inserttotalframenumber}
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.6\paperwidth,ht=2.25ex,dp=1ex,center]{footline}%
    \usebeamerfont{footline}\insertshorttitle
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.2\paperwidth,ht=2.25ex,dp=1ex,right]{footline}%
    \usebeamerfont{footline}%
    \hyperlinkframeendprev{$\vartriangle$}\hspace*{1ex}\hyperlinkframestartnext{$\triangledown$}%
    \hspace*{\beamer@rightmargin}
  \end{beamercolorbox}%
  }%
}

%% -------------------- inner template --------------------

\defbeamertemplate{title separator one}{simple}{%
  \hbox to \hsize{\hrulefill}%
}
\defbeamertemplate{title separator one}{triangle}{
  \hbox to \hsize{%
    \tiny\leaders\hbox to 1em{\hss$\triangleright$\hss}\hfill
  }%
}

\defbeamertemplate{title separator two}{simple}{
  \hbox to \hsize{\hrulefill}%
}
\defbeamertemplate{title separator two}{triangle}{
  \hbox to \hsize{%
    \tiny\leaders\hbox to 1em{\hss$\triangleleft$\hss}\hfill
  }%
}

\defbeamertemplate{title page}{simple}[1][]{
  \begin{beamercolorbox}[#1]{title}
    \usebeamerfont{title}\inserttitle
  \end{beamercolorbox}
  \ifx\insertsubtitle\@empty\else
  \vskip0.7em
    \begin{beamercolorbox}[#1]{subtitle}
      \usebeamerfont{subtitle}\insertsubtitle
    \end{beamercolorbox}
  \fi%
  \vskip18pt{%
    \usebeamercolor[fg]{title separator one}\usebeamertemplate{title separator one}%
  }\vskip18pt
  \begin{beamercolorbox}[#1]{author}
    \usebeamerfont{author}\insertauthor
  \end{beamercolorbox}
  \ifx\insertinstitute\@empty\else
  \vskip0.7em
    \begin{beamercolorbox}[#1]{institute}
      \usebeamerfont{institute}\insertinstitute
    \end{beamercolorbox}
  \fi%
  \vskip18pt{%
    \usebeamercolor[fg]{title separator two}\usebeamertemplate{title separator two}%
  }\vskip18pt
  \begin{beamercolorbox}[#1]{date}
  \usebeamerfont{date}\insertdate
  \end{beamercolorbox}
}

% sections and subsections

% create new template for section
\defbeamertemplate{section}{simple}{%
  \insertsectionnumber.\hspace*{1ex}\insertsection%
}

\AtBeginSection[]{\frame[plain]{\sectionpage}}

\defbeamertemplate{section page}{simple}{
  \begin{beamercolorbox}[wd=\textwidth,center]{section title}%
    \usebeamerfont{section title}
    \usebeamertemplate{section}%
  \end{beamercolorbox}
  {%
    \usebeamercolor[fg]{title separator one}%
    \usebeamertemplate{title separator one}%
  }%
}

% create new template for subsection
\defbeamertemplate{subsection}{simple}{%
  \insertsectionnumber.\insertsubsectionnumber\hspace*{2ex}\insertsubsection%
}

\AtBeginSubsection[]{\frame[plain]{\subsectionpage}}

\defbeamertemplate{subsection page}{simple}{
  \begin{beamercolorbox}[wd=\textwidth,center]{subsection title}%
  \usebeamerfont{subsection title}%
  \usebeamertemplate{subsection}%
  \end{beamercolorbox}%
  {%
    \usebeamercolor[fg]{title separator one}%
    \usebeamertemplate{title separator one}%
  }%
}

\defbeamertemplate{subsection in toc}{triangle}{%
  \leavevmode\leftskip=2.5em\scriptsize\raise1.25pt%
  \rlap{\hskip-1.5em\donotcoloroutermaths$\blacktriangleright$}%
  \normalsize\inserttocsubsection\par
}

% disable block style for theorems

\defbeamertemplate{theorem begin}{simple}
{%
  \upshape%\bfseries\inserttheoremheadfont
  {\usebeamercolor[fg]{theoremname}%
  \inserttheoremname\inserttheoremnumber
  \ifx\inserttheoremaddition\@empty\else\ (\inserttheoremaddition)\fi%
  %\inserttheorempunctuation
  }%
  \quad\normalfont
}
\defbeamertemplate{theorem end}{simple}{\par}

\defbeamertemplate{proof begin}{simple}
{%
  %\bfseries
  {\usebeamercolor[fg]{proofname}\insertproofname}%
  \quad\normalfont
}
\defbeamertemplate{proof end}{simple}{\par}

%% -------------------- font theme --------------------

\setbeamerfont{title}{size=\LARGE}
\setbeamerfont{subtitle}{size=\large}
\setbeamerfont{author}{size=\large}
\setbeamerfont{institute}{size=\normalsize}
\setbeamerfont{date}{size=\large}
\setbeamerfont{section in toc}{size=\large}
\setbeamerfont{subsection in toc}{size=\normalsize}
\setbeamerfont{frametitle}{size=\large}
\setbeamerfont{block title}{size=\normalsize}

\usefonttheme{professionalfonts} % there is some problem with default math fonts
\usepackage{arev} % use arev sans font

%% -------------------- color theme --------------------

\def\beamer@epyt@style@do@alpha{
  \definecolor{gray1}{gray}{0.1}
  \definecolor{red69}{HTML}{E55C5C}
  \definecolor{yellow69}{HTML}{E5E55C}
  \definecolor{yellow99}{HTML}{E6E617}
  \definecolor{green69}{HTML}{5CE55C}
  \definecolor{cyan69}{HTML}{5CE6E5}
  \definecolor{azure39}{HTML}{A1C3E5}
  \definecolor{magenta69}{HTML}{E55CE5}
  \colorlet{fgcolor}{white}
  \colorlet{bgcolor}{black}
  \colorlet{acolor1}{yellow69}
  \colorlet{acolor2}{green69}
  \colorlet{acolor3}{red69}
  \colorlet{acolor4}{cyan69}
  \colorlet{acolor5}{magenta69}
  \setbeamercolor{normal text}{bg=black,fg=white}
  \setbeamercolor{structure}{fg=yellow99}
  \setbeamercolor{local structure}{fg=azure39}
  \setbeamercolor{footline}{bg=,fg=white}
  \setbeamertemplate{background canvas}[myshading][top=black,middle=gray1,bottom=darkgray]
  \setbeamertemplate{background}[grid][step=1mm,color=fgcolor!10!bgcolor]
  \setbeamertemplate{footline}[simple]
  \setbeamertemplate{title separator one}[triangle]
  \setbeamertemplate{title separator two}[triangle]
  \setbeamertemplate{title page}[simple][left]
  \setbeamertemplate{section page}[simple]
  \setbeamertemplate{subsection page}[simple]
  \setbeamertemplate{theorem begin}[default]
  \setbeamertemplate{theorem end}[default]
  \setbeamertemplate{proof begin}[default]
  \setbeamertemplate{proof end}[default]
}
\def\beamer@epyt@style@do@beta{
  \definecolor{red99}{HTML}{E61717}
  \definecolor{yellow86}{HTML}{99991F}
  \definecolor{cyan95}{HTML}{0D8080}
  \definecolor{blue77}{HTML}{3636B2}
  \definecolor{blue99}{HTML}{1717E6}
  \definecolor{magenta88}{HTML}{CC29CC}
  \colorlet{fgcolor}{black}
  \colorlet{bgcolor}{white}
  \colorlet{acolor1}{blue99}
  \colorlet{acolor2}{cyan95}
  \colorlet{acolor3}{red99}
  \colorlet{acolor4}{yellow86}
  \colorlet{acolor5}{magenta88}
  \setbeamercolor{normal text}{bg=white,fg=black}
  \setbeamercolor{structure}{fg=blue99}
  \setbeamercolor{local structure}{fg=cyan95}
  \setbeamercolor{footline}{bg=blue77,fg=white}
  \setbeamertemplate{background canvas}[default]
  \setbeamertemplate{background}[grid][step=1mm,color=fgcolor!10!bgcolor]
  \setbeamertemplate{footline}[simple]
  \setbeamertemplate{title separator one}[triangle]
  \setbeamertemplate{title separator two}[triangle]
  \setbeamertemplate{title page}[simple][center]
  \setbeamertemplate{section page}[simple]
  \setbeamertemplate{subsection page}[simple]
  \setbeamertemplate{theorem begin}[simple]
  \setbeamertemplate{theorem end}[simple]
  \setbeamertemplate{proof begin}[simple]
  \setbeamertemplate{proof end}[simple]
}
\def\beamer@epyt@style@do@delta{
  \definecolor{red69}{HTML}{E55C5C}
  \definecolor{yellow69}{HTML}{E5E55C}
  \definecolor{yellow99}{HTML}{E6E617}
  \definecolor{green69}{HTML}{5CE55C}
  \definecolor{cyan69}{HTML}{5CE6E5}
  \definecolor{azure39}{HTML}{A1C3E5}
  \definecolor{blue77}{HTML}{3636B2}
  \definecolor{blue88}{HTML}{2929CC}
  \definecolor{blue97}{HTML}{1212B3}
  \definecolor{magenta69}{HTML}{E55CE5}
  \definecolor{purple94}{HTML}{660A38}
  \colorlet{fgcolor}{white}
  \colorlet{bgcolor}{blue77}
  \colorlet{acolor1}{yellow69}
  \colorlet{acolor2}{green69}
  \colorlet{acolor3}{red69}
  \colorlet{acolor4}{cyan69}
  \colorlet{acolor5}{magenta69}
  \setbeamercolor{normal text}{bg=blue77,fg=white}
  \setbeamercolor{structure}{fg=yellow99}
  \setbeamercolor{local structure}{fg=azure39}
  \setbeamercolor{footline}{bg=purple94,fg=white}
  \setbeamercolor{navigation symbols}{bg=purple94}
  \setbeamercolor{navigation symbols dimmed}{fg=purple94}
  \setbeamertemplate{background canvas}[myshading][top=blue97,middle=blue77,bottom=blue97]
  \setbeamertemplate{background}[grid][step=1mm,color=blue88]
  \setbeamertemplate{footline}[simple]
  \setbeamertemplate{title separator one}[simple]
  \setbeamertemplate{title separator two}[simple]
  \setbeamertemplate{title page}[simple][center]
  \setbeamertemplate{section page}[simple]
  \setbeamertemplate{subsection page}[simple]
  \setbeamertemplate{theorem begin}[simple]
  \setbeamertemplate{theorem end}[simple]
  \setbeamertemplate{proof begin}[simple]
  \setbeamertemplate{proof end}[simple]
}
\def\beamer@epyt@style@do@gamma{
  \definecolor{red69}{HTML}{E55C5C}
  \definecolor{brown96}{HTML}{99540F}
  \definecolor{yellow69}{HTML}{E5E55C}
  \definecolor{green33}{HTML}{364D36}
  \definecolor{green39}{HTML}{A1E5A1}
  \definecolor{green53}{HTML}{264D26}
  \definecolor{green69}{HTML}{5CE55C}
  \definecolor{cyan69}{HTML}{5CE6E5}
  \definecolor{magenta69}{HTML}{E55CE5}
  \colorlet{fgcolor}{white}
  \colorlet{bgcolor}{green33}
  \colorlet{acolor1}{yellow69}
  \colorlet{acolor2}{green69}
  \colorlet{acolor3}{red69}
  \colorlet{acolor4}{cyan69}
  \colorlet{acolor5}{magenta69}
  \setbeamercolor{normal text}{bg=green33,fg=white}
  \setbeamercolor{structure}{fg=yellow}
  \setbeamercolor{local structure}{fg=green39}
  \setbeamercolor{footline}{bg=brown96,fg=white}
  \setbeamercolor{navigation symbols}{bg=brown96}
  \setbeamercolor{navigation symbols dimmed}{fg=brown96}
  \setbeamertemplate{background canvas}[default]
  \setbeamertemplate{background}[grid][step=1mm,color=green53]
  \setbeamertemplate{footline}[simple]
  \setbeamertemplate{title separator one}[triangle]
  \setbeamertemplate{title separator two}[triangle]
  \setbeamertemplate{title page}[simple][center]
  \setbeamertemplate{section page}[simple]
  \setbeamertemplate{subsection page}[simple]
  \setbeamertemplate{theorem begin}[default]
  \setbeamertemplate{theorem end}[default]
  \setbeamertemplate{proof begin}[default]
  \setbeamertemplate{proof end}[default]
}
\def\beamer@epyt@style@do@zeta{
  \definecolor{red85}{HTML}{801919}
  \definecolor{red87}{HTML}{B32424}
  \definecolor{yellow69}{HTML}{E5E55C}
  \definecolor{yellow99}{HTML}{E6E617}
  \definecolor{green69}{HTML}{5CE55C}
  \definecolor{cyan69}{HTML}{5CE6E5}
  \definecolor{blue5x}{HTML}{8080FF}
  \definecolor{magenta6x}{HTML}{FF66FF}
  \colorlet{fgcolor}{white}
  \colorlet{bgcolor}{red87}
  \colorlet{acolor1}{yellow69}
  \colorlet{acolor2}{green69}
  \colorlet{acolor3}{magenta6x}
  \colorlet{acolor4}{cyan69}
  \colorlet{acolor5}{blue5x}
  \setbeamercolor{normal text}{bg=red87,fg=white}
  \setbeamercolor{structure}{fg=yellow99}
  \setbeamercolor{local structure}{fg=yellow99}
  \setbeamercolor{footline}{bg=black,fg=white}
  \setbeamercolor{navigation symbols}{bg=black}
  \setbeamercolor{navigation symbols dimmed}{fg=black}
  \setbeamertemplate{background canvas}[myshading][top=red85,middle=red87,bottom=red85]
  \setbeamertemplate{background}[grid][step=1mm,color=fgcolor!10!bgcolor]
  \setbeamertemplate{footline}[simple]
  \setbeamertemplate{title separator one}[simple]
  \setbeamertemplate{title separator two}[simple]
  \setbeamertemplate{title page}[simple][left]
  \setbeamertemplate{section page}[simple]
  \setbeamertemplate{subsection page}[simple]
  \setbeamertemplate{theorem begin}[default]
  \setbeamertemplate{theorem end}[default]
  \setbeamertemplate{proof begin}[default]
  \setbeamertemplate{proof end}[default]
}
\let\beamer@epyt@style@do@default=\beamer@epyt@style@do@beta

\def\beamer@epyt@style@do@common{
  \colorlet{fcolor1}{acolor1!50!bgcolor}
  \colorlet{fcolor2}{acolor2!50!bgcolor}
  \colorlet{fcolor3}{acolor3!50!bgcolor}
  \colorlet{fcolor4}{acolor4!50!bgcolor}
  \colorlet{fcolor5}{acolor5!50!bgcolor}
  \setbeamercolor{title separator one}{fg=fgcolor!50!bgcolor}
  \setbeamercolor{title separator two}{fg=fgcolor!50!bgcolor}
  \setbeamercolor{title}{use=structure,fg=structure.fg}
  \setbeamercolor{subtitle}{use={structure,normal text},fg=structure.fg!90!normal text.bg}
  \setbeamercolor{section in toc}{parent=title}
  \setbeamercolor{subsection in toc}{parent=subtitle}
  \setbeamercolor{section in toc shaded}{parent=normal text}
  \setbeamercolor{subsection in toc shaded}{parent=normal text}
  \setbeamercolor{frametitle}{parent=title}
  \setbeamercolor{theoremname}{parent=subtitle}
  \setbeamercolor{proofname}{parent=subtitle}
  \setbeamercolor{block title}{fg=acolor1,bg=darkgray}
  \setbeamercolor{block body}{bg=gray}
  \setbeamercolor{block title example}{fg=acolor2,bg=darkgray}
  \setbeamercolor{block body example}{bg=gray}
  \setbeamercolor{block title alerted}{fg=acolor3,bg=darkgray}
  \setbeamercolor{block body alerted}{bg=gray}
  \setbeamertemplate{frametitle}[simple]
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{section}[simple]
  \setbeamertemplate{subsection}[simple]
  \setbeamertemplate{section in toc}[sections numbered]
  \setbeamertemplate{subsection in toc}[triangle]
  \setbeamertemplate{section in toc shaded}[default][100]
  \setbeamertemplate{subsection in toc shaded}[default][100]
  \setbeamertemplate{itemize items}[default]
  \setbeamertemplate{enumerate items}[default]
}

%% apply user selected theme at last

\def\beamer@epyt@style@do{%
  \expandafter\let\expandafter\next
    \csname beamer@epyt@style@do@\beamer@epyt@style\endcsname
  \ifx\next\relax \let\next\beamer@epyt@style@do@default \fi
  \next
  \beamer@epyt@style@do@common
  % need this when switching color themes in the middle of the document
  \usebeamercolor[fg]{normal text}%
  %\renewcommand{\normalcolor}{\color{normal text.fg}}%
}

\beamer@epyt@style@do

\RequirePackage{xkeyval}
\define@key{epytsetup}{style}{\def\beamer@epyt@style{#1}}
\newcommand{\epytsetup}[1]{%
  \setkeys{epytsetup}{#1}%
  \beamer@epyt@style@do
}

%% empty background colors for handout

\mode<handout>{
  \setbeamertemplate{background canvas}{}
  \setbeamertemplate{background}{}
  \setbeamercolor{normal text}{fg=black, bg=white}
  \setbeamercolor{title}{fg=blue}
  \setbeamercolor{subtitle}{fg=blue!70!gray}
  \setbeamercolor{section in toc}{fg=blue!90!gray}
  \setbeamercolor{subsection in toc}{fg=blue!80!gray}
  \setbeamercolor{frametitle}{fg=blue!70!gray,bg=white}
  \setbeamercolor{theoremname}{fg=blue!60!gray}
  \setbeamercolor{proofname}{fg=blue!60!gray}
  \setbeamercolor{footline}{bg=white,fg=black}
}

\mode
<all>

\makeatother
