showtext.xml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <krpano>
  2. <!--
  3. showtext() xml plugin
  4. - showtext() and <textstyle> support for HTML5
  5. - docu: https://krpano.com/plugins/showtext/
  6. - krpano 1.21
  7. -->
  8. <!-- predefine a DEFAULT textstyle element -->
  9. <textstyle name="DEFAULT" />
  10. <!-- the automatic running (autorun=preinit) install action -->
  11. <action name="showtext_install" autorun="preinit" scope="private:showtext">
  12. <!-- remove the built-in 'showtext' function to use the 'showtext' <action> instead: -->
  13. delete(global.showtext);
  14. <!-- initialize internal variables -->
  15. set(showtext_style, DEFAULT);
  16. set(showtext_prevstyle, null);
  17. set(showtext_text, '');
  18. set(showtext_prevtext, '');
  19. set(showtext_timeout, 0.1);
  20. set(showtext_fadeout, 0.0);
  21. set(showtext_clipping, false);
  22. </action>
  23. <action name="showtext" scope="private:showtext" args="text, style">
  24. if(!style, set(style, DEFAULT));
  25. if(global.textstyle[get(style)],
  26. copy(showtext_style, style);
  27. ,
  28. warning("showtext() - there is no textstyle '", style, "' defined!");
  29. global.textstyle.createarrayitem(get(style));
  30. );
  31. copy(showtext_text, text);
  32. if(showtext_text != showtext_prevtext,
  33. copy(showtext_prevtext, showtext_text);
  34. showtext_createnewtext();
  35. ,
  36. delayedcall(showtext_timer, get(showtext_timeout), showtext_hide() );
  37. );
  38. </action>
  39. <action name="showtext_createnewtext" scope="private:showtext">
  40. <!-- stop running mouse and alpha update calls -->
  41. stopdelayedcall(showtext_mouseupdates);
  42. stoptween(global.layer[showtext_tf].alpha);
  43. <!-- remove the old textfield when the style has changed -->
  44. if(showtext_style != showtext_prevstyle,
  45. copy(showtext_prevstyle, showtext_style);
  46. removelayer(showtext_tf);
  47. );
  48. <!-- create a new textfield plugin layer -->
  49. addlayer(showtext_tf);
  50. <!-- create 'shortcut' variables (tf,ts) for faster access -->
  51. copy(tf, global.layer[showtext_tf]);
  52. copy(ts, global.textstyle[get(showtext_style)]);
  53. <!-- get the position settings -->
  54. if(ts.origin !== null, copy(ts_origin, ts.origin), set(ts_origin, 'cursor'));
  55. if(ts.edge !== null, copy(ts_edge, ts.edge), set(ts_edge, 'bottom'));
  56. if(ts.xoffset !== null, copy(ts_xoffset, ts.xoffset), set(ts_xoffset, 0));
  57. if(ts.yoffset !== null, copy(ts_yoffset, ts.yoffset), set(ts_yoffset, -3));
  58. <!-- set the position settings -->
  59. if(ts_origin == 'cursor',
  60. set(tf.align, 'lefttop');
  61. showtext_movetomouse();
  62. ,
  63. copy(tf.align, ts_origin);
  64. );
  65. copy(tf.edge, ts_edge);
  66. copy(tf.ox, ts_xoffset);
  67. copy(tf.oy, ts_yoffset);
  68. <!-- get the font settings -->
  69. if(ts.font !== null, copy(ts_font, ts.font), set(ts_font, 'Times'));
  70. if(ts.fontsize !== null, copy(ts_fontsize, ts.fontsize), set(ts_fontsize, 12.0));
  71. if(ts.bold !== null, copy(ts_bold, ts.bold), set(ts_bold, true));
  72. if(ts.italic !== null, copy(ts_italic, ts.italic), set(ts_italic, false));
  73. if(ts.textcolor !== null, copy(ts_textcolor, ts.textcolor), set(ts_textcolor, 0x000000));
  74. if(ts.textalign !== null, copy(ts_textalign, ts.textalign), set(ts_textalign, 'left'));
  75. <!-- use the font settings to build the CSS style -->
  76. set(tf_css, '');
  77. tohex(ts_textcolor, '#', 6);
  78. txtadd(tf_css, 'font-family:',get(ts_font),'; font-size:',get(ts_fontsize),'px; color:',get(ts_textcolor),'; ');
  79. if(ts_textalign != 'none', txtadd(tf_css, get(tf_css), 'text-align:',get(ts_textalign),'; '));
  80. if(ts_bold, txtadd(tf_css, 'font-weight:bold; '));
  81. if(ts_italic, txtadd(tf_css, 'font-style:italic; '));
  82. if(ts.css !== null, txtadd(tf_css, get(ts.css)));
  83. copy(tf.css, tf_css);
  84. <!-- size settings -->
  85. if(ts.width !== null AND ts.width !== '', copy(tf.width, ts.width));
  86. if(ts.height !== null AND ts.height !== '', copy(tf.height, ts.height));
  87. if(ts.vcenter !== null AND ts.vcenter !== '', copy(tf.vcenter, ts.vcenter));
  88. if(ts.padding !== null AND ts.padding !== '', copy(tf.padding, ts.padding), set(tf.padding,1));
  89. <!-- background, border, shadow settings -->
  90. if(ts.background !== null, copy(tf.background, ts.background));
  91. if(ts.backgroundcolor !== null, copy(tf.backgroundcolor, ts.backgroundcolor));
  92. if(ts.backgroundalpha !== null, copy(tf.backgroundalpha, ts.backgroundalpha));
  93. if(ts.border !== null, copy(tf.border, ts.border), set(tf.border,true));
  94. if(ts.bordercolor !== null, copy(tf.bordercolor, ts.bordercolor));
  95. if(ts.borderalpha !== null, copy(tf.borderalpha, ts.borderalpha));
  96. if(ts.borderwidth !== null, copy(tf.borderwidth, ts.borderwidth));
  97. if(ts.roundedge !== null, copy(tf.roundedge, ts.roundedge));
  98. if(ts.shadow !== null, copy(tf.shadow, ts.shadow));
  99. if(ts.shadowrange !== null, copy(tf.shadowrange, ts.shadowrange));
  100. if(ts.shadowangle !== null, copy(tf.shadowangle, ts.shadowangle));
  101. if(ts.shadowcolor !== null, copy(tf.shadowcolor, ts.shadowcolor));
  102. if(ts.shadowalpha !== null, copy(tf.shadowalpha, ts.shadowalpha));
  103. if(ts.textshadow !== null, copy(tf.textshadow, ts.textshadow));
  104. if(ts.textshadowrange !== null, copy(tf.textshadowrange, ts.textshadowrange));
  105. if(ts.textshadowangle !== null, copy(tf.textshadowangle, ts.textshadowangle));
  106. if(ts.textshadowcolor !== null, copy(tf.textshadowcolor, ts.textshadowcolor));
  107. if(ts.textshadowalpha !== null, copy(tf.textshadowalpha, ts.textshadowalpha));
  108. <!-- showing settings -->
  109. if(ts.alpha !== null, copy(ts_alpha, ts.alpha), set(ts_alpha, 1.0));
  110. if(ts.showtime !== null, copy(ts_showtime, ts.showtime), set(ts_showtime, 0.1));
  111. if(ts.fadetime !== null, copy(ts_fadetime, ts.fadetime), set(ts_fadetime, 0.0));
  112. if(ts.fadeintime !== null, copy(ts_fadeintime, ts.fadeintime), set(ts_fadeintime, 0.0));
  113. copy(showtext_timeout, ts_showtime);
  114. copy(showtext_fadeout, ts_fadetime);
  115. if(ts_fadeintime GT 0,
  116. set(tf.alpha, 0.0);
  117. tween(global.layer[showtext_tf].alpha, get(ts_alpha), get(ts_fadeintime), linear);
  118. ,
  119. copy(tf.alpha, ts_alpha);
  120. );
  121. if(ts.noclip !== null, copy(showtext_clipping,ts.noclip), set(showtext_clipping, true));
  122. if(showtext_clipping,
  123. set(tf.onloaded, showtext_do_clipping() );
  124. set(tf.onautosized, showtext_do_clipping() );
  125. );
  126. <!-- special flash-only settings -->
  127. if(ts.embeddedfonts !== null, copy(tf.embeddedfonts, ts.embeddedfonts));
  128. if(ts.effect !== null, copy(tf.effect, ts.effect));
  129. if(ts.blendmode !== null, copy(tf.blendmode, ts.blendmode));
  130. <!-- set the text and the basic settings to start showing the textfield -->
  131. copy(tf.html, showtext_text);
  132. set(tf.enabled, false);
  133. set(tf.zorder, 999999);
  134. if(ts.parent, copy(tf.parent, ts.parent) );
  135. set(tf.type, 'text');
  136. <!-- start the text-hiding timer -->
  137. delayedcall(showtext_timer, get(showtext_timeout), showtext_hide() );
  138. </action>
  139. <action name="showtext_do_clipping" scope="private:showtext">
  140. if(showtext_clipping,
  141. global.layer[showtext_tf].updatepos();
  142. copy(tf_px, global.layer[showtext_tf].pixelx);
  143. copy(tf_py, global.layer[showtext_tf].pixely);
  144. if(tf_px LT 0,
  145. sub(global.layer[showtext_tf].x, tf_px);
  146. ,
  147. add(tf_rightedge, tf_px, global.layer[showtext_tf].pixelwidth);
  148. if(tf_rightedge GE global.stagewidth, sub(tf_rightedge,global.stagewidth); sub(global.layer[showtext_tf].x,tf_rightedge); );
  149. );
  150. if(tf_py LT 0,
  151. sub(global.layer[showtext_tf].y, tf_py);
  152. ,
  153. add(tf_bottomedge, tf_py, global.layer[showtext_tf].pixelheight);
  154. if(tf_bottomedge GE global.stageheight, sub(tf_bottomedge,global.stageheight); sub(global.layer[showtext_tf].y,tf_bottomedge); );
  155. );
  156. );
  157. </action>
  158. <action name="showtext_movetomouse" scope="private:showtext">
  159. copy(global.layer[showtext_tf].x, global.mouse.stagex);
  160. copy(global.layer[showtext_tf].y, global.mouse.stagey);
  161. showtext_do_clipping();
  162. delayedcall(showtext_mouseupdates, 0, showtext_movetomouse() );
  163. </action>
  164. <action name="showtext_hide" scope="private:showtext">
  165. if(global.layer[showtext_tf],
  166. tween(global.layer[showtext_tf].alpha, 0.0, get(showtext_fadeout), linear,
  167. stopdelayedcall(showtext_mouseupdates);
  168. removelayer(showtext_tf);
  169. set(showtext_text, '');
  170. set(showtext_prevtext, '');
  171. );
  172. );
  173. </action>
  174. </krpano>