CDefHandler.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #pragma once
  2. #include "../lib/vcmi_endian.h"
  3. struct SDL_Surface;
  4. struct SDL_Color;
  5. /*
  6. * CDefHandler.h, part of VCMI engine
  7. *
  8. * Authors: listed in file AUTHORS in main folder
  9. *
  10. * License: GNU General Public License v2.0 or later
  11. * Full text of license available in license.txt file, in main folder
  12. *
  13. */
  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(); //d-tor
  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. public:
  78. int width, height; //width and height
  79. std::string defName;
  80. std::vector<Cimage> ourImages;
  81. bool notFreeImgs;
  82. CDefHandler(); //c-tor
  83. ~CDefHandler(); //d-tor
  84. SDL_Surface * getSprite (int SIndex, const ui8 * FDef, const SDL_Color * palette) const; //saves picture with given number to "testtt.bmp"
  85. static void expand(ui8 N,ui8 & BL, ui8 & BR);
  86. void openFromMemory(ui8 * table, const std::string & name);
  87. CDefEssential * essentialize();
  88. static CDefHandler * giveDef(const std::string & defName);
  89. static CDefEssential * giveDefEss(const std::string & defName);
  90. };