diff --git a/modules/juce_graphics/native/juce_Direct2DGraphicsContextImpl_windows.cpp b/modules/juce_graphics/native/juce_Direct2DGraphicsContextImpl_windows.cpp index 680ec38c53..ccbebf44e0 100644 --- a/modules/juce_graphics/native/juce_Direct2DGraphicsContextImpl_windows.cpp +++ b/modules/juce_graphics/native/juce_Direct2DGraphicsContextImpl_windows.cpp @@ -761,22 +761,6 @@ bool Direct2DGraphicsContext::Pimpl::fillSpriteBatch (const RectangleList owner.metrics.get()); } -Line Direct2DGraphicsContext::Pimpl::offsetShape (Line a, Point b) -{ - return Line { a.getStart() + b, a.getEnd() + b }; -} - -Rectangle Direct2DGraphicsContext::Pimpl::offsetShape (Rectangle a, Point b) -{ - return a + b; -} - -RectangleList Direct2DGraphicsContext::Pimpl::offsetShape (RectangleList a, Point b) -{ - a.offsetAll (b); - return a; -} - void Direct2DGraphicsContext::Pimpl::resetTransform (ID2D1DeviceContext1* context) { context->SetTransform (D2D1::IdentityMatrix()); diff --git a/modules/juce_graphics/native/juce_Direct2DGraphicsContextImpl_windows.h b/modules/juce_graphics/native/juce_Direct2DGraphicsContextImpl_windows.h index d7c5d1f89c..5bb8c9b830 100644 --- a/modules/juce_graphics/native/juce_Direct2DGraphicsContextImpl_windows.h +++ b/modules/juce_graphics/native/juce_Direct2DGraphicsContextImpl_windows.h @@ -91,42 +91,6 @@ public: bool fillSpriteBatch (const RectangleList& list); - static Line offsetShape (Line a, Point b); - static Rectangle offsetShape (Rectangle a, Point b); - static RectangleList offsetShape (RectangleList a, Point b); - - template - void paintPrimitive (const Shape& shape, Fn&& primitiveOp) - { - const auto& transform = owner.currentState->currentTransform; - - owner.applyPendingClipList(); - - auto deviceContext = getDeviceContext(); - - if (deviceContext == nullptr) - return; - - const auto fillTransform = transform.isOnlyTranslated - ? SavedState::BrushTransformFlags::applyWorldAndFillTypeTransforms - : SavedState::BrushTransformFlags::applyFillTypeTransform; - - const auto brush = owner.currentState->getBrush (fillTransform); - - if (transform.isOnlyTranslated) - { - const auto translated = offsetShape (shape, transform.offset.toFloat()); - - if (owner.currentState->doesIntersectClipList (translated)) - primitiveOp (translated, deviceContext, brush); - } - else if (owner.currentState->doesIntersectClipList (transform.boundsAfterTransform (shape))) - { - ScopedTransform scopedTransform { *this, owner.currentState }; - primitiveOp (shape, deviceContext, brush); - } - } - DirectWriteGlyphRun glyphRun; private: diff --git a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp index 0c7f4a7bbe..762601054b 100644 --- a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp +++ b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp @@ -472,6 +472,54 @@ void Direct2DGraphicsContext::setInterpolationQuality (Graphics::ResamplingQuali } } +Line Direct2DGraphicsContext::offsetShape (Line a, Point b) +{ + return { a.getStart() + b, a.getEnd() + b }; +} + +Rectangle Direct2DGraphicsContext::offsetShape (Rectangle a, Point b) +{ + return a + b; +} + +RectangleList Direct2DGraphicsContext::offsetShape (RectangleList a, Point b) +{ + a.offsetAll (b); + return a; +} + +template +void Direct2DGraphicsContext::paintPrimitive (const Shape& shape, Fn&& primitiveOp) +{ + const auto& transform = currentState->currentTransform; + + applyPendingClipList(); + + auto deviceContext = getPimpl()->getDeviceContext(); + + if (deviceContext == nullptr) + return; + + const auto fillTransform = transform.isOnlyTranslated + ? SavedState::BrushTransformFlags::applyWorldAndFillTypeTransforms + : SavedState::BrushTransformFlags::applyFillTypeTransform; + + const auto brush = currentState->getBrush (fillTransform); + + if (transform.isOnlyTranslated) + { + const auto translated = offsetShape (shape, transform.offset.toFloat()); + + if (currentState->doesIntersectClipList (translated)) + primitiveOp (translated, deviceContext, brush); + } + else if (currentState->doesIntersectClipList (transform.boundsAfterTransform (shape))) + { + ScopedTransform scopedTransform { *getPimpl(), currentState }; + primitiveOp (shape, deviceContext, brush); + } +} + void Direct2DGraphicsContext::fillRect (const Rectangle& r, bool replaceExistingContents) { if (r.isEmpty()) @@ -505,7 +553,7 @@ void Direct2DGraphicsContext::fillRect (const Rectangle& r, bool replaceExi deviceContext->FillRectangle (D2DUtilities::toRECT_F (rect), brush); }; - getPimpl()->paintPrimitive (r.toFloat(), fill); + paintPrimitive (r.toFloat(), fill); } void Direct2DGraphicsContext::fillRect (const Rectangle& r) @@ -519,7 +567,7 @@ void Direct2DGraphicsContext::fillRect (const Rectangle& r) deviceContext->FillRectangle (D2DUtilities::toRECT_F (rect), brush); }; - getPimpl()->paintPrimitive (r, fill); + paintPrimitive (r, fill); } void Direct2DGraphicsContext::fillRectList (const RectangleList& list) @@ -534,7 +582,7 @@ void Direct2DGraphicsContext::fillRectList (const RectangleList& list) deviceContext->FillRectangle (D2DUtilities::toRECT_F (r), brush); }; - getPimpl()->paintPrimitive (list, fill); + paintPrimitive (list, fill); } void Direct2DGraphicsContext::drawRect (const Rectangle& r, float lineThickness) @@ -548,7 +596,7 @@ void Direct2DGraphicsContext::drawRect (const Rectangle& r, float lineThi deviceContext->DrawRectangle (D2DUtilities::toRECT_F (rect.reduced (lineThickness * 0.5f)), brush, lineThickness); }; - getPimpl()->paintPrimitive (r, draw); + paintPrimitive (r, draw); } void Direct2DGraphicsContext::fillPath (const Path& p, const AffineTransform& transform) @@ -713,7 +761,7 @@ void Direct2DGraphicsContext::drawLineWithThickness (const Line& line, fl lineThickness); }; - getPimpl()->paintPrimitive (line, draw); + paintPrimitive (line, draw); } void Direct2DGraphicsContext::setFont (const Font& newFont) @@ -749,7 +797,7 @@ void Direct2DGraphicsContext::drawRoundedRectangle (const Rectangle& area deviceContext->DrawRoundedRectangle (roundedRect, brush, lineThickness); }; - getPimpl()->paintPrimitive (area, draw); + paintPrimitive (area, draw); } void Direct2DGraphicsContext::fillRoundedRectangle (const Rectangle& area, float cornerSize) @@ -763,7 +811,7 @@ void Direct2DGraphicsContext::fillRoundedRectangle (const Rectangle& area deviceContext->FillRoundedRectangle (roundedRect, brush); }; - getPimpl()->paintPrimitive (area, fill); + paintPrimitive (area, fill); } void Direct2DGraphicsContext::drawEllipse (const Rectangle& area, float lineThickness) @@ -778,7 +826,7 @@ void Direct2DGraphicsContext::drawEllipse (const Rectangle& area, float l deviceContext->DrawEllipse (ellipse, brush, lineThickness); }; - getPimpl()->paintPrimitive (area, draw); + paintPrimitive (area, draw); } void Direct2DGraphicsContext::fillEllipse (const Rectangle& area) @@ -793,7 +841,7 @@ void Direct2DGraphicsContext::fillEllipse (const Rectangle& area) deviceContext->FillEllipse (ellipse, brush); }; - getPimpl()->paintPrimitive (area, fill); + paintPrimitive (area, fill); } void Direct2DGraphicsContext::drawGlyphs (Span glyphNumbers, diff --git a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.h b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.h index 56d0186c54..b7f11e45cd 100644 --- a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.h +++ b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.h @@ -114,6 +114,13 @@ public: Direct2DMetrics::Ptr metrics; protected: + template + void paintPrimitive (const Shape& shape, Fn&& primitiveOp); + + static Line offsetShape (Line a, Point b); + static Rectangle offsetShape (Rectangle a, Point b); + static RectangleList offsetShape (RectangleList a, Point b); + struct SavedState; SavedState* currentState = nullptr;