Canvas.h 2.7 KB

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