CDefHandler.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 CDefHandler
  61. {
  62. private:
  63. ui32 DEFType;
  64. struct SEntry
  65. {
  66. std::string name;
  67. int offset;
  68. int group;
  69. } ;
  70. std::vector<SEntry> SEntries ;
  71. void openFromMemory(ui8 * table, const std::string & name);
  72. SDL_Surface * getSprite (int SIndex, const ui8 * FDef, const SDL_Color * palette) const;
  73. public:
  74. int width, height; //width and height
  75. std::string defName;
  76. std::vector<Cimage> ourImages;
  77. CDefHandler();
  78. ~CDefHandler();
  79. static CDefHandler * giveDef(const std::string & defName);
  80. };