From 7fe8bb0dba466798ca9efc448f772d37f360efe2 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 20 Mar 2021 09:31:02 +1100 Subject: Implement Stadium on all platforms except for Win32 GDI. --- qt/ScintillaEditBase/PlatQt.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'qt/ScintillaEditBase/PlatQt.cpp') diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index fa4c062d8..7e2fd3e98 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -524,6 +524,64 @@ void SurfaceImpl::Ellipse(PRectangle rc, FillStroke fillStroke) GetPainter()->drawEllipse(rect); } +void SurfaceImpl::Stadium(PRectangle rc, FillStroke fillStroke, Ends ends) { + const XYPOSITION halfStroke = fillStroke.stroke.width / 2.0f; + const XYPOSITION radius = rc.Height() / 2.0f - halfStroke; + PRectangle rcInner = rc; + rcInner.left += radius; + rcInner.right -= radius; + const XYPOSITION arcHeight = rc.Height() - fillStroke.stroke.width; + + PenColourWidth(fillStroke.stroke.colour, fillStroke.stroke.width); + BrushColour(fillStroke.fill.colour); + + QPainterPath path; + + const Ends leftSide = static_cast(static_cast(ends) & 0xf); + const Ends rightSide = static_cast(static_cast(ends) & 0xf0); + switch (leftSide) { + case Ends::leftFlat: + path.moveTo(rc.left + halfStroke, rc.top + halfStroke); + path.lineTo(rc.left + halfStroke, rc.bottom - halfStroke); + break; + case Ends::leftAngle: + path.moveTo(rcInner.left + halfStroke, rc.top + halfStroke); + path.lineTo(rc.left + halfStroke, rc.Centre().y); + path.lineTo(rcInner.left + halfStroke, rc.bottom - halfStroke); + break; + case Ends::semiCircles: + default: + path.moveTo(rcInner.left + halfStroke, rc.top + halfStroke); + QRectF rectangleArc(rc.left + halfStroke, rc.top + halfStroke, + arcHeight, arcHeight); + path.arcTo(rectangleArc, 90, 180); + break; + } + + switch (rightSide) { + case Ends::rightFlat: + path.lineTo(rc.right - halfStroke, rc.bottom - halfStroke); + path.lineTo(rc.right - halfStroke, rc.top + halfStroke); + break; + case Ends::rightAngle: + path.lineTo(rcInner.right - halfStroke, rc.bottom - halfStroke); + path.lineTo(rc.right - halfStroke, rc.Centre().y); + path.lineTo(rcInner.right - halfStroke, rc.top + halfStroke); + break; + case Ends::semiCircles: + default: + path.lineTo(rcInner.right - halfStroke, rc.bottom - halfStroke); + QRectF rectangleArc(rc.right - arcHeight - halfStroke, rc.top + halfStroke, + arcHeight, arcHeight); + path.arcTo(rectangleArc, 270, 180); + break; + } + + // Close the path to enclose it for stroking and for filling, then draw it + path.closeSubpath(); + GetPainter()->drawPath(path); +} + void SurfaceImpl::Copy(PRectangle rc, Point from, Surface &surfaceSource) { SurfaceImpl *source = dynamic_cast(&surfaceSource); -- cgit v1.2.3