summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/colourchange/colourchange.sty
blob: f53715295bff5889723e31f2ec17472b745c0cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
% This is the colour change package.
% By Seamus Bradley 2011.
% tex@seamusbradley.net
% Licensed under GPLv3.
% http://www.gnu.org/licenses/gpl-3.0.html

%%
\ProvidesPackage{colourchange}[2011/03/15 v1.22]
\RequirePackage{etoolbox}
\RequirePackage{calc}

% Some new ifs I use

\newif\ifclch@defaultstyle
\newif\ifclch@slidechange
\newif\ifclch@framechange
\newif\ifclch@draft
\newif\ifclch@final

% The default behaviour is "do nothing"

\DeclareOption{defaultstyle}{%
\clch@defaultstyletrue%
}

\DeclareOption{slidechange}{
\clch@slidechangetrue
\clch@framechangefalse
}

\DeclareOption{framechange}{
\clch@framechangetrue
\clch@slidechangefalse
}

\DeclareOption{draft}{
\clch@drafttrue
}

\DeclareOption{final}{
\clch@finaltrue
}

\ProcessOptions\relax

% Default option

\ifclch@defaultstyle
\useoutertheme[footline=authorinstitutetitle]{miniframes}
\useinnertheme{rectangles}
\fi


% This chunky command basically makes sure that all the colours are set each time the structure colour changes.

\newcommand\setcolours{%
\setbeamercolor*{palette primary}{use=structure,fg=white,bg=structure.fg}
\setbeamercolor*{palette secondary}{use=structure,fg=white,bg=structure.fg!75!black}
\setbeamercolor*{palette tertiary}{use=structure,fg=white,bg=structure.fg!50!black}
\setbeamercolor*{palette quaternary}{fg=white,bg=structure.fg!80!black}
\setbeamercolor*{sidebar}{use=structure,bg=structure.fg}
\setbeamercolor*{palette sidebar primary}{use=structure,fg=structure.fg!10}
\setbeamercolor*{palette sidebar secondary}{fg=white}
\setbeamercolor*{palette sidebar tertiary}{use=structure,fg=structure.fg!50}
\setbeamercolor*{palette sidebar quaternary}{fg=white}
\setbeamercolor*{titlelike}{parent=palette primary}
\setbeamercolor{itemize item}{bg=structure}
\setbeamercolor*{block title}{bg=structure.fg,fg=white}
\setbeamercolor*{block body}{bg=structure.fg!50!white}
}

%------------------------------
% Manual change command
%------------------------------

\newcommand\selectmanualcolour[1]{%
  \setbeamercolor{structure}{fg=#1}%
  \setcolours
}

\let\selectmanualcolor\selectmanualcolour

% All the work is bascially done by a few counters
% Some are for with the slidechange option, and some for the frame change option
% I'll let you guess which are which.

\newcounter{clch@slidefrac}
\newcounter{clch@slidetot}
\newcounter{clch@currslide}
\setcounter{clch@currslide}{1}

\newcounter{clch@framefrac}
\newcounter{clch@frametot}
\newcounter{clch@currframe}
\setcounter{clch@currframe}{1}

% At the start of each slide, step the counter, and set the fraction counter
% Only if the draft mode is off.
\ifclch@draft
\renewcommand\selectmanualcolour[1]{}
\renewcommand\selectmanualcolor[1]{}
\else
\ifclch@slidechange

  \newcommand\fractionate{
    \setcounter{clch@slidetot}{\inserttotalslidenumber}
    \setcounter{clch@slidefrac}{100 * \value{clch@currslide} / \value{clch@slidetot}}
  }
  
  \def\beamer@checkframetitle{\stepcounter{clch@currslide}%
    \fractionate%
    \@ifnextchar\bgroup\beamer@inlineframetitle{}}
  
  \fi

  \ifclch@framechange
    \newcommand\fractionate{
      \setcounter{clch@slidetot}{\inserttotalframenumber}
      \setcounter{clch@slidefrac}{100 * \insertframenumber / \value{clch@slidetot}}
    }

    \preto\frame{\fractionate\setcolours}
  \fi
\fi

% This command sets the fraction counter for the above command.
% Why do I have to set clch@slidetot here too? Well, if I put it in \AtBeginDocument, it seems to break...
% \inserttotalslidenumber is defined at the end (lines 61 et seq.)

% The colour setting commands don't like having counter names in them directly, so this workaround is necessary...

\definecolor{dred}{rgb}{0.9,0.15,0.15}
\def\first@colour{blue}
\def\second@colour{dred}
\newcommand\setstruccol[1]{%
  \setbeamercolor*{structure}{fg=\second@colour!#1!\first@colour}
}

\newcommand\setstruccolx{\setstruccol{\the\value{clch@slidefrac}}}

\newcommand\selectcolourchanges[2]{%
  \def\first@colour{#1}%
  \def\second@colour{#2}}
\let\selectcolorchanges\selectcolourchanges

% At the beginning of the document, we need to set the colours up for the first time...

\AtBeginDocument{\setstruccolx  \setcolours}

% We need to know how many slides there are, so I just ripped off the way beamer defines \inserttotalframenumber 

\def\inserttotalslidenumber{1}
\AtEndDocument{
      \immediate\write\@auxout{\string\@writefile{nav}%
        {\noexpand\headcommand{\noexpand\def\noexpand\inserttotalslidenumber{\the\value{clch@currslide}}}}}
}