CDefHandler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. struct SDL_Surface;
  3. struct BMPPalette;
  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. ui32 unknown1;
  23. ui32 totalInBlock;
  24. ui32 unknown2;
  25. ui32 unknown3;
  26. ui8 data[0];
  27. };
  28. // Def entry in file. Integer fields are all little endian and will
  29. // need to be converted.
  30. struct SDefEntry {
  31. ui32 DEFType;
  32. ui32 width;
  33. ui32 height;
  34. ui32 totalBlocks;
  35. struct {
  36. ui8 R;
  37. ui8 G;
  38. ui8 B;
  39. } palette[256];
  40. // SDefEntry is followed by a series of SDefEntryBlock
  41. // This is commented out because VC++ doesn't accept C99 syntax.
  42. //struct SDefEntryBlock blocks[];
  43. };
  44. // Def entry in file. Integer fields are all little endian and will
  45. // need to be converted.
  46. struct SSpriteDef {
  47. ui32 prSize;
  48. ui32 defType2;
  49. ui32 FullWidth;
  50. ui32 FullHeight;
  51. ui32 SpriteWidth;
  52. ui32 SpriteHeight;
  53. ui32 LeftMargin;
  54. ui32 TopMargin;
  55. };
  56. class CDefEssential //DefHandler with images only
  57. {
  58. public:
  59. std::vector<Cimage> ourImages;
  60. ~CDefEssential(); //d-tor
  61. };
  62. class CDefHandler
  63. {
  64. private:
  65. ui32 DEFType;
  66. struct SEntry
  67. {
  68. std::string name;
  69. int offset;
  70. int group;
  71. } ;
  72. std::vector<SEntry> SEntries ;
  73. public:
  74. int width, height; //width and height
  75. std::string defName;
  76. std::vector<Cimage> ourImages;
  77. bool notFreeImgs;
  78. CDefHandler(); //c-tor
  79. ~CDefHandler(); //d-tor
  80. SDL_Surface * getSprite (int SIndex, const ui8 * FDef, const BMPPalette * palette) const; //saves picture with given number to "testtt.bmp"
  81. static void expand(ui8 N,ui8 & BL, ui8 & BR);
  82. void openFromMemory(ui8 * table, const std::string & name);
  83. CDefEssential * essentialize();
  84. static CDefHandler * giveDef(const std::string & defName);
  85. static CDefEssential * giveDefEss(const std::string & defName);
  86. };