\usepackage{pgf,tikz}

\usepackage{calc}
\usetheme{boxes}

%% Dimension variables
\newdimen\beamer@sidebarwidth
\newdimen\beamer@circleoriginx
\newdimen\beamer@circleoriginy
\newdimen\beamer@circleradius
\newdimen\beamer@pheight
\newdimen\beamer@pwidth
\beamer@pheight=\the\paperheight
\beamer@pwidth=\the\paperwidth 

%% Background placement values
\beamer@sidebarwidth=2cm
\beamer@circleoriginx=10cm % (positive value) distance from the border

%% Seminar colors
\definecolor{lrdeblue}{rgb}{0.254,0.274,0.545}
\definecolor{lrdelightblue}{rgb}{0.670,0.780,0.898}

\definecolor{lrdelightred}{rgb}{1,0.43,0.39}
\definecolor{lrdered}{rgb}{0.43,0,0}

\definecolor{lrdegreen}{rgb}{0.118,0.314,0.255}
\definecolor{lrdelightgreen}{rgb}{0.510,0.863,0.686}

%% Defaults options
\def\beamer@seminarcolor{lrdeblue}
\def\beamer@seminarlightcolor{lrdelightblue}

\def\beamer@sidebarside{left}
\def\beamer@navigation{nonavsym}

%% Logo
\pgfdeclaremask{logo_mask}{lrdemask}
\pgfdeclareimage[mask=logo_mask,width=\beamer@sidebarwidth]{logo}{logo_lrde-blue}

%% Options mechanism
\DeclareOptionBeamer{color}{
  \def\beamer@seminarcolor{lrde#1}
  \def\beamer@seminarlightcolor{lrdelight#1}
  \pgfdeclareimage[mask=logo_mask,width=\beamer@sidebarwidth]{logo}{logo_lrde-#1}
}

\DeclareOptionBeamer{left}{\def\beamer@sidebarside{left}}
\DeclareOptionBeamer{right}{\def\beamer@sidebarside{right}}
\DeclareOptionBeamer{navsym}{\def\beamer@navigation{navsym}}
\DeclareOptionBeamer{nonavsym}{\def\beamer@navigation{nonavsym}}

\ProcessOptionsBeamer

%% Text defintions (for ifx use)
\def\beamer@textleft{left}
\def\beamer@textright{right}
\def\beamer@textnonavsym{nonavsym}
\def\beamer@textnavsym{navsym}

%% Font 
\usefonttheme{professionalfonts}

% Compute background infor
\beamer@circleoriginy=0.5\beamer@pheight
\beamer@circleradius=\beamer@pwidth
\addtolength{\beamer@circleradius}{-\beamer@sidebarwidth}
\addtolength{\beamer@circleradius}{\beamer@circleoriginx}

\ifx\beamer@sidebarside\beamer@textleft
  \addtolength{\beamer@circleoriginx}{\beamer@pwidth}
\else
  \beamer@circleoriginx=-\beamer@circleoriginx
\fi

\setbeamercolor{structure}{fg=\beamer@seminarcolor}
\colorlet{beamerstructure}{\beamer@seminarcolor}

%% Background curve

\usebackgroundtemplate{
  \begin{pgfpicture}{0cm}{0cm}{\the\paperwidth}{\the\paperheight}
    \pgfsetcolor{\beamer@seminarcolor}
    \pgfpathrectangle{\pgfpoint{0cm}{0cm}}{\pgfpoint{\the\paperwidth}{\the\paperheight}}
    \pgfusepath{clip,fill}

    \pgfsetcolor{white}
    \pgfpathcircle{\pgfpoint{\beamer@circleoriginx}{\beamer@circleoriginy}}{\beamer@circleradius}

    \ifx\beamer@sidebarside\beamer@textleft
      \pgfpathrectangle{\pgfpoint{\beamer@sidebarwidth}{\beamer@circleoriginy}}{\pgfpoint{\beamer@pwidth}{\beamer@pheight}}
      \pgfusepath{fill}

      \pgfsetcolor{\beamer@seminarcolor}
      \pgfpathcircle{\pgfpoint{\beamer@pwidth}{-1.5cm}}{2cm}
      \pgfusepath{fill}
			
      \pgftext[x=0.1cm,y=0.5cm,\beamer@sidebarside,base]{\pgfuseimage{logo}}
    \else
      \pgfpathrectangle{\pgfpoint{0cm}{\beamer@circleoriginy}}{\pgfpoint{\beamer@pwidth-\beamer@sidebarwidth}{\beamer@pheight}}
      \pgfusepath{fill}

      \pgfsetcolor{\beamer@seminarcolor}
      \pgfpathcircle{\pgfpoint{0cm}{-1.5cm}}{2cm}
      \pgfusepath{fill}
			
      \pgftext[x=\beamer@pwidth-0.1cm,y=0.5cm,\beamer@sidebarside,base]{\pgfuseimage{logo}}
    \fi
  \end{pgfpicture}
}

\useheadtemplate{}
\usefoottemplate{}

%% Frametitles
\beamertemplatelargeframetitle

%% Itemizes
\useitemizeitemtemplate{\tiny\raise1.5pt\hbox{\color{beamerstructure}$\blacktriangleright$}}
\usesubitemizeitemtemplate{\tiny\raise1.5pt\hbox{\color{beamerstructure}\textbullet}}
\usesubsubitemizeitemtemplate{\tiny\raise1.5pt\hbox{\color{beamerstructure}\textbullet}}

%% Sidesbar

\def\beamer@sidebarformat#1#2#3{
  \begin{beamercolorbox}[wd=\beamer@sidebarwidth,leftskip=#1,rightskip=1ex plus1fil,vmode]{#2}
    \vbox{}
    #3\par
    \vbox{}
    \vskip-1.5ex
  \end{beamercolorbox}
}

\defbeamertemplate*{section in sidebar}{sidebar theme}
{
  \vbox{
    \vskip1ex
    \beamer@sidebarformat{5pt}{section in sidebar}{\color{white}\insertsectionhead}
  }
}
\defbeamertemplate*{section in sidebar shaded}{sidebar theme}
{
  \vbox{
    \vskip1ex
    \beamer@sidebarformat{5pt}{section in sidebar shaded}{\insertsectionhead}
  }
}

\defbeamertemplate*{subsection in sidebar}{sidebar theme}
{
  \beamer@sidebarformat{8pt}{subsection in sidebar}{\color{white}\insertsubsectionhead}
}
\defbeamertemplate*{subsection in sidebar shaded}{sidebar theme}
{
  \beamer@sidebarformat{8pt}{subsection in sidebar shaded}{\insertsubsectionhead}
}

\defbeamertemplate*{headline in sidebar}{sidebar theme}
{
  \setbeamerfont{shortauthor in sidebar}{size=\large,series=\bfseries} 
  \setbeamercolor{shortauthor in sidebar}{fg=white} 
}

\setbeamersize{sidebar width \beamer@sidebarside=\beamer@sidebarwidth}
\defbeamertemplate*{sidebar \beamer@sidebarside}{sidebar theme}
{
  \color{\beamer@seminarlightcolor}
  \beamer@tempdim=\beamer@sidebarwidth
  \advance\beamer@tempdim by -6pt

  \vskip0.2cm

  \insertshorttitle[width=\beamer@sidebarwidth,center,respectlinebreaks]

  \vskip1.0cm
      
  \insertverticalnavigation{\beamer@sidebarwidth}
  \vfill
}

%% Navigation

\setbeamertemplate{navigation symbols}{}
\newcommand\setnavigation{
  \ifx\beamer@navigation\beamer@textnavsym
    \insertslidenavigationsymbol
    \insertsectionnavigationsymbol
    \insertdocnavigationsymbol
    \insertbackfindforwardnavigationsymbol
  \fi
}
  
\setbeamertemplate{footline} 
{
  \color{\beamer@seminarlightcolor}

  \makebox[\textwidth]{
    \ifx\beamer@sidebarside\beamer@textleft
      \makebox[\beamer@sidebarwidth + 0.5cm]{\insertshortauthor}
      % \makebox{\color{\beamer@seminarcolor} \insertshortsubtitle}
      \hfill
	\setnavigation
      \hskip0.5cm
      \makebox[0.72cm][r]{\insertframenumber~/~\inserttotalframenumber}
    \else
      \makebox[0.72cm][r]{\insertframenumber~/~\inserttotalframenumber}
      \hskip0.5cm
	\setnavigation
      \hfill
      % \makebox{\color{\beamer@seminarcolor} \insertshortsubtitle}
      \makebox[\beamer@sidebarwidth + 0.5cm]{\insertshortauthor}
    \fi
  }
  \vskip0.1cm
}

\setbeamersize{text margin left=0.5cm,text margin right=0.5cm}
\setbeamercolor{quote}{bg=\beamer@seminarlightcolor!10}

\mode<all>