Canvas.h 2.1 KB

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