% Written by Kristian Bredies and Dirk Lorenz, 2005-2008
%            Kristian Bredies, 2008-2009
%            Christian Clason, 2014,2021

\newif\ifbeamer@theme@german
\DeclareOptionBeamer{german}{\beamer@theme@germantrue}
\ProcessOptionsBeamer

%% define fonts
\setbeamerfont{title}{series=\bfseries}
\setbeamerfont{titlelike}{parent=title}
\setbeamerfont{frametitle}{parent=title}
\setbeamerfont{framesubtitle}{parent=title}
\setbeamerfont{frametitle continuation}{parent=title}
\setbeamerfont{title in head/foot}{series=\mdseries}

\mode<presentation>

\ifbeamer@theme@german
    \pgfdeclareimage[height=1cm]{kfu_logo}{kfulogo_de}
\else
    \pgfdeclareimage[height=1cm]{kfu_logo}{kfulogo_en}
\fi

%% title slide: left-justified
\setbeamertemplate{title graphic}{
    \vbox to 0pt {
        \vspace*{2em}
        \inserttitlegraphic%
    }%
    \nointerlineskip%
}
\setbeamertemplate{title}{
    \raggedright%
    \linespread{1.0}%
    \inserttitle%
    \par%
    \vspace*{0.5em}
}
\setbeamertemplate{subtitle}{
    \raggedright%
    \insertsubtitle%
    \par%
    \vspace*{0.5em}
}
\setbeamertemplate{author}{
    \vspace*{1em}
    \insertauthor%
    \par%
    \vspace*{1em}
}
\setbeamertemplate{date}{
    \vspace*{5mm}
    \insertdate%
    \par%
}
\setbeamertemplate{institute}{
    \insertinstitute%
    \par%
}
\setbeamertemplate{title page}{%
    \parbox[b][1cm][c]{0.8925\paperwidth}{\hfill\pgfuseimage{kfu_logo}}
    \vfill
    \begin{minipage}[b][0.7\paperheight]{\textwidth}
        \ifx\inserttitlegraphic\@empty\else\usebeamertemplate*{title graphic}\fi
        \vfill%
        \ifx\inserttitle\@empty\else\usebeamertemplate*{title}\fi
        \ifx\insertsubtitle\@empty\else\usebeamertemplate*{subtitle}\fi
        \ifx\beamer@shortauthor\@empty\else\usebeamertemplate*{author}\fi
        \ifx\insertinstitute\@empty\else\usebeamertemplate*{institute}\fi
        \ifx\insertdate\@empty\else\usebeamertemplate*{date}\fi
    \end{minipage}
    \vfill
}

%% header
\defbeamertemplate*{frametitle}{kfu theme}[1][left]{
    \@tempswafalse%
    \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
        \@tempdima=\textwidth%
        \advance\@tempdima by\beamer@leftmargin%
        \advance\@tempdima by\beamer@rightmargin%
        \begin{beamercolorbox}[sep=0.3cm,#1,wd=\the\@tempdima]{frametitle}
        \if@tempswa\else\csname beamer@fte#1\endcsname\fi{%
        \usebeamerfont{frametitle}\insertframetitle\par}%
        {%
            \ifx\insertframesubtitle\@empty%
        \else%
            {\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle\par}%
        \fi
    }%
    \if@tempswa\else\vskip-.3cm\fi% set inside beamercolorbox... evil here...
    {\color{kfu}\rule{0.9\paperwidth}{2pt}}
    \vskip0.5mm
\end{beamercolorbox}%
\vskip-0.5cm%
}

%% footer
% sections and slide numbers in footer, no navigation symbols!
\def\beamer@theme@footline@section{%
    \insertsectionnavigationhorizontal{.9\paperwidth}%
    {}{\hskip0pt plus1filll}%
}
\def\beamer@theme@footline@number{%
    {\usebeamercolor[fg]{page number in head/foot}\insertframenumber\,/\,\inserttotalframenumber}%
}
\defbeamertemplate*{navigation symbols}{ude theme}{}

\defbeamertemplate*{footline}{kfu theme}{%
    \hspace*{3mm}{\color{gray2}\rule{0.9\paperwidth}{0.5pt}}

    \vspace*{1ex}

    \parbox[b]{.9\paperwidth}{%
        \beamer@theme@footline@section%
    }
    \hfill
    \parbox[b]{.1\paperwidth}{%
        \hfill%
        \beamer@theme@footline@number\hspace*{2mm}
    }

    \vspace*{1mm}
}

%% separate block head from body
\addtobeamertemplate{block begin}{}{%
    {\usebeamercolor[white]{block title}{%
            \vspace*{-2.5ex}%
            \hspace*{-1ex}\rule{\paperwidth}{0.4pt}
    }}
}

\mode<all>
