diff options
-rw-r--r-- | include/cru/osx/graphics/quartz/Image.hpp | 6 | ||||
-rw-r--r-- | include/cru/platform/graphics/Image.hpp | 6 | ||||
-rw-r--r-- | src/osx/graphics/quartz/Image.cpp | 13 |
3 files changed, 24 insertions, 1 deletions
diff --git a/include/cru/osx/graphics/quartz/Image.hpp b/include/cru/osx/graphics/quartz/Image.hpp index 16b1ca2c..62b7fa8b 100644 --- a/include/cru/osx/graphics/quartz/Image.hpp +++ b/include/cru/osx/graphics/quartz/Image.hpp @@ -17,9 +17,15 @@ class QuartzImage : public OsxQuartzResource, public virtual IImage { ~QuartzImage() override; public: + float GetWidth() override; + float GetHeight() override; + + std::unique_ptr<IImage> CreateWithRect(const Rect& rect) override; + CGImageRef GetCGImage() const { return image_; } private: + IImageFactory* image_factory_; CGImageRef image_; bool auto_release_ = false; }; diff --git a/include/cru/platform/graphics/Image.hpp b/include/cru/platform/graphics/Image.hpp index bf1e8545..e8bf6671 100644 --- a/include/cru/platform/graphics/Image.hpp +++ b/include/cru/platform/graphics/Image.hpp @@ -2,5 +2,9 @@ #include "Resource.hpp" namespace cru::platform::graphics { -struct CRU_PLATFORM_GRAPHICS_API IImage : public virtual IGraphicsResource {}; +struct CRU_PLATFORM_GRAPHICS_API IImage : public virtual IGraphicsResource { + virtual float GetWidth() = 0; + virtual float GetHeight() = 0; + virtual std::unique_ptr<IImage> CreateWithRect(const Rect& rect) = 0; +}; } // namespace cru::platform::graphics diff --git a/src/osx/graphics/quartz/Image.cpp b/src/osx/graphics/quartz/Image.cpp index 901b3ff4..e2664322 100644 --- a/src/osx/graphics/quartz/Image.cpp +++ b/src/osx/graphics/quartz/Image.cpp @@ -1,10 +1,12 @@ #include "cru/osx/graphics/quartz/Image.hpp" +#include "cru/osx/graphics/quartz/Convert.hpp" namespace cru::platform::graphics::osx::quartz { QuartzImage::QuartzImage(IGraphicsFactory* graphics_factory, IImageFactory* image_factory, CGImageRef image, bool auto_release) : OsxQuartzResource(graphics_factory), + image_factory_(image_factory), image_(image), auto_release_(auto_release) {} @@ -13,4 +15,15 @@ QuartzImage::~QuartzImage() { CGImageRelease(image_); } } + +float QuartzImage::GetWidth() { return CGImageGetWidth(image_); } + +float QuartzImage::GetHeight() { return CGImageGetHeight(image_); } + +std::unique_ptr<IImage> QuartzImage::CreateWithRect(const Rect& rect) { + auto new_cg_image = CGImageCreateWithImageInRect(image_, Convert(rect)); + + return std::make_unique<QuartzImage>(GetGraphicsFactory(), image_factory_, + new_cg_image, true); +} } // namespace cru::platform::graphics::osx::quartz |