/TeXmacs-1.0.7.11-src/src/Typeset/Concat/concat_animate.cpp
C++ | 125 lines | 94 code | 13 blank | 18 comment | 32 complexity | 6dec5732b55d1e18f802c51a40e95f7c MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, MPL-2.0-no-copyleft-exception
1
2/******************************************************************************
3* MODULE : concat_animate.cpp
4* DESCRIPTION: "Typesetting" animations
5* COPYRIGHT : (C) 2005 Joris van der Hoeven
6*******************************************************************************
7* This software falls under the GNU general public license version 3 or later.
8* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10******************************************************************************/
11
12#include "concater.hpp"
13
14/******************************************************************************
15* Basic constructs for animations
16******************************************************************************/
17
18void
19concater_rep::typeset_anim_compose (tree t, path ip) {
20 int i, n= N(t);
21 array<box> bs(n);
22 for (i=0; i<n; i++) bs[i]= typeset_as_concat (env, t[i], descend (ip, i));
23 print (anim_compose_box (ip, bs));
24}
25
26void
27concater_rep::typeset_anim_repeat (tree t, path ip) {
28 if (N(t) != 1) { typeset_error (t, ip); return; }
29 box b= typeset_as_concat (env, t[0], descend (ip, 0));
30 print (anim_repeat_box (ip, b));
31}
32
33void
34concater_rep::typeset_anim_constant (tree t, path ip) {
35 if (N(t) != 2) { typeset_error (t, ip); return; }
36 box b= typeset_as_concat (env, t[0], descend (ip, 0));
37 int l= env->as_length (env->exec (t[1]));
38 print (anim_constant_box (ip, b, l));
39}
40
41static void
42effect_point (edit_env env, box b, tree xt, tree yt, SI& x, SI& y) {
43 if (is_double (xt)) x= as_int (b->x1 + as_double (xt) * b->w ());
44 else x= env->as_length (xt);
45 if (is_double (yt)) y= as_int (b->y1 + as_double (yt) * b->h ());
46 else y= env->as_length (yt);
47}
48
49void
50concater_rep::typeset_anim_translate (tree t, path ip) {
51 if (N(t) != 4) { typeset_error (t, ip); return; }
52 box b = typeset_as_concat (env, t[0], descend (ip, 0));
53 int len= env->as_length (t[1]);
54 tree t1 = env->exec (t[2]);
55 tree t2 = env->exec (t[3]);
56 SI x1= b->x1, y1= b->y1, x2= b->x1, y2= b->y1;
57 if (is_tuple (t1) && N(t1)==2) effect_point (env, b, t1[0], t1[1], x1, y1);
58 if (is_tuple (t2) && N(t2)==2) effect_point (env, b, t2[0], t2[1], x2, y2);
59 print (anim_translate_box (ip, b, len, x1, y1, x2, y2));
60}
61
62void
63concater_rep::typeset_anim_progressive (tree t, path ip) {
64 if (N(t) != 4) { typeset_error (t, ip); return; }
65 box b = typeset_as_concat (env, t[0], descend (ip, 0));
66 int len= env->as_length (t[1]);
67 tree t1 = env->exec (t[2]);
68 tree t2 = env->exec (t[3]);
69 rectangle r1 (b->x1, b->y1, b->x2, b->y2);
70 rectangle r2 (b->x1, b->y1, b->x2, b->y2);
71 if (is_tuple (t1) && N(t1)==4) {
72 effect_point (env, b, t1[0], t1[1], r1->x1, r1->y1);
73 effect_point (env, b, t1[2], t1[3], r1->x2, r1->y2);
74 }
75 if (is_tuple (t2) && N(t2)==4) {
76 effect_point (env, b, t2[0], t2[1], r2->x1, r2->y1);
77 effect_point (env, b, t2[2], t2[3], r2->x2, r2->y2);
78 }
79 print (anim_progressive_box (ip, b, len, r1, r2));
80}
81
82/******************************************************************************
83* Sounds
84******************************************************************************/
85
86void
87concater_rep::typeset_sound (tree t, path ip) {
88 if (N(t) != 1) { typeset_error (t, ip); return; }
89 tree sound_t= env->exec (t[0]);
90 url sound= url_none ();
91 if (is_atomic (sound_t)) {
92 url sound_u= sound_t->label;
93 sound= resolve (relative (env->base_file_name, sound_u));
94 }
95 if (!is_none (sound)) {
96 int sz= script (env->fn_size, env->index_level);
97 font gfn (tex_font ("cmr", sz, (int) (env->magn*env->dpi)));
98 print (sound_box (ip, sound, gfn->yx));
99 flag ("sound", ip, brown);
100 }
101 else typeset_dynamic (tree (ERROR, "bad sound", t[0]), ip);
102}
103
104/******************************************************************************
105* Videos
106******************************************************************************/
107
108void
109concater_rep::typeset_video (tree t, path ip) {
110 if (N(t) != 5) { typeset_error (t, ip); return; }
111 tree video_t= env->exec (t[0]);
112 url video= url_none ();
113 if (is_atomic (video_t)) {
114 url video_u= video_t->label;
115 video= resolve (relative (env->base_file_name, video_u));
116 }
117 if (!is_none (video)) {
118 SI w = env->as_length (t[1]);
119 SI h = env->as_length (t[2]);
120 int len= env->as_length (t[3]);
121 bool rep= env->exec (t[4]) != "false";
122 print (video_box (ip, video, w, h, env->alpha, len, rep));
123 }
124 else typeset_dynamic (tree (ERROR, "bad video", t[0]), ip);
125}