% -*- coding: utf-8 -*-
%
% Package epyt: a simple and clean theme for LaTeX beamer class
% Copyright (C) 2013-2015 Zou Hu <zohooo@yeah.net>
%
% Please report bugs, problems, and suggestions via
%     https://github.com/zohooo/epyt
%
% The package may be distributed and/or modified under the conditions
% of the LaTeX Project Public License, either version 1.3 of this
% license or (at your option) any later version. The latest version
% of this license is in
%     http://www.latex-project.org/lppl.txt

\ProvidesPackage{beamerthemeepyt}[2015/03/24 v0.6]

\makeatletter

\mode<presentation>

\def\beamer@epyt@color{white}
\DeclareOptionBeamer{color}[white]{\def\beamer@epyt@color{#1}}
\ProcessOptionsBeamer

%% basic settings

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

%% define some 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}{epyt shading}[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}%
}

%% color theme

\definecolor{dgray}{HTML}{202020}
\definecolor{lgray}{HTML}{404040}
\definecolor{dblue}{HTML}{3333B2}
\definecolor{tblue}{HTML}{000099}
\definecolor{gblue}{HTML}{0033CC}
\definecolor{lblue}{HTML}{ABCDEF}
\definecolor{dred}{HTML}{660033}
\definecolor{dgreen}{HTML}{254535}
\definecolor{ggreen}{HTML}{214131}
\definecolor{lgreen}{HTML}{A9EFA9}
\definecolor{dorange}{HTML}{C07000}

\def\beamer@epyt@color@do@white{
  \setbeamercolor{normal text}{bg=white,fg=black}
  \setbeamertemplate{background canvas}[default]
  \setbeamertemplate{background}[default]
  \setbeamercolor{structure}{fg=blue}
  \setbeamercolor{local structure}{fg=teal}
  \setbeamercolor{footline}{bg=dblue,fg=white}
}
\def\beamer@epyt@color@do@blue{
  \setbeamercolor{normal text}{bg=dblue,fg=white}
  \setbeamertemplate{background canvas}[epyt shading][top=tblue,middle=dblue,bottom=tblue]
  \setbeamertemplate{background}[grid][step=1mm,color=gblue]
  \setbeamercolor{structure}{fg=yellow}
  \setbeamercolor{local structure}{fg=lblue}
  \setbeamercolor{footline}{bg=dred,fg=white}
  \setbeamercolor{navigation symbols}{bg=dred}
  \setbeamercolor{navigation symbols dimmed}{fg=dred}
}
\def\beamer@epyt@color@do@green{
  \setbeamercolor{normal text}{bg=dgreen,fg=white}
  \setbeamertemplate{background canvas}[default]
  \setbeamertemplate{background}[grid][step=1mm,color=ggreen]
  \setbeamercolor{structure}{fg=yellow}
  \setbeamercolor{local structure}{fg=lgreen}
  \setbeamercolor{footline}{bg=dorange,fg=white}
  \setbeamercolor{navigation symbols}{bg=dorange}
  \setbeamercolor{navigation symbols dimmed}{fg=dorange}
}
\def\beamer@epyt@color@do@black{
  \setbeamercolor{normal text}{bg=black,fg=white}
  \setbeamertemplate{background canvas}[epyt shading][top=black,middle=dgray,bottom=lgray]
  \setbeamertemplate{background}[default]
  \setbeamercolor{structure}{fg=yellow}
  \setbeamercolor{local structure}{fg=lblue}
  \setbeamercolor{footline}{bg=,fg=white}
}

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

\beamer@epyt@color@do

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

\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{frametitle}{parent=title}
\setbeamercolor{theoremname}{parent=subtitle}
\setbeamercolor{proofname}{parent=subtitle}

%% 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=\large}
\setbeamerfont{frametitle}{size=\large}

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

%% inner theme

\setbeamertemplate{itemize items}[default]
\setbeamertemplate{enumerate items}[default]

\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}{}

% sections and subsections

\AtBeginSection[]{
\begin{frame}
  \begin{center}
    \usebeamerfont{section in toc}
    \tableofcontents[sectionstyle=show/hide,subsectionstyle=hide]
  \end{center}
\end{frame}
}

\AtBeginSubsection[]{
\begin{frame}
  \begin{beamercolorbox}[wd=\paperwidth,center]{subsection in toc}%
  \usebeamerfont{subsection in toc}\insertsectionnumber.\insertsubsectionnumber\hspace*{2ex}\insertsubsection%
  \end{beamercolorbox}%
\end{frame}
}

% disable block style for theorems

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


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

%% outer theme

\setbeamertemplate{frametitle}{\noindent\usebeamerfont{frametitle}\insertframetitle\par}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}
{
  \hbox{%
  \begin{beamercolorbox}[wd=.2\paperwidth,ht=2.25ex,dp=1ex,left]{footline}%
    \hspace*{1ex}\usebeamerfont{footline}\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}%
    \Acrobatmenu{GoBack}{$\lhd$}\hspace*{1ex}\Acrobatmenu{GoForward}{$\rhd$}\hspace*{1ex}%
    \hyperlinkframeendprev{$\vartriangle$}\hspace*{1ex}\hyperlinkframestartnext{$\triangledown$}\hspace*{1ex}
  \end{beamercolorbox}%
  }%
}

\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}
  \setbeamercolor{theoremname}{fg=blue!60!gray}
  \setbeamercolor{proofname}{fg=blue!60!gray}
  \setbeamercolor{footline}{bg=white,fg=black}
}

\mode
<all>

\makeatother
