CDefFile.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/vcmi_endian.h"
  12. #include "../../lib/filesystem/ResourcePath.h"
  13. class IImageLoader;
  14. struct SDL_Color;
  15. /// Class for def loading
  16. /// After loading will store general info (palette and frame offsets) and pointer to file itself
  17. class CDefFile
  18. {
  19. private:
  20. PACKED_STRUCT_BEGIN
  21. struct SSpriteDef
  22. {
  23. ui32 size;
  24. ui32 format; /// format in which pixel data is stored
  25. ui32 fullWidth; /// full width and height of frame, including borders
  26. ui32 fullHeight;
  27. ui32 width; /// width and height of pixel data, borders excluded
  28. ui32 height;
  29. si32 leftMargin;
  30. si32 topMargin;
  31. } PACKED_STRUCT_END;
  32. //offset[group][frame] - offset of frame data in file
  33. std::map<size_t, std::vector <size_t> > offset;
  34. std::unique_ptr<ui8[]> data;
  35. std::unique_ptr<SDL_Color[]> palette;
  36. public:
  37. CDefFile(const AnimationPath & Name);
  38. ~CDefFile();
  39. //load frame as SDL_Surface
  40. void loadFrame(size_t frame, size_t group, IImageLoader &loader) const;
  41. bool hasFrame(size_t frame, size_t group) const;
  42. const std::map<size_t, size_t> getEntries() const;
  43. };