Skip to content

Commit

Permalink
Make sure the inverted cursor is always readable (microsoft#3647)
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Aug 15, 2022
1 parent 1b3d004 commit deeaff8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/actions/spelling/allow/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ lround
Lsa
lsass
LSHIFT
LTGRAY
MAINWINDOW
memchr
memicmp
Expand Down Expand Up @@ -146,6 +147,7 @@ OUTLINETEXTMETRICW
overridable
PACL
PAGESCROLL
PATINVERT
PEXPLICIT
PICKFOLDERS
pmr
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/atlas/shader_ps.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ float4 main(float4 pos: SV_Position): SV_Target
[flatten] if (cursorColor == INVALID_COLOR && glyphs[cellPos].a != 0)
{
color = float4(1 - color.rgb, 1);

// Make sure the cursor is always readable (see gh-3647)
color = float4((((uint3(color.rgb * 255) ^ 0x3f) & 0xff) / 255.0).rgb, 1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/dx/CustomTextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ try
if (firstPass)
{
// Draw a backplate behind the cursor in the *background* color so that we can invert it later.
// We're going to draw the exact same color as the background behind the cursor
const til::color color{ drawingContext.backgroundBrush->GetColor() };
// Make sure the cursor is always readable (see gh-3647)
const til::color color{ til::color{ drawingContext.backgroundBrush->GetColor() } ^ RGB(63, 63, 63) };
RETURN_IF_FAILED(d2dContext->CreateSolidColorBrush(color.with_alpha(255),
&brush));
}
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/gdi/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,11 @@ bool GdiEngine::FontHasWesternScript(HDC hdc)

for (auto r : cursorInvertRects)
{
RETURN_HR_IF(E_FAIL, !(InvertRect(_hdcMemoryContext, &r)));
// Make sure the cursor is always readable (see gh-3647)
const auto PrevObject = SelectObject(_hdcMemoryContext, GetStockObject(LTGRAY_BRUSH));
const auto Result = PatBlt(_hdcMemoryContext, r.left, r.top, r.right - r.left, r.bottom - r.top, PATINVERT);
SelectObject(_hdcMemoryContext, PrevObject);
RETURN_HR_IF(E_FAIL, !Result);
}
}

Expand Down

0 comments on commit deeaff8

Please sign in to comment.