aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-08-22 21:15:33 +0800
committercrupest <crupest@outlook.com>2021-08-22 21:15:33 +0800
commit7fa6f61b1d7b253f749be73a4bfeee9a77cd2e88 (patch)
tree387d0d8e18c581a7fcced157817f0b81c33c17e5
parentc0616e3892e4f713bea7abd217191b8713a1d1bf (diff)
downloadcru-7fa6f61b1d7b253f749be73a4bfeee9a77cd2e88.tar.gz
cru-7fa6f61b1d7b253f749be73a4bfeee9a77cd2e88.tar.bz2
cru-7fa6f61b1d7b253f749be73a4bfeee9a77cd2e88.zip
...
-rw-r--r--include/cru/osx/graphics/quartz/Brush.hpp38
-rw-r--r--include/cru/osx/graphics/quartz/Painter.hpp12
-rw-r--r--include/cru/osx/graphics/quartz/Resource.hpp15
-rw-r--r--include/cru/platform/Color.hpp5
-rw-r--r--src/osx/graphics/quartz/Brush.cpp21
-rw-r--r--src/osx/graphics/quartz/CMakeLists.txt2
6 files changed, 89 insertions, 4 deletions
diff --git a/include/cru/osx/graphics/quartz/Brush.hpp b/include/cru/osx/graphics/quartz/Brush.hpp
new file mode 100644
index 00000000..fa0ef18c
--- /dev/null
+++ b/include/cru/osx/graphics/quartz/Brush.hpp
@@ -0,0 +1,38 @@
+#pragma once
+#include "Resource.hpp"
+#include "cru/common/Base.hpp"
+#include "cru/platform/graphics/Base.hpp"
+#include "cru/platform/graphics/Brush.hpp"
+
+#include <CoreGraphics/CoreGraphics.h>
+
+namespace cru::platform::graphics::osx::quartz {
+class QuartzBrush : public OsxQuartzResource, public virtual IBrush {
+ public:
+ QuartzBrush(IGraphFactory* graphics_factory)
+ : OsxQuartzResource(graphics_factory) {}
+ CRU_DELETE_COPY(QuartzBrush)
+ CRU_DELETE_MOVE(QuartzBrush)
+ ~QuartzBrush() override = default;
+};
+
+class QuartzSolidColorBrush : public QuartzBrush,
+ public virtual ISolidColorBrush {
+ public:
+ QuartzSolidColorBrush(IGraphFactory* graphics_factory, const Color& color);
+
+ CRU_DELETE_COPY(QuartzSolidColorBrush)
+ CRU_DELETE_MOVE(QuartzSolidColorBrush)
+
+ ~QuartzSolidColorBrush() override;
+
+ Color GetColor() override { return color_; }
+ void SetColor(const Color& color) override;
+
+ CGColorRef GetCGColorRef() const { return cg_color_; }
+
+ private:
+ Color color_;
+ CGColorRef cg_color_;
+};
+} // namespace cru::platform::graphics::osx::quartz
diff --git a/include/cru/osx/graphics/quartz/Painter.hpp b/include/cru/osx/graphics/quartz/Painter.hpp
index 7f775210..5dcc49dc 100644
--- a/include/cru/osx/graphics/quartz/Painter.hpp
+++ b/include/cru/osx/graphics/quartz/Painter.hpp
@@ -1,5 +1,7 @@
#pragma once
#include "Resource.hpp"
+#include "cru/common/Base.hpp"
+#include "cru/platform/graphics/Base.hpp"
#include "cru/platform/graphics/Painter.hpp"
#include <CoreGraphics/CoreGraphics.h>
@@ -8,8 +10,14 @@ namespace cru::platform::graphics::osx::quartz {
class QuartzCGContextPainter : public OsxQuartzResource,
public virtual IPainter {
public:
- explicit QuartzCGContextPainter(CGContextRef cg_context)
- : cg_context_(cg_context) {}
+ explicit QuartzCGContextPainter(IGraphFactory* graphics_factory,
+ CGContextRef cg_context)
+ : OsxQuartzResource(graphics_factory), cg_context_(cg_context) {}
+
+ CRU_DELETE_COPY(QuartzCGContextPainter)
+ CRU_DELETE_MOVE(QuartzCGContextPainter)
+
+ ~QuartzCGContextPainter() override = default;
public:
Matrix GetTransform() override;
diff --git a/include/cru/osx/graphics/quartz/Resource.hpp b/include/cru/osx/graphics/quartz/Resource.hpp
index b302c84c..2d3b4b08 100644
--- a/include/cru/osx/graphics/quartz/Resource.hpp
+++ b/include/cru/osx/graphics/quartz/Resource.hpp
@@ -1,14 +1,25 @@
#pragma once
#include "cru/osx/Resource.hpp"
+#include "cru/platform/graphics/Base.hpp"
+#include "cru/platform/graphics/Resource.hpp"
namespace cru::platform::graphics::osx::quartz {
-class OsxQuartzResource : public platform::osx::OsxResource {
+class OsxQuartzResource : public platform::osx::OsxResource,
+ public virtual IGraphResource {
public:
- CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(OsxQuartzResource)
+ explicit OsxQuartzResource(IGraphFactory* graphics_factory)
+ : graphics_factory_(graphics_factory) {}
+
CRU_DELETE_COPY(OsxQuartzResource)
CRU_DELETE_MOVE(OsxQuartzResource)
+ ~OsxQuartzResource() override = default;
public:
String GetPlatformId() const override { return u"OSX Quartz"; }
+
+ IGraphFactory* GetGraphFactory() override;
+
+ private:
+ IGraphFactory* graphics_factory_;
};
} // namespace cru::platform::graphics::osx::quartz
diff --git a/include/cru/platform/Color.hpp b/include/cru/platform/Color.hpp
index a6793269..3388de25 100644
--- a/include/cru/platform/Color.hpp
+++ b/include/cru/platform/Color.hpp
@@ -32,6 +32,11 @@ struct CRU_PLATFORM_API Color {
return result;
}
+ float GetFloatRed() const { return static_cast<float>(red) / 255.f; }
+ float GetFloatGreen() const { return static_cast<float>(green) / 255.f; }
+ float GetFloatBlue() const { return static_cast<float>(blue) / 255.f; }
+ float GetFloatAlpha() const { return static_cast<float>(alpha) / 255.f; }
+
std::string ToUtf8String() const;
std::u16string ToString() const;
diff --git a/src/osx/graphics/quartz/Brush.cpp b/src/osx/graphics/quartz/Brush.cpp
new file mode 100644
index 00000000..a930719c
--- /dev/null
+++ b/src/osx/graphics/quartz/Brush.cpp
@@ -0,0 +1,21 @@
+#include "cru/osx/graphics/quartz/Brush.hpp"
+
+namespace cru::platform::graphics::osx::quartz {
+QuartzSolidColorBrush::QuartzSolidColorBrush(IGraphFactory* graphics_factory,
+ const Color& color)
+ : QuartzBrush(graphics_factory), color_(color) {
+ cg_color_ =
+ CGColorCreateGenericRGB(color.GetFloatRed(), color.GetFloatGreen(),
+ color.GetFloatBlue(), color.GetFloatAlpha());
+}
+
+QuartzSolidColorBrush::~QuartzSolidColorBrush() { CGColorRelease(cg_color_); }
+
+void QuartzSolidColorBrush::SetColor(const Color& color) {
+ color_ = color;
+ CGColorRelease(cg_color_);
+ cg_color_ =
+ CGColorCreateGenericRGB(color.GetFloatRed(), color.GetFloatGreen(),
+ color.GetFloatBlue(), color.GetFloatAlpha());
+}
+} // namespace cru::platform::graphics::osx::quartz
diff --git a/src/osx/graphics/quartz/CMakeLists.txt b/src/osx/graphics/quartz/CMakeLists.txt
index 2d66c3e7..fcbda648 100644
--- a/src/osx/graphics/quartz/CMakeLists.txt
+++ b/src/osx/graphics/quartz/CMakeLists.txt
@@ -1,12 +1,14 @@
set(CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/osx/graphics/quartz)
add_library(cru_osx_graphics_quartz SHARED
+ Brush.cpp
Convert.cpp
Factory.cpp
Painter.cpp
Resource.cpp
)
target_sources(cru_osx_graphics_quartz PUBLIC
+ ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Brush.hpp
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Convert.hpp
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Factory.hpp
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Painter.hpp