%
% beamerthemeKenotom.sty
%
% A beamer style file to use in a kenotom presentation
%
% author: Christos Choutouridis <c.choutouridis@kenotom.com>
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerthemeKenotom}[2023/05/12 Kenotom beamer theme]


% Requirements
% =====================================================
\RequirePackage{xcolor}
\RequirePackage{fontspec}
\RequirePackage{tikz}
\RequirePackage{graphicx}
\RequirePackage{ifthen}
\RequirePackage[absolute,overlay]{textpos}

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

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

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

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

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

% key-value: fancy: {disable(default), enable}
\DeclareOptionBeamer{fancy}{\def\beamer@kenotom@fancy{#1}}

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

\ProcessOptionsBeamer

%\ProcessOptions\relax


% 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}: y-offset
% {5}: Opacity
\newcommand{\SetBackgroundImage}[5][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=#4\paperheight, opacity=#5] 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.03\paperwidth]{media/Social.png}
		};%
		\fi
		\end{tikzpicture}%
	}
}

\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{TitleColorFancy}{KenotomWhite}
	\colorlet{TitleColorAux}{KenotomGreenLight}
	\colorlet{FrameTitleColor}{KenotomGrey}
	\colorlet{BlockTitleColor}{KenotomGrey}

	\colorlet{TextColor}{KenotomGreenGreyLight}
	\colorlet{StructureColor}{KenotomGreenLight}

	\colorlet{NavigationColor}{KenotomGreen}
	\colorlet{NavigationColorFancy}{KenotomWhite}
	\colorlet{NavigationArrowsColor}{KenotomGreyLight}
	\colorlet{NavigationArrowsColorFancy}{KenotomWhite}

	\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{TitleColorFancy}{KenotomWhite}
	\colorlet{TitleColorAux}{KenotomGreen}
	\colorlet{FrameTitleColor}{KenotomGrey}
	\colorlet{BlockTitleColor}{KenotomGrey}

	\colorlet{TextColor}{KenotomGrey}
	\colorlet{StructureColor}{KenotomGreen}

	\colorlet{NavigationColor}{KenotomGreen}
	\colorlet{NavigationColorFancy}{KenotomWhite}
	\colorlet{NavigationArrowsColor}{KenotomGrey}
	\colorlet{NavigationArrowsColorFancy}{KenotomWhite}

	\colorlet{TableCaptionColor}{KenotomGrey}
	\colorlet{TableCaptionTextColor}{KenotomWhite}
	\colorlet{TableRowColor1}{KenotomLightBlue1}
	\colorlet{TableRowColor2}{KenotomLightBlue2}
\else % clasic
	\colorlet{BackgroundCanvasColor}{KenotomWhite}
	\colorlet{TitleColor}{KenotomGreyDark1}
	\colorlet{TitleColorFancy}{KenotomWhite}
	\colorlet{TitleColorAux}{KenotomGreen}
	\colorlet{FrameTitleColor}{KenotomGreyDark2}
	\colorlet{BlockTitleColor}{KenotomGreyDark2}

	\colorlet{TextColor}{KenotomGreenGrey}
	\colorlet{StructureColor}{KenotomGreen}

	\colorlet{NavigationColor}{KenotomGreen}
	\colorlet{NavigationColorFancy}{KenotomWhite}
	\colorlet{NavigationArrowsColor}{KenotomGreyDark1}
	\colorlet{NavigationArrowsColorFancy}{KenotomWhite}

	\colorlet{TableCaptionColor}{KenotomGreyDark1}
	\colorlet{TableCaptionTextColor}{KenotomWhite}
	\colorlet{TableRowColor1}{KenotomLightBlue1}
	\colorlet{TableRowColor2}{KenotomLightBlue2}
\fi\fi

% Apply theme colors
\setbeamercolor{background canvas}{bg=BackgroundCanvasColor}
\setbeamercolor{title}{fg=TitleColor}
\setbeamercolor{subtitle}{fg=TitleColor}
\setbeamercolor{frametitle}{fg=FrameTitleColor}

\setbeamercolor{section title}{fg=FrameTitleColor}
\setbeamercolor{subsection title}{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.04}{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
% =====================================================

\newcommand{\TitleSize}{\Huge}
\newcommand{\SectionSize}{\Large}

\ifnum \isequal{\beamer@kenotom@title}{small}=0
	\newcommand{\FrameTitleSize}{\large}
\else\ifnum \isequal{\beamer@kenotom@title}{normal}=0
	\newcommand{\FrameTitleSize}{\Large}
\else\ifnum \isequal{\beamer@kenotom@title}{large}=0
	\newcommand{\FrameTitleSize}{\huge}
\else % default = normal
	\newcommand{\FrameTitleSize}{\Large}
\fi\fi\fi%

\newcommand{\AuthorSize}{\Large}
\newcommand{\InstituteSize}{\normalsize}
\newcommand{\ContactInfoSize}{\normalize}

\newcommand{\FancyTitleSize}{\LARGE}
\newcommand{\FancyTitleFontStyle}[1]{\textbf{#1}}

%\newcommand{\FancyDateSize}{\normalize}
%\newcommand{\FancyDateFontStyle}[1]{\textrm{#1}}

\newcommand{\FancySectionSize}{\huge}
\newcommand{\FancySectionFontStyle}[1]{\textbf{#1}}

% Title page style
\setbeamertemplate{title page}[default][left]
\setbeamerfont{title}{family=\rmfamily,size=\TitleSize}
\setbeamerfont{author}{size=\AuthorSize}
\setbeamerfont{institute}{size=\InstituteSize}

\renewcommand{\maketitle}{%
	\ifnum \isequal{\beamer@kenotom@fancy}{enable}=0
		\TitleFrameFancy
	\else {% once
		\SetBackgroundImage{media/BannerLink.png}{media/Ribon.png}{0.04}{0.4}
		\begin{frame}
			\titlepage
		\end{frame}
	} \fi
}

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


% Frame title style
\setbeamerfont{frametitle}{family=\rmfamily,size=\FrameTitleSize,series=\bfseries}
\setbeamertemplate{frametitle}{
	\vskip0.05\paperheight
	\insertframetitle
}

%\setbeamerfont{section title}{size=\LARGE,series=\bfseries}
%\setbeamerfont{subsection title}{size=\Large,series=\bfseries}

% 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}

% Section frames
\AtBeginSection[]{%
	\ifnum \isequal{\beamer@kenotom@fancy}{enable}=0
		\SectionFrameFancy
	\fi
}
%\AtBeginEnvironment{tabular}{\color{black}}


\newcommand{\InsertFancyTitle}{%
	\FancyTitleSize
	\textcolor{TitleColorFancy}{\FancyTitleFontStyle{\inserttitle}}
}

\newcommand{\InsertFancySection}{%
	\FancySectionSize
	\textcolor{TitleColorFancy}{
		\ifnum \thesection<10
			\FancySectionFontStyle{0\thesection}  \\
		\else
			\FancySectionFontStyle{\thesection}   \\
		\fi
		\FancySectionFontStyle{\insertsection}
	}
}

\newcommand{\InsertFancyDate}{%
	\textcolor{TitleColorFancy}{\insertdate}
}

\newcommand{\InsertAuthorEmail}{%
	\AuthorEmail
}

\newcommand{\InsertAddress}{%
	\textcolor{StructureColor}{\Address}
}

\newcommand{\InsertTelephone}{%
	\textcolor{StructureColor}{\Telephone}
}

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

% Kenotom CoverFrame
\newcommand{\TitleFrameFancy}{ {% once
	\SetBackgroundImage[social]{media/BannerLink.png}{media/Ribon.png}{0.12}{0.1}
	\setbeamercolor{navigation symbols}{fg=NavigationColor, bg=NavigationArrowsColorFancy}
	\addtobeamertemplate{background}{}{%
		\begin{tikzpicture}[overlay,remember picture]
			% Logo
			\node[anchor=center, inner sep=0pt, yshift=0.275\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 the
			\node[anchor=north, inner sep=0pt, yshift=0.08\paperheight] at (current page.center) {%
				\includegraphics[width=\paperwidth, keepaspectratio]{media/CarCover.png}
			};%
			% TitleBox center:0.58\paperheight
			\node[anchor=center, inner sep=0pt, yshift=0.08\paperheight] at (current page.center) {%
				\includegraphics[width=0.7\paperwidth, keepaspectratio]{media/FancyTitleBox.png}
			};%
		\end{tikzpicture}
	}
	\begin{frame}
		\setlength{\TPHorizModule}{\paperwidth}
		\setlength{\TPVertModule}{\paperheight}
		% hsize:
		%         0.58 = {BoxLength=7.697}/{TotlaLength=13.333}
		% hpos: 0.56
		%    (1.6/2)/13.333 in = 0.06\paperwidth
		%             0.5+0.06 = 0.56
		% vpos: 0.42
		%         0.42 = 0.5 - 0.08
		\begin{textblock}{0.58}[0.5,0.5](0.56,0.42)
			\centering
			\InsertFancyTitle
		\end{textblock}
		% Date @ bottom right
		\begin{textblock}{0.5}[1,1](0.95,0.95)
			\begin{flushright}
				\InsertFancyDate
			\end{flushright}
		\end{textblock}
	\end{frame}
	}
}

% [nosubsections]
% {1} : Outline Text Grey
% {2} : Outline Text Green
\newcommand{\OutlineFrameFancy}[3][subsections]{ {% once
	\SetBackgroundImage{media/BannerLink.png}{media/Ribon.png}{0.04}{0.1}
	\begin{frame}
		\begin{columns}
			\begin{column}{0.6\textwidth}
				\setlength{\TPHorizModule}{\textwidth}
				\setlength{\TPVertModule}{\textheight}
				\begin{textblock}{1}[0.5,0.5](0.5,0.35)
					\centering
					\huge \textbf {\textcolor{KenotomGrey}{#2} \textcolor{KenotomGreen}{#3}}
				\end{textblock}
			\end{column}
			\begin{column}{0.4\textwidth}
				\vspace{0.2\textheight}
				\ifnum \isequal{#1}{nosubsections}=0
					\setcounter{tocdepth}{1}
				\fi
				\tableofcontents
				\Vfill
			\end{column}
		\end{columns}
	\end{frame}
	}
}

\newcommand{\OutlineFrame}[3][subsections]{%
	\ifnum \isequal{\beamer@kenotom@fancy}{enable}=0
		\OutlineFrameFancy[#1]{#2}{#3}
	\else
		\begin{frame}{#2 #3}
			\vspace{0.2\textheight}
			\ifnum \isequal{#1}{nosubsections}=0
				\setcounter{tocdepth}{1}
			\fi
				\tableofcontents
			\Vfill
		\end{frame}
	\fi
}

\newcommand{\SectionFrameFancy}{ {% once
	\SetBackgroundImage{media/nothing.png}{media/SectionBackground.png}{0}{1.0}
	\setbeamercolor{navigation symbols}{fg=NavigationColorFancy, bg=NavigationArrowsColorFancy}
	\begin{frame}
		\setlength{\TPHorizModule}{\paperwidth}
		\setlength{\TPVertModule}{\paperheight}
		% hsize:
		%         0.4 = {AvailableLength}/{TotlaLength}
		% hpos: 0.9
		%         // The line in svg ends @12in
		%         0.9 = {LineEnds}/{TotalLength} = 12/13.333
		% vpos: 0.475
		%       // 0.025 above center
		%       0.475 = 0.5 - 0.025
		\begin{textblock}{0.4}[1,1](0.9,0.475)
			\begin{flushright}
				\InsertFancySection
			\end{flushright}
		\end{textblock}
	\end{frame}
	}
}

\newcommand{\BackFrame}{ {% once
	\SetBackgroundImage[social]{media/BannerThankYou.png}{media/Ribon.png}{0.04}{0.4}
	\addtobeamertemplate{background}{}{%
		\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}
			};%
			\node[anchor=south, inner sep=0pt] at (current page.south) {%
				\includegraphics[width=\paperwidth]{media/BottomGradient.png}
			};%
		\end{tikzpicture}
	}
	\begin{frame}
		\Vfill
		\insertauthor         \\
		\InsertAuthorEmail    \\
		\InsertAddress        \\
		\InsertTelephone
		\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}
}


