This commit is contained in:
Pankaj Bhojwani 2021-08-09 11:24:00 -07:00
parent b0e9bf33f2
commit 0be9b2afec
4 changed files with 28 additions and 9 deletions

View file

@ -2381,6 +2381,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _core.TaskbarProgress();
}
// Method Description:
// - Toggles the spotlight on the cursor
// - If the cursor is currently off the screen, does nothing
void TermControl::HighlightCursor()
{
if (CursorLight::GetIsTarget(RootGrid()))
@ -2389,6 +2392,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
else if (!_core.IsCursorOffScreen())
{
// Compute the location of where to place the light
const auto charSizeInPixels = CharacterDimensions();
const auto htInDips = charSizeInPixels.Height / SwapChainPanel().CompositionScaleY();
const auto wtInDips = charSizeInPixels.Width / SwapChainPanel().CompositionScaleX();
@ -2398,6 +2402,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const til::point cursorPosInPixels{ cursorPos * fontSize };
const til::point cursorPosInDIPs{ cursorPosInPixels / SwapChainPanel().CompositionScaleX() };
const til::point cursorLocationInDIPs{ cursorPosInDIPs + marginsInDips };
CursorLight().ChangeLocation(gsl::narrow_cast<float>(cursorLocationInDIPs.x()) + wtInDips / 2,
gsl::narrow_cast<float>(cursorLocationInDIPs.y()) + htInDips / 2);
CursorLight::SetIsTarget(RootGrid(), true);

View file

@ -73,12 +73,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
else
{
auto spotLight{ Window::Current().Compositor().CreateSpotLight() };
spotLight.InnerConeColor(Windows::UI::Colors::White());
spotLight.InnerConeAngleInDegrees(10);
spotLight.OuterConeAngleInDegrees(25);
spotLight.Offset({ xCoord, yCoord, 100 });
CompositionLight(spotLight);
_InitializeHelper(xCoord, yCoord);
}
}
@ -88,6 +83,20 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// Arguments:
// - newElement: unused
void CursorLight::OnConnected(UIElement const& /* newElement */)
{
if (!CompositionLight())
{
_InitializeHelper(0, 0);
}
}
// Method Description:
// - Helper to initialize the propoerties of the spotlight such as the location and
// the angles of the inner and outer cones
// Arguments:
// - xCoord: the x-coordinate of where to put the light
// - yCoord: the y-coordinate of where to put the light
void CursorLight::_InitializeHelper(float xCoord, float yCoord)
{
if (!CompositionLight())
{
@ -95,6 +104,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
spotLight.InnerConeColor(Windows::UI::Colors::White());
spotLight.InnerConeAngleInDegrees(10);
spotLight.OuterConeAngleInDegrees(25);
spotLight.Offset({ xCoord, yCoord, 100 });
CompositionLight(spotLight);
}
}

View file

@ -107,6 +107,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
private:
static void _InitializeProperties();
static Windows::UI::Xaml::DependencyProperty _IsTargetProperty;
void _InitializeHelper(float xCoord, float yCoord);
};
}

View file

@ -1208,13 +1208,15 @@ bool Terminal::IsCursorBlinkingAllowed() const noexcept
return cursor.IsBlinkingAllowed();
}
// Method Description:
// - Computes whether the cursor is currently off the screen
// Return value:
// - True if the cursor if off the screen, false otherwise
bool Terminal::IsCursorOffScreen() noexcept
{
const auto absoluteCursorPosY = _buffer->GetCursor().GetPosition().Y;
const auto viewport = _GetMutableViewport();
const auto viewHeight = viewport.Height();
const auto scrollOffset = GetScrollOffset();
return absoluteCursorPosY < scrollOffset || absoluteCursorPosY >= (scrollOffset + viewHeight);
return absoluteCursorPosY < scrollOffset || absoluteCursorPosY >= (scrollOffset + _GetMutableViewport().Height());
}
// Method Description: