Skip to content

Commit

Permalink
deduplicate code: UpdateSettings now calls UpdateAppearance
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed Dec 2, 2020
1 parent 235bbd7 commit dc8328d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 79 deletions.
66 changes: 19 additions & 47 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_settings = newSettings;
auto weakThis{ get_weak() };

UpdateAppearance(newSettings);

// Dispatch a call to the UI thread to apply the new settings to the
// terminal.
co_await winrt::resume_foreground(Dispatcher());
Expand All @@ -290,8 +292,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
auto lock = _terminal->LockForWriting();

// Update DxEngine settings under the lock
_renderEngine->SetSelectionBackground(_settings.SelectionBackground());

_renderEngine->SetRetroTerminalEffects(_settings.RetroTerminalEffect());
_renderEngine->SetForceFullRepaintRendering(_settings.ForceFullRepaintRendering());
_renderEngine->SetSoftwareRendering(_settings.SoftwareRendering());
Expand Down Expand Up @@ -341,12 +341,22 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
Windows::Foundation::Uri imageUri{ newAppearance.BackgroundImage() };

// Note that BitmapImage handles the image load asynchronously,
// which is especially important since the image
// may well be both large and somewhere out on the
// internet.
Media::Imaging::BitmapImage image(imageUri);
BackgroundImage().Source(image);
// Check if the image brush is already pointing to the image
// in the modified settings; if it isn't (or isn't there),
// set a new image source for the brush
auto imageSource = BackgroundImage().Source().try_as<Media::Imaging::BitmapImage>();

if (imageSource == nullptr ||
imageSource.UriSource() == nullptr ||
imageSource.UriSource().RawUri() != imageUri.RawUri())
{
// Note that BitmapImage handles the image load asynchronously,
// which is especially important since the image
// may well be both large and somewhere out on the
// internet.
Media::Imaging::BitmapImage image(imageUri);
BackgroundImage().Source(image);
}

// Apply stretch, opacity and alignment settings
BackgroundImage().Stretch(_settings.BackgroundImageStretchMode());
Expand All @@ -363,6 +373,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
COLORREF bg = newAppearance.DefaultBackground();
_BackgroundColorChanged(bg);

// Set TSF Foreground
Media::SolidColorBrush foregroundBrush{};
foregroundBrush.Color(static_cast<til::color>(newAppearance.DefaultForeground()));
TSFInputControl().Foreground(foregroundBrush);
Expand Down Expand Up @@ -411,9 +422,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
_InitializeBackgroundBrush();

COLORREF bg = _settings.DefaultBackground();
_BackgroundColorChanged(bg);

// Apply padding as swapChainPanel's margin
auto newMargin = _ParseThicknessFromPadding(_settings.Padding());
SwapChainPanel().Margin(newMargin);
Expand All @@ -431,10 +439,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_actualFont = { fontFace, 0, fontWeight.Weight, { 0, fontHeight }, CP_UTF8, false };
_desiredFont = { _actualFont };

// set TSF Foreground
Media::SolidColorBrush foregroundBrush{};
foregroundBrush.Color(static_cast<til::color>(_settings.DefaultForeground()));
TSFInputControl().Foreground(foregroundBrush);
TSFInputControl().Margin(newMargin);

// Apply settings for scrollbar
Expand Down Expand Up @@ -523,38 +527,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_renderEngine->SetDefaultTextBackgroundOpacity(1.0f);
}
}

if (!_settings.BackgroundImage().empty())
{
Windows::Foundation::Uri imageUri{ _settings.BackgroundImage() };

// Check if the image brush is already pointing to the image
// in the modified settings; if it isn't (or isn't there),
// set a new image source for the brush
auto imageSource = BackgroundImage().Source().try_as<Media::Imaging::BitmapImage>();

if (imageSource == nullptr ||
imageSource.UriSource() == nullptr ||
imageSource.UriSource().RawUri() != imageUri.RawUri())
{
// Note that BitmapImage handles the image load asynchronously,
// which is especially important since the image
// may well be both large and somewhere out on the
// internet.
Media::Imaging::BitmapImage image(imageUri);
BackgroundImage().Source(image);
}

// Apply stretch, opacity and alignment settings
BackgroundImage().Stretch(_settings.BackgroundImageStretchMode());
BackgroundImage().Opacity(_settings.BackgroundImageOpacity());
BackgroundImage().HorizontalAlignment(_settings.BackgroundImageHorizontalAlignment());
BackgroundImage().VerticalAlignment(_settings.BackgroundImageVerticalAlignment());
}
else
{
BackgroundImage().Source(nullptr);
}
}

// Method Description:
Expand Down
33 changes: 1 addition & 32 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void Terminal::CreateFromSettings(ICoreSettings settings,
// - settings: an ICoreSettings with new settings values for us to use.
void Terminal::UpdateSettings(ICoreSettings settings)
{
_defaultFg = settings.DefaultForeground();
_defaultBg = settings.DefaultBackground();
UpdateAppearance(settings);

CursorType cursorShape = CursorType::VerticalBar;
switch (settings.CursorShape())
Expand Down Expand Up @@ -188,36 +187,6 @@ void Terminal::UpdateAppearance(IAppearance appearance)
{
_defaultFg = appearance.DefaultForeground();
_defaultBg = appearance.DefaultBackground();

CursorType cursorShape = CursorType::VerticalBar;
switch (appearance.CursorShape())
{
case CursorStyle::Underscore:
cursorShape = CursorType::Underscore;
break;
case CursorStyle::FilledBox:
cursorShape = CursorType::FullBox;
break;
case CursorStyle::EmptyBox:
cursorShape = CursorType::EmptyBox;
break;
case CursorStyle::Vintage:
cursorShape = CursorType::Legacy;
break;
default:
case CursorStyle::Bar:
cursorShape = CursorType::VerticalBar;
break;
}

if (_buffer)
{
_buffer->GetCursor().SetStyle(GetCursorHeight(),
GetCursorColor(),
cursorShape);
}

_defaultCursorShape = cursorShape;
}

// Method Description:
Expand Down

1 comment on commit dc8328d

@github-actions

This comment was marked as outdated.

Please sign in to comment.