%Berkeley / Goettingen / Hannover / Marburg / PaloAlto / Rochester
\usetheme[hideothersubsections]{Goettingen}

\RequirePackage{pgf}
\RequirePackage{tikz}
\RequirePackage{pdfrender}

\tikzset{
  rectangle with rounded corners north west/.initial=4pt,
  rectangle with rounded corners south west/.initial=4pt,
  rectangle with rounded corners north east/.initial=4pt,
  rectangle with rounded corners south east/.initial=4pt,
}
%\makeatletter
\pgfdeclareshape{rectangle with rounded corners}{
  \inheritanchorborder[from=rectangle]
  \savedmacro{\neoffset}{
    \pgfkeysgetvalue{/tikz/rectangle with rounded corners north east}{\pgf@rectc}
    \let\neoffset\pgf@rectc
  }
  \savedmacro{\nwoffset}{
    \pgfkeysgetvalue{/tikz/rectangle with rounded corners north west}{\pgf@rectc}
    \let\nwoffset\pgf@rectc
  }
  \savedmacro{\seoffset}{
    \pgfkeysgetvalue{/tikz/rectangle with rounded corners south east}{\pgf@rectc}
    \let\seoffset\pgf@rectc
  }
  \savedmacro{\swoffset}{
    \pgfkeysgetvalue{/tikz/rectangle with rounded corners south west}{\pgf@rectc}
    \let\swoffset\pgf@rectc
  }
  \savedanchor{\north}{
    \pgf@y=.5\ht\pgfnodeparttextbox
    \pgf@x=0pt
    \setlength{\pgf@ya}{\pgfshapeminheight}
    \ifdim\pgf@y<.5\pgf@ya
      \pgf@y=.5\pgf@ya
    \fi
  }
  \savedanchor{\south}{
    \pgf@y=-.5\ht\pgfnodeparttextbox
    \pgf@x=0pt
    \setlength{\pgf@ya}{\pgfshapeminheight}
    \ifdim\pgf@y>-.5\pgf@ya
      \pgf@y=-.5\pgf@ya
    \fi
  }
  \savedanchor{\east}{
    \pgf@y=0pt
    \pgf@x=.5\wd\pgfnodeparttextbox
    \addtolength{\pgf@x}{2ex}
    \setlength{\pgf@xa}{\pgfshapeminwidth}
    \ifdim\pgf@x<.5\pgf@xa
      \pgf@x=.5\pgf@xa
    \fi
  }
  \savedanchor{\west}{
    \pgf@y=0pt
    \pgf@x=-.5\wd\pgfnodeparttextbox
    \addtolength{\pgf@x}{-2ex}
    \setlength{\pgf@xa}{\pgfshapeminwidth}
    \ifdim\pgf@x>-.5\pgf@xa
      \pgf@x=-.5\pgf@xa
    \fi
  }
  \savedanchor{\northeast}{
    \pgf@y=.5\ht\pgfnodeparttextbox % height of the box
    \pgf@x=.5\wd\pgfnodeparttextbox % width of the box
    \addtolength{\pgf@x}{2ex}
    \setlength{\pgf@xa}{\pgfshapeminwidth}
    \ifdim\pgf@x<.5\pgf@xa
      \pgf@x=.5\pgf@xa
    \fi
    \setlength{\pgf@ya}{\pgfshapeminheight}
    \ifdim\pgf@y<.5\pgf@ya
      \pgf@y=.5\pgf@ya
    \fi
  }
  \savedanchor{\southwest}{
    \pgf@y=-.5\ht\pgfnodeparttextbox
    \pgf@x=-.5\wd\pgfnodeparttextbox
    \addtolength{\pgf@x}{-2ex}
%     \pgf@x=0pt
    \setlength{\pgf@xa}{\pgfshapeminwidth}
    \ifdim\pgf@x>-.5\pgf@xa
      \pgf@x=-.5\pgf@xa
    \fi
    \setlength{\pgf@ya}{\pgfshapeminheight}
    \ifdim\pgf@y>-.5\pgf@ya
      \pgf@y=-.5\pgf@ya
    \fi
  }
  \anchor{text}{%
    \northeast%
    \pgf@x=-.5\wd\pgfnodeparttextbox%
    \pgfmathsetlength{\pgf@y}{-.5ex}
  }
  \anchor{north east}{
    \northeast
    \pgfmathsetmacro{\nw}{(1-sin(45))*\neoffset}
    \addtolength{\pgf@x}{-\nw pt}
    \addtolength{\pgf@y}{-\nw pt}
  }
  \anchor{center}{
    \pgf@x=0pt
    \pgf@y=0pt
  }
  \anchor{south west}{
    \southwest
    \pgfmathsetmacro{\nw}{(1-sin(45))*\swoffset}
    \addtolength{\pgf@x}{\nw pt}
    \addtolength{\pgf@y}{\nw pt}
  }
  \anchor{north west}{
    \northeast
    \pgfmathsetmacro{\temp@x}{\pgf@x}
    \southwest
    \pgfmathsetmacro{\temp@xtwo}{\pgf@x}
    \northeast
    \pgfmathsetmacro{\xdiff}{\temp@x-\temp@xtwo}
    \def\pgf@xa{\pgf@x-\xdiff}
    \
    \pgfmathsetmacro{\nw}{(1-sin(45))*\nwoffset}
    \def\pgf@xaa{\pgf@xa+\nw}
    \def\pgf@yaa{\pgf@y-\nw}
    \pgfpoint{\pgf@xaa}{\pgf@yaa}
  }
  \anchor{south east}{
    \southwest
    \pgfmathsetmacro{\temp@x}{\pgf@x}
    \northeast
    \pgfmathsetmacro{\temp@xtwo}{\pgf@x}
    \southwest
    \pgfmathsetmacro{\xdiff}{\temp@x-\temp@xtwo}
    \def\pgf@xa{\pgf@x-\xdiff}
    \pgfmathsetmacro{\nw}{(1-sin(45))*\seoffset}
    \def\pgf@xaa{\pgf@xa-\nw}
    \def\pgf@yaa{\pgf@y+\nw}
    \pgfpoint{\pgf@xaa}{\pgf@yaa}
  }
  \anchor{south}{\south}
  \anchor{north}{\north}
  \anchor{east}{\east}
  \anchor{west}{\west}
  \backgroundpath{% this is new
    % store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % construct main path
    \pgfkeysgetvalue{/tikz/rectangle with rounded corners north west}{\pgf@rectc}
    \pgfsetcornersarced{\pgfpoint{\pgf@rectc}{\pgf@rectc}}
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfkeysgetvalue{/tikz/rectangle with rounded corners north east}{\pgf@rectc}
    \pgfsetcornersarced{\pgfpoint{\pgf@rectc}{\pgf@rectc}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
    \pgfkeysgetvalue{/tikz/rectangle with rounded corners south east}{\pgf@rectc}
    \pgfsetcornersarced{\pgfpoint{\pgf@rectc}{\pgf@rectc}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
    \pgfkeysgetvalue{/tikz/rectangle with rounded corners south west}{\pgf@rectc}
    \pgfsetcornersarced{\pgfpoint{\pgf@rectc}{\pgf@rectc}}
    \pgfpathclose
 }
}

\pgfdeclareimage[width=1.4em]{uniheader}{\meta/config/images/logo}
\pgfdeclareimage[width=2.8em]{uniheadertitle}{\meta/config/images/logo}
\setbeamertemplate{blocks}[shadow=false]
\setbeamercovered{transparent}

\beamer@headheight=0.1\paperheight

\setbeamercolor*{Title bar}{fg=unibablueI}
\setbeamercolor*{Location bar}{fg=unibablueI,bg=white}
\setbeamercolor*{frametitle}{parent=Title bar}
\setbeamercolor*{block title}{bg=unibablueI,fg=white}
\setbeamercolor*{block body}{bg=unibagrayV,fg=black}
\setbeamercolor*{block title alerted}{bg=nounibaredII,fg=white}
\setbeamercolor*{block body alerted}{bg=unibaredV,fg=black}
\setbeamercolor*{block title example}{bg=unibayellowII,fg=black}
\setbeamercolor*{block body example}{bg=unibayellowV,fg=black}
\setbeamercolor*{normal text}{bg=white,fg=black}
\setbeamercolor*{alerted text}{fg=nounibaredII}
\setbeamercolor*{section in head/foot}{fg=unibablueI}
\setbeamercolor*{item}{fg=unibablueI, bg=unibagrayV}

\usecolortheme[named=unibablueI]{structure}

\setbeamerfont{section in head/foot}{size=\tiny,series=\normalfont}
\setbeamerfont{frametitle}{size=\large}

\setbeamertemplate{title page}{
\begin{tikzpicture}[remember picture,overlay]
\node[
anchor=south east,
  draw=unibablueV,
  thin,
  fill=unibablueV,
  shape=rectangle with rounded corners,
  minimum height=\paperheight-.2cm, minimum width=\beamer@sidebarwidth-.2cm,
  rectangle with rounded corners north west=0pt,
  rectangle with rounded corners south west=0pt,
  rectangle with rounded corners north east=18pt,
  rectangle with rounded corners south east=0pt,
] at ($(current page.south east)+(-.1,.1)$) (b) {};
\draw[anchor=north east] node(logo) at ($(b.north east)+(.15,.15)$) { \pgfuseimage{uniheadertitle} };
%\draw[unibablueI] node(uniba) [below of=logo, anchor=center]{\scriptsize\unibastring};
\end{tikzpicture}
\vskip-0.3\beamer@headheight
    \begin{beamercolorbox}[sep=8pt]{institute}
      \usebeamerfont{institute}\insertinstitute
    \end{beamercolorbox}
    \vskip2em\par
    \begin{beamercolorbox}[sep=16pt]{title}
      \usebeamerfont{title}\inserttitle\par%
      \ifx\insertsubtitle\@empty%
      \else%
        \vskip0.25em%
        {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
      \fi%
    \end{beamercolorbox}%
    \vskip2em\par
    \begin{beamercolorbox}[sep=16pt]{date}
      \usebeamerfont{date}\insertdate
    \end{beamercolorbox}\vskip-0.5em
    \begin{beamercolorbox}[sep=16pt]{author}
      \usebeamerfont{author}\insertauthor
    \end{beamercolorbox}
    \vfill
}


\setbeamertemplate{frametitle}
{
\ifx\insertframesubtitle\empty
  \vskip+0.1cm
  \usebeamerfont*{frametitle}\insertframetitle
  \vskip+0.15cm
\else
  \usebeamerfont*{frametitle}\insertframetitle
  \vskip+0.1cm
  \hskip+0.5cm\usebeamerfont*{framesubtitle}\insertframesubtitle
  \vskip+0.15cm
\fi
}

%\setbeamertemplate{headline}
%{
% \vskip -\beamer@headheight
%  \linethickness{0pt}
%  \framelatex{
%  \begin{beamercolorbox}[wd=\paperwidth,ht=\beamer@headheight]{Title bar}
%    \usebeamerfont{section in head/foot}
%    %\insertsectionnavigationhorizontal{0pt}{\hskip0.22cm}{}%
%  \end{beamercolorbox}}
%}

\setbeamertemplate{footline}
{
\begin{tikzpicture}[remember picture, overlay]
\draw[thick, unibablueI] ($(current page.south west)+(.1,0.37\beamer@headheight)$) -- ($(current page.south east)+(-.1,0.37\beamer@headheight)$);
\end{tikzpicture}

  \linethickness{0pt}
  \framelatex{
  \begin{beamercolorbox}[leftskip=0.2cm, rightskip=0.2cm, wd=\paperwidth,ht=0.35\beamer@headheight,sep=0.05cm]{Location bar}
    \usebeamerfont{section in head/foot}%
    \begin{tikzpicture}[remember picture, overlay]
      \node[anchor=south west] at ($(current page.south west)+(.1,0)$){\insertshorttitle \ | \insertshortauthor \ | \insertshortinstitute};
      \node[anchor=south] at (current page.south){\ifgit\gitMarkFormat{\gitMarkPref\,\textbullet{}\,\gitMark}\fi};
      \node[anchor=south east] at ($(current page.south east)+(-.1,0)$){\insertframenumber/\inserttotalframenumber};
    \end{tikzpicture}
  \end{beamercolorbox}}
}

\setbeamertemplate{sidebar canvas \beamer@sidebarside}[vertical shading]
         [top=white,bottom=white]

\setbeamertemplate{sidebar \beamer@sidebarside}
  {
  \begin{tikzpicture}[remember picture,overlay]
\node[
anchor=south east,
  draw=unibablueV,
  thin,
  fill=unibablueV,
  shape=rectangle with rounded corners,
  minimum height=\paperheight-.2cm, minimum width=\beamer@sidebarwidth-.2cm,
  rectangle with rounded corners north west=0pt,
  rectangle with rounded corners south west=0pt,
  rectangle with rounded corners north east=18pt,
  rectangle with rounded corners south east=0pt,
] at ($(current page.south east)+(-.1,.1)$) (b) {};
\draw[anchor=north east] node(logo) at ($(b.north east)+(.15,.15)$) { \pgfuseimage{uniheadertitle} };
\end{tikzpicture}
    \vskip12em%
    \hskip1em\insertverticalnavigation{\beamer@sidebarwidth}%
    \vfill
    \ifx\beamer@sidebarside\beamer@lefttext%
    \else%
      \usebeamercolor{normal text}%
      \llap{\usebeamertemplate***{navigation symbols}\hskip0.1cm}%
      \vskip2pt%
    \fi%
  %

  \ifx\beamer@sidebarside\beamer@lefttext%
    \defbeamertemplate*{sidebar right}{sidebar theme}
    {%
      \vfill%
      \llap{\usebeamertemplate***{navigation symbols}\hskip0.1cm}%
      \vskip2pt}
  \fi
  }
