showtext.xml 8.3 KB

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