%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% BEAMER THEME FOR CRANS %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% place in same folder as your .tex
% \usetheme{ens} in preamble
% also need crans-logo.png

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{ensbeamer}[2019/09/04 Beamer Theme]
\RequirePackage{tikz}
\RequirePackage{xcolor}

\makeatletter
\newif\if@section\@sectionfalse
\DeclareOption{sectiontitle}{
  \@sectiontrue
}

\ProcessOptions\relax

\definecolor{rougecrans}{RGB}{207,14,34} % rougecrans !

\setbeamercolor{structure}{fg=rougecrans}
%\setbeamercolor{sidebar}{fg=rougecrans,bg=white}
\setbeamercolor{sidebar}{bg=white,fg=rougecrans}
%\setbeamercolor{title in sidebar}{fg=white}
%\setbeamercolor{section in sidebar}{fg=white}
 \setbeamercolor{section in sidebar shaded}{fg=rougecrans!40}
 \setbeamercolor{subsection in sidebar}{fg=rougecrans}
 \setbeamercolor{subsection in sidebar shaded}{fg=rougecrans!60}
 \setbeamercolor{frametitle}{fg=rougecrans,bg=white}

\def\swidth{2cm}

%
% -----------------------------
% Title Page

\setbeamerfont{title}{size=\Huge}
\setbeamerfont{author}{size=\large}
\setbeamerfont{institut}{size=\Large}
\setbeamerfont{subtitle}{size=\Large}
\setbeamerfont{date}{size=\Large}
\setbeamertemplate{title page}{%
\begin{tikzpicture}[remember picture,overlay]
\fill[white]
  (current page.north west) rectangle (current page.south east);
\node
  at ([yshift=+.15\textheight]current page.center) (title)
  {\usebeamerfont{title}\textcolor{rougecrans}{\inserttitle}};

\node[below=2em]
  at(title) (subtitle)
  {\usebeamerfont{subtitle}\textcolor{rougecrans}{\insertsubtitle}};

\node
  at ([yshift=-70pt]current page.center) (institute)
  {\usebeamerfont{institute}\textcolor{rougecrans}{\insertinstitute}};

\node
  at ([yshift=-50pt]current page.center) (author)
  {\usebeamerfont{author}\textcolor{rougecrans}{\insertauthor}};

\node [opacity=.15] at (current page.center) {\includegraphics[height=0.9\textheight]{crans-logo} };

\end{tikzpicture}
}



%
% --------------------------------------
% Sidebar

\useoutertheme[height=0pt,width=\swidth, hideothersubsections]{sidebar}

\setbeamertemplate{sidebar left}
{
  {\vspace{0.9em}
\hspace{-0.4em}
    \begin{minipage}{\swidth}
      \centering
      \insertlogo
    \end{minipage}
  \usebeamerfont{title in sidebar}%
    \vskip1em%
    \usebeamercolor[fg]{title in sidebar}%
    \insertshorttitle[width=\swidth,center,respectlinebreaks]\par%
    \vskip.5em%
  }%
  \insertverticalnavigation{\swidth}%
  \vfill
  \hbox to2cm{\hskip0.6cm\usebeamerfont{section in sidebar} \strut\usebeamercolor[fg]{section in    sidebar}\insertframenumber/\inserttotalframenumber\hfill}%
  \vskip3pt%
}%


% --------------------------------------------------------------------------
% Section as frame title
\if@section
\addtobeamertemplate{frametitle}{
   \let\insertframetitle\insertsectionhead}{}
\addtobeamertemplate{frametitle}{
   \let\insertframesubtitle\insertsubsectionhead}{}

\makeatletter
 \CheckCommand*\beamer@checkframetitle{\@ifnextchar\bgroup\beamer@inlineframetitle{}}
  \renewcommand*\beamer@checkframetitle{\global\let\beamer@frametitle\relax\@ifnextchar\bgroup\beamer@inlineframetitle{}}

  \fi

\setbeamertemplate{caption}{\raggedright\insertcaption\par}
\setbeamertemplate{navigation symbols}[horizontal]

% ---------------------------------------------------
% BLOC

\setbeamertemplate{blocks}[rounded][shadow=false]
\setbeamercolor{block body}{fg=black,bg=rougecrans!20}
\setbeamercolor{block title}{fg=black,bg=rougecrans!40}

\setbeamercolor{block body example}{fg=black,bg=gray!40}
\setbeamercolor{block title example}{fg=black,bg=gray}

\setbeamercolor{block body alerted}{fg=black,bg=blue!40}
\setbeamercolor{block title alerted}{fg=black,bg=blue}

\setbeamercolor{subitem}{fg=rougecrans!20}

\makeatother
% LOGO :
\logo{\includegraphics[width=\swidth]{crans-logo.png}}
