Debian Codegraph @

texmf-dist/tex/generic/pgf/libraries/pgflibrarytimelines.code.tex

raw
1 % Copyright 2018 by Till Tantau
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 \ProvidesFileRCS{pgflibrarytimelines.code.tex}
11
12
13 % We need the animation module:
14
15 \usepgfmodule{animations}%
16
17
18 % Starts a fixed timeline
19 %
20 % Description:
21 %
22 % A (fixed) timeline defines for a specific number of seconds how a
23 % different objects are animated. In contrast to a dynamic timeline,
24 % the animation must be fixed beforehand, that is, in a fixed timeline
25 % you can specify things like "be there after 2s and there after 4s
26 % and be red after 5s" but not "be there after that other animation
27 % has finished and then stay there until another animation has
28 % finished or something has been clicked". Note that while a fixed
29 % timeline describes a fixed sequence of animations, the starting
30 % point of the timeline may depend for instance on when some button is
31 % clicked; only when the timeline's animation gets started there is
32 % nothing dynamic about it till its end (a timeline may be ended
33 % prematurely, however).
34 %
35 % This command allows you to start a timeline. Once the timeline has
36 % been started, you can call the following macro repeatedly:
37 %
38 % \pgftimelineentry{time}{object}{attribute}{value}
39 %
40 % The time is some time when the given attribute should have the given
41 % value. The important thing is that the entries need not come in any
42 % specific order; it is the job of the timeline library to sort them
43 % into a sensible order.
44 %
45 % At the end of the timeline, you will have specified for a whole
46 % bunch of objects and attributes their values at certain time
47 % points. The macro \pgftimelineend will now call \pgfanimateattribute
48 % for all attributes and objects mentioned in the timeline.
49 %
50 %
51 % Internally, pgf keeps track of all objects in a timeline and all
52 % attributes and sorts the times using a simple insertion sort (which
53 % will be fastest when the times are given in increasing order as
54 % happens most of the time).
55
56 \def\pgftimelinebegin{%
57 \pgf@timeline@todo@saved=\pgf@timeline@todo%
58 \begingroup%
59 \advance\pgf@timeline@depth by1\relax%
60 \pgf@timeline@todo{}%
61 }%
62
63 \newcount\pgf@timeline@depth
64 \newtoks\pgf@timeline@todo
65 \newtoks\pgf@timeline@todo@saved
66
67
68 % Ends a timeline
69 %
70 % Description:
71 %
72 % This command will scan \pgfanimateattribute for the objects and
73 % attributes mentioned in the timeline.
74
75 \def\pgftimelineend{%
76 \the\pgf@timeline@todo%
77 \endgroup%
78 \global\pgf@timeline@todo=\pgf@timeline@todo@saved%
79 }%
80
81
82 % Adds an entry to a timeline
83 %
84 % #1 = a time (evaluated using \pgfparsetime)
85 % #2 = an object (a "whom" in the sense of pgfmoduleanimations, will
86 % be expanded)
87 % #3 = an attribute (in the sense of pgfmoduleanimations, will be expanded)
88 % #4 = a value
89 %
90 % Description:
91 %
92 % Adds a new entry to the timeline. For a fixed #1, several calls to
93 % this macro allow you to specify a key frame by specifying the
94 % different values of the different attributes of the different
95 % objects in the key frame.
96
97 \def\pgftimelineentry#1#2#3#4{%
98 \begingroup%
99 \pgfparsetime{#1}%
100 \edef\pgf@timeline@whom{#2}%
101 \edef\pgf@timeline@attr{#3}%
102 \expandafter\let\expandafter\pgf@timeline@entry\csname pgf@tl@\pgf@timeline@whom @\pgf@timeline@attr @\the\pgf@timeline@depth\endcsname%
103 \ifx\pgf@timeline@entry\relax%
104 \edef\pgf@timeline@entry{\noexpand\pgf@timeline@setup{\pgf@timeline@whom}{\pgf@timeline@attr}}%
105 \fi%
106 \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\pgf@timeline@entry\expandafter\expandafter\expandafter%
107 {\expandafter\pgf@timeline@entry\expandafter\pgf@timeline@doentry\expandafter{\pgftimeresult}{#4}}%
108 \expandafter\global\expandafter\let\csname pgf@tl@\pgf@timeline@whom @\pgf@timeline@attr @\the\pgf@timeline@depth\endcsname\pgf@timeline@entry%
109 \global\pgf@timeline@todo\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgf@timeline@todo\expandafter\pgf@timeline@handle\csname pgf@tl@\pgf@timeline@whom @\pgf@timeline@attr @\the\pgf@timeline@depth\endcsname}%
110 \endgroup%
111 }%
112
113
114 \newtoks\pgf@timeline@sort@toks
115 \countdef\pgf@timeline@sort@count=0\relax%
116 \countdef\pgf@timeline@count@down=1\relax%
117 \countdef\pgf@timeline@count@down@next=2\relax%
118
119 % Handles one entry in a timeline
120
121 \def\pgf@timeline@handle#1{%
122 \ifx#1\relax%
123 \else%
124 % Do an inserting sort. The time is kept in the dimension registers
125 % 1 to n, the value in the token registers 1 to n.
126 {%
127 \pgf@timeline@sort@count=1\relax%
128 #1% will start a group
129 % Now we collect the toks:
130 \pgf@timeline@count@down=1\relax%
131 \pgf@timeline@sort@toks{}%
132 \pgfutil@loop%
133 \ifnum\pgf@timeline@count@down<\pgf@timeline@sort@count\relax%
134 \edef\pgf@temp{\the\pgf@timeline@sort@toks\noexpand\pgf@timeline@donow{\the\dimen\pgf@timeline@count@down}{\the\toks\pgf@timeline@count@down}}%
135 \pgf@timeline@sort@toks\expandafter{\pgf@temp}%
136 \advance\pgf@timeline@count@down by1\relax%
137 \pgfutil@repeat%
138 % Do computations now
139 \pgf@timeline@compute@duration%
140 %
141 \edef\pgf@temp{\noexpand\pgf@timeline@call@attribute{\pgf@timeline@whom}{\pgf@timeline@attr}{\the\pgf@timeline@sort@toks}}
142 \expandafter%
143 \endgroup%
144 \pgf@temp%
145 }%
146 \global\let#1\relax% cleanup
147 \fi%
148 }%
149
150 \def\pgf@timeline@compute@duration{%
151 \advance\pgf@timeline@sort@count by-1\relax%
152 \pgfmathparse{\the\dimen\pgf@timeline@sort@count}%
153 \global\let\pgf@timeline@duration\pgfmathresult%
154 }%
155
156
157 \def\pgf@timeline@setup#1#2{%
158 \def\pgf@timeline@whom{#1}%
159 \def\pgf@timeline@attr{#2}%
160 \begingroup%
161 }%
162
163 \def\pgf@timeline@doentry#1#2{%
164 \dimen\pgf@timeline@sort@count=#1pt\relax%
165 \toks\pgf@timeline@sort@count{#2}%
166 \pgf@timeline@count@down\pgf@timeline@sort@count\relax%
167 \pgfutil@loop%
168 \ifnum\pgf@timeline@count@down>1\relax%
169 \pgf@timeline@count@down@next\pgf@timeline@count@down%
170 \advance\pgf@timeline@count@down@next by-1\relax%
171 \ifdim\dimen\pgf@timeline@count@down<\dimen\pgf@timeline@count@down@next\relax%
172 % Swap:
173 \toks0=\toks\pgf@timeline@count@down%
174 \dimen0=\dimen\pgf@timeline@count@down%
175 \toks\pgf@timeline@count@down=\toks\pgf@timeline@count@down@next%
176 \dimen\pgf@timeline@count@down=\dimen\pgf@timeline@count@down@next%
177 \toks\pgf@timeline@count@down@next=\toks0\relax%
178 \dimen\pgf@timeline@count@down@next=\dimen0\relax%
179 \pgf@timeline@count@down\pgf@timeline@count@down@next\relax%
180 \else%
181 \pgf@timeline@count@down1\relax%
182 \fi%
183 \pgfutil@repeat%
184 \advance\pgf@timeline@sort@count by1\relax%
185 }%
186
187
188 \def\pgf@timeline@call@attribute#1#2#3{%
189 \pgfanimateattributecode{#2}{\pgfkeys{/pgf/animation/whom={#1},/pgf/animation/duration=\pgf@timeline@duration}#3}%
190 }%
191
192 \def\pgf@timeline@donow#1#2{%
193 \pgfkeys{/pgf/animation/key time={#1/\pgf@timeline@duration}}%
194 \pgfkeys{/pgf/animation/value={#2}}%
195 }%
196
197 \endinput