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

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

\LoadClass[final, 10pt, aspectratio=169]{beamer} % t: align columns to top
\beamertemplatenavigationsymbolsempty



\institute{Paul Scherrer Institut PSI}

\newcommand\location[1]{\def\insertlocation{#1}}
\location{}

\newcommand\titleimage[1]{\def\inserttitleimage{#1}}
\let\inserttitleimage\empty

\newcommand\titlecolor[1]{\def\inserttitlecolor{#1}}
\titlecolor{blue}



\RequirePackage{polyglossia}
\RequirePackage{microtype}
\RequirePackage{fontspec}
\RequirePackage{csquotes}
\RequirePackage{tikz}



\setmainlanguage{english}

\setbeamersize{
  text margin left=0.055\paperwidth,
  text margin right=0.055\paperwidth
}

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

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

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



\input{psipresentation/psicolors}



% boxes

\setbeamerfont{block title}{series=\bfseries, size=\normalsize}
\setbeamercolor{block title}{fg=black, bg=white}



% lists

\setlength{\leftmargini}{10pt}
\setlength{\leftmarginii}{10pt}
\setlength{\leftmarginiii}{10pt}

\newcommand\ibullet{\raisebox{-0.2em}{\scalebox{2.2}{$\cdot$}}}

\setbeamertemplate{itemize item}{\ibullet}
\setbeamertemplate{itemize subitem}{\ibullet}
\setbeamertemplate{itemize subsubitem}{\ibullet}

\setbeamercolor{itemize item}{fg=black}
\setbeamercolor{itemize subitem}{fg=black}
\setbeamercolor{itemize subsubitem}{fg=black}

\setbeamercolor{enumerate item}{fg=black}
\setbeamercolor{enumerate subitem}{fg=black}
\setbeamercolor{enumerate subsubitem}{fg=black}



% title page

\newcommand{\titletextleftedge}{0.056}

\newcommand{\titlelogowidth}{0.14}
\newcommand{\titlelogoupperedge}{0.84}

\newcommand{\titleboxheight}{0.27}

\newcommand{\titleimageheight}{0.78}

\newcommand{\ypostitle}{4.65}
\newcommand{\ypossubtitle}{3.8}
\newcommand{\yposauthor}{1.1}
\newcommand{\yposlocationdate}{0.75}

\colorlet{authorfont}{white}
\colorlet{datefont}{white}


\defbeamertemplate*{title page}{PSI}[1][]
{
  \begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}] % use the whole page

    \ifx \inserttitleimage \empty

      \colorlet{titlefont}{white}
      \colorlet{subtitlefont}{white}
      \newcommand{\logocolor}{white}
      \newcommand{\titletextspace}{0.66}

      \node[inner sep=0pt, anchor=south west] (bkg) at (-0.01, -0.01) {
        \includegraphics[height=\paperheight]{psipresentation/imgs/bkgs/\inserttitlecolor}
      };

    \else

      \colorlet{titlefont}{black}
      \colorlet{subtitlefont}{black}
      \newcommand{\logocolor}{black}
      \newcommand{\titletextspace}{0.43}

      \fill[\inserttitlecolor] (0, \titleboxheight\paperheight) rectangle ++(\paperwidth, -\paperheight); % bottom color box

      \node[inner sep=0pt, anchor=west] (image) at (\paperwidth/2 + 5, \paperheight/2 + 5) {
        \includegraphics[height=\titleimageheight\paperheight]{\inserttitleimage}
      };

    \fi

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

    %TODO: make the following a command?

    \node[inner sep=0pt, anchor=south] (titletext) at (\titletextleftedge\paperwidth, \ypostitle) {
      \rlap{\huge\textbf{\textcolor{titlefont}{%
        \parbox[t]{\titletextspace\paperwidth}{%
          \inserttitle%
        }
      }}}};

    \node[inner sep=0pt] (subtitletext) at (\titletextleftedge\paperwidth, \ypossubtitle) {
      \rlap{\large\textbf{\textcolor{subtitlefont}{%
        \parbox[t]{\titletextspace\paperwidth}{%
          \insertsubtitle{}%
        }
      }}}};

    \node[inner sep=0pt] (authortext) at (\titletextleftedge\paperwidth, \yposauthor) {
      \rlap{\footnotesize{\textcolor{authorfont}{%
        \parbox[t]{\titletextspace\paperwidth}{%
          \insertauthor{}%
        }
      }}}};

    \node[inner sep=0pt] (locationdatetext) at (\titletextleftedge\paperwidth, \yposlocationdate) {
       \rlap{\footnotesize{\textcolor{datefont}{
        \parbox[t]{\titletextspace\paperwidth}{%
          \insertlocation, \insertdate%
        }
      }}}};

  \end{tikzpicture}
}



% frame

\newcommand{\headspace}{0.09}

\newcommand{\frametitlelogowidth}{0.075}
\newcommand{\frametitlelogoupperedge}{0.96}
\newcommand{\frametitlelogorightedge}{0.94}

\newcommand{\frametitleupperedge}{0.95}
\newcommand{\frametitleleftedge}{0.055}
\newcommand{\frametitlespace}{0.75}

\newcommand{\bottomupperedge}{0.06}
\newcommand{\bottomauthorleftedge}{\frametitleleftedge}
\newcommand{\bottominstituteleftedge}{0.12}
\newcommand{\bottomdaterightedge}{0.94} % 1 - 0.06

\colorlet{frametitlefont}{black}
\colorlet{bottomfont}{black}


\setbeamertemplate{frametitle}
{
  \begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}] % use the whole page

    \node[inner sep=0pt, anchor=north east] (psi-logo) at (\frametitlelogorightedge\paperwidth, \frametitlelogoupperedge\paperheight) {
      \includegraphics[width=\frametitlelogowidth\paperwidth]{psipresentation/imgs/logos/psi-logo-black}
    };

    \node[inner sep=0pt, anchor=north west] (frame-title) at (\frametitleleftedge\paperwidth, \frametitleupperedge\paperheight) {
      \parbox[t]{\frametitlespace\paperwidth}{%
        \textcolor{frametitlefont}{\large\textbf{\insertframetitle}}%
      }
    };

    \node[inner sep=0pt, anchor=west] (page-num) at (\bottomauthorleftedge\paperwidth, \bottomupperedge\paperheight) {
      \textcolor{bottomfont}{\tiny\insertframenumber}
    };

    \node[inner sep=0pt, anchor=west] (institute) at (\bottominstituteleftedge\paperwidth, \bottomupperedge\paperheight) {
      \textcolor{bottomfont}{\tiny\insertinstitute}
    };

    \node[inner sep=0pt, anchor=east] (author) at (\bottomdaterightedge\paperwidth, \bottomupperedge\paperheight) {
      \textcolor{bottomfont}{\tiny\insertdate}
    };

  \end{tikzpicture}

  % since the above is all overlay, simply add enough space to cover the head
  \vskip\headspace\paperheight
}



