% 
% beamerthemeKenotom.sty
% 
% A beamer style file to use in a kenotom presentation
%
% author: Christos Choutouridis <c.choutouridis@kenotom.com>
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerthemeKenotom}


% Requirements
% =====================================================
\RequirePackage{xcolor}
%\RequirePackage{silence}
%\RequirePackage{etoolbox}
\RequirePackage{fontspec}
\RequirePackage{tikz}
\RequirePackage{graphicx}
%\RequirePackage{hyperref}
\RequirePackage{ifthen}


% Options
% =====================================================

% theme: {classic(default), light, dark}
\DeclareOptionBeamer{theme}{\def\beamer@kenotom@theme{#1}}

% backround: {none(default), ribon}
\DeclareOptionBeamer{backround}{\def\beamer@kenotom@backround{#1}}

% title: {normal(default), small, large}
\DeclareOptionBeamer{title}{\def\beamer@kenotom@title{#1}}

% nonavigation: {enable(default), disable}
\DeclareOptionBeamer{navigation}{\def\beamer@kenotom@navigation{#1}}

% Set default options
\ExecuteOptionsBeamer{theme=classic}
\ExecuteOptionsBeamer{backround=none}
\ExecuteOptionsBeamer{title=normal}
\ExecuteOptionsBeamer{navigation=enable}

\ProcessOptionsBeamer

%\ProcessOptions\relax
%\WarningsOff[mathdesign/mdbch]


% Colors
% =====================================================

% Define some colors
\definecolor{KenotomGreenLight}{RGB}{127,213,201}
\definecolor{KenotomGreen}{RGB}{57,174,157}
\definecolor{KenotomGreenDark}{RGB}{39,103,96}

\definecolor{KenotomGreenGreyLight}{RGB}{203,217,217}
\definecolor{KenotomGreenGrey}{RGB}{67,91,92}
\definecolor{KenotomGreenGreyDark}{RGB}{13,34,39}

\definecolor{KenotomGreyLight}{RGB}{215,216,216}
\definecolor{KenotomGrey}{RGB}{154,155,157}
\definecolor{KenotomGreyDark1}{RGB}{108,108,108}
\definecolor{KenotomGreyDark2}{RGB}{92,96,98}

\definecolor{KenotomLightBlue1}{RGB}{207,226,234}
\definecolor{KenotomLightBlue2}{RGB}{232,241,245}

\definecolor{KenotomBlack}{RGB}{0,0,0}
\definecolor{KenotomWhite}{RGB}{255,255,255}


% Local commands
% =====================================================

\newcommand{\Vfill}{\vskip0pt plus 1filll}

% Define a string equality test
\newcommand{\isequal}[2]{ \pdf@strcmp{#1}{#2} }

\newcommand{\SetItemize}[1]{%
	\setbeamertemplate{itemize item}{\small{#1}}
	\setbeamertemplate{itemize subitem}{\scriptsize{#1}}
	\setbeamertemplate{itemize subsubitem}{\tiny{#1}}
}

\newcommand{\SetGraphItemize}[2]{
	\setbeamertemplate{itemize item}{\small\includegraphics[height=#1]{#2}}
	\setbeamertemplate{itemize subitem}{\scriptsize\includegraphics[height=#1]{#2}}
	\setbeamertemplate{itemize subsubitem}{\tiny\includegraphics[height=#1]{#2}}
}

% [1]: Banner image
\newcommand{\SetBackroundPlain}[1]{%
	\setbeamertemplate{background}{%
		\begin{tikzpicture}[overlay,remember picture]
		% Banner
		\node[anchor=east, inner sep=0pt, yshift=-0.06\paperheight] at (current page.north east) {%
			\includegraphics[width=0.2\paperwidth]{#1}
		};%
		\end{tikzpicture}%
	}
}

% [1]: [social]: 
% {2}: Banner image
% {3}: background image
% {4}: Opacity
\newcommand{\SetBackgroundImage}[4][noSocial]{%
	
	\setbeamertemplate{background}{%
		\begin{tikzpicture}[overlay,remember picture]
		% Banner
		\node[anchor=east, inner sep=0pt, yshift=-0.06\paperheight] at (current page.north east) {%
			\includegraphics[width=0.2\paperwidth]{#2}
		};%
		% Image
		\node[anchor=center, inner sep=0pt, yshift=0.04\paperheight, opacity=#4] at (current page.center) {%
			\includegraphics[width=\paperwidth]{#3}
		};%
		% Social links 
		\ifnum \isequal{#1}{social}=0
		\node[anchor=west, inner sep=0pt, xshift=0.05\paperwidth, yshift=-0.06\paperheight] at (current page.north west) {%
			\includegraphics[width=0.5cm]{media/Social.png}
		};%
		\fi
		\end{tikzpicture}%
	}
}

%\SetBackgroundImage[social]{media/kenotomBannerRight.png}{media/ribon.png}{0.15}
%\SetBackgroundImage{media/kenotomBannerRight.png}{media/ribon.png}{0.15}


% {1}: Banner image
% {2}: color 1
% {3}: color 1
%\newcommand{\SetBackgroundBicolor}[3]{%
%	\setbeamertemplate{background}{%
%		\begin{tikzpicture}[overlay,remember picture]
%		% Fill
%%		\node [shading = axis,rectangle, left color=left, right color=left!30!white,shading angle=135, anchor=north, minimum width=\paperwidth, minimum height=5.5cm] (box) at (current page.north){};
%		\node[shading=axis,rectangle, left color=KenotomGreen, right color=KenotomGrey, middle color=KenotomGreen!30, shading angle=135, opacity=0.2, anchor=north, minimum width=\paperwidth, minimum height=\paperheight] (box) at (current page.north){};%
%
%%		\fill[shading=axis, shading angle=135, left color=KenotomGreen, right color=KenotomGrey, middle color=KenotomGreen!5, opacity=0.5] (current page.south west)
%%		-- +(0, \paperheight) -- +(\paperwidth, \paperheight) -- (current page.south east) -- cycle;%
%		% Banner
%		\node[anchor=north east, inner sep=0pt, yshift=-0.06\paperheight] at (current page.north east) {%
%			\includegraphics[width=0.2\paperwidth]{#1}
%		};%
%		\end{tikzpicture}%
%	}
%}
%
%\SetBackgroundBicolor{media/kenotomBannerRight.png}{ }{ }

\newcommand{\BeginCountingFrames}{%
	\addtobeamertemplate{navigation symbols}{}{%
		\hspace{2em} \usebeamerfont{footline} \texttt{ \scriptsize{\insertframenumber/\inserttotalframenumber}}
	}
	\setcounter{framenumber}{0}
}

%
% [1]: Color
% [2]: Text
%\newcommand{\InsertBackroundToText}[2]{%
%%	\colorbox{#1}{%
%%		\parbox{\dimexpr\textwidth-2\fboxsep\relax}{#2}
%	\colorbox{#1}{#2}
%
%	}
%}

%
% Theme
% =====================================================

\ifnum \isequal{\beamer@kenotom@theme}{dark}=0
	\colorlet{BackgroundCanvasColor}{KenotomGreenGreyDark}
	\colorlet{TitleColor}{KenotomGreyLight}
	\colorlet{TitleColorAux}{KenotomGreenLight}
	\colorlet{FrameTitleColor}{KenotomGrey}
	\colorlet{BlockTitleColor}{KenotomGrey}
	
	\colorlet{TextColor}{KenotomGreenGreyLight}
	\colorlet{StructureColor}{KenotomGreenLight}
	
	\colorlet{NavigationColor}{KenotomGreen}
	\colorlet{NavigationArrowsColor}{KenotomGreyLight}
	
	\colorlet{TableCaptionColor}{KenotomGreyDark1}
	\colorlet{TableCaptionTextColor}{KenotomWhite}
	\colorlet{TableRowColor1}{KenotomLightBlue1}
	\colorlet{TableRowColor2}{KenotomLightBlue2}
\else \ifnum \isequal{\beamer@kenotom@theme}{light}=0
	\colorlet{BackgroundCanvasColor}{KenotomWhite}
	\colorlet{TitleColor}{KenotomGrey}
	\colorlet{TitleColorAux}{KenotomGreen}
	\colorlet{FrameTitleColor}{KenotomGrey}
	\colorlet{BlockTitleColor}{KenotomGrey}
	
	\colorlet{TextColor}{KenotomGrey}
	\colorlet{StructureColor}{KenotomGreen}
	
	\colorlet{NavigationColor}{KenotomGreen}
	\colorlet{NavigationArrowsColor}{KenotomGrey}
	
	\colorlet{TableCaptionColor}{KenotomGrey}
	\colorlet{TableCaptionTextColor}{KenotomWhite}
	\colorlet{TableRowColor1}{KenotomLightBlue1}
	\colorlet{TableRowColor2}{KenotomLightBlue2}
\else % clasic
	\colorlet{BackgroundCanvasColor}{KenotomWhite}
	\colorlet{TitleColor}{KenotomGreyDark1}
	\colorlet{TitleColorAux}{KenotomGreen}
	\colorlet{FrameTitleColor}{KenotomGreyDark2}
	\colorlet{BlockTitleColor}{KenotomGreyDark2}
	
	\colorlet{TextColor}{KenotomGreenGrey}
	\colorlet{StructureColor}{KenotomGreen}
	
	\colorlet{NavigationColor}{KenotomGreen}
	\colorlet{NavigationArrowsColor}{KenotomGreyDark1}
	
	\colorlet{TableCaptionColor}{KenotomGreyDark1}
	\colorlet{TableCaptionTextColor}{KenotomWhite}
	\colorlet{TableRowColor1}{KenotomLightBlue1}
	\colorlet{TableRowColor2}{KenotomLightBlue2}
\fi\fi

% Apply theme colors
\setbeamercolor{background canvas}{bg=BackgroundCanvasColor}
\setbeamercolor{titlelike}{fg=FrameTitleColor}
\setbeamercolor{block title}{fg=BlockTitleColor}

\setbeamercolor{normal text}{fg=TextColor}
\setbeamercolor{structure}{fg=StructureColor}
\setbeamercolor{navigation symbols}{fg=NavigationColor, bg=NavigationArrowsColor}



%
% Layout and global settings
% =====================================================
\newcommand{\SideMargin}{2em}

% Frame layout
\setbeamersize{
	text margin left=\SideMargin,
	text margin right=\SideMargin
}
\setlength{\leftmargini}{1.25em}
\setlength{\leftmarginii}{1em}
\setlength{\leftmarginiii}{1em}

\addtobeamertemplate{footnote}{}{\vspace{2ex}}

% Default backround (We overwrite it temporary inside kenotom frame environments)
\ifnum \isequal{\beamer@kenotom@backround}{ribon}=0
	\SetBackgroundImage{media/BannerLogoLink.png}{media/Ribon.png}{0.15}
\else %None
	\SetBackgroundPlain{media/BannerLogoLink.png}
\fi%


% Fonts
\setromanfont{Georgia}
\setsansfont[Scale=MatchLowercase]{Open Sans}

% General
\ifnum \isequal{\beamer@kenotom@navigation}{disable}=0
	\setbeamertemplate{navigation symbols}{}
\fi
\setbeamertemplate{caption}[numbered]

% Default itemize symbols (We overwrite them with kenotom environments)
\SetItemize{\textbullet}

% Content style
% =====================================================

% Title page style
\setbeamertemplate{title page}[default][left]
\setbeamerfont{title}{family=\rmfamily,size=\Huge}
\setbeamerfont{author}{size=\Large}
\setbeamerfont{institute}{size=\normalsize}

% footline
%\setbeamertemplate{navigation symbols}{}
%\setbeamertemplate{footlline}{\hfill \insertnavigation{0.3\textwidth}}


% Frame title style
\ifnum \isequal{\beamer@kenotom@title}{small}=0
	\setbeamerfont{frametitle}{family=\rmfamily,size=\large,series=\bfseries}
\else\ifnum \isequal{\beamer@kenotom@title}{normal}=0
	\setbeamerfont{frametitle}{family=\rmfamily,size=\Large,series=\bfseries}
\else\ifnum \isequal{\beamer@kenotom@title}{large}=0
	\setbeamerfont{frametitle}{family=\rmfamily,size=\huge,series=\bfseries}
\else % default = normal
	\setbeamerfont{frametitle}{size=\Large,series=\bfseries}
\fi\fi\fi%
\setbeamertemplate{frametitle}{
	\vskip0.05\paperheight
	\insertframetitle
}

% Block style
\setbeamerfont{block title}{family=\rmfamily,size=\large}


% Table style
\renewcommand{\arraystretch}{1.2}
\newcommand{\tableheadrow}{\rowcolor{TableCaptionColor}}
\newcommand{\tableheadcol}[1]{{\bfseries\color{TableCaptionTextColor}#1}}
\rowcolors{2}{TableRowColor1}{TableRowColor2}

%\AtBeginEnvironment{tabular}{\color{black}}


% Kenotom environments
% =====================================================

% Kenotom CoverFrame
\newcommand{\CoverFrame}{{%
	\SetBackgroundImage[social]{media/BannerLink.png}{media/Ribon.png}{0.1}
	\begin{frame}
		\begin{tikzpicture}[overlay,remember picture]
		% Logo
		\node[anchor=center, inner sep=0pt, yshift=0.25\paperheight] at (current page.center) {%
			\ifnum \isequal{\beamer@kenotom@theme}{dark}=0
				\includegraphics[width=\paperwidth]{media/LogoWhite.png}
			\else
				\includegraphics[width=\paperwidth]{media/Logo.png}
			\fi
		};%
		% Car
		\node[anchor=north, inner sep=0pt, yshift=0.16\paperheight] at (current page.center) {%
			\includegraphics[width=\paperwidth, keepaspectratio]{media/CarCover.png}
		};%
		\end{tikzpicture}
	\end{frame}
	}
}

\newcommand{\TitleFrame}{{%
	\SetBackgroundImage{media/BannerLink.png}{media/Ribon.png}{0.4}
	\begin{frame}
		\vspace{0.15\textheight}
		\textcolor{TitleColor}{
			\rmfamily \Huge
			\Title               \\[0.5ex]
			\normalsize
			\SubTitle            \\[10ex]
		}
		\textcolor{TextColor}{
			\Large
			\AuthorName          \\[1.5ex]
			\normalsize
			\Date
		}
	\end{frame}
	}
}

\newcommand{\BackCoverFrame}{{%
	\SetBackgroundImage[social]{media/BannerThankYou.png}{media/Ribon.png}{0.4}
	\begin{frame}
		\Vfill
		\begin{tikzpicture}[overlay,remember picture]
			\node[anchor=center, inner sep=0pt, yshift=0.04\paperheight] at (current page.center) {%
				\includegraphics[width=\paperwidth]{media/LogoDetails.png}
			};%
		\end{tikzpicture}
		\Vfill
		\AuthorName    \\
		\AuthorMail    \\
		\textcolor{StructureColor}{%
			\Address   \\
			\Telephone
		}
		\vspace{0.125\paperheight}
	\end{frame}
	}
}

\newenvironment{tickmarks}{%
	\SetGraphItemize{1.6ex}{media/Tickmark.png}
	\begin{itemize}
	}{%
	\end{itemize}
}

\newenvironment{bullets}{%
	\SetGraphItemize{1.3em}{media/Bullet.png}
	\begin{itemize}
	}{%
	\end{itemize}
}


