1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Direct2D: Allow drawing rects with very small widths/heights

This commit is contained in:
reuk 2024-06-10 20:59:03 +01:00
parent 182dd84e59
commit 8acd81e587
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -1291,21 +1291,16 @@ void Direct2DGraphicsContext::fillRectList (const RectangleList<float>& list)
void Direct2DGraphicsContext::drawRect (const Rectangle<float>& r, float lineThickness)
{
// ID2D1DeviceContext::DrawRectangle centers the stroke around the edges of the specified rectangle, but
// the software renderer contains the stroke within the rectangle
// To match the software renderer, reduce the rectangle by half the stroke width
if (r.getWidth() * 0.5f < lineThickness || r.getHeight() * 0.5f < lineThickness)
return;
auto draw = [&] (Rectangle<float> rect, ComSmartPtr<ID2D1DeviceContext1> deviceContext, ComSmartPtr<ID2D1Brush> brush)
{
// ID2D1DeviceContext::DrawRectangle centers the stroke around the edges of the specified rectangle, but
// the software renderer contains the stroke within the rectangle
// To match the software renderer, reduce the rectangle by half the stroke width
if (brush != nullptr)
deviceContext->DrawRectangle (D2DUtilities::toRECT_F (rect), brush, lineThickness);
deviceContext->DrawRectangle (D2DUtilities::toRECT_F (rect.reduced (lineThickness * 0.5f)), brush, lineThickness);
};
auto reducedR = r.reduced (lineThickness * 0.5f);
getPimpl()->paintPrimitive (reducedR, draw);
getPimpl()->paintPrimitive (r, draw);
}
void Direct2DGraphicsContext::fillPath (const Path& p, const AffineTransform& transform)