diff options
-rw-r--r-- | include/cru/win/graphics/direct/Geometry.h | 7 | ||||
-rw-r--r-- | src/win/graphics/direct/Geometry.cpp | 31 |
2 files changed, 35 insertions, 3 deletions
diff --git a/include/cru/win/graphics/direct/Geometry.h b/include/cru/win/graphics/direct/Geometry.h index 802b5ec0..7c231d69 100644 --- a/include/cru/win/graphics/direct/Geometry.h +++ b/include/cru/win/graphics/direct/Geometry.h @@ -49,7 +49,7 @@ class CRU_WIN_GRAPHICS_DIRECT_API D2DGeometry public IComResource<ID2D1Geometry> { public: D2DGeometry(DirectGraphicsFactory* factory, - Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry); + Microsoft::WRL::ComPtr<ID2D1Geometry> geometry); CRU_DELETE_COPY(D2DGeometry) CRU_DELETE_MOVE(D2DGeometry) @@ -61,8 +61,11 @@ class CRU_WIN_GRAPHICS_DIRECT_API D2DGeometry public: bool FillContains(const Point& point) override; + Rect GetBounds() override; + std::unique_ptr<IGeometry> Transform(const Matrix& matrix) override; + std::unique_ptr<IGeometry> CreateStrokeGeometry(float width) override; private: - Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry_; + Microsoft::WRL::ComPtr<ID2D1Geometry> geometry_; }; } // namespace cru::platform::graphics::win::direct diff --git a/src/win/graphics/direct/Geometry.cpp b/src/win/graphics/direct/Geometry.cpp index b59cdf61..bb7ea06a 100644 --- a/src/win/graphics/direct/Geometry.cpp +++ b/src/win/graphics/direct/Geometry.cpp @@ -2,6 +2,7 @@ #include <d2d1.h> #include <d2d1helper.h> +#include "cru/common/platform/win/Exception.h" #include "cru/win/graphics/direct/ConvertUtil.h" #include "cru/win/graphics/direct/Exception.h" #include "cru/win/graphics/direct/Factory.h" @@ -83,7 +84,7 @@ std::unique_ptr<IGeometry> D2DGeometryBuilder::Build() { } D2DGeometry::D2DGeometry(DirectGraphicsFactory* factory, - Microsoft::WRL::ComPtr<ID2D1PathGeometry> geometry) + Microsoft::WRL::ComPtr<ID2D1Geometry> geometry) : DirectGraphicsResource(factory), geometry_(std::move(geometry)) {} bool D2DGeometry::FillContains(const Point& point) { @@ -92,4 +93,32 @@ bool D2DGeometry::FillContains(const Point& point) { Convert(point), D2D1::Matrix3x2F::Identity(), &result)); return result != 0; } + +Rect D2DGeometry::GetBounds() { + D2D1_RECT_F bounds; + ThrowIfFailed(geometry_->GetBounds(D2D1::Matrix3x2F::Identity(), &bounds)); + return Convert(bounds); +} + +std::unique_ptr<IGeometry> D2DGeometry::Transform(const Matrix& matrix) { + Microsoft::WRL::ComPtr<ID2D1TransformedGeometry> d2d1_geometry; + ThrowIfFailed(GetDirectFactory()->GetD2D1Factory()->CreateTransformedGeometry( + geometry_.Get(), Convert(matrix), &d2d1_geometry)); + return std::make_unique<D2DGeometry>(GetDirectFactory(), + std::move(d2d1_geometry)); +} + +std::unique_ptr<IGeometry> D2DGeometry::CreateStrokeGeometry(float width) { + Microsoft::WRL::ComPtr<ID2D1PathGeometry> d2d1_geometry; + ThrowIfFailed( + GetDirectFactory()->GetD2D1Factory()->CreatePathGeometry(&d2d1_geometry)); + Microsoft::WRL::ComPtr<ID2D1GeometrySink> d2d1_geometry_sink; + ThrowIfFailed(d2d1_geometry->Open(&d2d1_geometry_sink)); + ThrowIfFailed( + geometry_->Widen(width, nullptr, nullptr, d2d1_geometry_sink.Get())); + d2d1_geometry_sink->Close(); + + return std::make_unique<D2DGeometry>(GetDirectFactory(), + std::move(d2d1_geometry)); +} } // namespace cru::platform::graphics::win::direct |