%-------------------------------------------------------------------------
% Common document formatting and macros for GLFW manuals
%-------------------------------------------------------------------------

% Misc. document info
\date{\today}

% Packages
\usepackage{fancyhdr}
\usepackage{titling}
\usepackage{lastpage}
\usepackage{listings}
\usepackage{color}
\usepackage[overload]{textcase}
\usepackage{needspace}
\usepackage{times}

% Logo macros
\newcommand{\OpenGL}[1][0]{OpenGL\textsuperscript{\textregistered}}
\newcommand{\GLFW}[1][0]{GLFW}

% Encoding
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

% Page formatting
\usepackage[hmargin=2.5cm]{geometry}
\raggedright
\raggedbottom
\sloppy
\usepackage{parskip}

% Header and footer
\pagestyle{fancy}
%\lhead{\textit{GLFW Reference Manual}}
\lhead{\textit{GLFW \glfwdoctype}}
\chead{API version \glfwapiver}
\rhead{Page \thepage/\pageref{LastPage}}
\lfoot{}
\cfoot{}
\rfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.0pt}

% Titlepage
\newcommand{\glfwmaketitle}{\begin{titlepage}\ \\%
                            \begin{center}%
                            \vspace{7.0cm}{\Huge\textbf{GLFW}}\\%
                            \rule{10.0cm}{0.5pt}\\%
                            \vspace{0.5cm}{\LARGE\textbf{\glfwdoctype}}\\%
                            \vspace{0.8cm}{\large\textbf{API version \glfwapiver}}\\%
                            \textit{\today}\\%
                            \vspace{1.5cm}\textbf{\textcopyright2002-2006 Marcus Geelnard}\\
                                          \textbf{\textcopyright2006-2010 Camilla Berglund}\\%
                            \end{center}\end{titlepage}\newpage}

% Colors
\definecolor{code}{rgb}{0.9,0.9,1.0}
\definecolor{link}{rgb}{0.6,0.0,0.0}
\definecolor{codeA}{rgb}{0.9,1.0,0.9}
\definecolor{codeB}{rgb}{1.0,0.9,0.9}

% Code listings
\lstset{frame=single,frameround=tttt,backgroundcolor=\color{code},%
        language=C,basicstyle={\ttfamily},%
        breaklines,breakindent=0pt,postbreak=\space\space\space\space}


% A simple hack for keeping lines together
\newenvironment{mysamepage}[1][2]{\begin{samepage}\needspace{#1\baselineskip}}{\end{samepage}}

% Macros for automating function reference entries
\newenvironment{refparameters}[1][0]{\begin{mysamepage}\textbf{Parameters}\\}{\end{mysamepage}\bigskip}
\newenvironment{refreturn}[1][0]{\begin{mysamepage}\textbf{Return values}\\}{\end{mysamepage}\bigskip}
\newenvironment{refdescription}[1][0]{\begin{mysamepage}\textbf{Description}\\}{\end{mysamepage}\bigskip}
\newenvironment{refnotes}[1][0]{\begin{mysamepage}\textbf{Notes}\\}{\end{mysamepage}\bigskip}

% hyperref (bookmarks, links etc) - use this package last
\usepackage[colorlinks=true,linkcolor=link,bookmarks=true,bookmarksopen=true,%
            pdfhighlight=/N,bookmarksnumbered=true,bookmarksopenlevel=1,%
            pdfview=FitH,pdfstartview=FitH]{hyperref}
