aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-30 22:23:59 +0800
committercrupest <crupest@outlook.com>2022-01-30 22:23:59 +0800
commitb9a553d4acc15ec981636b30db537be280d593e5 (patch)
treec909657f2bbd112abafc104db28034b67d895d45
parent1909ee98b92ea993e6fbbdb628da0cf586db7d52 (diff)
downloadcru-b9a553d4acc15ec981636b30db537be280d593e5.tar.gz
cru-b9a553d4acc15ec981636b30db537be280d593e5.tar.bz2
cru-b9a553d4acc15ec981636b30db537be280d593e5.zip
...
-rw-r--r--include/cru/osx/graphics/quartz/Image.hpp2
-rw-r--r--include/cru/osx/graphics/quartz/Painter.hpp2
-rw-r--r--include/cru/platform/graphics/Base.hpp3
-rw-r--r--include/cru/platform/graphics/NullPainter.hpp8
-rw-r--r--include/cru/platform/graphics/Painter.hpp2
-rw-r--r--src/osx/graphics/quartz/Painter.cpp7
6 files changed, 22 insertions, 2 deletions
diff --git a/include/cru/osx/graphics/quartz/Image.hpp b/include/cru/osx/graphics/quartz/Image.hpp
index 66d7dca0..16b1ca2c 100644
--- a/include/cru/osx/graphics/quartz/Image.hpp
+++ b/include/cru/osx/graphics/quartz/Image.hpp
@@ -17,6 +17,8 @@ class QuartzImage : public OsxQuartzResource, public virtual IImage {
~QuartzImage() override;
public:
+ CGImageRef GetCGImage() const { return image_; }
+
private:
CGImageRef image_;
bool auto_release_ = false;
diff --git a/include/cru/osx/graphics/quartz/Painter.hpp b/include/cru/osx/graphics/quartz/Painter.hpp
index 83f15516..c88987a0 100644
--- a/include/cru/osx/graphics/quartz/Painter.hpp
+++ b/include/cru/osx/graphics/quartz/Painter.hpp
@@ -48,6 +48,8 @@ class QuartzCGContextPainter : public OsxQuartzResource,
void DrawText(const Point& offset, ITextLayout* text_layout,
IBrush* brush) override;
+ void DrawImage(const Rect& rect, IImage* image) override;
+
void PushLayer(const Rect& bounds) override;
void PopLayer() override;
diff --git a/include/cru/platform/graphics/Base.hpp b/include/cru/platform/graphics/Base.hpp
index 3a18e39d..416f0df4 100644
--- a/include/cru/platform/graphics/Base.hpp
+++ b/include/cru/platform/graphics/Base.hpp
@@ -16,7 +16,6 @@
#define CRU_PLATFORM_GRAPHICS_API
#endif
-
namespace cru::platform::graphics {
// forward declarations
struct IGraphicsFactory;
@@ -25,6 +24,8 @@ struct ISolidColorBrush;
struct IFont;
struct IGeometry;
struct IGeometryBuilder;
+struct IImage;
+struct IImageFactory;
struct IPainter;
struct ITextLayout;
diff --git a/include/cru/platform/graphics/NullPainter.hpp b/include/cru/platform/graphics/NullPainter.hpp
index b5c796d3..a47546b6 100644
--- a/include/cru/platform/graphics/NullPainter.hpp
+++ b/include/cru/platform/graphics/NullPainter.hpp
@@ -3,7 +3,8 @@
#include "cru/common/Base.hpp"
namespace cru::platform::graphics {
-class CRU_PLATFORM_GRAPHICS_API NullPainter : public Object, public virtual IPainter {
+class CRU_PLATFORM_GRAPHICS_API NullPainter : public Object,
+ public virtual IPainter {
public:
NullPainter() = default;
@@ -65,6 +66,11 @@ class CRU_PLATFORM_GRAPHICS_API NullPainter : public Object, public virtual IPai
CRU_UNUSED(brush)
}
+ void DrawImage(const Rect& rect, IImage* image) override {
+ CRU_UNUSED(rect)
+ CRU_UNUSED(image)
+ }
+
void PushLayer(const Rect& bounds) override { CRU_UNUSED(bounds) }
void PopLayer() override {}
diff --git a/include/cru/platform/graphics/Painter.hpp b/include/cru/platform/graphics/Painter.hpp
index 4104a752..eb5bf8e1 100644
--- a/include/cru/platform/graphics/Painter.hpp
+++ b/include/cru/platform/graphics/Painter.hpp
@@ -27,6 +27,8 @@ struct CRU_PLATFORM_GRAPHICS_API IPainter : virtual IPlatformResource {
virtual void DrawText(const Point& offset, ITextLayout* text_layout,
IBrush* brush) = 0;
+ virtual void DrawImage(const Rect& rect, IImage* image) = 0;
+
virtual void PushLayer(const Rect& bounds) = 0;
virtual void PopLayer() = 0;
diff --git a/src/osx/graphics/quartz/Painter.cpp b/src/osx/graphics/quartz/Painter.cpp
index 9750d6a5..3c39ec61 100644
--- a/src/osx/graphics/quartz/Painter.cpp
+++ b/src/osx/graphics/quartz/Painter.cpp
@@ -4,6 +4,7 @@
#include "cru/osx/graphics/quartz/Brush.hpp"
#include "cru/osx/graphics/quartz/Convert.hpp"
#include "cru/osx/graphics/quartz/Geometry.hpp"
+#include "cru/osx/graphics/quartz/Image.hpp"
#include "cru/osx/graphics/quartz/TextLayout.hpp"
#include "cru/platform/Check.hpp"
#include "cru/platform/Color.hpp"
@@ -173,6 +174,12 @@ void QuartzCGContextPainter::DrawText(const Point& offset,
CGContextRestoreGState(cg_context_);
}
+void QuartzCGContextPainter::DrawImage(const Rect& rect, IImage* image) {
+ Validate();
+ auto i = CheckPlatform<QuartzImage>(image, GetPlatformId());
+ CGContextDrawImage(cg_context_, Convert(rect), i->GetCGImage());
+}
+
void QuartzCGContextPainter::PushLayer(const Rect& bounds) {
Validate();
clip_stack_.push_back(bounds);