SWF_Types.h 9.8 KB

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