%% psipresentation.cls
\ProvidesClass{psipresentation}[2020/05/21 Unofficial PSI Presentation Class by Sven Augustin]
\NeedsTeXFormat{LaTeX2e}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{beamer}}
\ProcessOptions\relax

\LoadClass[final, 9pt]{beamer} % t: align columns to top
\beamertemplatenavigationsymbolsempty


\setbeamersize{
  text margin left=0.111\paperwidth,
  text margin right=0.05\paperwidth
}


\RequirePackage{polyglossia}
\setmainlanguage{english}

\RequirePackage{microtype}
\RequirePackage{fontspec}
%\RequirePackage{unicode-math}


\setmainfont{Georgia}[
Path = psipresentation/fonts/Georgia/,
Extension = .ttf,
UprightFont = *-Regular,
BoldFont = *-Bold,
ItalicFont = *-Italic,
BoldItalicFont = *-Bold-Italic
]

\setsansfont{MetaPro}[
Path = psipresentation/fonts/MetaPro/,
Extension = .otf,
UprightFont = *-Regular,
BoldFont = *-Bold,
ItalicFont = *-Italic,
BoldItalicFont = *-Bold-Italic
]

\setmonofont{FiraMono}[
Path = psipresentation/fonts/FiraMono/,
Extension = .otf,
UprightFont = *-Regular,
BoldFont = *-Bold,
Scale = MatchLowercase
]


\RequirePackage{tikz}

\input{psipresentation/psicolors}


\colorlet{boxlightgrey}{light}
\colorlet{boxdarkgrey}{dark}

\definecolor{overlayfontgrey}{cmyk}{0, 0, 0, 0.9}
\definecolor{authorfontgrey}{cmyk}{0, 0, 0, 0.4}
\definecolor{titlefontgrey}{cmyk}{0, 0, 0, 0.7}
\definecolor{datefontgrey}{cmyk}{0, 0, 0, 0.4}


\definecolor{blocktitlefontgrey}{cmyk}{0, 0, 0, 0.4}
\definecolor{blockbodyfontgrey}{cmyk}{0, 0, 0, 0.7}


% set colors for blocks
\setbeamercolor{block title}{fg=blocktitlefontgrey, bg=white}
\setbeamercolor{block body}{fg=blockbodyfontgrey, bg=white}

% set the fonts
\setbeamerfont{block title}{series=\bfseries}

\setbeamercolor{block alerted title}{fg=blocktitlefontgrey, bg=green!75}
\setbeamercolor{block alerted body}{fg=blockbodyfontgrey, bg=white}


\setbeamercolor{itemize item}{fg=green}
\setbeamercolor{itemize subitem}{fg=green!80}
\setbeamercolor{itemize subsubitem}{fg=green!60}

\setbeamercolor{enumerate item}{fg=green!80!black}
\setbeamercolor{enumerate subitem}{fg=green!80!black!80}
\setbeamercolor{enumerate subsubitem}{fg=green!80!black!60}


\newlength{\inboxwd}
\newlength{\iinboxwd}
\newlength{\inboxrule}


\setlength{\iinboxwd}{\inboxwd}
\setlength{\inboxrule}{\inboxwd}
\addtolength{\iinboxwd}{-0.5cm}
\addtolength{\inboxrule}{0.5cm}


% Alert block definition (with frame)
\setbeamertemplate{block alerted begin}
{
  \par\vskip\medskipamount
  \begin{beamercolorbox}[sep=0ex,rounded=true,center,dp={2ex}]{block alerted title}
    \vskip0.01cm
    \usebeamerfont{block title}\large\insertblocktitle
  \end{beamercolorbox}
  {\parskip0pt\par}
  \usebeamerfont{block body}
  \vskip-0.8cm
  \begin{beamercolorbox}[sep=0.5cm, rounded=true,center]{block alerted title}
  \setlength{\inboxwd}{\linewidth}
  \addtolength{\inboxwd}{-1cm}
  \begin{beamercolorbox}[rounded=true,wd={\inboxwd},center]{block alerted body}
  \setlength{\iinboxwd}{\inboxwd}
  \setlength{\inboxrule}{\inboxwd}
  \addtolength{\iinboxwd}{-0.5cm}
  \addtolength{\inboxrule}{0.5cm}
  \begin{center}
  \begin{minipage}{\iinboxwd}
%  \justifying
}

\setbeamertemplate{block alerted end}
{
  \end{minipage}
  \end{center}
  \end{beamercolorbox}
  \end{beamercolorbox}
  \vskip\smallskipamount
}



% title page

\newcommand\function[1]{\def\insertfunction{#1}}
\function{}


\defbeamertemplate*{title page}{customized}[1][]
{
  \newcommand{\titlewhitemargin}{0.043}
  \newcommand{\titleboxheight}{0.49}
  \newcommand{\titleleftboxwidth}{0.279}
  \newcommand{\titlerightboxwidth}{0.078}
  \newcommand{\titlephotocenterpos}{0.6005}% 0.279 + (1-0.279-0.078)/2 = 0.6005
  \newcommand{\titletextleftedge}{0.092}

  \newcommand{\titlelogowidth}{0.133}
  \newcommand{\titlelogoupperedge}{0.855}
  \newcommand{\titletextspace}{0.85}

  \newcommand{\titlesmallboxsidelength}{0.078}

  \begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}] % use the whole page
%    \draw (0, 0) -- (\paperwidth, \paperheight);
%    \draw (0, \paperheight) -- (\paperwidth, 0);

    \begin{scope}[shift={(0, -\titlewhitemargin\paperheight)}] % upper white margin

      \fill[boxlightgrey] (0, \paperheight) rectangle ++(\titleleftboxwidth\paperwidth, -\titleboxheight\paperheight); % left grey box

      \node[inner sep=0pt, anchor=north] (psi-photo) at (\titlephotocenterpos\paperwidth, \paperheight) {
        \includegraphics[height=\titleboxheight\paperheight]{psipresentation/imgs/psi-photo-large-cropped.jpg}
      };

      \fill[boxlightgrey] (\paperwidth, \paperheight) rectangle ++(-\titlerightboxwidth\paperwidth, -\titleboxheight\paperheight); % right grey box
    \end{scope}


    \node[fill=white, fill opacity=0.75, inner sep=2.25pt, anchor=south east] (overlay) at ([xshift=0.1pt,yshift=-0.1pt]psi-photo.south east) { % tiny shifts to make sure corner is covered
      \textcolor{overlayfontgrey}{\textbf{\fontsize{5.75}{0}\selectfont
      \,WIR SCHAFFEN WISSEN – HEUTE FÜR MORGEN\,
    }}}; % overlay box


    \node[inner sep=0pt, anchor=south west] (psi-logo) at (\titletextleftedge\paperwidth, \titlelogoupperedge\paperheight) {
      \includegraphics[width=\titlelogowidth\paperwidth]{psipresentation/imgs/psilogo}
    };


    \node[inner sep=0pt] (titletext1) at (\titletextleftedge\paperwidth, 3.5) {
      \rlap{\footnotesize\textbf{\textcolor{authorfontgrey}{%
        \parbox[t]{\titletextspace\paperwidth}{%
          \insertauthor{}~~::~~\insertfunction{}~~::~~\insertinstitute{}%
        }
      }}}};

    \node[inner sep=0pt] (titletext2) at (\titletextleftedge\paperwidth, 2.5) {
      \rlap{\Large\textrm{\textcolor{titlefontgrey}{%
        \parbox[t]{\titletextspace\paperwidth}{%
          \inserttitle%
        }
      }}}};

    \node[inner sep=0pt] (titletext3) at (\titletextleftedge\paperwidth, 1.5) {
       \rlap{\footnotesize\textbf{\textcolor{datefontgrey}{
        \parbox[t]{\titletextspace\paperwidth}{%
          \insertdate
        }
      }}}};


    \fill[boxdarkgrey] (\titletextleftedge\paperwidth, 0) rectangle ++(\titlesmallboxsidelength\paperwidth, \titlesmallboxsidelength\paperwidth); % small bottom box

  \end{tikzpicture}
}



% frame

\setbeamertemplate{frametitle}
{
  \newcommand{\titlelogowidth}{0.111}
  \newcommand{\titlelogoupperedge}{0.96} % 1 - 0.04
  \newcommand{\titlelogoleftedge}{0.092}

  \newcommand{\titleframetitleupperedge}{0.95} % 1 - 0.05
  \newcommand{\titleframetitleleftedge}{0.23}

  \newcommand{\titleframetitlespace}{0.73}

  \newcommand{\titlesmallboxsidelength}{0.078}

  \begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}] % use the whole page
%    \draw (0, 0) -- (\paperwidth, \paperheight);
%    \draw (0, \paperheight) -- (\paperwidth, 0);

    \node[inner sep=0pt, anchor=north west] (psi-logo) at (\titlelogoleftedge\paperwidth, \titlelogoupperedge\paperheight) {
      \includegraphics[width=\titlelogowidth\paperwidth]{psipresentation/imgs/psilogo}
    };

    \node[inner sep=0pt, anchor=north west] (frame-title) at (\titleframetitleleftedge\paperwidth, \titleframetitleupperedge\paperheight) {
      \parbox[t]{\titleframetitlespace\paperwidth}{%
        \textrm{\textcolor{titlefontgrey}{\LARGE\insertframetitle}}
      }
    };

    \fill[boxdarkgrey] (0, 0.79\paperheight) rectangle ++(\titlesmallboxsidelength\paperwidth, -\titlesmallboxsidelength\paperwidth); % small bottom box

  \end{tikzpicture}

  % since the above is all overlay, simply add enough space to cover the head
  \vskip0.118\paperheight % 0.21 - 0.092
}



