RenderHandler.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * RenderHandler.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 "../render/IRenderHandler.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class EntityService;
  14. VCMI_LIB_NAMESPACE_END
  15. class CDefFile;
  16. class SDLImageShared;
  17. class ISharedImage;
  18. class RenderHandler : public IRenderHandler
  19. {
  20. using AnimationLayoutMap = std::map<size_t, std::vector<ImageLocator>>;
  21. std::map<AnimationPath, std::shared_ptr<CDefFile>> animationFiles;
  22. std::map<AnimationPath, AnimationLayoutMap> animationLayouts;
  23. std::map<ImageLocator, std::shared_ptr<const ISharedImage>> imageFiles;
  24. std::map<EFonts, std::shared_ptr<const IFont>> fonts;
  25. std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
  26. std::optional<ResourcePath> getPathForScaleFactor(ResourcePath path, std::string factor);
  27. std::pair<ResourcePath, int> getScalePath(ResourcePath p);
  28. AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
  29. void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);
  30. void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
  31. void addImageListEntries(const EntityService * service);
  32. void storeCachedImage(const ImageLocator & locator, std::shared_ptr<const ISharedImage> image);
  33. std::shared_ptr<const ISharedImage> loadImageImpl(const ImageLocator & config);
  34. std::shared_ptr<const ISharedImage> loadImageFromFileUncached(const ImageLocator & locator);
  35. std::shared_ptr<const ISharedImage> loadImageFromFile(const ImageLocator & locator);
  36. std::shared_ptr<const ISharedImage> transformImage(const ImageLocator & locator, std::shared_ptr<const ISharedImage> image);
  37. std::shared_ptr<const ISharedImage> scaleImage(const ImageLocator & locator, std::shared_ptr<const ISharedImage> image);
  38. ImageLocator getLocatorForAnimationFrame(const AnimationPath & path, int frame, int group);
  39. int getScalingFactor() const;
  40. public:
  41. // IRenderHandler implementation
  42. void onLibraryLoadingFinished(const Services * services) override;
  43. std::shared_ptr<IImage> loadImage(const ImageLocator & locator, EImageBlitMode mode) override;
  44. std::shared_ptr<IImage> loadImage(const ImagePath & path, EImageBlitMode mode) override;
  45. std::shared_ptr<IImage> loadImage(const AnimationPath & path, int frame, int group, EImageBlitMode mode) override;
  46. std::shared_ptr<CAnimation> loadAnimation(const AnimationPath & path, EImageBlitMode mode) override;
  47. std::shared_ptr<IImage> createImage(SDL_Surface * source) override;
  48. /// Returns font with specified identifer
  49. std::shared_ptr<const IFont> loadFont(EFonts font) override;
  50. };