Back to index

texmacs  1.0.7.15
concat_animate.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : concat_animate.cpp
00004 * DESCRIPTION: "Typesetting" animations
00005 * COPYRIGHT  : (C) 2005  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "concater.hpp"
00013 
00014 /******************************************************************************
00015 * Basic constructs for animations
00016 ******************************************************************************/
00017 
00018 void
00019 concater_rep::typeset_anim_compose (tree t, path ip) {
00020   int i, n= N(t);
00021   array<box> bs(n);
00022   for (i=0; i<n; i++) bs[i]= typeset_as_concat (env, t[i], descend (ip, i));
00023   print (anim_compose_box (ip, bs));
00024 }
00025 
00026 void
00027 concater_rep::typeset_anim_repeat (tree t, path ip) {
00028   if (N(t) != 1) { typeset_error (t, ip); return; }
00029   box b= typeset_as_concat (env, t[0], descend (ip, 0));
00030   print (anim_repeat_box (ip, b));
00031 }
00032 
00033 void
00034 concater_rep::typeset_anim_constant (tree t, path ip) {
00035   if (N(t) != 2) { typeset_error (t, ip); return; }
00036   box b= typeset_as_concat (env, t[0], descend (ip, 0));
00037   int l= env->as_length (env->exec (t[1]));
00038   print (anim_constant_box (ip, b, l));
00039 }
00040 
00041 static void
00042 effect_point (edit_env env, box b, tree xt, tree yt, SI& x, SI& y) {
00043   if (is_double (xt)) x= as_int (b->x1 + as_double (xt) * b->w ());
00044   else x= env->as_length (xt);
00045   if (is_double (yt)) y= as_int (b->y1 + as_double (yt) * b->h ());
00046   else y= env->as_length (yt);
00047 }
00048 
00049 void
00050 concater_rep::typeset_anim_translate (tree t, path ip) {
00051   if (N(t) != 4) { typeset_error (t, ip); return; }
00052   box b  = typeset_as_concat (env, t[0], descend (ip, 0));
00053   int  len= env->as_length (t[1]);
00054   tree t1 = env->exec (t[2]);
00055   tree t2 = env->exec (t[3]);
00056   SI x1= b->x1, y1= b->y1, x2= b->x1, y2= b->y1;
00057   if (is_tuple (t1) && N(t1)==2) effect_point (env, b, t1[0], t1[1], x1, y1);
00058   if (is_tuple (t2) && N(t2)==2) effect_point (env, b, t2[0], t2[1], x2, y2);
00059   print (anim_translate_box (ip, b, len, x1, y1, x2, y2));
00060 }
00061 
00062 void
00063 concater_rep::typeset_anim_progressive (tree t, path ip) {
00064   if (N(t) != 4) { typeset_error (t, ip); return; }
00065   box b  = typeset_as_concat (env, t[0], descend (ip, 0));
00066   int  len= env->as_length (t[1]);
00067   tree t1 = env->exec (t[2]);
00068   tree t2 = env->exec (t[3]);
00069   rectangle r1 (b->x1, b->y1, b->x2, b->y2);
00070   rectangle r2 (b->x1, b->y1, b->x2, b->y2);
00071   if (is_tuple (t1) && N(t1)==4) {
00072     effect_point (env, b, t1[0], t1[1], r1->x1, r1->y1);
00073     effect_point (env, b, t1[2], t1[3], r1->x2, r1->y2);
00074   }
00075   if (is_tuple (t2) && N(t2)==4) {
00076     effect_point (env, b, t2[0], t2[1], r2->x1, r2->y1);
00077     effect_point (env, b, t2[2], t2[3], r2->x2, r2->y2);
00078   }
00079   print (anim_progressive_box (ip, b, len, r1, r2));
00080 }
00081 
00082 /******************************************************************************
00083 * Sounds
00084 ******************************************************************************/
00085 
00086 void
00087 concater_rep::typeset_sound (tree t, path ip) {
00088   if (N(t) != 1) { typeset_error (t, ip); return; }
00089   tree sound_t= env->exec (t[0]);
00090   url sound= url_none ();
00091   if (is_atomic (sound_t)) {
00092     url sound_u= sound_t->label;
00093     sound= resolve (relative (env->base_file_name, sound_u));
00094   }
00095   if (!is_none (sound)) {
00096     int sz= script (env->fn_size, env->index_level);
00097     font gfn (tex_font ("cmr", sz, (int) (env->magn*env->dpi)));
00098     print (sound_box (ip, sound, gfn->yx));
00099     flag ("sound", ip, brown);
00100   }
00101   else typeset_dynamic (tree (ERROR, "bad sound", t[0]), ip);
00102 }
00103 
00104 /******************************************************************************
00105 * Videos
00106 ******************************************************************************/
00107 
00108 void
00109 concater_rep::typeset_video (tree t, path ip) {
00110   if (N(t) != 5) { typeset_error (t, ip); return; }
00111   tree video_t= env->exec (t[0]);
00112   url video= url_none ();
00113   if (is_atomic (video_t)) {
00114     url video_u= video_t->label;
00115     video= resolve (relative (env->base_file_name, video_u));
00116   }
00117   if (!is_none (video)) {
00118     SI   w  = env->as_length (t[1]);
00119     SI   h  = env->as_length (t[2]);
00120     int  len= env->as_length (t[3]);
00121     bool rep= env->exec (t[4]) != "false";
00122     print (video_box (ip, video, w, h, env->alpha, len, rep));
00123   }
00124   else typeset_dynamic (tree (ERROR, "bad video", t[0]), ip);
00125 }