Canvas.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /// constructs canvas using existing surface. Caller maintains ownership on the surface
  26. explicit Canvas(SDL_Surface * surface);
  27. /// copy contructor
  28. Canvas(const Canvas & other);
  29. public:
  30. Canvas & operator = (const Canvas & other) = delete;
  31. Canvas & operator = (Canvas && other) = delete;
  32. /// move contructor
  33. Canvas(Canvas && other);
  34. /// creates canvas that only covers specified subsection of a surface
  35. Canvas(const Canvas & other, const Rect & clipRect);
  36. /// constructs canvas of specified size
  37. explicit Canvas(const Point & size);
  38. /// constructs canvas using existing surface. Caller maintains ownership on the surface
  39. /// Compatibility method. AVOID USAGE. To be removed once SDL abstraction layer is finished.
  40. static Canvas createFromSurface(SDL_Surface * surface);
  41. ~Canvas();
  42. /// if set to true, drawing this canvas onto another canvas will use alpha channel information
  43. void applyTransparency(bool on);
  44. /// applies grayscale filter onto current image
  45. void applyGrayscale();
  46. /// renders image onto this canvas at specified position
  47. void draw(const std::shared_ptr<IImage>& image, const Point & pos);
  48. /// renders section of image bounded by sourceRect at specified position
  49. void draw(const std::shared_ptr<IImage>& image, const Point & pos, const Rect & sourceRect);
  50. /// renders another canvas onto this canvas
  51. void draw(const Canvas &image, const Point & pos);
  52. /// renders another canvas onto this canvas with transparency
  53. void drawTransparent(const Canvas & image, const Point & pos, double transparency);
  54. /// renders another canvas onto this canvas with scaling
  55. void drawScaled(const Canvas &image, const Point & pos, const Point & targetSize);
  56. /// renders single pixels with specified color
  57. void drawPoint(const Point & dest, const ColorRGBA & color);
  58. /// renders continuous, 1-pixel wide line with color gradient
  59. void drawLine(const Point & from, const Point & dest, const ColorRGBA & colorFrom, const ColorRGBA & colorDest);
  60. /// renders dashed, 1-pixel wide line with specified color
  61. void drawLineDashed(const Point & from, const Point & dest, const ColorRGBA & color);
  62. /// renders rectangular, solid-color border in specified location
  63. void drawBorder(const Rect & target, const SDL_Color & color, int width = 1);
  64. /// renders rectangular, dashed border in specified location
  65. void drawBorderDashed(const Rect & target, const ColorRGBA & color);
  66. /// renders single line of text with specified parameters
  67. void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::string & text );
  68. /// renders multiple lines of text with specified parameters
  69. void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text );
  70. /// fills selected area with solid color, ignoring any transparency
  71. void drawColor(const Rect & target, const SDL_Color & color);
  72. /// Compatibility method. AVOID USAGE. To be removed once SDL abstraction layer is finished.
  73. SDL_Surface * getInternalSurface();
  74. };