CCanvas.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * CCanvas.cpp, 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. #include "StdInc.h"
  11. #include "CCanvas.h"
  12. #include "SDL_Extensions.h"
  13. #include "Geometries.h"
  14. #include "CAnimation.h"
  15. CCanvas::CCanvas(SDL_Surface * surface):
  16. surface(surface)
  17. {
  18. surface->refcount++;
  19. }
  20. CCanvas::CCanvas(const Point & size)
  21. {
  22. surface = CSDL_Ext::newSurface(size.x, size.y);
  23. }
  24. CCanvas::~CCanvas()
  25. {
  26. SDL_FreeSurface(surface);
  27. }
  28. void CCanvas::draw(std::shared_ptr<IImage> image, const Point & pos)
  29. {
  30. image->draw(surface, pos.x, pos.y);
  31. }
  32. void CCanvas::draw(std::shared_ptr<CCanvas> image, const Point & pos)
  33. {
  34. image->copyTo(surface, pos);
  35. }
  36. void CCanvas::drawLine(const Point & from, const Point & dest, const SDL_Color & colorFrom, const SDL_Color & colorDest)
  37. {
  38. CSDL_Ext::drawLine(surface, from.x, from.y, dest.x, dest.y, colorFrom, colorDest);
  39. }
  40. void CCanvas::copyTo(SDL_Surface * to, const Point & pos)
  41. {
  42. blitAt(to, pos.x, pos.y, surface);
  43. }