CDefFile.h 1.6 KB

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