SWF_Dictionary.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #pragma hdrstop
  21. #include "../idlib/precompiled.h"
  22. /*
  23. ========================
  24. idSWF::idSWFDictionaryEntry::idSWFDictionaryEntry
  25. ========================
  26. */
  27. idSWFDictionaryEntry::idSWFDictionaryEntry() :
  28. type( SWF_DICT_NULL ),
  29. material( NULL ),
  30. shape( NULL ),
  31. sprite( NULL ),
  32. font( NULL ),
  33. text( NULL ),
  34. edittext( NULL ),
  35. imageSize( 0, 0 ),
  36. imageAtlasOffset( 0, 0 ),
  37. channelScale( 1.0f, 1.0f, 1.0f, 1.0f ) {
  38. }
  39. /*
  40. ========================
  41. idSWF::idSWFDictionaryEntry::idSWFDictionaryEntry
  42. ========================
  43. */
  44. idSWFDictionaryEntry::~idSWFDictionaryEntry() {
  45. delete shape;
  46. delete sprite;
  47. delete font;
  48. delete text;
  49. delete edittext;
  50. }
  51. /*
  52. ========================
  53. idSWF::idSWFDictionaryEntry::operator=
  54. This exists mostly so idList works right
  55. ========================
  56. */
  57. idSWFDictionaryEntry & idSWFDictionaryEntry::operator=( idSWFDictionaryEntry & other ) {
  58. type = other.type;
  59. material = other.material;
  60. shape = other.shape;
  61. sprite = other.sprite;
  62. font = other.font;
  63. text = other.text;
  64. edittext = other.edittext;
  65. imageSize = other.imageSize;
  66. imageAtlasOffset = other.imageAtlasOffset;
  67. other.type = SWF_DICT_NULL;
  68. other.material = NULL;
  69. other.shape = NULL;
  70. other.sprite = NULL;
  71. other.font = NULL;
  72. other.text = NULL;
  73. other.edittext = NULL;
  74. return *this;
  75. }
  76. /*
  77. ========================
  78. idSWF::AddDictionaryEntry
  79. ========================
  80. */
  81. idSWFDictionaryEntry * idSWF::AddDictionaryEntry( int characterID, swfDictType_t type ) {
  82. if ( dictionary.Num() < characterID + 1 ) {
  83. dictionary.SetNum( characterID + 1 );
  84. }
  85. if ( dictionary[ characterID ].type != SWF_DICT_NULL ) {
  86. idLib::Warning( "%s: Duplicate character %d", filename.c_str(), characterID );
  87. return NULL;
  88. }
  89. dictionary[ characterID ].type = type;
  90. if ( ( type == SWF_DICT_SHAPE ) || ( type == SWF_DICT_MORPH ) ) {
  91. dictionary[ characterID ].shape = new (TAG_SWF) idSWFShape;
  92. } else if ( type == SWF_DICT_SPRITE ) {
  93. dictionary[ characterID ].sprite = new (TAG_SWF) idSWFSprite( this );
  94. } else if ( type == SWF_DICT_FONT ) {
  95. dictionary[ characterID ].font = new (TAG_SWF) idSWFFont;
  96. } else if ( type == SWF_DICT_TEXT ) {
  97. dictionary[ characterID ].text = new (TAG_SWF) idSWFText;
  98. } else if ( type == SWF_DICT_EDITTEXT ) {
  99. dictionary[ characterID ].edittext = new (TAG_SWF) idSWFEditText;
  100. }
  101. return &dictionary[ characterID ];
  102. }
  103. /*
  104. ========================
  105. FindDictionaryEntry
  106. ========================
  107. */
  108. idSWFDictionaryEntry * idSWF::FindDictionaryEntry( int characterID, swfDictType_t type ) {
  109. if ( dictionary.Num() < characterID + 1 ) {
  110. idLib::Warning( "%s: Could not find character %d", filename.c_str(), characterID );
  111. return NULL;
  112. }
  113. if ( dictionary[ characterID ].type != type ) {
  114. idLib::Warning( "%s: Character %d is the wrong type", filename.c_str(), characterID );
  115. return NULL;
  116. }
  117. return &dictionary[ characterID ];
  118. }
  119. /*
  120. ========================
  121. FindDictionaryEntry
  122. ========================
  123. */
  124. idSWFDictionaryEntry * idSWF::FindDictionaryEntry( int characterID ) {
  125. if ( dictionary.Num() < characterID + 1 ) {
  126. idLib::Warning( "%s: Could not find character %d", filename.c_str(), characterID );
  127. return NULL;
  128. }
  129. return &dictionary[ characterID ];
  130. }