CDefHandler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. ui8 R;
  40. ui8 G;
  41. ui8 B;
  42. } palette[256];
  43. // SDefEntry is followed by a series of SDefEntryBlock
  44. // This is commented out because VC++ doesn't accept C99 syntax.
  45. //struct SDefEntryBlock blocks[];
  46. } PACKED_STRUCT;
  47. // Def entry in file. Integer fields are all little endian and will
  48. // need to be converted.
  49. struct SSpriteDef
  50. {
  51. ui32 prSize;
  52. ui32 defType2;
  53. ui32 FullWidth;
  54. ui32 FullHeight;
  55. ui32 SpriteWidth;
  56. ui32 SpriteHeight;
  57. ui32 LeftMargin;
  58. ui32 TopMargin;
  59. } PACKED_STRUCT;
  60. class CDefEssential //DefHandler with images only
  61. {
  62. public:
  63. std::vector<Cimage> ourImages;
  64. ~CDefEssential();
  65. };
  66. class CDefHandler
  67. {
  68. private:
  69. ui32 DEFType;
  70. struct SEntry
  71. {
  72. std::string name;
  73. int offset;
  74. int group;
  75. } ;
  76. std::vector<SEntry> SEntries ;
  77. void openFromMemory(ui8 * table, const std::string & name);
  78. SDL_Surface * getSprite (int SIndex, const ui8 * FDef, const SDL_Color * palette) const;
  79. public:
  80. int width, height; //width and height
  81. std::string defName;
  82. std::vector<Cimage> ourImages;
  83. bool notFreeImgs;
  84. CDefHandler();
  85. ~CDefHandler();
  86. CDefEssential * essentialize();
  87. static CDefHandler * giveDef(const std::string & defName);
  88. static CDefEssential * giveDefEss(const std::string & defName);
  89. };