From 74bb9cd27242b9320f99ff4d2b50c3051576cc14 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 16:53:51 +0800 Subject: ... --- include/cru/osx/graphics/quartz/Brush.h | 47 ++++++++++++ include/cru/osx/graphics/quartz/Brush.hpp | 47 ------------ include/cru/osx/graphics/quartz/Convert.h | 23 ++++++ include/cru/osx/graphics/quartz/Convert.hpp | 23 ------ include/cru/osx/graphics/quartz/Factory.h | 35 +++++++++ include/cru/osx/graphics/quartz/Factory.hpp | 35 --------- include/cru/osx/graphics/quartz/Font.h | 25 +++++++ include/cru/osx/graphics/quartz/Font.hpp | 25 ------- include/cru/osx/graphics/quartz/Geometry.h | 48 ++++++++++++ include/cru/osx/graphics/quartz/Geometry.hpp | 48 ------------ include/cru/osx/graphics/quartz/Image.h | 32 ++++++++ include/cru/osx/graphics/quartz/Image.hpp | 32 -------- include/cru/osx/graphics/quartz/ImageFactory.h | 19 +++++ include/cru/osx/graphics/quartz/ImageFactory.hpp | 19 ----- include/cru/osx/graphics/quartz/Painter.h | 83 +++++++++++++++++++++ include/cru/osx/graphics/quartz/Painter.hpp | 83 --------------------- include/cru/osx/graphics/quartz/Resource.h | 25 +++++++ include/cru/osx/graphics/quartz/Resource.hpp | 25 ------- include/cru/osx/graphics/quartz/TextLayout.h | 95 ++++++++++++++++++++++++ include/cru/osx/graphics/quartz/TextLayout.hpp | 95 ------------------------ 20 files changed, 432 insertions(+), 432 deletions(-) create mode 100644 include/cru/osx/graphics/quartz/Brush.h delete mode 100644 include/cru/osx/graphics/quartz/Brush.hpp create mode 100644 include/cru/osx/graphics/quartz/Convert.h delete mode 100644 include/cru/osx/graphics/quartz/Convert.hpp create mode 100644 include/cru/osx/graphics/quartz/Factory.h delete mode 100644 include/cru/osx/graphics/quartz/Factory.hpp create mode 100644 include/cru/osx/graphics/quartz/Font.h delete mode 100644 include/cru/osx/graphics/quartz/Font.hpp create mode 100644 include/cru/osx/graphics/quartz/Geometry.h delete mode 100644 include/cru/osx/graphics/quartz/Geometry.hpp create mode 100644 include/cru/osx/graphics/quartz/Image.h delete mode 100644 include/cru/osx/graphics/quartz/Image.hpp create mode 100644 include/cru/osx/graphics/quartz/ImageFactory.h delete mode 100644 include/cru/osx/graphics/quartz/ImageFactory.hpp create mode 100644 include/cru/osx/graphics/quartz/Painter.h delete mode 100644 include/cru/osx/graphics/quartz/Painter.hpp create mode 100644 include/cru/osx/graphics/quartz/Resource.h delete mode 100644 include/cru/osx/graphics/quartz/Resource.hpp create mode 100644 include/cru/osx/graphics/quartz/TextLayout.h delete mode 100644 include/cru/osx/graphics/quartz/TextLayout.hpp (limited to 'include/cru/osx/graphics') diff --git a/include/cru/osx/graphics/quartz/Brush.h b/include/cru/osx/graphics/quartz/Brush.h new file mode 100644 index 00000000..677a0b6c --- /dev/null +++ b/include/cru/osx/graphics/quartz/Brush.h @@ -0,0 +1,47 @@ +#pragma once +#include "Resource.h" +#include "cru/common/Base.h" +#include "cru/platform/graphics/Base.h" +#include "cru/platform/graphics/Brush.h" + +#include + +#include + +namespace cru::platform::graphics::osx::quartz { +class QuartzBrush : public OsxQuartzResource, public virtual IBrush { + public: + QuartzBrush(IGraphicsFactory* graphics_factory) + : OsxQuartzResource(graphics_factory) {} + CRU_DELETE_COPY(QuartzBrush) + CRU_DELETE_MOVE(QuartzBrush) + ~QuartzBrush() override = default; + + public: + virtual void Select(CGContextRef context) = 0; +}; + +class QuartzSolidColorBrush : public QuartzBrush, + public virtual ISolidColorBrush { + public: + QuartzSolidColorBrush(IGraphicsFactory* 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_; } + + void Select(CGContextRef context) override; + + String GetDebugString() override; + + private: + Color color_; + CGColorRef cg_color_; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Brush.hpp b/include/cru/osx/graphics/quartz/Brush.hpp deleted file mode 100644 index 1fa26794..00000000 --- a/include/cru/osx/graphics/quartz/Brush.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -#include "Resource.hpp" -#include "cru/common/Base.hpp" -#include "cru/platform/graphics/Base.hpp" -#include "cru/platform/graphics/Brush.hpp" - -#include - -#include - -namespace cru::platform::graphics::osx::quartz { -class QuartzBrush : public OsxQuartzResource, public virtual IBrush { - public: - QuartzBrush(IGraphicsFactory* graphics_factory) - : OsxQuartzResource(graphics_factory) {} - CRU_DELETE_COPY(QuartzBrush) - CRU_DELETE_MOVE(QuartzBrush) - ~QuartzBrush() override = default; - - public: - virtual void Select(CGContextRef context) = 0; -}; - -class QuartzSolidColorBrush : public QuartzBrush, - public virtual ISolidColorBrush { - public: - QuartzSolidColorBrush(IGraphicsFactory* 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_; } - - void Select(CGContextRef context) override; - - String GetDebugString() override; - - private: - Color color_; - CGColorRef cg_color_; -}; -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Convert.h b/include/cru/osx/graphics/quartz/Convert.h new file mode 100644 index 00000000..8d486069 --- /dev/null +++ b/include/cru/osx/graphics/quartz/Convert.h @@ -0,0 +1,23 @@ +#pragma once +#include "cru/common/Range.h" +#include "cru/common/String.h" +#include "cru/common/io/Stream.h" +#include "cru/platform/Matrix.h" + +#include + +namespace cru::platform::graphics::osx::quartz { +CGAffineTransform Convert(const Matrix& matrix); +Matrix Convert(const CGAffineTransform& matrix); + +CGPoint Convert(const Point& point); +Point Convert(const CGPoint& point); + +CGSize Convert(const Size& size); +Size Convert(const CGSize& size); + +CGRect Convert(const Rect& rect); +Rect Convert(const CGRect& rect); + +CGDataProviderRef ConvertStreamToCGDataProvider(io::Stream* stream); +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Convert.hpp b/include/cru/osx/graphics/quartz/Convert.hpp deleted file mode 100644 index ba2b1be1..00000000 --- a/include/cru/osx/graphics/quartz/Convert.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "cru/common/Range.hpp" -#include "cru/common/String.hpp" -#include "cru/common/io/Stream.hpp" -#include "cru/platform/Matrix.hpp" - -#include - -namespace cru::platform::graphics::osx::quartz { -CGAffineTransform Convert(const Matrix& matrix); -Matrix Convert(const CGAffineTransform& matrix); - -CGPoint Convert(const Point& point); -Point Convert(const CGPoint& point); - -CGSize Convert(const Size& size); -Size Convert(const CGSize& size); - -CGRect Convert(const Rect& rect); -Rect Convert(const CGRect& rect); - -CGDataProviderRef ConvertStreamToCGDataProvider(io::Stream* stream); -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Factory.h b/include/cru/osx/graphics/quartz/Factory.h new file mode 100644 index 00000000..1a5abdc1 --- /dev/null +++ b/include/cru/osx/graphics/quartz/Factory.h @@ -0,0 +1,35 @@ +#pragma once +#include "Resource.h" +#include "cru/common/Base.h" +#include "cru/osx/graphics/quartz/ImageFactory.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/ImageFactory.h" + +namespace cru::platform::graphics::osx::quartz { +class QuartzGraphicsFactory : public OsxQuartzResource, + public virtual IGraphicsFactory { + public: + QuartzGraphicsFactory(); + + CRU_DELETE_COPY(QuartzGraphicsFactory) + CRU_DELETE_MOVE(QuartzGraphicsFactory) + + ~QuartzGraphicsFactory() override; + + public: + std::unique_ptr CreateSolidColorBrush() override; + + std::unique_ptr CreateGeometryBuilder() override; + + std::unique_ptr CreateFont(String font_family, + float font_size) override; + + std::unique_ptr CreateTextLayout(std::shared_ptr font, + String text) override; + + IImageFactory* GetImageFactory() override; + + private: + std::unique_ptr image_factory_; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Factory.hpp b/include/cru/osx/graphics/quartz/Factory.hpp deleted file mode 100644 index 59433b54..00000000 --- a/include/cru/osx/graphics/quartz/Factory.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include "Resource.hpp" -#include "cru/common/Base.hpp" -#include "cru/osx/graphics/quartz/ImageFactory.hpp" -#include "cru/platform/graphics/Factory.hpp" -#include "cru/platform/graphics/ImageFactory.hpp" - -namespace cru::platform::graphics::osx::quartz { -class QuartzGraphicsFactory : public OsxQuartzResource, - public virtual IGraphicsFactory { - public: - QuartzGraphicsFactory(); - - CRU_DELETE_COPY(QuartzGraphicsFactory) - CRU_DELETE_MOVE(QuartzGraphicsFactory) - - ~QuartzGraphicsFactory() override; - - public: - std::unique_ptr CreateSolidColorBrush() override; - - std::unique_ptr CreateGeometryBuilder() override; - - std::unique_ptr CreateFont(String font_family, - float font_size) override; - - std::unique_ptr CreateTextLayout(std::shared_ptr font, - String text) override; - - IImageFactory* GetImageFactory() override; - - private: - std::unique_ptr image_factory_; -}; -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Font.h b/include/cru/osx/graphics/quartz/Font.h new file mode 100644 index 00000000..d53c6a20 --- /dev/null +++ b/include/cru/osx/graphics/quartz/Font.h @@ -0,0 +1,25 @@ +#pragma once +#include "Resource.h" +#include "cru/common/Base.h" +#include "cru/platform/graphics/Font.h" + +#include + +namespace cru::platform::graphics::osx::quartz { +class OsxCTFont : public OsxQuartzResource, public virtual IFont { + public: + OsxCTFont(IGraphicsFactory* graphics_factory, const String& name, float size); + + CRU_DELETE_COPY(OsxCTFont) + CRU_DELETE_MOVE(OsxCTFont) + + ~OsxCTFont() override; + + CTFontRef GetCTFont() const { return ct_font_; } + + float GetFontSize() override; + + private: + CTFontRef ct_font_; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Font.hpp b/include/cru/osx/graphics/quartz/Font.hpp deleted file mode 100644 index 1ea2b891..00000000 --- a/include/cru/osx/graphics/quartz/Font.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "Resource.hpp" -#include "cru/common/Base.hpp" -#include "cru/platform/graphics/Font.hpp" - -#include - -namespace cru::platform::graphics::osx::quartz { -class OsxCTFont : public OsxQuartzResource, public virtual IFont { - public: - OsxCTFont(IGraphicsFactory* graphics_factory, const String& name, float size); - - CRU_DELETE_COPY(OsxCTFont) - CRU_DELETE_MOVE(OsxCTFont) - - ~OsxCTFont() override; - - CTFontRef GetCTFont() const { return ct_font_; } - - float GetFontSize() override; - - private: - CTFontRef ct_font_; -}; -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Geometry.h b/include/cru/osx/graphics/quartz/Geometry.h new file mode 100644 index 00000000..8e42491b --- /dev/null +++ b/include/cru/osx/graphics/quartz/Geometry.h @@ -0,0 +1,48 @@ +#pragma once +#include "Resource.h" +#include "cru/platform/graphics/Geometry.h" + +#include + +#include + +namespace cru::platform::graphics::osx::quartz { +class QuartzGeometry : public OsxQuartzResource, public virtual IGeometry { + public: + QuartzGeometry(IGraphicsFactory *graphics_factory, CGPathRef cg_path); + + CRU_DELETE_COPY(QuartzGeometry) + CRU_DELETE_MOVE(QuartzGeometry) + + ~QuartzGeometry() override; + + CGPathRef GetCGPath() const { return cg_path_; } + + bool FillContains(const Point &point) override; + + private: + CGPathRef cg_path_; +}; + +class QuartzGeometryBuilder : public OsxQuartzResource, + public virtual IGeometryBuilder { + public: + explicit QuartzGeometryBuilder(IGraphicsFactory *graphics_factory); + + CRU_DELETE_COPY(QuartzGeometryBuilder) + CRU_DELETE_MOVE(QuartzGeometryBuilder) + + ~QuartzGeometryBuilder() override; + + void BeginFigure(const Point &point) override; + void CloseFigure(bool close) override; + void LineTo(const Point &point) override; + void QuadraticBezierTo(const Point &control_point, + const Point &end_point) override; + + std::unique_ptr Build() override; + + private: + CGMutablePathRef cg_mutable_path_; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Geometry.hpp b/include/cru/osx/graphics/quartz/Geometry.hpp deleted file mode 100644 index 565c5b86..00000000 --- a/include/cru/osx/graphics/quartz/Geometry.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once -#include "Resource.hpp" -#include "cru/platform/graphics/Geometry.hpp" - -#include - -#include - -namespace cru::platform::graphics::osx::quartz { -class QuartzGeometry : public OsxQuartzResource, public virtual IGeometry { - public: - QuartzGeometry(IGraphicsFactory *graphics_factory, CGPathRef cg_path); - - CRU_DELETE_COPY(QuartzGeometry) - CRU_DELETE_MOVE(QuartzGeometry) - - ~QuartzGeometry() override; - - CGPathRef GetCGPath() const { return cg_path_; } - - bool FillContains(const Point &point) override; - - private: - CGPathRef cg_path_; -}; - -class QuartzGeometryBuilder : public OsxQuartzResource, - public virtual IGeometryBuilder { - public: - explicit QuartzGeometryBuilder(IGraphicsFactory *graphics_factory); - - CRU_DELETE_COPY(QuartzGeometryBuilder) - CRU_DELETE_MOVE(QuartzGeometryBuilder) - - ~QuartzGeometryBuilder() override; - - void BeginFigure(const Point &point) override; - void CloseFigure(bool close) override; - void LineTo(const Point &point) override; - void QuadraticBezierTo(const Point &control_point, - const Point &end_point) override; - - std::unique_ptr Build() override; - - private: - CGMutablePathRef cg_mutable_path_; -}; -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Image.h b/include/cru/osx/graphics/quartz/Image.h new file mode 100644 index 00000000..458f5db0 --- /dev/null +++ b/include/cru/osx/graphics/quartz/Image.h @@ -0,0 +1,32 @@ +#pragma once +#include "Resource.h" +#include "cru/platform/graphics/Image.h" +#include "cru/platform/graphics/ImageFactory.h" + +#include + +namespace cru::platform::graphics::osx::quartz { +class QuartzImage : public OsxQuartzResource, public virtual IImage { + public: + QuartzImage(IGraphicsFactory* graphics_factory, IImageFactory* image_factory, + CGImageRef image, bool auto_release); + + CRU_DELETE_COPY(QuartzImage) + CRU_DELETE_MOVE(QuartzImage) + + ~QuartzImage() override; + + public: + float GetWidth() override; + float GetHeight() override; + + std::unique_ptr CreateWithRect(const Rect& rect) override; + + CGImageRef GetCGImage() const { return image_; } + + private: + IImageFactory* image_factory_; + CGImageRef image_; + bool auto_release_ = false; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Image.hpp b/include/cru/osx/graphics/quartz/Image.hpp deleted file mode 100644 index 62b7fa8b..00000000 --- a/include/cru/osx/graphics/quartz/Image.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include "Resource.hpp" -#include "cru/platform/graphics/Image.hpp" -#include "cru/platform/graphics/ImageFactory.hpp" - -#include - -namespace cru::platform::graphics::osx::quartz { -class QuartzImage : public OsxQuartzResource, public virtual IImage { - public: - QuartzImage(IGraphicsFactory* graphics_factory, IImageFactory* image_factory, - CGImageRef image, bool auto_release); - - CRU_DELETE_COPY(QuartzImage) - CRU_DELETE_MOVE(QuartzImage) - - ~QuartzImage() override; - - public: - float GetWidth() override; - float GetHeight() override; - - std::unique_ptr CreateWithRect(const Rect& rect) override; - - CGImageRef GetCGImage() const { return image_; } - - private: - IImageFactory* image_factory_; - CGImageRef image_; - bool auto_release_ = false; -}; -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/ImageFactory.h b/include/cru/osx/graphics/quartz/ImageFactory.h new file mode 100644 index 00000000..e9854738 --- /dev/null +++ b/include/cru/osx/graphics/quartz/ImageFactory.h @@ -0,0 +1,19 @@ +#pragma once +#include "Resource.h" +#include "cru/platform/graphics/ImageFactory.h" + +namespace cru::platform::graphics::osx::quartz { +class QuartzImageFactory : public OsxQuartzResource, + public virtual IImageFactory { + public: + explicit QuartzImageFactory(IGraphicsFactory* graphics_factory); + + CRU_DELETE_COPY(QuartzImageFactory) + CRU_DELETE_MOVE(QuartzImageFactory) + + ~QuartzImageFactory() override; + + public: + std::unique_ptr DecodeFromStream(io::Stream* stream) override; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/ImageFactory.hpp b/include/cru/osx/graphics/quartz/ImageFactory.hpp deleted file mode 100644 index 027f3f2a..00000000 --- a/include/cru/osx/graphics/quartz/ImageFactory.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "Resource.hpp" -#include "cru/platform/graphics/ImageFactory.hpp" - -namespace cru::platform::graphics::osx::quartz { -class QuartzImageFactory : public OsxQuartzResource, - public virtual IImageFactory { - public: - explicit QuartzImageFactory(IGraphicsFactory* graphics_factory); - - CRU_DELETE_COPY(QuartzImageFactory) - CRU_DELETE_MOVE(QuartzImageFactory) - - ~QuartzImageFactory() override; - - public: - std::unique_ptr DecodeFromStream(io::Stream* stream) override; -}; -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Painter.h b/include/cru/osx/graphics/quartz/Painter.h new file mode 100644 index 00000000..19428583 --- /dev/null +++ b/include/cru/osx/graphics/quartz/Painter.h @@ -0,0 +1,83 @@ +#pragma once +#include "Resource.h" +#include "cru/common/Base.h" +#include "cru/platform/graphics/Base.h" +#include "cru/platform/graphics/Painter.h" + +#include + +#include + +namespace cru::platform::graphics::osx::quartz { +class QuartzCGContextPainter : public OsxQuartzResource, + public virtual IPainter { + CRU_DEFINE_CLASS_LOG_TAG( + u"cru::platform::graphics::osx::quartz::QuartzCGContextPainter") + + public: + explicit QuartzCGContextPainter( + IGraphicsFactory* graphics_factory, CGContextRef cg_context, + bool auto_release, const Size& size, + std::function on_end_draw); + + CRU_DELETE_COPY(QuartzCGContextPainter) + CRU_DELETE_MOVE(QuartzCGContextPainter) + + ~QuartzCGContextPainter() override; + + public: + Matrix GetTransform() override; + void SetTransform(const Matrix& matrix) override; + + void ConcatTransform(const Matrix& matrix) override; + + void Clear(const Color& color) override; + + void DrawLine(const Point& start, const Point& end, IBrush* brush, + float width) override; + void StrokeRectangle(const Rect& rectangle, IBrush* brush, + float width) override; + void FillRectangle(const Rect& rectangle, IBrush* brush) override; + void StrokeEllipse(const Rect& outline_rect, IBrush* brush, + float width) override; + void FillEllipse(const Rect& outline_rect, IBrush* brush) override; + + void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) override; + void FillGeometry(IGeometry* geometry, IBrush* brush) override; + + void DrawText(const Point& offset, ITextLayout* text_layout, + IBrush* brush) override; + + void DrawImage(const Point& offset, IImage* image) override; + + void PushLayer(const Rect& bounds) override; + + void PopLayer() override; + + void EndDraw() override; + + void PushState() override; + + void PopState() override; + + private: + void SetLineWidth(float width); + + void DoEndDraw(); + + void Validate(); + + private: + CGContextRef cg_context_; + + bool auto_release_; + + Size size_; + + Matrix transform_; + + std::function on_end_draw_; + + std::vector clip_stack_; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Painter.hpp b/include/cru/osx/graphics/quartz/Painter.hpp deleted file mode 100644 index e5b8e767..00000000 --- a/include/cru/osx/graphics/quartz/Painter.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once -#include "Resource.hpp" -#include "cru/common/Base.hpp" -#include "cru/platform/graphics/Base.hpp" -#include "cru/platform/graphics/Painter.hpp" - -#include - -#include - -namespace cru::platform::graphics::osx::quartz { -class QuartzCGContextPainter : public OsxQuartzResource, - public virtual IPainter { - CRU_DEFINE_CLASS_LOG_TAG( - u"cru::platform::graphics::osx::quartz::QuartzCGContextPainter") - - public: - explicit QuartzCGContextPainter( - IGraphicsFactory* graphics_factory, CGContextRef cg_context, - bool auto_release, const Size& size, - std::function on_end_draw); - - CRU_DELETE_COPY(QuartzCGContextPainter) - CRU_DELETE_MOVE(QuartzCGContextPainter) - - ~QuartzCGContextPainter() override; - - public: - Matrix GetTransform() override; - void SetTransform(const Matrix& matrix) override; - - void ConcatTransform(const Matrix& matrix) override; - - void Clear(const Color& color) override; - - void DrawLine(const Point& start, const Point& end, IBrush* brush, - float width) override; - void StrokeRectangle(const Rect& rectangle, IBrush* brush, - float width) override; - void FillRectangle(const Rect& rectangle, IBrush* brush) override; - void StrokeEllipse(const Rect& outline_rect, IBrush* brush, - float width) override; - void FillEllipse(const Rect& outline_rect, IBrush* brush) override; - - void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) override; - void FillGeometry(IGeometry* geometry, IBrush* brush) override; - - void DrawText(const Point& offset, ITextLayout* text_layout, - IBrush* brush) override; - - void DrawImage(const Point& offset, IImage* image) override; - - void PushLayer(const Rect& bounds) override; - - void PopLayer() override; - - void EndDraw() override; - - void PushState() override; - - void PopState() override; - - private: - void SetLineWidth(float width); - - void DoEndDraw(); - - void Validate(); - - private: - CGContextRef cg_context_; - - bool auto_release_; - - Size size_; - - Matrix transform_; - - std::function on_end_draw_; - - std::vector clip_stack_; -}; -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Resource.h b/include/cru/osx/graphics/quartz/Resource.h new file mode 100644 index 00000000..916a376f --- /dev/null +++ b/include/cru/osx/graphics/quartz/Resource.h @@ -0,0 +1,25 @@ +#pragma once +#include "cru/osx/Resource.h" +#include "cru/platform/graphics/Base.h" +#include "cru/platform/graphics/Resource.h" + +namespace cru::platform::graphics::osx::quartz { +class OsxQuartzResource : public platform::osx::OsxResource, + public virtual IGraphicsResource { + public: + explicit OsxQuartzResource(IGraphicsFactory* 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"; } + + IGraphicsFactory* GetGraphicsFactory() override { return graphics_factory_; } + + private: + IGraphicsFactory* graphics_factory_; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Resource.hpp b/include/cru/osx/graphics/quartz/Resource.hpp deleted file mode 100644 index 8b8f8bbc..00000000 --- a/include/cru/osx/graphics/quartz/Resource.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#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, - public virtual IGraphicsResource { - public: - explicit OsxQuartzResource(IGraphicsFactory* 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"; } - - IGraphicsFactory* GetGraphicsFactory() override { return graphics_factory_; } - - private: - IGraphicsFactory* graphics_factory_; -}; -} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/TextLayout.h b/include/cru/osx/graphics/quartz/TextLayout.h new file mode 100644 index 00000000..c0abc7f9 --- /dev/null +++ b/include/cru/osx/graphics/quartz/TextLayout.h @@ -0,0 +1,95 @@ +#pragma once +#include "Resource.h" + +#include "Font.h" +#include "cru/common/Base.h" +#include "cru/platform/graphics/TextLayout.h" + +#include + +namespace cru::platform::graphics::osx::quartz { +class OsxCTTextLayout : public OsxQuartzResource, public virtual ITextLayout { + public: + OsxCTTextLayout(IGraphicsFactory* graphics_factory, + std::shared_ptr font, const String& str); + + CRU_DELETE_COPY(OsxCTTextLayout) + CRU_DELETE_MOVE(OsxCTTextLayout) + + ~OsxCTTextLayout() override; + + public: + String GetText() override { return text_; } + void SetText(String new_text) override; + + std::shared_ptr GetFont() override { return font_; } + void SetFont(std::shared_ptr font) override; + + void SetMaxWidth(float max_width) override; + void SetMaxHeight(float max_height) override; + + bool IsEditMode() override; + void SetEditMode(bool enable) override; + + Index GetLineIndexFromCharIndex(Index char_index) override; + Index GetLineCount() override; + float GetLineHeight(Index line_index) override; + + Rect GetTextBounds(bool includingTrailingSpace = false) override; + std::vector TextRangeRect(const TextRange& text_range) override; + Rect TextSinglePoint(Index position, bool trailing) override; + TextHitTestResult HitTest(const Point& point) override; + + CTFrameRef GetCTFrameRef() const { return ct_frame_; } + + CTFrameRef CreateFrameWithColor(const Color& color); + + Matrix GetTransform() { return transform_; } + + String GetDebugString() override; + + private: + void DoSetText(String text); + + void ReleaseResource(); + void RecreateFrame(); + + CGRect DoGetTextBounds(bool includingTrailingSpace = false); + CGRect DoGetTextBoundsIncludingEmptyLines( + bool includingTrailingSpace = false); + std::vector DoTextRangeRect(const TextRange& text_range); + CGRect DoTextSinglePoint(Index position, bool trailing); + + private: + float max_width_; + float max_height_; + + bool edit_mode_; + + std::shared_ptr font_; + + String text_; + String actual_text_; + CFMutableAttributedStringRef cf_attributed_text_; + + CTFramesetterRef ct_framesetter_ = nullptr; + float suggest_height_; + CTFrameRef ct_frame_ = nullptr; + int line_count_; + std::vector line_origins_; + std::vector lines_; + std::vector line_ascents_; + std::vector line_descents_; + std::vector line_heights_; + // The empty line count in the front of the lines. + int head_empty_line_count_; + // The trailing empty line count in the back of the lines. + int tail_empty_line_count_; + + // Just for cache. + CGRect text_bounds_without_trailing_space_; + CGRect text_bounds_with_trailing_space_; + + Matrix transform_; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/TextLayout.hpp b/include/cru/osx/graphics/quartz/TextLayout.hpp deleted file mode 100644 index 2c6347db..00000000 --- a/include/cru/osx/graphics/quartz/TextLayout.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#pragma once -#include "Resource.hpp" - -#include "Font.hpp" -#include "cru/common/Base.hpp" -#include "cru/platform/graphics/TextLayout.hpp" - -#include - -namespace cru::platform::graphics::osx::quartz { -class OsxCTTextLayout : public OsxQuartzResource, public virtual ITextLayout { - public: - OsxCTTextLayout(IGraphicsFactory* graphics_factory, - std::shared_ptr font, const String& str); - - CRU_DELETE_COPY(OsxCTTextLayout) - CRU_DELETE_MOVE(OsxCTTextLayout) - - ~OsxCTTextLayout() override; - - public: - String GetText() override { return text_; } - void SetText(String new_text) override; - - std::shared_ptr GetFont() override { return font_; } - void SetFont(std::shared_ptr font) override; - - void SetMaxWidth(float max_width) override; - void SetMaxHeight(float max_height) override; - - bool IsEditMode() override; - void SetEditMode(bool enable) override; - - Index GetLineIndexFromCharIndex(Index char_index) override; - Index GetLineCount() override; - float GetLineHeight(Index line_index) override; - - Rect GetTextBounds(bool includingTrailingSpace = false) override; - std::vector TextRangeRect(const TextRange& text_range) override; - Rect TextSinglePoint(Index position, bool trailing) override; - TextHitTestResult HitTest(const Point& point) override; - - CTFrameRef GetCTFrameRef() const { return ct_frame_; } - - CTFrameRef CreateFrameWithColor(const Color& color); - - Matrix GetTransform() { return transform_; } - - String GetDebugString() override; - - private: - void DoSetText(String text); - - void ReleaseResource(); - void RecreateFrame(); - - CGRect DoGetTextBounds(bool includingTrailingSpace = false); - CGRect DoGetTextBoundsIncludingEmptyLines( - bool includingTrailingSpace = false); - std::vector DoTextRangeRect(const TextRange& text_range); - CGRect DoTextSinglePoint(Index position, bool trailing); - - private: - float max_width_; - float max_height_; - - bool edit_mode_; - - std::shared_ptr font_; - - String text_; - String actual_text_; - CFMutableAttributedStringRef cf_attributed_text_; - - CTFramesetterRef ct_framesetter_ = nullptr; - float suggest_height_; - CTFrameRef ct_frame_ = nullptr; - int line_count_; - std::vector line_origins_; - std::vector lines_; - std::vector line_ascents_; - std::vector line_descents_; - std::vector line_heights_; - // The empty line count in the front of the lines. - int head_empty_line_count_; - // The trailing empty line count in the back of the lines. - int tail_empty_line_count_; - - // Just for cache. - CGRect text_bounds_without_trailing_space_; - CGRect text_bounds_with_trailing_space_; - - Matrix transform_; -}; -} // namespace cru::platform::graphics::osx::quartz -- cgit v1.2.3