From 06d1d0442276a05b6caad6e3468f4afb1e8ee5df Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 28 Jun 2020 00:03:11 +0800 Subject: ... --- include/cru/platform/graph/Base.hpp | 24 ++++++++++++++++++++++++ include/cru/platform/graph/Brush.hpp | 11 +++++++++++ include/cru/platform/graph/Factory.hpp | 25 +++++++++++++++++++++++++ include/cru/platform/graph/Font.hpp | 8 ++++++++ include/cru/platform/graph/Geometry.hpp | 20 ++++++++++++++++++++ include/cru/platform/graph/Painter.hpp | 29 +++++++++++++++++++++++++++++ include/cru/platform/graph/Resource.hpp | 10 ++++++++++ include/cru/platform/graph/base.hpp | 24 ------------------------ include/cru/platform/graph/brush.hpp | 11 ----------- include/cru/platform/graph/factory.hpp | 25 ------------------------- include/cru/platform/graph/font.hpp | 8 -------- include/cru/platform/graph/geometry.hpp | 20 -------------------- include/cru/platform/graph/painter.hpp | 29 ----------------------------- include/cru/platform/graph/resource.hpp | 10 ---------- include/cru/platform/graph/util/Painter.hpp | 17 +++++++++++++++++ include/cru/platform/graph/util/painter.hpp | 17 ----------------- 16 files changed, 144 insertions(+), 144 deletions(-) create mode 100644 include/cru/platform/graph/Base.hpp create mode 100644 include/cru/platform/graph/Brush.hpp create mode 100644 include/cru/platform/graph/Factory.hpp create mode 100644 include/cru/platform/graph/Font.hpp create mode 100644 include/cru/platform/graph/Geometry.hpp create mode 100644 include/cru/platform/graph/Painter.hpp create mode 100644 include/cru/platform/graph/Resource.hpp delete mode 100644 include/cru/platform/graph/base.hpp delete mode 100644 include/cru/platform/graph/brush.hpp delete mode 100644 include/cru/platform/graph/factory.hpp delete mode 100644 include/cru/platform/graph/font.hpp delete mode 100644 include/cru/platform/graph/geometry.hpp delete mode 100644 include/cru/platform/graph/painter.hpp delete mode 100644 include/cru/platform/graph/resource.hpp create mode 100644 include/cru/platform/graph/util/Painter.hpp delete mode 100644 include/cru/platform/graph/util/painter.hpp (limited to 'include/cru/platform/graph') diff --git a/include/cru/platform/graph/Base.hpp b/include/cru/platform/graph/Base.hpp new file mode 100644 index 00000000..61cfc5ef --- /dev/null +++ b/include/cru/platform/graph/Base.hpp @@ -0,0 +1,24 @@ +#pragma once +#include "../GraphBase.hpp" +#include "../Matrix.hpp" +#include "../Resource.hpp" + +#include + +namespace cru::platform::graph { +// forward declarations +struct IGraphFactory; +struct IBrush; +struct ISolidColorBrush; +struct IFont; +struct IGeometry; +struct IGeometryBuilder; +struct IPainter; +struct ITextLayout; + +struct TextHitTestResult { + int position; + bool trailing; + bool insideText; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/Brush.hpp b/include/cru/platform/graph/Brush.hpp new file mode 100644 index 00000000..e67384de --- /dev/null +++ b/include/cru/platform/graph/Brush.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "Resource.hpp" + +namespace cru::platform::graph { +struct IBrush : virtual IGraphResource {}; + +struct ISolidColorBrush : virtual IBrush { + virtual Color GetColor() = 0; + virtual void SetColor(const Color& color) = 0; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/Factory.hpp b/include/cru/platform/graph/Factory.hpp new file mode 100644 index 00000000..0a425d15 --- /dev/null +++ b/include/cru/platform/graph/Factory.hpp @@ -0,0 +1,25 @@ +#pragma once +#include "Resource.hpp" + +#include "Brush.hpp" +#include "Font.hpp" +#include "Geometry.hpp" +#include "TextLayout.hpp" + +#include +#include + +namespace cru::platform::graph { +// Entry point of the graph module. +struct IGraphFactory : virtual INativeResource { + virtual std::unique_ptr CreateSolidColorBrush() = 0; + + virtual std::unique_ptr CreateGeometryBuilder() = 0; + + virtual std::unique_ptr CreateFont(const std::string_view& font_family, + float font_size) = 0; + + virtual std::unique_ptr CreateTextLayout( + std::shared_ptr font, std::string text) = 0; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/Font.hpp b/include/cru/platform/graph/Font.hpp new file mode 100644 index 00000000..182cc15b --- /dev/null +++ b/include/cru/platform/graph/Font.hpp @@ -0,0 +1,8 @@ +#pragma once +#include "Resource.hpp" + +namespace cru::platform::graph { +struct IFont : virtual IGraphResource { + virtual float GetFontSize() = 0; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/Geometry.hpp b/include/cru/platform/graph/Geometry.hpp new file mode 100644 index 00000000..354efd97 --- /dev/null +++ b/include/cru/platform/graph/Geometry.hpp @@ -0,0 +1,20 @@ +#pragma once +#include "Resource.hpp" + +namespace cru::platform::graph { +struct IGeometry : virtual IGraphResource { + virtual bool FillContains(const Point& point) = 0; +}; + +// After called Build, calling every method will throw a + +struct IGeometryBuilder : virtual IGraphResource { + virtual void BeginFigure(const Point& point) = 0; + virtual void LineTo(const Point& point) = 0; + virtual void QuadraticBezierTo(const Point& control_point, + const Point& end_point) = 0; + virtual void CloseFigure(bool close) = 0; + + virtual std::unique_ptr Build() = 0; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/Painter.hpp b/include/cru/platform/graph/Painter.hpp new file mode 100644 index 00000000..27ae420b --- /dev/null +++ b/include/cru/platform/graph/Painter.hpp @@ -0,0 +1,29 @@ +#pragma once +#include "Resource.hpp" + +namespace cru::platform::graph { + +struct IPainter : virtual INativeResource { + virtual Matrix GetTransform() = 0; + virtual void SetTransform(const Matrix& matrix) = 0; + + virtual void Clear(const Color& color) = 0; + + virtual void StrokeRectangle(const Rect& rectangle, IBrush* brush, + float width) = 0; + virtual void FillRectangle(const Rect& rectangle, IBrush* brush) = 0; + + virtual void StrokeGeometry(IGeometry* geometry, IBrush* brush, + float width) = 0; + virtual void FillGeometry(IGeometry* geometry, IBrush* brush) = 0; + + virtual void DrawText(const Point& offset, ITextLayout* text_layout, + IBrush* brush) = 0; + + virtual void PushLayer(const Rect& bounds) = 0; + + virtual void PopLayer() = 0; + + virtual void EndDraw() = 0; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/Resource.hpp b/include/cru/platform/graph/Resource.hpp new file mode 100644 index 00000000..8859360c --- /dev/null +++ b/include/cru/platform/graph/Resource.hpp @@ -0,0 +1,10 @@ +#pragma once +#include "Base.hpp" + +namespace cru::platform::graph { +struct IGraphFactory; + +struct IGraphResource : virtual INativeResource { + virtual IGraphFactory* GetGraphFactory() = 0; +}; +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/base.hpp b/include/cru/platform/graph/base.hpp deleted file mode 100644 index 61cfc5ef..00000000 --- a/include/cru/platform/graph/base.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "../GraphBase.hpp" -#include "../Matrix.hpp" -#include "../Resource.hpp" - -#include - -namespace cru::platform::graph { -// forward declarations -struct IGraphFactory; -struct IBrush; -struct ISolidColorBrush; -struct IFont; -struct IGeometry; -struct IGeometryBuilder; -struct IPainter; -struct ITextLayout; - -struct TextHitTestResult { - int position; - bool trailing; - bool insideText; -}; -} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/brush.hpp b/include/cru/platform/graph/brush.hpp deleted file mode 100644 index e67384de..00000000 --- a/include/cru/platform/graph/brush.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include "Resource.hpp" - -namespace cru::platform::graph { -struct IBrush : virtual IGraphResource {}; - -struct ISolidColorBrush : virtual IBrush { - virtual Color GetColor() = 0; - virtual void SetColor(const Color& color) = 0; -}; -} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/factory.hpp b/include/cru/platform/graph/factory.hpp deleted file mode 100644 index 0a425d15..00000000 --- a/include/cru/platform/graph/factory.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "Resource.hpp" - -#include "Brush.hpp" -#include "Font.hpp" -#include "Geometry.hpp" -#include "TextLayout.hpp" - -#include -#include - -namespace cru::platform::graph { -// Entry point of the graph module. -struct IGraphFactory : virtual INativeResource { - virtual std::unique_ptr CreateSolidColorBrush() = 0; - - virtual std::unique_ptr CreateGeometryBuilder() = 0; - - virtual std::unique_ptr CreateFont(const std::string_view& font_family, - float font_size) = 0; - - virtual std::unique_ptr CreateTextLayout( - std::shared_ptr font, std::string text) = 0; -}; -} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/font.hpp b/include/cru/platform/graph/font.hpp deleted file mode 100644 index 182cc15b..00000000 --- a/include/cru/platform/graph/font.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "Resource.hpp" - -namespace cru::platform::graph { -struct IFont : virtual IGraphResource { - virtual float GetFontSize() = 0; -}; -} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/geometry.hpp b/include/cru/platform/graph/geometry.hpp deleted file mode 100644 index 354efd97..00000000 --- a/include/cru/platform/graph/geometry.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "Resource.hpp" - -namespace cru::platform::graph { -struct IGeometry : virtual IGraphResource { - virtual bool FillContains(const Point& point) = 0; -}; - -// After called Build, calling every method will throw a - -struct IGeometryBuilder : virtual IGraphResource { - virtual void BeginFigure(const Point& point) = 0; - virtual void LineTo(const Point& point) = 0; - virtual void QuadraticBezierTo(const Point& control_point, - const Point& end_point) = 0; - virtual void CloseFigure(bool close) = 0; - - virtual std::unique_ptr Build() = 0; -}; -} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/painter.hpp b/include/cru/platform/graph/painter.hpp deleted file mode 100644 index 27ae420b..00000000 --- a/include/cru/platform/graph/painter.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include "Resource.hpp" - -namespace cru::platform::graph { - -struct IPainter : virtual INativeResource { - virtual Matrix GetTransform() = 0; - virtual void SetTransform(const Matrix& matrix) = 0; - - virtual void Clear(const Color& color) = 0; - - virtual void StrokeRectangle(const Rect& rectangle, IBrush* brush, - float width) = 0; - virtual void FillRectangle(const Rect& rectangle, IBrush* brush) = 0; - - virtual void StrokeGeometry(IGeometry* geometry, IBrush* brush, - float width) = 0; - virtual void FillGeometry(IGeometry* geometry, IBrush* brush) = 0; - - virtual void DrawText(const Point& offset, ITextLayout* text_layout, - IBrush* brush) = 0; - - virtual void PushLayer(const Rect& bounds) = 0; - - virtual void PopLayer() = 0; - - virtual void EndDraw() = 0; -}; -} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/resource.hpp b/include/cru/platform/graph/resource.hpp deleted file mode 100644 index 8859360c..00000000 --- a/include/cru/platform/graph/resource.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include "Base.hpp" - -namespace cru::platform::graph { -struct IGraphFactory; - -struct IGraphResource : virtual INativeResource { - virtual IGraphFactory* GetGraphFactory() = 0; -}; -} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/util/Painter.hpp b/include/cru/platform/graph/util/Painter.hpp new file mode 100644 index 00000000..f9aec027 --- /dev/null +++ b/include/cru/platform/graph/util/Painter.hpp @@ -0,0 +1,17 @@ +#pragma once +#include "../Painter.hpp" + +#include +#include + +namespace cru::platform::graph::util { +template +void WithTransform(IPainter* painter, const Matrix& matrix, const Fn& action) { + static_assert(std::is_invocable_v, + "Action must can be be invoked with painter."); + const auto old = painter->GetTransform(); + painter->SetTransform(old * matrix); + action(painter); + painter->SetTransform(old); +} +} // namespace cru::platform::graph::util diff --git a/include/cru/platform/graph/util/painter.hpp b/include/cru/platform/graph/util/painter.hpp deleted file mode 100644 index f9aec027..00000000 --- a/include/cru/platform/graph/util/painter.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "../Painter.hpp" - -#include -#include - -namespace cru::platform::graph::util { -template -void WithTransform(IPainter* painter, const Matrix& matrix, const Fn& action) { - static_assert(std::is_invocable_v, - "Action must can be be invoked with painter."); - const auto old = painter->GetTransform(); - painter->SetTransform(old * matrix); - action(painter); - painter->SetTransform(old); -} -} // namespace cru::platform::graph::util -- cgit v1.2.3