SDLImage.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SDLImage.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/IImage.h"
  12. #include "../../lib/Point.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class JsonNode;
  15. VCMI_LIB_NAMESPACE_END
  16. class CDefFile;
  17. struct SDL_Surface;
  18. struct SDL_Palette;
  19. /*
  20. * Wrapper around SDL_Surface
  21. */
  22. class SDLImage : public IImage
  23. {
  24. public:
  25. const static int DEFAULT_PALETTE_COLORS = 256;
  26. //Surface without empty borders
  27. SDL_Surface * surf;
  28. //size of left and top borders
  29. Point margins;
  30. //total size including borders
  31. Point fullSize;
  32. EImageBlitMode blitMode;
  33. public:
  34. //Load image from def file
  35. SDLImage(CDefFile *data, size_t frame, size_t group=0);
  36. //Load from bitmap file
  37. SDLImage(const ImagePath & filename, EImageBlitMode blitMode);
  38. SDLImage(const JsonNode & conf, EImageBlitMode blitMode);
  39. //Create using existing surface, extraRef will increase refcount on SDL_Surface
  40. SDLImage(SDL_Surface * from, EImageBlitMode blitMode);
  41. ~SDLImage();
  42. // Keep the original palette, in order to do color switching operation
  43. void savePalette();
  44. void draw(SDL_Surface * where, int posX=0, int posY=0, const Rect *src=nullptr) const override;
  45. void draw(SDL_Surface * where, const Rect * dest, const Rect * src) const override;
  46. std::shared_ptr<IImage> scaleFast(const Point & size) const override;
  47. void exportBitmap(const boost::filesystem::path & path) const override;
  48. void playerColored(PlayerColor player) override;
  49. void setFlagColor(PlayerColor player) override;
  50. bool isTransparent(const Point & coords) const override;
  51. Point dimensions() const override;
  52. void horizontalFlip() override;
  53. void verticalFlip() override;
  54. void doubleFlip() override;
  55. void shiftPalette(uint32_t firstColorID, uint32_t colorsToMove, uint32_t distanceToMove) override;
  56. void adjustPalette(const ColorFilter & shifter, uint32_t colorsToSkipMask) override;
  57. void resetPalette(int colorID) override;
  58. void resetPalette() override;
  59. void setAlpha(uint8_t value) override;
  60. void setBlitMode(EImageBlitMode mode) override;
  61. void setSpecialPalette(const SpecialPalette & SpecialPalette, uint32_t colorsToSkipMask) override;
  62. friend class SDLImageLoader;
  63. private:
  64. SDL_Palette * originalPalette;
  65. };