PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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