aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2022-08-01 11:03:53 +1000
committerNeil <nyamatongwe@gmail.com>2022-08-01 11:03:53 +1000
commitee4e08d81f633437034b05b56a82dc20f474991a (patch)
tree6103faeaba122db4cc6c9010c5bda4f7ea61f6df
parent5d0f00f0ce3cda283149f0ed71fb195fcd5060d8 (diff)
downloadscintilla-mirror-ee4e08d81f633437034b05b56a82dc20f474991a.tar.gz
Improve drawing of rounded rectangles with Direct2D.
Treat case where outline and fill are same colour as single fill call for more uniform appearance. In thin rectangles, shift to semi-circular ends when no room for full rounded corners. Use different radius for fill and stroke for more uniform appearance.
-rw-r--r--doc/ScintillaHistory.html3
-rw-r--r--win32/PlatWin.cxx30
2 files changed, 23 insertions, 10 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 7895d131a..e7ac0cc1b 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -596,6 +596,9 @@
The translucency of INDIC_COMPOSITIONTHICK can be changed with SCI_INDICSETOUTLINEALPHA.
</li>
<li>
+ Improve drawing of rounded rectangles on Direct2D.
+ </li>
+ <li>
Line state optimized to avoid excess allocations by always allocating for every line.
This makes SCI_GETMAXLINESTATE less useful although it can still distinguish cases
where line state was never set for any lines.
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 293e7d3cb..761c00193 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -1651,17 +1651,27 @@ void SurfaceD2D::FillRectangle(PRectangle rc, Surface &surfacePattern) {
void SurfaceD2D::RoundedRectangle(PRectangle rc, FillStroke fillStroke) {
if (pRenderTarget) {
- D2D1_ROUNDED_RECT roundedRectFill = {
- RectangleFromPRectangle(rc.Inset(1.0)),
- 4, 4};
- D2DPenColourAlpha(fillStroke.fill.colour);
- pRenderTarget->FillRoundedRectangle(roundedRectFill, pBrush);
+ const FLOAT minDimension = static_cast<FLOAT>(std::min(rc.Width(), rc.Height())) / 2.0f;
+ const FLOAT radius = std::min(4.0f, minDimension);
+ if (fillStroke.fill.colour == fillStroke.stroke.colour) {
+ D2D1_ROUNDED_RECT roundedRectFill = {
+ RectangleFromPRectangle(rc),
+ radius, radius };
+ D2DPenColourAlpha(fillStroke.fill.colour);
+ pRenderTarget->FillRoundedRectangle(roundedRectFill, pBrush);
+ } else {
+ D2D1_ROUNDED_RECT roundedRectFill = {
+ RectangleFromPRectangle(rc.Inset(1.0)),
+ radius-1, radius-1 };
+ D2DPenColourAlpha(fillStroke.fill.colour);
+ pRenderTarget->FillRoundedRectangle(roundedRectFill, pBrush);
- D2D1_ROUNDED_RECT roundedRect = {
- RectangleFromPRectangle(rc.Inset(0.5)),
- 4, 4};
- D2DPenColourAlpha(fillStroke.stroke.colour);
- pRenderTarget->DrawRoundedRectangle(roundedRect, pBrush, fillStroke.stroke.WidthF());
+ D2D1_ROUNDED_RECT roundedRect = {
+ RectangleFromPRectangle(rc.Inset(0.5)),
+ radius, radius };
+ D2DPenColourAlpha(fillStroke.stroke.colour);
+ pRenderTarget->DrawRoundedRectangle(roundedRect, pBrush, fillStroke.stroke.WidthF());
+ }
}
}