Canvas.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. /// Current rendering area, all rendering operations will be moved into selected area
  24. Rect renderArea;
  25. public:
  26. Canvas & operator = (const Canvas & other) = delete;
  27. /// constructs canvas using existing surface. Caller maintains ownership on the surface
  28. explicit Canvas(SDL_Surface * surface);
  29. /// copy contructor
  30. Canvas(const Canvas & other);
  31. /// creates canvas that only covers specified subsection of a surface
  32. Canvas(const Canvas & other, const Rect & clipRect);
  33. /// constructs canvas of specified size
  34. explicit Canvas(const Point & size);
  35. ~Canvas();
  36. /// if set to true, drawing this canvas onto another canvas will use alpha channel information
  37. void applyTransparency(bool on);
  38. /// applies grayscale filter onto current image
  39. void applyGrayscale();
  40. /// renders image onto this canvas at specified position
  41. void draw(const std::shared_ptr<IImage>& image, const Point & pos);
  42. /// renders section of image bounded by sourceRect at specified position
  43. void draw(const std::shared_ptr<IImage>& image, const Point & pos, const Rect & sourceRect);
  44. /// renders another canvas onto this canvas
  45. void draw(const Canvas &image, const Point & pos);
  46. /// renders another canvas onto this canvas with transparency
  47. void drawTransparent(const Canvas & image, const Point & pos, double transparency);
  48. /// renders another canvas onto this canvas with scaling
  49. void drawScaled(const Canvas &image, const Point & pos, const Point & targetSize);
  50. /// renders single pixels with specified color
  51. void drawPoint(const Point & dest, const ColorRGBA & color);
  52. /// renders continuous, 1-pixel wide line with color gradient
  53. void drawLine(const Point & from, const Point & dest, const ColorRGBA & colorFrom, const ColorRGBA & colorDest);
  54. /// renders dashed, 1-pixel wide line with specified color
  55. void drawLineDashed(const Point & from, const Point & dest, const ColorRGBA & color);
  56. /// renders rectangular, dashed border in specified location
  57. void drawBorderDashed(const Rect & target, const ColorRGBA & color);
  58. /// renders single line of text with specified parameters
  59. void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::string & text );
  60. /// renders multiple lines of text with specified parameters
  61. void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text );
  62. };