CCanvas.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * CCanvas.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 "Geometries.h"
  12. struct SDL_Color;
  13. struct SDL_Surface;
  14. class IImage;
  15. enum EFonts : int;
  16. /// Class that represents surface for drawing on
  17. class CCanvas
  18. {
  19. SDL_Surface * surface;
  20. public:
  21. /// constructs canvas using existing surface. Caller maintains ownership on the surface
  22. CCanvas(SDL_Surface * surface);
  23. /// constructs canvas of specified size
  24. CCanvas(const Point & size);
  25. ~CCanvas();
  26. /// renders image onto this canvas at specified position
  27. void draw(std::shared_ptr<IImage> image, const Point & pos);
  28. /// renders section of image bounded by sourceRect at specified position
  29. void draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect);
  30. /// renders another canvas onto this canvas
  31. void draw(std::shared_ptr<CCanvas> image, const Point & pos);
  32. /// renders continuous, 1-pixel wide line with color gradient
  33. void drawLine(const Point & from, const Point & dest, const SDL_Color & colorFrom, const SDL_Color & colorDest);
  34. /// renders single line of text with specified parameters
  35. void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::string & text );
  36. /// renders multiple lines of text with specified parameters
  37. void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text );
  38. /// for compatibility, returns pointer to internal SDL surface
  39. SDL_Surface * getSurface();
  40. };