CDefHandler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * CDefHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../lib/vcmi_endian.h"
  12. struct SDL_Surface;
  13. struct SDL_Color;
  14. struct Cimage
  15. {
  16. int groupNumber;
  17. std::string imName; //name without extension
  18. SDL_Surface * bitmap;
  19. };
  20. // Def entry in file. Integer fields are all little endian and will
  21. // need to be converted.
  22. struct SDefEntryBlock
  23. {
  24. ui32 unknown1;
  25. ui32 totalInBlock;
  26. ui32 unknown2;
  27. ui32 unknown3;
  28. ui8 data[0];
  29. } PACKED_STRUCT;
  30. // Def entry in file. Integer fields are all little endian and will
  31. // need to be converted.
  32. struct SDefEntry
  33. {
  34. ui32 DEFType;
  35. ui32 width;
  36. ui32 height;
  37. ui32 totalBlocks;
  38. struct
  39. {
  40. ui8 R;
  41. ui8 G;
  42. ui8 B;
  43. } palette[256];
  44. // SDefEntry is followed by a series of SDefEntryBlock
  45. // This is commented out because VC++ doesn't accept C99 syntax.
  46. //struct SDefEntryBlock blocks[];
  47. } PACKED_STRUCT;
  48. // Def entry in file. Integer fields are all little endian and will
  49. // need to be converted.
  50. struct SSpriteDef
  51. {
  52. ui32 prSize;
  53. ui32 defType2;
  54. ui32 FullWidth;
  55. ui32 FullHeight;
  56. ui32 SpriteWidth;
  57. ui32 SpriteHeight;
  58. ui32 LeftMargin;
  59. ui32 TopMargin;
  60. } PACKED_STRUCT;
  61. class CDefEssential //DefHandler with images only
  62. {
  63. public:
  64. std::vector<Cimage> ourImages;
  65. ~CDefEssential();
  66. };
  67. class CDefHandler
  68. {
  69. private:
  70. ui32 DEFType;
  71. struct SEntry
  72. {
  73. std::string name;
  74. int offset;
  75. int group;
  76. };
  77. std::vector<SEntry> SEntries;
  78. void openFromMemory(ui8 * table, const std::string & name);
  79. SDL_Surface * getSprite(int SIndex, const ui8 * FDef, const SDL_Color * palette) const;
  80. public:
  81. int width, height; //width and height
  82. std::string defName;
  83. std::vector<Cimage> ourImages;
  84. bool notFreeImgs;
  85. CDefHandler();
  86. ~CDefHandler();
  87. CDefEssential * essentialize();
  88. static CDefHandler * giveDef(const std::string & defName);
  89. static CDefEssential * giveDefEss(const std::string & defName);
  90. };