%% This is file `beamerinnerthemeBFH.sty' version 2.2.3 (2025-04-01),
%% it is part of
%% BFH-CI -- Corporate Design for Bern University of Applied Sciences
%% ----------------------------------------------------------------------------
%%
%%  Copyright (C) 2021--2025 by
%%      Marei Peischl <marei@peitex.de>
%%      Andreas Habegger <andreas.habegger@bfh.ch>
%%
%% ============================================================================
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008/05/04 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainers of this work are
%%   Marei Peischl <bfh-ci@peitex.de>
%%   Andreas Habegger <andreas.habegger@bfh.ch>
%%
%% The development respository can be found at
%% https://gitlab.ti.bfh.ch/bfh-latex/bfh-ci/
%% Please use the issue tracker for feedback!
%%
%% ============================================================================
%%
\ProvidesExplPackage{beamerinnerthemeBFH}{2025-04-01}{2.2.3}{BFH-CI beamer inner theme, CI of Bern University of Applied Sciences}

\RequirePackage{l3keys2e}

\mode<presentation>

\RequirePackage{trimclip}


\keys_define:nn {ptxcd/beamer/inner} {
	authorontitle .bool_gset:N = \g_ptxcd_authorontitle_bool,
	authorontitle .initial:n = false,
	authorontitle .default:n = true,
	logofile .tl_gset:N = \g_ptxcd_logofile_tl,
	logofile .initial:n =,
	enforce-title-logo .bool_gset:N = \g_ptxcd_enforce_titlelogo_bool,
	enforce-title-logo .initial:n = false,
}
\ProcessKeysOptions{ptxcd/beamer/inner}

%logo setup & fallback
\PassOptionsToPackage{variant=C,init-inverted=true,height=\g__ptxcd_logo_height_dim}{bfhlogo}

\file_if_exist:nTF {bfhlogo.sty}
{
	\RequirePackage{bfhlogo}
}
{
	\tl_if_empty:NT \g_ptxcd_logofile_tl {
		\msg_new:nnnn {bfh-ci} {missing-bfhlogo}
		{I~could~not~find~the~bfhlogo~package.}
		{Please~have~a~look~at~the~bfh-ci~documentation~for~more~information~or~provide~an~alternative~using~the~logofile~option.}
		\msg_warning:nn {bfh-ci} {missing-bfhlogo}
	}
}

\box_if_exist:NF \g__ptxcd_logo_box {
	\box_new:N \g__ptxcd_logo_box
	\box_new:N \g__ptxcd_inverted_logo_box
}

\tl_if_empty:NF \g_ptxcd_logofile_tl {
	\hbox_gset:Nn \g__ptxcd_logo_box {\includegraphics[height=\g__ptxcd_logo_height_dim]{\g_ptxcd_logofile_tl}}
	\box_gset_eq:NN \g__ptxcd_inverted_logo_box \g__ptxcd_logo_box
}

\box_new:N \l__ptxcd_titlegraphic_box
\box_new:N \l__ptxcd_titlehead_box
\dim_new:N \l__ptxcd_titlegraphic_ht_dim
\dim_new:N \l__ptxcd_titlegraphic_wd_dim

\dim_new:N \g__ptxcd_titlerule_dim
\dim_gset:Nn \g__ptxcd_titlerule_dim {4pt}

%initialize sidebarwidth, only required if sidebar is not active (\z@)
\newdimen\beamer@sidebarwidth

\@ifpackageloaded{beamerouterthemeBFH}{}{
	\dim_new:N \g__ptxcd_beamer_logosep_dim
	\dim_new:N \l__ptxcd_beamer_extraindent_dim
	\dim_new:N \g__ptxcd_beamer_sep_dim
}

\newcommand*{\partnerlogo}[1]{\def\insertpartnerlogo{\def\height{\g__ptxcd_logo_height_dim}#1}}
\partnerlogo{}

\RenewDocumentCommand{\titlegraphic}{sm}{
	\IfBooleanTF{#1}{
		\def\inserttitlegraphic{
			\hbox_set:Nn \l__ptxcd_titlegraphic_box {\raisebox{\depth}{#2}}
			\box_resize_to_wd:Nn \l__ptxcd_titlegraphic_box {\l__ptxcd_titlegraphic_wd_dim}
			\dim_compare:nTF {\box_ht:N \l__ptxcd_titlegraphic_box - \l__ptxcd_titlegraphic_ht_dim > \c_zero_dim}
			{
				\dim_set:Nn \l_tmpa_dim {.5\box_ht:N \l__ptxcd_titlegraphic_box - .5\l__ptxcd_titlegraphic_ht_dim}
				\clipbox{0pt~\dim_eval:n{\l_tmpa_dim}~0pt~\dim_eval:n{\l_tmpa_dim}}{\box_use:N \l__ptxcd_titlegraphic_box}
			}{
				\box_resize_to_ht:Nn \l__ptxcd_titlegraphic_box {\l__ptxcd_titlegraphic_ht_dim}
				\dim_set:Nn \l_tmpa_dim {(\box_wd:N \l__ptxcd_titlegraphic_box - \l__ptxcd_titlegraphic_wd_dim) / 2}
				\clipbox{\dim_eval:n{\l_tmpa_dim}~0pt~\dim_eval:n{\l_tmpa_dim}~0pt}{\box_use:N \l__ptxcd_titlegraphic_box}
			}
		}
	}{
		\def\inserttitlegraphic{#2}
	}
}

\newcommand*{\inserttitleVcenter}[1]{
	\usebeamerfont{title}
	\vbox_to_ht:nn {#1} {
		\skip_vertical:n {.6\g__ptxcd_logo_height_dim plus 1 fill}
		\leavevmode\inserttitle
		\skip_vertical:n {\c_zero_dim plus 1 fill}
	}
}

\defbeamertemplate*{title~page~logo}{BFH}[1][\g__ptxcd_logo_box]{
	\skip_vertical:n {.333\g__ptxcd_logo_height_dim }
	\leavevmode\box_use:N #1
	\ifx\insertpartnerlogo\@empty
	\else
		\hfill
		\raisebox{\dim_eval:n {-\height+\box_ht:N #1}}[0pt][0pt]{\insertpartnerlogo}
	\fi
	\par\nointerlineskip
	\skip_vertical:n {\c_zero_dim plus 1 fill}
}

\defbeamertemplate*{author~inst~sep}{BFH}{{\usebeamercolor{author~inst~sep}\usebeamerfont{author~inst~sep}\space|\space}}

\defbeamertemplate*{author~in~title~page}{BFH}{
	\begingroup
	\usebeamerfont{author}
	\ifx\insertauthor\@empty
	\else
		{\usebeamercolor[fg]{author}\usebeamerfont{author}\insertauthor}
	\fi
	\ifx\insertinstitute\@empty
	\else
		\ifx\insertauthor\@empty
		\else
			\usebeamertemplate{author~inst~sep}
		\fi
		{\usebeamercolor[fg]{institute}\usebeamerfont{institute}\insertinstitute}
	\fi
	\endgroup
}

\defbeamertemplate*{title~ page}{BFH}[1][]
{
	\vskip-\beamer@frametopskip
	\nointerlineskip
	\vbox to \paperheight{
		\begin{beamercolorbox}[
				ht=.65\paperheight,
				wd=\dimexpr\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi\relax,
				leftskip=\beamer@leftmargin,
				rightskip=\beamer@rightmargin,
				vmode,
				#1
			]{title~page}
			\vbox_to_ht:nn {.65\paperheight} {
			\bool_if:NT \g_ptxcd_enforce_titlelogo_bool {
				\setbeamertemplate{title~page~logo}[BFH][\g__ptxcd_inverted_logo_box]
				\usebeamertemplate{title~page~logo}
			}
			\skip_vertical:n {.833\g__ptxcd_logo_height_dim plus 1 fill}
			\usebeamerfont{title}\inserttitle\par%
			\ifx\insertsubtitle\@empty%
			\else%
				\vskip0.25em%
				{\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
			\fi%
			\par
			\vskip1em\par
			{\usebeamercolor[fg]{date}\usebeamerfont{date}\insertdate\par}
			\par
			\vfill
			\bool_if:NT \g_ptxcd_authorontitle_bool {
				\usebeamertemplate{author~in~title~page}
				\skip_vertical:n {.333\g__ptxcd_logo_height_dim}
			}
			\null
			}
		\end{beamercolorbox}
		\par
		\nointerlineskip
		\begin{beamercolorbox}[
				ht=\g__ptxcd_titlerule_dim,
				wd=\dim_eval:n {\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi}
			]{title~rule}
		\end{beamercolorbox}
		\ifbeamer@plainframe
			\vspace*{\fill}
			\usebeamertemplate{footline}\par
		\fi
	}
}

\defbeamertemplate{title~ page}{BFH-Orange}[1][]
{
	\vskip-\beamer@frametopskip
	\nointerlineskip
	\vbox to \paperheight{
		\begin{beamercolorbox}[
				ht=.8\paperheight,
				dp=0pt,
				wd=\dimexpr\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi\relax,
				leftskip=\beamer@leftmargin,
				rightskip=\beamer@rightmargin,
				vmode
			]{title~page.invert}
			\vbox_to_ht:nn {.8\paperheight} {
			\usebeamertemplate{title~page~logo}
			{\usebeamercolor[fg]{title}\usebeamerfont{title}\inserttitle\par}%
			\ifx\insertsubtitle\@empty%
			\else%
				\vskip0.25em%
				{\usebeamercolor[fg]{subtitle}\usebeamerfont{subtitle}\insertsubtitle\par}%
			\fi%
			\par
			\vskip1em\par
			{\usebeamercolor[fg]{date}\usebeamerfont{date}\insertdate\par}
			\vfill
			\bool_if:NT \g_ptxcd_authorontitle_bool {
				\usebeamertemplate{author~in~title~page}
				\skip_vertical:n {.333\g__ptxcd_logo_height_dim}
			}
			\null
			}
		\end{beamercolorbox}
		\nointerlineskip
		\begin{beamercolorbox}[
				ht=\g__ptxcd_titlerule_dim,
				wd=\dim_eval:n {\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi}
			]{title~rule.invert}
		\end{beamercolorbox}
		\ifbeamer@plainframe
			\vspace*{\fill}
			\usebeamertemplate{footline}\par
		\fi
	}
}

\defbeamertemplate{title~ page}{BFH-graphic}[1][]
{
	\vskip-\beamer@frametopskip
	\nointerlineskip
	\dim_set:Nn \l__ptxcd_titlegraphic_ht_dim {.65\paperheight}
	\dim_set:Nn \l__ptxcd_titlegraphic_wd_dim {\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi}
	\vbox_to_ht:nn {\paperheight}{
		\begin{beamercolorbox}[
				wd=\dimexpr\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi\relax,
				ht=0pt,
				dp=0pt,
				vmode]{title~page}
			\raisebox{-\height}{\inserttitlegraphic}
		\end{beamercolorbox}
		\nointerlineskip
		\vbox_to_ht:nn {\l__ptxcd_titlegraphic_ht_dim}{
			\usebeamertemplate{title~page~logo}
			\vfill
		}
		\nointerlineskip
		\begin{beamercolorbox}[
				ht=\g__ptxcd_titlerule_dim,
				wd=\dimexpr\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi\relax
			]{title~rule}
		\end{beamercolorbox}
		\vskip.5\baselineskip
		\begin{beamercolorbox}[wd=\dimexpr\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi\relax,leftskip=\beamer@leftmargin,
				rightskip=\beamer@rightmargin,#1]{title~page.bottom}
			{\usebeamerfont{title}\inserttitle\par}%
			\ifx\insertsubtitle\@empty%
			\else%
				\vskip0.25em%
				{\usebeamerfont{subtitle}\insertsubtitle\par}%
			\fi%
			\par
			\ifx\insertsubtitle\@empty%
				\else%
				{\usebeamerfont{date}\insertdate}
				\par
			\fi
			\bool_if:NT \g_ptxcd_authorontitle_bool {
				\usebeamertemplate{author~in~title~page}
			}
		\end{beamercolorbox}
		\ifbeamer@plainframe
			\vspace*{\fill}
			\usebeamertemplate{footline}\par
		\fi
	}
}

\defbeamertemplate{title~ page}{BFH-fullgraphic}[1][]
{
	\vskip-\beamer@frametopskip
	\nointerlineskip
	\dim_set:Nn \l__ptxcd_titlegraphic_ht_dim {\paperheight}
	\dim_set:Nn \l__ptxcd_titlegraphic_wd_dim {\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi}
	\vbox_to_ht:nn {\paperheight}{
		\begin{beamercolorbox}[wd=\l__ptxcd_titlegraphic_wd_dim,ht=0pt,dp=0pt,vmode]{title~page}
			\raisebox{-\height}{\inserttitlegraphic}
		\end{beamercolorbox}
		\nointerlineskip
		\vbox_to_ht:nn {.5\paperheight}{
			\usebeamertemplate{title~page~logo}
			\vfill
		}
		\nointerlineskip
		\begin{beamercolorbox}[
				ht=\g__ptxcd_titlerule_dim,
				wd=\dim_eval:n {.75\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi},
			]{title~rule}
		\end{beamercolorbox}\nointerlineskip
		\begin{beamercolorbox}[
				wd=\dim_eval:n {.75\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi},
				ht=.3\paperheight,
				sep=1ex,
				vmode,
				#1
			]{title~page.boxed}
			\vbox_to_ht:nn {.3\paperheight} {
			\vskip1.25em
			{\usebeamerfont{title}\inserttitle\par}%
			\ifx\insertsubtitle\@empty%
			\else%
				\vskip0.25em%
				{\usebeamerfont{subtitle}\insertsubtitle\par}%
			\fi%
			\par\vfill
			\ifx\insertsubtitle\@empty%
				\else%
				{\usebeamerfont{date}\leavevmode\insertdate}
				\par
			\fi
			\bool_if:NT \g_ptxcd_authorontitle_bool {
				\usebeamertemplate{author~in~title~page}
			}
			}
		\end{beamercolorbox}
		\ifbeamer@plainframe
			\vspace*{\fill}
			\usebeamertemplate{footline}\par
		\fi
	}
}

\cs_new:Nn \__ptxcd_content_separator:n {
	\vskip-\beamer@frametopskip\relax
	\nointerlineskip
	\vbox_to_ht:nn {\paperheight}{
		\bool_if:NT \l__ptxcd_content_separator_ruled_bool {
			\vspace*{.1\paperheight}
			\begin{beamercolorbox}[ht=\g__ptxcd_titlerule_dim,wd=\dimexpr\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi\relax]{title~rule}
			\end{beamercolorbox}
			\nointerlineskip
		}
		\begin{beamercolorbox}[ht=\bool_if:NTF \l__ptxcd_content_separator_ruled_bool {.5} {.65}\paperheight,wd=\dimexpr\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi\relax,leftskip=\beamer@leftmargin,rightskip=\beamer@rightmargin,vmode]{title~page}
			\vbox_to_ht:nn {\bool_if:NTF \l__ptxcd_content_separator_ruled_bool {.5} {.65}\paperheight} {
				\skip_vertical:n {.333\g__ptxcd_logo_height_dim \bool_if:NT \l__ptxcd_content_separator_ruled_bool {plus 1 fill} }
				\leavevmode
				\usebeamerfont{#1~title}
				\use:c {insert#1}
				\vfill
				\null
			}
		\end{beamercolorbox}
		\nointerlineskip
		\begin{beamercolorbox}[ht=\g__ptxcd_titlerule_dim,wd=\dimexpr\paperwidth\ifbeamer@plainframe\else-\beamer@sidebarwidth\fi\relax]{title~rule}
		\end{beamercolorbox}
		\bool_if:NT \l__ptxcd_content_separator_ruled_bool {\vfill}
		\ifbeamer@plainframe
		\vspace*{\fill}
		\usebeamertemplate{footline}\par
		\fi
	}
}

\NewDocumentCommand{\separatorpage}{sm}{
	\IfBooleanTF{#1}
		{\bool_set_true:N \l__ptxcd_content_separator_ruled_bool}
		{\bool_set_false:N \l__ptxcd_content_separator_ruled_bool}
	\__ptxcd_content_separator:n {#2}
}


\cs_new:Nn \__ptxcd_block_begin:n {
	\par\vskip\medskipamount%
	\begin{beamercolorbox}[
			wd=\dimexpr\linewidth+2\l__ptxcd_beamer_extraindent_dim,
			sep=1.5pt,
			leftskip=\dimexpr\ifdim\l__ptxcd_beamer_extraindent_dim>\z@\l__ptxcd_beamer_extraindent_dim-\beamer@colbox@sep\else\z@\fi,
		]{block~frame#1}
		\ifx\insertblocktitle\@empty
		\else
			\begin{beamercolorbox}[wd={\dimexpr\linewidth-3pt},colsep=.75ex]{block~title#1}
				\usebeamerfont*{block~title#1}\insertblocktitle%
			\end{beamercolorbox}%
			\vskip1.5pt\par\nointerlineskip
		\fi
		\leavevmode
		\usebeamerfont{block~body#1}%
		\begin{beamercolorbox}[wd={\dimexpr\linewidth-3pt},colsep=.75ex]{block~body#1}%
			}

			\cs_new:Nn \__ptxcd_block_end: {\end{beamercolorbox}\end{beamercolorbox}\vskip\smallskipamount}

\defbeamertemplate*{block~begin}{BFH}{\__ptxcd_block_begin:n {}}
\defbeamertemplate*{block~end}{BFH}{\__ptxcd_block_end:}

\defbeamertemplate*{block~alerted~begin}{BFH}{\__ptxcd_block_begin:n {~alerted}}
\defbeamertemplate*{block~alerted~end}{BFH}{\__ptxcd_block_end:}

\defbeamertemplate*{block~example~begin}{BFH}{\__ptxcd_block_begin:n {~example}}
\defbeamertemplate*{block~example~end}{BFH}{\__ptxcd_block_end:}

%Itemize Items
\defbeamertemplate*{itemize~item}{BFH}{\usebeamerfont*{itemize~item}\raise\dimexpr.4\ht\strutbox-.4ex\hbox{\rule{.8ex}{.8ex}}}
\defbeamertemplate*{itemize~subitem}{BFH}{\usebeamerfont*{itemize~item}\setlength{\fboxsep}{\z@}\setlength{\fboxrule}{1pt}\raise\dimexpr.4\ht\strutbox-.2ex-\fboxrule\hbox{\fbox{\color{bg}\rule{.4ex}{.4ex}}}}
\defbeamertemplate*{itemize~subsubitem}{BFH}{\usebeamerfont*{itemize~subitem}\hbox{--}}

\def\maketitle{
	\ifbeamer@inframe\titlepage\else\frame[plain]{\titlepage}\fi
}


\clist_map_inline:nn {section,subsection,lecture} {
	\exp_args:Nc \def{#1page}{
		\ifbeamer@inframe\usebeamertemplate*{#1~page}\else\frame[plain]{\usebeamertemplate*{#1~page}}\fi
	}

\defbeamertemplate*{#1~page}{BFH}
	{\separatorpage{#1}}

\defbeamertemplate{#1~page}{BFH-ruled}
	{\separatorpage*{#1}}
}



\mode<all>

\endinput

