Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Differential Drawing fixes for #5345 #5427

Merged
merged 28 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1f2a2e0
Merge remote-tracking branch 'origin/master' into dev/migrie/dpi
zadjii-msft Apr 16, 2020
ef246ca
This seems to work, but can it avoid resizing the buffer twice on a D…
zadjii-msft Apr 16, 2020
87f833c
Add a doc comment that should have been in the previous commit
zadjii-msft Apr 16, 2020
96c6ba9
Remove some dead code I didn't end up needing
zadjii-msft Apr 16, 2020
727fb06
convert TSFInputControl::_RedrawCanvas to use til wherever possible
zadjii-msft Apr 16, 2020
defba05
I think this works fine on high-dpi for latin, cyrillic, emoji, chinese
zadjii-msft Apr 16, 2020
4c41188
This _actaully_ works and displays the composition correctly. Needs c…
zadjii-msft Apr 16, 2020
f870470
Clean up this code significantly
zadjii-msft Apr 16, 2020
ace7a88
This does in fact work
zadjii-msft Apr 16, 2020
24eb455
Skip one of the two resizes during a DPI scale change.
zadjii-msft Apr 17, 2020
936735e
This definitely fixes the gutters, but lets try to be more surgical a…
zadjii-msft Apr 17, 2020
3535b5a
Add some comments
zadjii-msft Apr 17, 2020
436a05c
This fixes the 'vim open in an inactive tab' bug I was seeing, but I …
zadjii-msft Apr 17, 2020
ed81ce7
More good good til helpers
zadjii-msft Apr 17, 2020
1d11c23
rewrite TermControl::_GetTerminalPosition, this might all be wrong th…
zadjii-msft Apr 17, 2020
ed74b72
Do pointer event scaling in DIPs
zadjii-msft Apr 17, 2020
fb20b13
Largely cleanup, but also add a TODO as it's almost 5pm here
zadjii-msft Apr 17, 2020
b067f3c
Remove unused code, comments about receiving a useless ScaleChanged e…
zadjii-msft Apr 20, 2020
f56a9b5
Update the font size in response to a settings reload
zadjii-msft Apr 20, 2020
4a32b33
Fix blanking vim on a settings update
zadjii-msft Apr 20, 2020
831ad65
good bot
zadjii-msft Apr 20, 2020
1fb76ec
Immediately tell the VT Engine about the new viewport size when we re…
zadjii-msft Apr 20, 2020
8c47a3f
Merge remote-tracking branch 'origin/master' into dev/migrie/dpi
zadjii-msft Apr 20, 2020
7caad39
Merge remote-tracking branch 'origin/dev/miniksa/dpi' into dev/migrie…
zadjii-msft Apr 20, 2020
0a6ad8f
fix the bitmap::all() function so we can actually use it
zadjii-msft Apr 20, 2020
2b1baa5
maybe I should let it finish building before I commit
zadjii-msft Apr 20, 2020
a23d3f2
Hey what's this doing here
zadjii-msft Apr 20, 2020
c163f17
Account for IME wrapping
zadjii-msft Apr 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 47 additions & 30 deletions src/cascadia/TerminalControl/TSFInputControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,52 +175,69 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
auto fontArgs = winrt::make_self<FontInfoEventArgs>();
_CurrentFontInfoHandlers(*this, *fontArgs);

const auto fontWidth = fontArgs->FontSize().Width;
const auto fontHeight = fontArgs->FontSize().Height;
const til::size fontSize{ til::math::flooring, fontArgs->FontSize() };

// Convert text buffer cursor position to client coordinate position within the window
COORD clientCursorPos;
clientCursorPos.X = ::base::ClampMul(_currentTerminalCursorPos.x(), ::base::ClampedNumeric<ptrdiff_t>(fontWidth));
clientCursorPos.Y = ::base::ClampMul(_currentTerminalCursorPos.y(), ::base::ClampedNumeric<ptrdiff_t>(fontHeight));
// Convert text buffer cursor position to client coordinate position
// within the window. This point is in _pixels_
const til::point clientCursorPos{ _currentTerminalCursorPos * fontSize };

// position textblock to cursor position
Canvas().SetLeft(TextBlock(), clientCursorPos.X);
Canvas().SetTop(TextBlock(), clientCursorPos.Y);
// Get scale factor for view
const double scaleFactor = DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel();

const til::point clientCursorInDips{ clientCursorPos / scaleFactor };

// Position our TextBlock at the cursor position
Canvas().SetLeft(TextBlock(), clientCursorInDips.x<double>());
Canvas().SetTop(TextBlock(), clientCursorInDips.y<double>());

// calculate FontSize in pixels from Points
const double fontSizePx = (fontSize.height<double>() * 72) / USER_DEFAULT_SCREEN_DPI;

// calculate FontSize in pixels from DPIs
const double fontSizePx = (fontHeight * 72) / USER_DEFAULT_SCREEN_DPI;
TextBlock().FontSize(fontSizePx);
// Make sure to unscale the font size to correct for DPI! XAML needs
// things in DIPs, and the fontSize is in pixels.
TextBlock().FontSize(fontSizePx / scaleFactor);
TextBlock().FontFamily(Media::FontFamily(fontArgs->FontFace()));

const auto widthToTerminalEnd = _currentCanvasWidth - ::base::ClampedNumeric<double>(clientCursorPos.X);
const auto widthToTerminalEnd = _currentCanvasWidth - clientCursorInDips.x<double>();
// Make sure that we're setting the MaxWidth to a positive number - a
// negative number here will crash us in mysterious ways with a useless
// stack trace
const auto newMaxWidth = std::max<double>(0.0, widthToTerminalEnd);
TextBlock().MaxWidth(newMaxWidth);

// Get window in screen coordinates, this is the entire window including tabs
const auto windowBounds = CoreWindow::GetForCurrentThread().Bounds();
// Get window in screen coordinates, this is the entire window including
// tabs. THIS IS IN DIPs
const auto windowBounds{ CoreWindow::GetForCurrentThread().Bounds() };
const til::point windowOrigin{ til::math::flooring, windowBounds };

// Convert from client coordinate to screen coordinate by adding window position
COORD screenCursorPos;
screenCursorPos.X = ::base::ClampAdd(clientCursorPos.X, ::base::ClampedNumeric<short>(windowBounds.X));
screenCursorPos.Y = ::base::ClampAdd(clientCursorPos.Y, ::base::ClampedNumeric<short>(windowBounds.Y));
// Get the offset (margin + tabs, etc..) of the control within the window
const til::point controlOrigin{ til::math::flooring,
this->TransformToVisual(nullptr).TransformPoint(Point(0, 0)) };

// get any offset (margin + tabs, etc..) of the control within the window
const auto offsetPoint = this->TransformToVisual(nullptr).TransformPoint(winrt::Windows::Foundation::Point(0, 0));
// The controlAbsoluteOrigin is the origin of the control relative to
// the origin of the displays. THIS IS IN DIPs
const til::point controlAbsoluteOrigin{ windowOrigin + controlOrigin };

// add the margin offsets if any
screenCursorPos.X = ::base::ClampAdd(screenCursorPos.X, ::base::ClampedNumeric<short>(offsetPoint.X));
screenCursorPos.Y = ::base::ClampAdd(screenCursorPos.Y, ::base::ClampedNumeric<short>(offsetPoint.Y));
// Convert the control origin to pixels
const til::point scaledFrameOrigin = controlAbsoluteOrigin * scaleFactor;

// Get scale factor for view
const double scaleFactor = DisplayInformation::GetForCurrentView().RawPixelsPerViewPixel();
const auto yOffset = ::base::ClampedNumeric<float>(_currentTextBlockHeight) - fontHeight;
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
const auto textBottom = ::base::ClampedNumeric<float>(screenCursorPos.Y) + yOffset;
// Get the location of the cursor in the display, in pixels.
til::point screenCursorPos{ scaledFrameOrigin + clientCursorPos };

// GH #5007 - make sure to account for wrapping the IME composition at
// the right side of the viewport.
const ptrdiff_t textBlockHeight = ::base::ClampMul(_currentTextBlockHeight, scaleFactor);

// Get the bounds of the composition text, in pixels.
const til::rectangle textBounds{ til::point{ screenCursorPos.x(), screenCursorPos.y() },
til::size{ 0, textBlockHeight } };

_currentTextBounds = textBounds;

_currentTextBounds = ScaleRect(Rect(screenCursorPos.X, textBottom, 0, fontHeight), scaleFactor);
_currentControlBounds = ScaleRect(Rect(screenCursorPos.X, screenCursorPos.Y, 0, fontHeight), scaleFactor);
_currentControlBounds = Rect(screenCursorPos.x<float>(),
screenCursorPos.y<float>(),
0,
fontSize.height<float>());
}

// Method Description:
Expand Down
Loading