Canvas.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Canvas.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 "Geometries.h"
  12. struct SDL_Color;
  13. struct SDL_Surface;
  14. class IImage;
  15. enum EFonts : int;
  16. /// Class that represents surface for drawing on
  17. class Canvas
  18. {
  19. /// Target surface
  20. SDL_Surface * surface;
  21. /// Clip rect that was in use on surface originally and needs to be restored on destruction
  22. boost::optional<Rect> clipRect;
  23. /// Current rendering area offset, all rendering operations will be moved into selected area
  24. Point renderOffset;
  25. Canvas & operator = (Canvas & other) = delete;
  26. public:
  27. /// constructs canvas using existing surface. Caller maintains ownership on the surface
  28. Canvas(SDL_Surface * surface);
  29. /// copy contructor
  30. Canvas(Canvas & other);
  31. /// creates canvas that only covers specified subsection of a surface
  32. Canvas(Canvas & other, const Rect & clipRect);
  33. /// constructs canvas of specified size
  34. Canvas(const Point & size);
  35. ~Canvas();
  36. /// renders image onto this canvas at specified position
  37. void draw(std::shared_ptr<IImage> image, const Point & pos);
  38. /// renders section of image bounded by sourceRect at specified position
  39. void draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect);
  40. /// renders section of image bounded by sourceRect at specified position at specific transparency value
  41. /// disabled for now as never used in code with alpha support
  42. // void draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect, uint8_t alpha);
  43. /// renders another canvas onto this canvas
  44. void draw(Canvas & image, const Point & pos);
  45. /// renders continuous, 1-pixel wide line with color gradient
  46. void drawLine(const Point & from, const Point & dest, const SDL_Color & colorFrom, const SDL_Color & colorDest);
  47. /// renders single line of text with specified parameters
  48. void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::string & text );
  49. /// renders multiple lines of text with specified parameters
  50. void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text );
  51. };