% This is the outer theme file of the Feather theme.
% Copyright (c) 2014 by Lilyana Vaskova Vankova <lilqna.v@gmail.com>
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You can find the GNU General Public License at <http://www.gnu.org/licenses/>.

%----------------------------------------------------------------------------------------------------------------------------------

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{beamerouterthemeFeather}[2017/08/22 v1.1.0 The Feather Beamer Theme]

%----------------------------------------------------------------------------------------------------------------------------------

% Load required packages

\RequirePackage{tikz}
\RequirePackage{calc}

%% LLT: Added \logofile to make logo configurable
\newcommand{\logofile}{2-logo}
\newcommand{\logoscale}{0.875}

%% LLT: Added unnumberedframe to keep track of
%% Frames to be ignored for progressbar
\newcounter{unnumberedframe}
\define@key{beamerframe}{noframenumbering}[true]{\stepcounter{unnumberedframe}\beamer@noframenumberingtrue}


%----------------------------------------------------------------------------------------------------------------------------------

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Theme options, definitions and templates.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------------------------------------------------

% Options for the progress bar/circle
\def\beamer@progressmovingCircCnt{movingCircCnt} % moving circular counter
\def\beamer@progressfixedCircCnt{fixedCircCnt} % fixed circular counter
\def\beamer@progresscorner{corner} % a counter
\def\beamer@progressstyle{movingCircCnt} % default
\DeclareOptionBeamer{progressstyle}{\def\beamer@progressstyle{#1}}
\DeclareOptionBeamer{rotationcw}{\def\beamer@rotationcw{true}}
\DeclareOptionBeamer{shownavsym}{\def\beamer@shownavsym{true}}
\ProcessOptionsBeamer

%----------------------------------------------------------------------------------------------------------------------------------

% The height of the header is 2.5 times the lineheight of the frame title
\newlength{\beamer@height}
\usebeamerfont{frametitle} % Use the frame title font
\setlength{\beamer@height}{2.5\baselineskip}

%----------------------------------------------------------------------------------------------------------------------------------

% Reset fonts
\reset@font

%----------------------------------------------------------------------------------------------------------------------------------

% Radius of the logo
\newlength{\beamer@logoradius}
\setlength{\beamer@logoradius}{0.95\beamer@height/2}

%----------------------------------------------------------------------------------------------------------------------------------

% Width of the border
\newlength{\beamer@borderwidth}
               \setlength{\beamer@borderwidth}{1.05mm} % As small is the thickness of the border the whole circle goes up
 
%----------------------------------------------------------------------------------------------------------------------------------

% Inner radius of border of the logo frame
\newlength{\beamer@logoinnerradius}
\setlength{\beamer@logoinnerradius}{0.85\beamer@logoradius} 

%----------------------------------------------------------------------------------------------------------------------------------

% Radius of the outer border of the logo frame
\newlength{\beamer@logoouterradius}
\setlength{\beamer@logoouterradius}{\beamer@logoinnerradius+\beamer@borderwidth}

%----------------------------------------------------------------------------------------------------------------------------------

% Radius of the counters
\newlength{\beamer@counterradius}
\setlength{\beamer@counterradius}{\beamer@logoinnerradius/2+\beamer@logoouterradius/2}

%----------------------------------------------------------------------------------------------------------------------------------

% Beamer specific options
\mode<presentation> % Refers to the first four modes (beamer,handout,second and trans). That is, to all modes except the article mode
{
\ifbeamercolorempty[fg]{Feather}{
	\setbeamercolor{Feather}{use = {structure, palette sidebar primary}, fg = palette sidebar primary.fg, bg = structure.fg}
}

%----------------------------------------------------------------------------------------------------------------------------------

 % Headline
\setbeamertemplate{headline}{\featherheaderbackground}

%----------------------------------------------------------------------------------------------------------------------------------

% Footline  
\setbeamertemplate{footline}
	{
	\begin{beamercolorbox}[wd = 1.0\paperwidth, ht = 1.25ex, dp = 1ex, left]{headfoot}
		{\usebeamercolor[fg]{frametitle}\usebeamerfont{section in head/foot}\hspace*{3.5ex}
		\insertshortauthor\ |\ 
		\insertshorttitle
		\insertshortsubtitle
		}
	\end{beamercolorbox}
	}

%----------------------------------------------------------------------------------------------------------------------------------

% Frame title
\setbeamertemplate{frametitle}
	{
	\begin{minipage}[c][0.9\beamer@height][c]{\textwidth}
		{\usebeamercolor[fg]{frametitle}\usebeamerfont{frametitle}\insertframetitle\par}
		{\usebeamercolor[fg]{framesubtitle}\usebeamerfont{framesubtitle}\insertframesubtitle\par}
	\end{minipage}
	}
	\ifx\beamer@shownavsym\undefined % insert navigation symbols
		\setbeamertemplate{navigation symbols}
		
	\fi % Saut de ligne obligatoire ici
}

%----------------------------------------------------------------------------------------------------------------------------------

% Macros used in the theme 
%% Coordinate the fancy header background
\newcommand{\featherheaderbackground}[0]{
	\begin{tikzpicture}[overlay]
		\coordinate (UL) at (0,0); % Upper left corner of the slide
		\coordinate (HLR) at (\paperwidth,-0.9\beamer@height); % Lower right of the header
		\coordinate (ULL) at (0,-0.95\beamer@height); % Upper left corner of the line 
		\coordinate (LLR) at (\paperwidth,-1\beamer@height); % Lower right corner of the line 
		\coordinate (ULF) at (0, \dimexpr-\paperheight+1.6em\relax);
		%\coordinate (ULF) at (0,-5.90\beamer@height); % Upper left corner of the footline 
		\coordinate (LFR) at (\paperwidth,-\paperheight);
		%\coordinate (LFR) at (\paperwidth,-6.08\beamer@height); % Lower right corner of the footline 

		\coordinate (logopos) at ([shift = {(-\beamer@logoouterradius-2.05\beamer@borderwidth, \beamer@height-\beamer@logoouterradius-5.5\beamer@borderwidth)}] HLR); % Coordinate of the logo and the circ position

%----------------------------------------------------------------------------------------------------------------------------------

%% Draw the background of the header, the circle and the logo
	{
		\usebeamercolor{Feather}

%----------------------------------------------------------------------------------------------------------------------------------

%% Draw the blue background rectangle of the header and the line below it
		\draw[draw = none, fill = Feather.bg] (UL) rectangle (HLR); % Background rectangle
		\draw[draw = none, fill = Feather.fg] (ULL) rectangle (LLR); % Line below the background rectangle
		\draw[draw = none, fill = Feather.bg] (ULF) rectangle (LFR); % Footline 

%----------------------------------------------------------------------------------------------------------------------------------

%% Draw the outer circle
		\fill[fill = Feather.fg] (logopos) circle (\beamer@logoouterradius);

%----------------------------------------------------------------------------------------------------------------------------------

%% Draw the inner circle
		\fill[fill = normal text.bg] (logopos) circle (\beamer@logoinnerradius);

%----------------------------------------------------------------------------------------------------------------------------------

%% Place the logo in the circle
%% LLT: use customisable \logofile
		\node at (logopos) {\includegraphics[width = \dimexpr \logoscale \beamer@logoradius * 2\relax]{\logofile}};

%----------------------------------------------------------------------------------------------------------------------------------

%% Draw progress circle/bar
		\ifx\beamer@progressstyle\beamer@progressmovingCircCnt % The circular counter with a moving counter

%----------------------------------------------------------------------------------------------------------------------------------

%% Calculate end position
%%% LLT: modified to discount unnumbered frames, and
%%% Make the arc go a complete circle at end of
%%% Presentation
		\ifx\beamer@rotationcw\undefined % Counterclockwise rotation
			\pgfmathsetmacro{\effectivetotalframe}{max(\inserttotalframenumber-\theunnumberedframe,1)}
			\pgfmathsetmacro{\progress}{(\insertframenumber-\theunnumberedframe)/\effectivetotalframe*360};
		\else % Clockwise rotation
			\pgfmathsetmacro{\progress}{(\insertframenumber-\theunnumberedframe)/\effectivetotalframe*(-360)}; 
		\fi

%----------------------------------------------------------------------------------------------------------------------------------

%% Draw the arc
		\draw[color = Feather.bg, line width = 0.2*\beamer@borderwidth] ([xshift = \beamer@counterradius] logopos) arc[radius = \beamer@counterradius, start angle = 0, end angle = \progress];
		\fill[fill = Feather.bg] ([shift = {(\progress:\beamer@counterradius)}] logopos) circle (0.25\beamer@borderwidth);

%----------------------------------------------------------------------------------------------------------------------------------

%% Place the current frame number
		\node[fill = normal text.bg, draw = Feather.fg, thick, circle,minimum width = 2*\beamer@borderwidth] at ([xshift = \beamer@counterradius]logopos) {{\usebeamercolor[fg]{normal text}\insertframenumber}};
		\fi      
		\ifx\beamer@progressstyle\beamer@progressfixedCircCnt % The circular counter with a fixed counter

%----------------------------------------------------------------------------------------------------------------------------------

%% Draw the current frame number
		\ifx\beamer@rotationcw\undefined % Counterclockwise rotation
			\pgfmathsetmacro{\progress}{360*\insertframestartpage};
		\else % Clockwise rotation
			\pgfmathsetmacro{\progress}{-360*\insertframestartpage};
		\fi

%----------------------------------------------------------------------------------------------------------------------------------

%% Draw the arc
		\draw[color = Feather.bg, line width = 0.5*\beamer@borderwidth] ([xshift = \beamer@counterradius] logopos) arc (0:\progress:\beamer@counterradius);

%----------------------------------------------------------------------------------------------------------------------------------

%% Place the current frame number
		\node[fill = normal text.bg, draw = Feather.fg, circle, thick, minimum width = 2*\beamer@borderwidth] at ([shift = {(\progress:\beamer@counterradius)}] logopos) {{\usebeamercolor[fg]{normal text}\insertframenumber}};
		\fi
	}
	\end{tikzpicture}
}

%----------------------------------------------------------------------------------------------------------------------------------

%% Setting the blocks
\setbeamertemplate{blocks}[rounded][shadow = true]
\setbeamercolor{block title}{fg = frametitle.fg, bg = frametitle.bg} 
\setbeamercolor{block body}{parent = normal text, use = block title, bg = Feather.fg!30}

\mode<all>