Canvas.h 3.9 KB

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