diff options
Diffstat (limited to 'include/cru')
24 files changed, 325 insertions, 181 deletions
diff --git a/include/cru/common/auto_delete.hpp b/include/cru/common/auto_delete.hpp deleted file mode 100644 index ae66f7bf..00000000 --- a/include/cru/common/auto_delete.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "base.hpp" - -namespace cru { -// A instance of class implementing this interface is able to -// delete itseft when program exits. Such as IGraphFactory, -// IUiApplication. -struct IAutoDelete : virtual Interface { - // Get whether it will delete itself when program exits. - virtual bool IsAutoDelete() const = 0; - // Set whether it will delete itself when program exits. - virtual void SetAutoDelete(bool value) = 0; -}; -} // namespace cru diff --git a/include/cru/common/endable.hpp b/include/cru/common/endable.hpp deleted file mode 100644 index 4459b069..00000000 --- a/include/cru/common/endable.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include "base.hpp" - -namespace cru { -// Although c++ has destructor called automatically. But there is -// occasion when an instance of class needs to end with a result -// and release all internal resources. -// eg. IGeometryBuild will end with building a Geometry and release -// some resources. IPainter will end drawing and release some -// resources and map the drawing result onto target. -// note: You can't call End twice. And most methods on the object -// is invalid to call after End is called. Get whether it is ended -// by IsEnded. -template<typename TResult> -struct IEndable : virtual Interface { - // Get whether the object is ended. - virtual bool IsEnded() const = 0; - // End the object with a result. - virtual TResult End() = 0; -}; -} diff --git a/include/cru/platform/graph/brush.hpp b/include/cru/platform/graph/brush.hpp index 7688ec4a..d292ae82 100644 --- a/include/cru/platform/graph/brush.hpp +++ b/include/cru/platform/graph/brush.hpp @@ -1,13 +1,46 @@ #pragma once -#include "cru/common/base.hpp" - -#include "cru/common/ui_base.hpp" +#include "../graphic_base.hpp" +#include "../native_resource.hpp" namespace cru::platform::graph { -struct IBrush : public virtual Interface {}; +class Brush : public NativeResource { + protected: + Brush() = default; + + public: + Brush(const Brush& other) = delete; + Brush& operator=(const Brush& other) = delete; + + Brush(Brush&& other) = delete; + Brush& operator=(Brush&& other) = delete; + + ~Brush() override = default; +}; + +class SolidColorBrush : public Brush { + protected: + SolidColorBrush() = default; + + public: + SolidColorBrush(const SolidColorBrush& other) = delete; + SolidColorBrush& operator=(const SolidColorBrush& other) = delete; + + SolidColorBrush(SolidColorBrush&& other) = delete; + SolidColorBrush& operator=(SolidColorBrush&& other) = delete; + + ~SolidColorBrush() = default; + + public: + Color GetColor() { return color_; } + void SetColor(const Color& color) { + color_ = color; + OnSetColor(color); + } + + protected: + virtual void OnSetColor(const Color& color) = 0; -struct ISolidColorBrush : public virtual IBrush { - virtual ui::Color GetColor() = 0; - virtual void SetColor(const ui::Color& color) = 0; + protected: + Color color_ = colors::black; }; -} // namespace cru::platform +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/font.hpp b/include/cru/platform/graph/font.hpp index f74dc7db..bd470256 100644 --- a/include/cru/platform/graph/font.hpp +++ b/include/cru/platform/graph/font.hpp @@ -1,8 +1,18 @@ #pragma once -#include "cru/common/base.hpp" +#include "../native_resource.hpp" namespace cru::platform::graph { -struct IFontDescriptor : virtual Interface { +class Font : public NativeResource { + protected: + Font() = default; + public: + Font(const Font& other) = delete; + Font& operator=(const Font& other) = delete; + + Font(Font&& other) = delete; + Font& operator=(Font&& other) = delete; + + ~Font() override = default; }; -} +} // namespace cru::platform::graph diff --git a/include/cru/platform/graph/geometry.hpp b/include/cru/platform/graph/geometry.hpp index 71bf8c73..d31b3b27 100644 --- a/include/cru/platform/graph/geometry.hpp +++ b/include/cru/platform/graph/geometry.hpp @@ -1,19 +1,45 @@ #pragma once -#include "cru/common/base.hpp" - -#include "cru/common/endable.hpp" -#include "cru/common/ui_base.hpp" +#include "../graphic_base.hpp" +#include "../native_resource.hpp" namespace cru::platform::graph { -struct IGeometry : virtual Interface { - virtual bool FillContains(const ui::Point& point) = 0; +class Geometry : public NativeResource { + protected: + Geometry() = default; + + public: + Geometry(const Geometry& other) = delete; + Geometry& operator=(const Geometry& other) = delete; + + Geometry(Geometry&& other) = delete; + Geometry& operator=(Geometry&& other) = delete; + + ~Geometry() override = default; + + public: + virtual bool FillContains(const Point& point) = 0; }; -struct IGeometryBuilder : virtual Interface, virtual IEndable<IGeometry*> { - virtual void BeginFigure(const ui::Point& point) = 0; - virtual void LineTo(const ui::Point& point) = 0; - virtual void QuadraticBezierTo(const ui::Point& control_point, - const ui::Point& end_point) = 0; +class GeometryBuilder : public NativeResource { + protected: + GeometryBuilder() = default; + + public: + GeometryBuilder(const GeometryBuilder& other) = delete; + GeometryBuilder& operator=(const GeometryBuilder& other) = delete; + + GeometryBuilder(GeometryBuilder&& other) = delete; + GeometryBuilder& operator=(GeometryBuilder&& other) = delete; + + ~GeometryBuilder() override = default; + + public: + 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 Geometry* Build() = 0; }; } // namespace cru::platform::graph diff --git a/include/cru/platform/graph/graph_factory.hpp b/include/cru/platform/graph/graph_factory.hpp index 60d4ed8a..69afc7b3 100644 --- a/include/cru/platform/graph/graph_factory.hpp +++ b/include/cru/platform/graph/graph_factory.hpp @@ -1,8 +1,6 @@ #pragma once -#include "cru/common/base.hpp" - -#include "cru/common/auto_delete.hpp" -#include "cru/common/ui_base.hpp" +#include "../graphic_base.hpp" +#include "../native_resource.hpp" #include "brush.hpp" #include "font.hpp" @@ -20,20 +18,42 @@ namespace cru::platform::graph { // IGraphFactory::CreateInstance and set auto-delete to true. // The manual creation method of IGraphFactory provides a you a way to use graph // related tools without interact with actual ui like window system. -struct IGraphFactory : virtual Interface, virtual IAutoDelete { +class GraphFactory : public NativeResource { + public: // Create a platform-specific instance and save it as the global instance. // Do not create the instance twice. Implements should assert for that. // After creating, get the instance by GetInstance. - static IGraphFactory* CreateInstance(); + static GraphFactory* CreateInstance(); // Get the global instance. If it is not created, then return nullptr. - static IGraphFactory* GetInstance(); - - virtual ISolidColorBrush* CreateSolidColorBrush(const ui::Color& color) = 0; - virtual IGeometryBuilder* CreateGeometryBuilder() = 0; - virtual IFontDescriptor* CreateFontDescriptor( - const std::wstring_view& font_family, float font_size) = 0; - virtual ITextLayout* CreateTextLayout(std::shared_ptr<IFontDescriptor> font, - std::wstring text) = 0; + static GraphFactory* GetInstance(); + + protected: + GraphFactory() = default; + + public: + GraphFactory(const GraphFactory& other) = delete; + GraphFactory& operator=(const GraphFactory& other) = delete; + + GraphFactory(GraphFactory&& other) = delete; + GraphFactory& operator=(GraphFactory&& other) = delete; + + ~GraphFactory() override = default; + + public: + virtual SolidColorBrush* CreateSolidColorBrush() = 0; + SolidColorBrush* CreateSolidColorBrush(const Color& color) { + const auto brush = CreateSolidColorBrush(); + brush->SetColor(color); + return brush; + } + + virtual GeometryBuilder* CreateGeometryBuilder() = 0; + + virtual Font* CreateFont(const std::wstring_view& font_family, + float font_size) = 0; + + virtual TextLayout* CreateTextLayout(std::shared_ptr<Font> font, + std::wstring text) = 0; }; } // namespace cru::platform::graph diff --git a/include/cru/platform/graph/painter.hpp b/include/cru/platform/graph/painter.hpp index 34c895d4..1096aa7c 100644 --- a/include/cru/platform/graph/painter.hpp +++ b/include/cru/platform/graph/painter.hpp @@ -1,26 +1,41 @@ #pragma once -#include "cru/common/base.hpp" - +#include "../graphic_base.hpp" #include "../matrix.hpp" -#include "cru/common/endable.hpp" -#include "cru/common/ui_base.hpp" +#include "../native_resource.hpp" namespace cru::platform::graph { -struct IBrush; -struct IGeometry; -struct ITextLayout; +class Brush; +class Geometry; +class TextLayout; + +class Painter : public NativeResource { + protected: + Painter() = default; + + public: + Painter(const Painter& other) = delete; + Painter& operator=(const Painter& other) = delete; + + Painter(Painter&& other) = delete; + Painter& operator=(Painter&& other) = delete; + + ~Painter() override = default; -struct IPainter : virtual Interface, virtual IEndable<void> { + public: virtual Matrix GetTransform() = 0; virtual void SetTransform(const Matrix& matrix) = 0; - virtual void Clear(const ui::Color& color) = 0; - virtual void StrokeRectangle(const ui::Rect& rectangle, IBrush* brush, + + virtual void Clear(const Color& color) = 0; + + virtual void StrokeRectangle(const Rect& rectangle, Brush* brush, float width) = 0; - virtual void FillRectangle(const ui::Rect& rectangle, IBrush* brush) = 0; - virtual void StrokeGeometry(IGeometry* geometry, IBrush* brush, + virtual void FillRectangle(const Rect& rectangle, Brush* brush) = 0; + + virtual void StrokeGeometry(Geometry* geometry, Brush* brush, float width) = 0; - virtual void FillGeometry(IGeometry* geometry, IBrush* brush) = 0; - virtual void DrawText(const ui::Point& offset, ITextLayout* text_layout, - IBrush* brush) = 0; + virtual void FillGeometry(Geometry* geometry, Brush* brush) = 0; + + virtual void DrawText(const Point& offset, TextLayout* text_layout, + Brush* brush) = 0; }; } // namespace cru::platform::graph diff --git a/include/cru/platform/graph/text_layout.hpp b/include/cru/platform/graph/text_layout.hpp index 894c1408..56943098 100644 --- a/include/cru/platform/graph/text_layout.hpp +++ b/include/cru/platform/graph/text_layout.hpp @@ -1,24 +1,38 @@ #pragma once -#include "cru/common/base.hpp" - -#include "cru/common/ui_base.hpp" +#include "../graphic_base.hpp" +#include "../native_resource.hpp" #include <memory> #include <string> #include <vector> namespace cru::platform::graph { -struct IFontDescriptor; +class Font; + +class TextLayout : public NativeResource { + protected: + TextLayout() = default; + + public: + TextLayout(const TextLayout& other) = delete; + TextLayout& operator=(const TextLayout& other) = delete; + + TextLayout(TextLayout&& other) = delete; + TextLayout& operator=(TextLayout&& other) = delete; -struct ITextLayout : virtual Interface { + ~TextLayout() override = default; + + public: virtual std::wstring GetText() = 0; virtual void SetText(std::wstring new_text) = 0; - virtual std::shared_ptr<IFontDescriptor> GetFont() = 0; - virtual void SetFont(std::shared_ptr<IFontDescriptor> font) = 0; + + virtual std::shared_ptr<Font> GetFont() = 0; + virtual void SetFont(std::shared_ptr<Font> font) = 0; + virtual void SetMaxWidth(float max_width) = 0; virtual void SetMaxHeight(float max_height) = 0; - virtual ui::Rect GetTextBounds() = 0; - virtual std::vector<ui::Rect> TextRangeRect( - const ui::TextRange& text_range) = 0; + + virtual Rect GetTextBounds() = 0; + virtual std::vector<Rect> TextRangeRect(const TextRange& text_range) = 0; }; -} // namespace cru::platform +} // namespace cru::platform::graph diff --git a/include/cru/common/ui_base.hpp b/include/cru/platform/graphic_base.hpp index 017e3bd1..2aa4e2cb 100644 --- a/include/cru/common/ui_base.hpp +++ b/include/cru/platform/graphic_base.hpp @@ -1,11 +1,11 @@ #pragma once -#include "pre_config.hpp" +#include "cru/common/pre_config.hpp" #include <cstdint> #include <optional> #include <utility> -namespace cru::ui { +namespace cru::platform { struct Point final { constexpr Point() = default; constexpr Point(const float x, const float y) : x(x), y(y) {} diff --git a/include/cru/platform/matrix.hpp b/include/cru/platform/matrix.hpp index 37e4725e..b0165a88 100644 --- a/include/cru/platform/matrix.hpp +++ b/include/cru/platform/matrix.hpp @@ -1,7 +1,5 @@ #pragma once -#include "cru/common/pre_config.hpp" - -#include "cru/common/ui_base.hpp" +#include "graphic_base.hpp" #include <cmath> diff --git a/include/cru/platform/native_resource.hpp b/include/cru/platform/native_resource.hpp new file mode 100644 index 00000000..787c46a5 --- /dev/null +++ b/include/cru/platform/native_resource.hpp @@ -0,0 +1,22 @@ +#pragma once +#include "cru/common/base.hpp" + +#include <string_view> + +namespace cru::platform { +class NativeResource : public Object { + protected: + NativeResource() = default; + + public: + NativeResource(NativeResource&& other) = delete; + NativeResource& operator=(NativeResource&& other) = delete; + + NativeResource(NativeResource&& other) = delete; + NativeResource& operator=(NativeResource&& other) = delete; + ~NativeResource() override = default; + + public: + virtual std::wstring_view GetPlatformId() const = 0; +}; +} // namespace cru::platform diff --git a/include/cru/win/exception.hpp b/include/cru/win/exception.hpp index 39c52c45..9e038960 100644 --- a/include/cru/win/exception.hpp +++ b/include/cru/win/exception.hpp @@ -6,7 +6,7 @@ #include <stdexcept> #include <string_view> -namespace cru::win { +namespace cru::platform::win { class HResultError : public platform::PlatformException { public: explicit HResultError(HRESULT h_result); diff --git a/include/cru/win/graph/direct/brush.hpp b/include/cru/win/graph/direct/brush.hpp new file mode 100644 index 00000000..9775b5c1 --- /dev/null +++ b/include/cru/win/graph/direct/brush.hpp @@ -0,0 +1,26 @@ +#pragma once +#include "com_resource.hpp" +#include "direct_factory.hpp" + +#include "cru/platform/graph/brush.hpp" + +namespace cru::platform::graph::win::direct { +class D2DSolidColorBrush : public SolidColorBrush, + public IComResource<ID2D1SolidColorBrush> { + public: + explicit D2DSolidColorBrush(IDirectFactory* factory); + D2DSolidColorBrush(const D2DSolidColorBrush& other) = delete; + D2DSolidColorBrush(D2DSolidColorBrush&& other) = delete; + D2DSolidColorBrush& operator=(const D2DSolidColorBrush& other) = delete; + D2DSolidColorBrush& operator=(D2DSolidColorBrush&& other) = delete; + ~D2DSolidColorBrush() override = default; + + ID2D1SolidColorBrush* GetComInterface() override { return brush_.Get(); } + + protected: + void OnSetColor(const Color& color) override; + + private: + Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> brush_; +}; +} // namespace cru::platform::graph::win::direct diff --git a/include/cru/win/graph/direct/com_resource.hpp b/include/cru/win/graph/direct/com_resource.hpp new file mode 100644 index 00000000..aa2c366b --- /dev/null +++ b/include/cru/win/graph/direct/com_resource.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "../../win_pre_config.hpp" + +namespace cru::platform::graph::win::direct { +template<typename TInterface> +struct IComResource { + virtual ~IComResource() = default; + + virtual TInterface* GetComInterface() = 0; +}; +} // namespace cru::platform::graph::win_direct diff --git a/include/cru/win/graph/util/convert_util.hpp b/include/cru/win/graph/direct/convert_util.hpp index 4b5368b1..2c45c63a 100644 --- a/include/cru/win/graph/util/convert_util.hpp +++ b/include/cru/win/graph/direct/convert_util.hpp @@ -1,10 +1,10 @@ #pragma once #include "../../win_pre_config.hpp" -#include "cru/common/ui_base.hpp" +#include "cru/platform/graphic_base.hpp" #include "cru/platform/matrix.hpp" -namespace cru::win::graph::util { +namespace cru::platform::graph::win::direct { inline D2D1_MATRIX_3X2_F Convert(const platform::Matrix& matrix) { D2D1_MATRIX_3X2_F m; m._11 = matrix.m11; @@ -16,26 +16,26 @@ inline D2D1_MATRIX_3X2_F Convert(const platform::Matrix& matrix) { return m; } -inline D2D1_COLOR_F Convert(const ui::Color& color) { +inline D2D1_COLOR_F Convert(const Color& color) { return D2D1::ColorF(color.red / 255.0f, color.green / 255.0f, color.blue / 255.0f, color.alpha / 255.0f); } -inline D2D1_POINT_2F Convert(const ui::Point& point) { +inline D2D1_POINT_2F Convert(const Point& point) { return D2D1::Point2F(point.x, point.y); } -inline D2D1_RECT_F Convert(const ui::Rect& rect) { +inline D2D1_RECT_F Convert(const Rect& rect) { return D2D1::RectF(rect.left, rect.top, rect.left + rect.width, rect.top + rect.height); } -inline D2D1_ROUNDED_RECT Convert(const ui::RoundedRect& rounded_rect) { +inline D2D1_ROUNDED_RECT Convert(const RoundedRect& rounded_rect) { return D2D1::RoundedRect(Convert(rounded_rect.rect), rounded_rect.radius_x, rounded_rect.radius_y); } -inline D2D1_ELLIPSE Convert(const ui::Ellipse& ellipse) { +inline D2D1_ELLIPSE Convert(const Ellipse& ellipse) { return D2D1::Ellipse(Convert(ellipse.center), ellipse.radius_x, ellipse.radius_y); } @@ -45,28 +45,28 @@ inline platform::Matrix Convert(const D2D1_MATRIX_3X2_F& matrix) { matrix._22, matrix._31, matrix._32}; } -inline ui::Color Convert(const D2D1_COLOR_F& color) { +inline Color Convert(const D2D1_COLOR_F& color) { auto floor = [](float n) { return static_cast<std::uint8_t>(n + 0.5f); }; - return ui::Color{floor(color.r * 255.0f), floor(color.g * 255.0f), + return Color{floor(color.r * 255.0f), floor(color.g * 255.0f), floor(color.b * 255.0f), floor(color.a * 255.0f)}; } -inline ui::Point Convert(const D2D1_POINT_2F& point) { - return ui::Point(point.x, point.y); +inline Point Convert(const D2D1_POINT_2F& point) { + return Point(point.x, point.y); } -inline ui::Rect Convert(const D2D1_RECT_F& rect) { - return ui::Rect(rect.left, rect.top, rect.right - rect.left, +inline Rect Convert(const D2D1_RECT_F& rect) { + return Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); } -inline ui::RoundedRect Convert(const D2D1_ROUNDED_RECT& rounded_rect) { - return ui::RoundedRect(Convert(rounded_rect.rect), rounded_rect.radiusX, +inline RoundedRect Convert(const D2D1_ROUNDED_RECT& rounded_rect) { + return RoundedRect(Convert(rounded_rect.rect), rounded_rect.radiusX, rounded_rect.radiusY); } -inline ui::Ellipse Convert(const D2D1_ELLIPSE& ellipse) { - return ui::Ellipse(Convert(ellipse.point), ellipse.radiusX, ellipse.radiusY); +inline Ellipse Convert(const D2D1_ELLIPSE& ellipse) { + return Ellipse(Convert(ellipse.point), ellipse.radiusX, ellipse.radiusY); } inline bool operator==(const D2D1_POINT_2F& left, const D2D1_POINT_2F& right) { @@ -105,4 +105,4 @@ inline bool operator==(const D2D1_ELLIPSE& left, const D2D1_ELLIPSE& right) { inline bool operator!=(const D2D1_ELLIPSE& left, const D2D1_ELLIPSE& right) { return !(left == right); } -} // namespace cru::win::graph::util +} // namespace cru::platform::graph::win::direct diff --git a/include/cru/win/graph/win_native_factory.hpp b/include/cru/win/graph/direct/direct_factory.hpp index f5ad033c..b150d5aa 100644 --- a/include/cru/win/graph/win_native_factory.hpp +++ b/include/cru/win/graph/direct/direct_factory.hpp @@ -1,11 +1,11 @@ #pragma once -#include "../win_pre_config.hpp" +#include "../../win_pre_config.hpp" -#include "cru/common/base.hpp" - -namespace cru::win::graph { +namespace cru::platform::graph::win::direct { // Interface provides access to root d2d resources. -struct IWinNativeFactory : virtual Interface { +struct IDirectFactory { + virtual ~IDirectFactory() = default; + virtual ID2D1Factory1* GetD2D1Factory() const = 0; virtual ID2D1DeviceContext* GetD2D1DeviceContext() const = 0; virtual ID3D11Device* GetD3D11Device() const = 0; @@ -13,4 +13,4 @@ struct IWinNativeFactory : virtual Interface { virtual IDWriteFactory* GetDWriteFactory() const = 0; virtual IDWriteFontCollection* GetSystemFontCollection() const = 0; }; -} +} // namespace cru::platform::graph::win::direct diff --git a/include/cru/win/graph/direct/exception.hpp b/include/cru/win/graph/direct/exception.hpp new file mode 100644 index 00000000..bfa14aaf --- /dev/null +++ b/include/cru/win/graph/direct/exception.hpp @@ -0,0 +1,36 @@ +#pragma once +#include "../../win_pre_config.hpp" + +#include "cru/platform/exception.hpp" + +#include <stdexcept> +#include <string_view> + +namespace cru::platform::graph::win::direct { + +class HResultError : public PlatformException { + public: + explicit HResultError(HRESULT h_result); + explicit HResultError(HRESULT h_result, + const std::string_view& additional_message); + HResultError(const HResultError& other) = default; + HResultError(HResultError&& other) = default; + HResultError& operator=(const HResultError& other) = default; + HResultError& operator=(HResultError&& other) = default; + ~HResultError() override = default; + + HRESULT GetHResult() const { return h_result_; } + + private: + HRESULT h_result_; +}; + +inline void ThrowIfFailed(const HRESULT h_result) { + if (FAILED(h_result)) throw HResultError(h_result); +} + +inline void ThrowIfFailed(const HRESULT h_result, + const std::string_view& message) { + if (FAILED(h_result)) throw HResultError(h_result, message); +} +} // namespace cru::platform::graph::win::direct
\ No newline at end of file diff --git a/include/cru/win/graph/win_font.hpp b/include/cru/win/graph/direct/font.hpp index 44fa7edd..44fa7edd 100644 --- a/include/cru/win/graph/win_font.hpp +++ b/include/cru/win/graph/direct/font.hpp diff --git a/include/cru/win/graph/win_geometry.hpp b/include/cru/win/graph/direct/geometry.hpp index e312f13c..e312f13c 100644 --- a/include/cru/win/graph/win_geometry.hpp +++ b/include/cru/win/graph/direct/geometry.hpp diff --git a/include/cru/win/graph/win_graph_factory.hpp b/include/cru/win/graph/direct/graph_factory.hpp index 2df7ed9a..b3c901be 100644 --- a/include/cru/win/graph/win_graph_factory.hpp +++ b/include/cru/win/graph/direct/graph_factory.hpp @@ -1,27 +1,26 @@ #pragma once -#include "../win_pre_config.hpp" +#include "direct_factory.hpp" + +#include "brush.hpp" #include "cru/platform/graph/graph_factory.hpp" -#include "win_native_factory.hpp" -namespace cru::win::graph { -class WinGraphFactory : public Object, - public virtual platform::graph::IGraphFactory, - public virtual IWinNativeFactory { - friend IGraphFactory* IGraphFactory::CreateInstance(); +namespace cru::platform::graph::win::direct { +class DirectGraphFactory : public GraphFactory, IDirectFactory { + friend GraphFactory* GraphFactory::CreateInstance(); public: - static WinGraphFactory* GetInstance(); + static DirectGraphFactory* GetInstance(); private: - explicit WinGraphFactory(); + DirectGraphFactory(); public: - WinGraphFactory(const WinGraphFactory& other) = delete; - WinGraphFactory(WinGraphFactory&& other) = delete; - WinGraphFactory& operator=(const WinGraphFactory& other) = delete; - WinGraphFactory& operator=(WinGraphFactory&& other) = delete; - ~WinGraphFactory() override; + DirectGraphFactory(const DirectGraphFactory& other) = delete; + DirectGraphFactory(DirectGraphFactory&& other) = delete; + DirectGraphFactory& operator=(const DirectGraphFactory& other) = delete; + DirectGraphFactory& operator=(DirectGraphFactory&& other) = delete; + ~DirectGraphFactory() override; ID2D1Factory1* GetD2D1Factory() const override { return d2d1_factory_.Get(); } ID2D1DeviceContext* GetD2D1DeviceContext() const override { @@ -36,14 +35,14 @@ class WinGraphFactory : public Object, return dwrite_system_font_collection_.Get(); } - platform::graph::ISolidColorBrush* CreateSolidColorBrush( - const ui::Color& color) override; - platform::graph::IGeometryBuilder* CreateGeometryBuilder() override; - platform::graph::IFontDescriptor* CreateFontDescriptor( - const std::wstring_view& font_family, float font_size); - platform::graph::ITextLayout* CreateTextLayout( - std::shared_ptr<platform::graph::IFontDescriptor> font, - std::wstring text); + D2DSolidColorBrush* CreateSolidColorBrush() override; + + D2DGeometryBuilder* CreateGeometryBuilder() override; + D2DFont* CreateFont( + const std::wstring_view& font_family, float font_size) override; + DWriteTextLayout* CreateTextLayout( + std::shared_ptr<Font> font, + std::wstring text) override; bool IsAutoDelete() const override { return auto_delete_; } void SetAutoDelete(bool value) override { auto_delete_ = value; } diff --git a/include/cru/win/graph/win_painter.hpp b/include/cru/win/graph/direct/painter.hpp index f218488c..f218488c 100644 --- a/include/cru/win/graph/win_painter.hpp +++ b/include/cru/win/graph/direct/painter.hpp diff --git a/include/cru/win/graph/win_text_layout.hpp b/include/cru/win/graph/direct/text_layout.hpp index 7339eff9..7339eff9 100644 --- a/include/cru/win/graph/win_text_layout.hpp +++ b/include/cru/win/graph/direct/text_layout.hpp diff --git a/include/cru/win/graph/win_brush.hpp b/include/cru/win/graph/win_brush.hpp deleted file mode 100644 index c81019c0..00000000 --- a/include/cru/win/graph/win_brush.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include "../win_pre_config.hpp" - -#include "cru/platform/graph/brush.hpp" - -namespace cru::win::graph { -struct IWinNativeFactory; - -struct IWinBrush : virtual platform::graph::IBrush { - virtual ID2D1Brush* GetD2DBrush() = 0; -}; - -class WinSolidColorBrush : public Object, - public virtual platform::graph::ISolidColorBrush, - public virtual IWinBrush { - public: - WinSolidColorBrush(IWinNativeFactory* factory, const ui::Color& color); - WinSolidColorBrush(const WinSolidColorBrush& other) = delete; - WinSolidColorBrush(WinSolidColorBrush&& other) = delete; - WinSolidColorBrush& operator=(const WinSolidColorBrush& other) = delete; - WinSolidColorBrush& operator=(WinSolidColorBrush&& other) = delete; - ~WinSolidColorBrush() override = default; - - ui::Color GetColor() override; - void SetColor(const ui::Color& color) override; - - ID2D1Brush* GetD2DBrush() override { return brush_.Get(); } - - private: - Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> brush_; -}; -} // namespace cru::win::graph diff --git a/include/cru/win/win_pre_config.hpp b/include/cru/win/win_pre_config.hpp index 6962eb7b..7466a62c 100644 --- a/include/cru/win/win_pre_config.hpp +++ b/include/cru/win/win_pre_config.hpp @@ -5,6 +5,7 @@ #include <Windows.h> #undef CreateWindow #undef DrawText +#undef CreateFont #include <d2d1_2.h> #include <d3d11.h> |