CDefHandler.h 2.2 KB

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