SWF_TextInstance.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __SWF_TEXTINSTANCE_H__
  21. #define __SWF_TEXTINSTANCE_H__
  22. struct subTimingWordData_t {
  23. subTimingWordData_t() {
  24. startTime = 0;
  25. forceBreak = false;
  26. }
  27. idStr phrase;
  28. int startTime;
  29. bool forceBreak;
  30. };
  31. class idSWFTextInstance {
  32. public:
  33. idSWFTextInstance();
  34. ~idSWFTextInstance();
  35. void Init( idSWFEditText * editText, idSWF * _swf );
  36. idSWFScriptObject * GetScriptObject() { return &scriptObject; }
  37. bool GetHasDropShadow() { return useDropShadow; }
  38. bool HasStroke() { return useStroke; }
  39. float GetStrokeStrength() { return strokeStrength; }
  40. float GetStrokeWeight() { return strokeWeight; }
  41. // used for when text has random render mode set
  42. bool IsGeneratingRandomText() { return generatingText; }
  43. void StartRandomText( int time );
  44. idStr GetRandomText( int time );
  45. void StartParagraphText( int time );
  46. idStr GetParagraphText( int time );
  47. bool NeedsGenerateRandomText() { return triggerGenerate; }
  48. bool NeedsSoundPlayed();
  49. void ClearPlaySound() { needsSoundUpdate = false; }
  50. idStr GetSoundClip() { return soundClip; }
  51. void SetIgnoreColor( bool ignore ) { ignoreColor = ignore; }
  52. void SetStrokeInfo( bool use, float strength = 0.75f, float weight = 1.75f );
  53. int CalcMaxScroll( int numLines = -1 );
  54. int CalcNumLines();
  55. // subtitle functions
  56. void SwitchSubtitleText( int time );
  57. bool UpdateSubtitle( int time );
  58. bool IsSubtitle() { return isSubtitle; }
  59. bool IsUpdatingSubtitle() { return subUpdating; }
  60. void SetSubEndIndex( int endChar, int time );
  61. int GetLastWordIndex() { return subLastWordIndex; }
  62. int GetPrevLastWordIndex() { return subPrevLastWordIndex; }
  63. void LastWordChanged( int wordCount, int time );
  64. void SetSubStartIndex( int value ) { subCharStartIndex = value; }
  65. int GetSubEndIndex() { return subCharEndIndex; }
  66. int GetSubStartIndex() { return subCharStartIndex; }
  67. void SetSubNextStartIndex( int value );
  68. int GetApporoximateSubtitleBreak( int time );
  69. bool SubNeedsSwitch() { return subNeedsSwitch; }
  70. idStr GetPreviousText() { return subtitleText.c_str(); }
  71. void SubtitleComplete();
  72. int GetSubAlignment() { return subAlign; }
  73. idStr GetSpeaker() { return subSpeaker.c_str(); }
  74. void SubtitleCleanup();
  75. float GetTextLength();
  76. int GetInputStartChar( ) { return inputTextStartChar; }
  77. void SetInputStartCharacter( int c ) { inputTextStartChar = c; }
  78. const idSWFEditText * GetEditText() const { return editText; }
  79. void SetText( idStr val ) { text = val; lengthCalculated = false; }
  80. // Removing the private access control statement due to cl 214702
  81. // Apparently MS's C++ compiler supports the newer C++ standard, and GCC supports C++03
  82. // In the new C++ standard, nested members of a friend class have access to private/protected members of the class granting friendship
  83. // In C++03, nested members defined in a friend class do NOT have access to private/protected members of the class granting friendship
  84. idSWFEditText * editText;
  85. idSWF * swf;
  86. // this text instance's script object
  87. idSWFScriptObject scriptObject;
  88. idStr text;
  89. idStr randomtext;
  90. idStr variable;
  91. swfColorRGBA_t color;
  92. bool visible;
  93. bool tooltip;
  94. int selectionStart;
  95. int selectionEnd;
  96. bool ignoreColor;
  97. int scroll;
  98. int scrollTime;
  99. int maxscroll;
  100. int maxLines;
  101. float glyphScale;
  102. swfRect_t bounds;
  103. float linespacing;
  104. bool shiftHeld;
  105. int lastInputTime;
  106. bool useDropShadow;
  107. bool useStroke;
  108. float strokeStrength;
  109. float strokeWeight;
  110. int textLength;
  111. bool lengthCalculated;
  112. swfTextRenderMode_t renderMode;
  113. bool generatingText;
  114. int rndSpotsVisible;
  115. int rndSpacesVisible;
  116. int charMultiplier;
  117. int textSpotsVisible;
  118. int rndTime;
  119. int startRndTime;
  120. int prevReplaceIndex;
  121. bool triggerGenerate;
  122. int renderDelay;
  123. bool scrollUpdate;
  124. idStr soundClip;
  125. bool needsSoundUpdate;
  126. idList<int, TAG_SWF> indexArray;
  127. idRandom2 rnd;
  128. // used for subtitles
  129. bool isSubtitle;
  130. int subLength;
  131. int subCharDisplayTime;
  132. int subAlign;
  133. bool subUpdating;
  134. int subCharStartIndex;
  135. int subNextStartIndex;
  136. int subCharEndIndex;
  137. int subDisplayTime;
  138. int subStartTime;
  139. int subSourceID;
  140. idStr subtitleText;
  141. bool subNeedsSwitch;
  142. bool subForceKillQueued;
  143. bool subForceKill;
  144. int subKillTimeDelay;
  145. int subSwitchTime;
  146. int subLastWordIndex;
  147. int subPrevLastWordIndex;
  148. idStr subSpeaker;
  149. bool subWaitClear;
  150. bool subInitialLine;
  151. // input text
  152. int inputTextStartChar;
  153. idList< subTimingWordData_t, TAG_SWF > subtitleTimingInfo;
  154. };
  155. /*
  156. ================================================
  157. This is the prototype object that all the text instance script objects reference
  158. ================================================
  159. */
  160. class idSWFScriptObject_TextInstancePrototype : public idSWFScriptObject {
  161. public:
  162. idSWFScriptObject_TextInstancePrototype();
  163. //----------------------------------
  164. // Native Script Functions
  165. //----------------------------------
  166. #define SWF_TEXT_FUNCTION_DECLARE( x ) \
  167. class idSWFScriptFunction_##x : public idSWFScriptFunction_RefCounted { \
  168. public: \
  169. void AddRef() {} \
  170. void Release() {} \
  171. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ); \
  172. } scriptFunction_##x;
  173. SWF_TEXT_FUNCTION_DECLARE( onKey );
  174. SWF_TEXT_FUNCTION_DECLARE( onChar );
  175. SWF_TEXT_FUNCTION_DECLARE( generateRnd );
  176. SWF_TEXT_FUNCTION_DECLARE( calcNumLines );
  177. SWF_NATIVE_VAR_DECLARE( text );
  178. SWF_NATIVE_VAR_DECLARE( autoSize );
  179. SWF_NATIVE_VAR_DECLARE( dropShadow );
  180. SWF_NATIVE_VAR_DECLARE( _stroke );
  181. SWF_NATIVE_VAR_DECLARE( _strokeStrength );
  182. SWF_NATIVE_VAR_DECLARE( _strokeWeight );
  183. SWF_NATIVE_VAR_DECLARE( variable );
  184. SWF_NATIVE_VAR_DECLARE( _alpha );
  185. SWF_NATIVE_VAR_DECLARE( textColor );
  186. SWF_NATIVE_VAR_DECLARE( _visible );
  187. SWF_NATIVE_VAR_DECLARE( scroll );
  188. SWF_NATIVE_VAR_DECLARE( maxscroll );
  189. SWF_NATIVE_VAR_DECLARE( selectionStart );
  190. SWF_NATIVE_VAR_DECLARE( selectionEnd );
  191. SWF_NATIVE_VAR_DECLARE( isTooltip );
  192. SWF_NATIVE_VAR_DECLARE( mode );
  193. SWF_NATIVE_VAR_DECLARE( delay );
  194. SWF_NATIVE_VAR_DECLARE( renderSound );
  195. SWF_NATIVE_VAR_DECLARE( updateScroll );
  196. SWF_NATIVE_VAR_DECLARE( subtitle );
  197. SWF_NATIVE_VAR_DECLARE( subtitleAlign );
  198. SWF_NATIVE_VAR_DECLARE( subtitleSourceID );
  199. SWF_NATIVE_VAR_DECLARE( subtitleSpeaker );
  200. SWF_NATIVE_VAR_DECLARE_READONLY( _textLength );
  201. SWF_TEXT_FUNCTION_DECLARE( subtitleSourceCheck );
  202. SWF_TEXT_FUNCTION_DECLARE( subtitleStart );
  203. SWF_TEXT_FUNCTION_DECLARE( subtitleLength );
  204. SWF_TEXT_FUNCTION_DECLARE( killSubtitle );
  205. SWF_TEXT_FUNCTION_DECLARE( forceKillSubtitle );
  206. SWF_TEXT_FUNCTION_DECLARE( subLastLine );
  207. SWF_TEXT_FUNCTION_DECLARE( addSubtitleInfo );
  208. SWF_TEXT_FUNCTION_DECLARE( terminateSubtitle );
  209. SWF_TEXT_FUNCTION_DECLARE( clearTimingInfo );
  210. };
  211. #endif // !__SWF_TEXTINSTANCE_H__