CDefFile.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * CDefFile.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/GameConstants.h"
  12. #ifdef IN
  13. #undef IN
  14. #endif
  15. #ifdef OUT
  16. #undef OUT
  17. #endif
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. class JsonNode;
  20. class Rect;
  21. class Point;
  22. VCMI_LIB_NAMESPACE_END
  23. struct SDL_Surface;
  24. struct SDL_Color;
  25. class CDefFile;
  26. class ColorFilter;
  27. /// Class for def loading
  28. /// After loading will store general info (palette and frame offsets) and pointer to file itself
  29. class CDefFile
  30. {
  31. private:
  32. PACKED_STRUCT_BEGIN
  33. struct SSpriteDef
  34. {
  35. ui32 size;
  36. ui32 format; /// format in which pixel data is stored
  37. ui32 fullWidth; /// full width and height of frame, including borders
  38. ui32 fullHeight;
  39. ui32 width; /// width and height of pixel data, borders excluded
  40. ui32 height;
  41. si32 leftMargin;
  42. si32 topMargin;
  43. } PACKED_STRUCT_END;
  44. //offset[group][frame] - offset of frame data in file
  45. std::map<size_t, std::vector <size_t> > offset;
  46. std::unique_ptr<ui8[]> data;
  47. std::unique_ptr<SDL_Color[]> palette;
  48. public:
  49. CDefFile(std::string Name);
  50. ~CDefFile();
  51. //load frame as SDL_Surface
  52. template<class ImageLoader>
  53. void loadFrame(size_t frame, size_t group, ImageLoader &loader) const;
  54. const std::map<size_t, size_t> getEntries() const;
  55. };