CDefHandler.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef __CDEFHANDLER_H__
  2. #define __CDEFHANDLER_H__
  3. #include "../global.h"
  4. struct SDL_Surface;
  5. struct BMPPalette;
  6. /*
  7. * CDefHandler.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  15. struct Cimage
  16. {
  17. int groupNumber;
  18. std::string imName; //name without extension
  19. SDL_Surface * bitmap;
  20. };
  21. // Def entry in file. Integer fields are all little endian and will
  22. // need to be converted.
  23. struct SDefEntryBlock {
  24. ui32 unknown1;
  25. ui32 totalInBlock;
  26. ui32 unknown2;
  27. ui32 unknown3;
  28. unsigned char data[0];
  29. };
  30. // Def entry in file. Integer fields are all little endian and will
  31. // need to be converted.
  32. struct SDefEntry {
  33. ui32 DEFType;
  34. ui32 width;
  35. ui32 height;
  36. ui32 totalBlocks;
  37. struct {
  38. unsigned char R;
  39. unsigned char G;
  40. unsigned char 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. };
  46. // Def entry in file. Integer fields are all little endian and will
  47. // need to be converted.
  48. struct SSpriteDef {
  49. ui32 prSize;
  50. ui32 defType2;
  51. ui32 FullWidth;
  52. ui32 FullHeight;
  53. ui32 SpriteWidth;
  54. ui32 SpriteHeight;
  55. ui32 LeftMargin;
  56. ui32 TopMargin;
  57. };
  58. class CDefEssential //DefHandler with images only
  59. {
  60. public:
  61. std::vector<Cimage> ourImages;
  62. ~CDefEssential(); //d-tor
  63. };
  64. class CDefHandler
  65. {
  66. private:
  67. unsigned int DEFType;
  68. int length;
  69. //unsigned int * RWEntries;
  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 unsigned char * FDef, const BMPPalette * palette) const; //saves picture with given number to "testtt.bmp"
  85. static void expand(unsigned char N,unsigned char & BL, unsigned char & BR);
  86. void openFromMemory(unsigned char * 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. };
  91. #endif // __CDEFHANDLER_H__