SWF_Types.h (10063B)
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_TYPES1_H__ 29 #define __SWF_TYPES1_H__ 30 31 ID_INLINE float SWFTWIP( int twip ) { return twip * ( 1.0f / 20.0f ); } 32 ID_INLINE float SWFFIXED16( int fixed ) { return fixed * ( 1.0f / 65536.0f ); } 33 ID_INLINE float SWFFIXED8( int fixed ) { return fixed * ( 1.0f / 256.0f ); } 34 35 struct swfHeader_t { 36 byte compression; 37 byte W; 38 byte S; 39 byte version; 40 uint32 fileLength; 41 }; 42 struct swfRect_t { 43 swfRect_t(); 44 idVec2 tl; 45 idVec2 br; 46 }; 47 struct swfMatrix_t { 48 swfMatrix_t(); 49 float xx, yy; 50 float xy, yx; 51 float tx, ty; 52 idVec2 Scale( const idVec2 & in ) const; 53 idVec2 Transform( const idVec2 & in ) const; 54 swfMatrix_t Multiply( const swfMatrix_t & a ) const; 55 swfMatrix_t Inverse() const; 56 swfMatrix_t & operator=( const swfMatrix_t & a ) { xx = a.xx; yy = a.yy; xy = a.xy; yx = a.yx; tx = a.tx; ty = a.ty; return *this; } 57 }; 58 struct swfColorRGB_t { 59 swfColorRGB_t(); 60 idVec4 ToVec4() const; 61 uint8 r, g, b; 62 }; 63 struct swfColorRGBA_t : public swfColorRGB_t { 64 swfColorRGBA_t(); 65 idVec4 ToVec4() const; 66 uint8 a; 67 }; 68 struct swfLineStyle_t { 69 swfLineStyle_t(); 70 uint16 startWidth; 71 uint16 endWidth; 72 swfColorRGBA_t startColor; 73 swfColorRGBA_t endColor; 74 }; 75 struct swfGradientRecord_t { 76 swfGradientRecord_t(); 77 uint8 startRatio; 78 uint8 endRatio; 79 swfColorRGBA_t startColor; 80 swfColorRGBA_t endColor; 81 }; 82 struct swfGradient_t { 83 swfGradient_t(); 84 uint8 numGradients; 85 swfGradientRecord_t gradientRecords[ 16 ]; 86 }; 87 struct swfFillStyle_t { 88 swfFillStyle_t(); 89 uint8 type; // 0 = solid, 1 = gradient, 4 = bitmap 90 uint8 subType; // 0 = linear, 2 = radial, 3 = focal; 0 = repeat, 1 = clamp, 2 = near repeat, 3 = near clamp 91 swfColorRGBA_t startColor; // if type = 0 92 swfColorRGBA_t endColor; // if type = 0 93 swfMatrix_t startMatrix; // if type > 0 94 swfMatrix_t endMatrix; // if type > 0 95 swfGradient_t gradient; // if type = 1 96 float focalPoint; // if type = 1 and subType = 3 97 uint16 bitmapID; // if type = 4 98 }; 99 class idSWFShapeDrawFill { 100 public: 101 swfFillStyle_t style; 102 idList< idVec2, TAG_SWF > startVerts; 103 idList< idVec2, TAG_SWF > endVerts; 104 idList< uint16, TAG_SWF > indices; 105 }; 106 class idSWFShapeDrawLine { 107 public: 108 swfLineStyle_t style; 109 idList< idVec2, TAG_SWF > startVerts; 110 idList< idVec2, TAG_SWF > endVerts; 111 idList< uint16, TAG_SWF > indices; 112 }; 113 class idSWFShape { 114 public: 115 ~idSWFShape() { 116 fillDraws.Clear(); 117 lineDraws.Clear(); 118 } 119 swfRect_t startBounds; 120 swfRect_t endBounds; 121 idList< idSWFShapeDrawFill, TAG_SWF > fillDraws; 122 idList< idSWFShapeDrawLine, TAG_SWF > lineDraws; 123 }; 124 class idSWFFontGlyph { 125 public: 126 idSWFFontGlyph(); 127 uint16 code; 128 int16 advance; 129 idList< idVec2, TAG_SWF > verts; 130 idList< uint16, TAG_SWF > indices; 131 }; 132 class idSWFFont { 133 public: 134 idSWFFont(); 135 class idFont * fontID; 136 int16 ascent; 137 int16 descent; 138 int16 leading; 139 idList< idSWFFontGlyph, TAG_SWF > glyphs; 140 }; 141 class idSWFTextRecord { 142 public: 143 idSWFTextRecord(); 144 uint16 fontID; 145 swfColorRGBA_t color; 146 int16 xOffset; 147 int16 yOffset; 148 uint16 textHeight; 149 uint16 firstGlyph; 150 uint8 numGlyphs; 151 }; 152 struct swfGlyphEntry_t { 153 swfGlyphEntry_t(); 154 uint32 index; 155 int32 advance; 156 }; 157 class idSWFText { 158 public: 159 swfRect_t bounds; 160 swfMatrix_t matrix; 161 idList< idSWFTextRecord, TAG_SWF > textRecords; 162 idList< swfGlyphEntry_t, TAG_SWF > glyphs; 163 }; 164 enum swfEditTextFlags_t { 165 SWF_ET_NONE = 0, 166 SWF_ET_WORDWRAP = BIT(0), 167 SWF_ET_MULTILINE = BIT(1), 168 SWF_ET_PASSWORD = BIT(2), 169 SWF_ET_READONLY = BIT(3), 170 SWF_ET_AUTOSIZE = BIT(4), 171 SWF_ET_BORDER = BIT(5), 172 }; 173 enum swfEditTextAlign_t { 174 SWF_ET_ALIGN_LEFT, 175 SWF_ET_ALIGN_RIGHT, 176 SWF_ET_ALIGN_CENTER, 177 SWF_ET_ALIGN_JUSTIFY 178 }; 179 enum swfTextRenderMode_t { 180 SWF_TEXT_RENDER_NORMAL = 0, 181 SWF_TEXT_RENDER_RANDOM_APPEAR, 182 SWF_TEXT_RENDER_RANDOM_APPEAR_CAPS, 183 SWF_TEXT_RENDER_PARAGRAPH, 184 SWF_TEXT_RENDER_AUTOSCROLL, 185 SWF_TEXT_RENDER_MODE_COUNT, 186 }; 187 188 class idSWFEditText { 189 public: 190 idSWFEditText(); 191 swfRect_t bounds; 192 uint32 flags; 193 uint16 fontID; 194 uint16 fontHeight; 195 swfColorRGBA_t color; 196 uint16 maxLength; 197 swfEditTextAlign_t align; 198 uint16 leftMargin; 199 uint16 rightMargin; 200 uint16 indent; 201 int16 leading; 202 idStr variable; 203 idStr initialText; 204 }; 205 struct swfColorXform_t { 206 swfColorXform_t(); 207 idVec4 mul; 208 idVec4 add; 209 swfColorXform_t Multiply( const swfColorXform_t & a ) const; 210 swfColorXform_t & operator=( const swfColorXform_t & a ) { mul = a.mul; add = a.add; return *this; } 211 }; 212 struct swfDisplayEntry_t { 213 swfDisplayEntry_t(); 214 uint16 characterID; 215 uint16 depth; 216 uint16 clipDepth; 217 uint16 blendMode; 218 swfMatrix_t matrix; 219 swfColorXform_t cxf; 220 float ratio; 221 // if this entry is a sprite, then this will point to the specific instance of that sprite 222 class idSWFSpriteInstance * spriteInstance; 223 // if this entry is text, then this will point to the specific instance of the text 224 class idSWFTextInstance * textInstance; 225 }; 226 struct swfRenderState_t { 227 swfRenderState_t(); 228 swfMatrix_t matrix; 229 swfColorXform_t cxf; 230 const idMaterial * material; 231 int materialWidth; 232 int materialHeight; 233 int activeMasks; 234 uint8 blendMode; 235 float ratio; 236 stereoDepthType_t stereoDepth; 237 }; 238 239 ID_INLINE swfRect_t::swfRect_t() : 240 tl( 0.0f, 0.0f ), 241 br( 0.0f, 0.0f ) 242 { 243 } 244 245 ID_INLINE swfMatrix_t::swfMatrix_t() : 246 xx( 1.0f ), yy( 1.0f ), 247 yx( 0.0f ), xy( 0.0f ), 248 tx( 0.0f ), ty( 0.0f ) 249 { 250 } 251 252 ID_INLINE idVec2 swfMatrix_t::Scale( const idVec2 & in ) const { 253 return idVec2( ( in.x * xx ) + ( in.y * xy ), 254 ( in.y * yy ) + ( in.x * yx ) ); 255 } 256 257 ID_INLINE idVec2 swfMatrix_t::Transform( const idVec2 & in ) const { 258 return idVec2( ( in.x * xx ) + ( in.y * xy ) + tx, 259 ( in.y * yy ) + ( in.x * yx ) + ty ); 260 } 261 262 ID_INLINE swfMatrix_t swfMatrix_t::Inverse() const { 263 swfMatrix_t inverse; 264 float det = ( ( xx * yy ) - ( yx * xy ) ); 265 if ( idMath::Fabs( det ) < idMath::FLT_SMALLEST_NON_DENORMAL ) { 266 return *this; 267 } 268 float invDet = 1.0f / det; 269 inverse.xx = invDet * yy; 270 inverse.yx = invDet * -yx; 271 inverse.xy = invDet * -xy; 272 inverse.yy = invDet * xx; 273 //inverse.tx = invDet * ( xy * ty ) - ( yy * tx ); 274 //inverse.ty = invDet * ( yx * tx ) - ( xx * ty ); 275 return inverse; 276 } 277 278 ID_INLINE swfMatrix_t swfMatrix_t::Multiply( const swfMatrix_t & a ) const { 279 swfMatrix_t result; 280 result.xx = xx * a.xx + yx * a.xy; 281 result.yx = xx * a.yx + yx * a.yy; 282 result.xy = xy * a.xx + yy * a.xy; 283 result.yy = xy * a.yx + yy * a.yy; 284 result.tx = tx * a.xx + ty * a.xy + a.tx; 285 result.ty = tx * a.yx + ty * a.yy + a.ty; 286 return result; 287 } 288 289 ID_INLINE swfColorRGB_t::swfColorRGB_t() : 290 r( 255 ), g( 255 ), b( 255 ) 291 { 292 } 293 294 ID_INLINE idVec4 swfColorRGB_t::ToVec4() const { 295 return idVec4( r * ( 1.0f / 255.0f ), g * ( 1.0f / 255.0f ), b * ( 1.0f / 255.0f ), 1.0f ); 296 } 297 298 ID_INLINE swfColorRGBA_t::swfColorRGBA_t() : 299 a( 255 ) 300 { 301 } 302 303 ID_INLINE idVec4 swfColorRGBA_t::ToVec4() const { 304 return idVec4( r * ( 1.0f / 255.0f ), g * ( 1.0f / 255.0f ), b * ( 1.0f / 255.0f ), a * ( 1.0f / 255.0f ) ); 305 } 306 307 ID_INLINE swfLineStyle_t::swfLineStyle_t() : 308 startWidth( 20 ), 309 endWidth( 20 ) 310 { 311 } 312 313 ID_INLINE swfGradientRecord_t::swfGradientRecord_t() : 314 startRatio( 0 ), 315 endRatio( 0 ) 316 { 317 } 318 319 ID_INLINE swfGradient_t::swfGradient_t() : 320 numGradients( 0 ) 321 { 322 } 323 324 ID_INLINE swfFillStyle_t::swfFillStyle_t() : 325 type( 0 ), 326 subType( 0 ), 327 focalPoint( 0.0f ), 328 bitmapID( 0 ) 329 { 330 } 331 332 ID_INLINE swfColorXform_t::swfColorXform_t() : 333 mul( 1.0f, 1.0f, 1.0f, 1.0f ), 334 add( 0.0f, 0.0f, 0.0f, 0.0f ) 335 { 336 } 337 338 ID_INLINE swfColorXform_t swfColorXform_t::Multiply( const swfColorXform_t & a ) const { 339 swfColorXform_t result; 340 result.mul = mul.Multiply( a.mul ); 341 result.add = ( add.Multiply( a.mul ) ) + a.add; 342 return result; 343 } 344 345 ID_INLINE swfDisplayEntry_t::swfDisplayEntry_t() : 346 characterID( 0 ), 347 ratio( 0.0f ), 348 depth( 0 ), 349 clipDepth( 0 ), 350 blendMode( 0 ), 351 spriteInstance( NULL ), 352 textInstance( NULL ) 353 { 354 } 355 356 ID_INLINE swfRenderState_t::swfRenderState_t() : 357 material( NULL ), 358 materialWidth( 0 ), 359 materialHeight( 0 ), 360 activeMasks( 0 ), 361 blendMode( 0 ), 362 ratio( 0.0f ), 363 stereoDepth( STEREO_DEPTH_TYPE_NONE ) 364 { 365 } 366 367 ID_INLINE idSWFFontGlyph::idSWFFontGlyph() : 368 code( 0 ), 369 advance( 0 ) 370 { 371 } 372 373 ID_INLINE idSWFFont::idSWFFont() : 374 fontID( 0 ), 375 ascent( 0 ), 376 descent( 0 ), 377 leading( 0 ) 378 { 379 } 380 381 ID_INLINE idSWFTextRecord::idSWFTextRecord() : 382 fontID( 0 ), 383 xOffset( 0 ), 384 yOffset( 0 ), 385 textHeight( 0 ), 386 firstGlyph( 0 ), 387 numGlyphs( 0 ) 388 { 389 } 390 391 ID_INLINE idSWFEditText::idSWFEditText() : 392 flags( SWF_ET_NONE ), 393 fontID( 0 ), 394 fontHeight( 24 ), 395 maxLength( 0xFFFF ), 396 align( SWF_ET_ALIGN_LEFT ), 397 leftMargin( 0 ), 398 rightMargin( 0 ), 399 indent( 0 ), 400 leading( 0 ) 401 { 402 } 403 404 ID_INLINE swfGlyphEntry_t::swfGlyphEntry_t() : 405 index( 0 ), 406 advance( 0 ) 407 { 408 } 409 410 #endif // !__SWF_TYPES1_H__