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