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

Strawman: Dumb implementation of text D2D effects. #817

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 51 additions & 1 deletion src/cascadia/TerminalApp/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ static const std::wstring CLOSEONEXIT_KEY{ L"closeOnExit" };
static const std::wstring PADDING_KEY{ L"padding" };
static const std::wstring STARTINGDIRECTORY_KEY{ L"startingDirectory" };
static const std::wstring ICON_KEY{ L"icon" };
static const std::wstring USESHADOW_KEY{ L"useShadow" };
static const std::wstring SHADOWBLUR_KEY{ L"shadowBlur" };
static const std::wstring SHADOWOFFSETX_KEY{ L"shadowOffsetX" };
static const std::wstring SHADOWOFFSETY_KEY{ L"shadowOffsetY" };
static const std::wstring SHADOWCOLOR_KEY{ L"shadowColor" };

// Possible values for Scrollbar state
static const std::wstring ALWAYS_VISIBLE{ L"visible" };
Expand Down Expand Up @@ -71,7 +76,12 @@ Profile::Profile() :
_scrollbarState{ },
_closeOnExit{ true },
_padding{ DEFAULT_PADDING },
_icon{ }
_icon{ },
_useShadow{ false },
_shadowBlur{ 3.0 },
_shadowOffsetX{ 0.0 },
_shadowOffsetY{ 0.0 },
_shadowColor{ DEFAULT_SHADOW_COLOR }
{
UuidCreate(&_guid);
}
Expand Down Expand Up @@ -163,6 +173,12 @@ TerminalSettings Profile::CreateTerminalSettings(const std::vector<ColorScheme>&
terminalSettings.DefaultBackground(_defaultBackground.value());
}

terminalSettings.UseShadow(_useShadow);
terminalSettings.ShadowBlur(_shadowBlur);
terminalSettings.ShadowOffsetX(_shadowOffsetX);
terminalSettings.ShadowOffsetY(_shadowOffsetY);
terminalSettings.ShadowColor(_shadowColor);

if (_scrollbarState)
{
ScrollbarState result = ParseScrollbarState(_scrollbarState.value());
Expand Down Expand Up @@ -200,6 +216,11 @@ JsonObject Profile::ToJson() const
const auto useAcrylic = JsonValue::CreateBooleanValue(_useAcrylic);
const auto closeOnExit = JsonValue::CreateBooleanValue(_closeOnExit);
const auto padding = JsonValue::CreateStringValue(_padding);
const auto useShadow = JsonValue::CreateBooleanValue(_useShadow);
const auto shadowBlur = JsonValue::CreateNumberValue(_shadowBlur);
const auto shadowOffsetX = JsonValue::CreateNumberValue(_shadowOffsetX);
const auto shadowOffsetY = JsonValue::CreateNumberValue(_shadowOffsetY);
const auto shadowColor = JsonValue::CreateStringValue(Utils::ColorToHexString(_shadowColor));

if (_startingDirectory)
{
Expand Down Expand Up @@ -270,6 +291,12 @@ JsonObject Profile::ToJson() const
jsonObject.Insert(ICON_KEY, icon);
}

jsonObject.Insert(USESHADOW_KEY, useShadow);
jsonObject.Insert(SHADOWBLUR_KEY, shadowBlur);
jsonObject.Insert(SHADOWOFFSETX_KEY, shadowOffsetX);
jsonObject.Insert(SHADOWOFFSETY_KEY, shadowOffsetY);
jsonObject.Insert(SHADOWCOLOR_KEY, shadowColor);

return jsonObject;
}

Expand Down Expand Up @@ -401,6 +428,29 @@ Profile Profile::FromJson(winrt::Windows::Data::Json::JsonObject json)
{
result._icon = json.GetNamedString(ICON_KEY);
}
if (json.HasKey(USESHADOW_KEY))
{
result._useShadow = json.GetNamedBoolean(USESHADOW_KEY);
}
if (json.HasKey(SHADOWBLUR_KEY))
{
result._shadowBlur = json.GetNamedNumber(SHADOWBLUR_KEY);
}
if (json.HasKey(SHADOWOFFSETX_KEY))
{
result._shadowOffsetX = json.GetNamedNumber(SHADOWOFFSETX_KEY);
}
if (json.HasKey(SHADOWOFFSETY_KEY))
{
result._shadowOffsetY = json.GetNamedNumber(SHADOWOFFSETY_KEY);
}
if (json.HasKey(SHADOWCOLOR_KEY))
{
const auto colorString = json.GetNamedString(SHADOWCOLOR_KEY);
// TODO: MSFT:20737698 - if this fails, display an approriate error
const auto color = Utils::ColorFromHexString(colorString.c_str());
result._shadowColor = color;
}

return result;
}
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,11 @@ class TerminalApp::Profile final
bool _closeOnExit;
std::wstring _padding;

bool _useShadow;
double _shadowBlur;
double _shadowOffsetX;
double _shadowOffsetY;
uint32_t _shadowColor;

std::optional<std::wstring> _icon;
};
9 changes: 9 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// Refresh our font with the renderer
_UpdateFont();

THROW_IF_FAILED(_renderEngine->UpdateShadow(_settings.UseShadow(),
static_cast<float>(_settings.ShadowBlur()),
_settings.ShadowColor()));

const auto width = _swapChainPanel.ActualWidth();
const auto height = _swapChainPanel.ActualHeight();
if (width != 0 && height != 0)
Expand Down Expand Up @@ -323,6 +327,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// Tell the DX Engine to notify us when the swap chain changes.
dxEngine->SetCallback(std::bind(&TermControl::SwapChainChanged, this));

// FIXME: pull out renderer settings to pass to DxEngine.
THROW_IF_FAILED(dxEngine->UpdateShadow(_settings.UseShadow(),
static_cast<float>(_settings.ShadowBlur()),
_settings.ShadowColor()));

THROW_IF_FAILED(dxEngine->Enable());
_renderEngine = std::move(dxEngine);

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalControl/TerminalControl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</ItemGroup>
<ItemDefinitionGroup>
<Link>
<AdditionalDependencies>dwrite.lib;dxgi.lib;d2d1.lib;d3d11.lib;shcore.lib;winmm.lib;pathcch.lib;propsys.lib;uiautomationcore.lib;Shlwapi.lib;ntdll.lib;user32.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>dwrite.lib;dxgi.lib;dxguid.lib;d2d1.lib;d3d11.lib;shcore.lib;winmm.lib;pathcch.lib;propsys.lib;uiautomationcore.lib;Shlwapi.lib;ntdll.lib;user32.lib;kernel32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ClCompile>
<AdditionalIncludeDirectories>$(OpenConsoleDir)src\types\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand All @@ -66,4 +66,4 @@
</PropertyGroup>
<Import Project="$(OpenConsoleDir)src\common.build.post.props" />
<Import Project="$(OpenConsoleDir)src\cppwinrt.build.post.props" />
</Project>
</Project>
5 changes: 0 additions & 5 deletions src/cascadia/TerminalControl/TerminalControl.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
<ClCompile Include="KeyChord.cpp" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on here? Why are these getting removed? (and below)

It doesn't look like you otherwise manipulated this module. Were these moved out by someone else and the filters wasn't updated?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea! I guess so, as the .vcxproj wasn't changed.

<ClCompile Include="TermControl.cpp" />
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="KeyChord.h" />
<ClInclude Include="TermControl.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="TermControl.idl" />
<Midl Include="KeyChord.idl" />
<Midl Include="IKeyBindings.idl" />
<Midl Include="IControlSettings.idl" />
</ItemGroup>
<ItemGroup>
<None Include="TerminalControl.def" />
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettings/IControlSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ namespace Microsoft.Terminal.Settings
String StartingDirectory;
String EnvironmentVariables;

Boolean UseShadow;
Double ShadowBlur;
Double ShadowOffsetX;
Double ShadowOffsetY;
UInt32 ShadowColor;
};
}
56 changes: 55 additions & 1 deletion src/cascadia/TerminalSettings/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_fontFace{ DEFAULT_FONT_FACE },
_fontSize{ DEFAULT_FONT_SIZE },
_keyBindings{ nullptr },
_scrollbarState{ ScrollbarState::Visible }
_scrollbarState{ ScrollbarState::Visible },
_shadowBlur{ 3.0 },
_shadowColor{ DEFAULT_SHADOW_COLOR },
_shadowOffsetX{ 0 },
_shadowOffsetY{ 0 }
{

}
Expand Down Expand Up @@ -231,6 +235,56 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_envVars = value;
}

bool TerminalSettings::UseShadow()
{
return _useShadow;
}

void TerminalSettings::UseShadow(bool const value)
{
_useShadow = value;
}

double TerminalSettings::ShadowBlur()
{
return _shadowBlur;
}

void TerminalSettings::ShadowBlur(double const value)
{
_shadowBlur = value;
}

double TerminalSettings::ShadowOffsetX()
{
return _shadowOffsetX;
}

void TerminalSettings::ShadowOffsetX(double const value)
{
_shadowOffsetX = value;
}

double TerminalSettings::ShadowOffsetY()
{
return _shadowOffsetY;
}

void TerminalSettings::ShadowOffsetY(double const value)
{
_shadowOffsetY = value;
}

uint32_t TerminalSettings::ShadowColor()
{
return _shadowColor;
}

void TerminalSettings::ShadowColor(uint32_t const value)
{
_shadowColor = value;
}

Settings::ScrollbarState TerminalSettings::ScrollState() const noexcept
{
return _scrollbarState;
Expand Down
22 changes: 22 additions & 0 deletions src/cascadia/TerminalSettings/terminalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
hstring EnvironmentVariables();
void EnvironmentVariables(hstring const& value);

bool UseShadow();
void UseShadow(bool const value);

double ShadowBlur();
void ShadowBlur(double const value);

double ShadowOffsetX();
void ShadowOffsetX(double const value);

double ShadowOffsetY();
void ShadowOffsetY(double const value);

uint32_t ShadowColor();
void ShadowColor(uint32_t const value);

ScrollbarState ScrollState() const noexcept;
void ScrollState(winrt::Microsoft::Terminal::Settings::ScrollbarState const& value) noexcept;

Expand All @@ -97,6 +112,13 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
hstring _commandline;
hstring _startingDir;
hstring _envVars;

bool _useShadow;
uint32_t _shadowColor;
double _shadowBlur;
double _shadowOffsetX;
double _shadowOffsetY;

Settings::IKeyBindings _keyBindings;
Settings::ScrollbarState _scrollbarState;
};
Expand Down
2 changes: 2 additions & 0 deletions src/inc/DefaultSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ const std::wstring DEFAULT_STARTING_DIRECTORY{ L"%USERPROFILE%" };

constexpr COLORREF DEFAULT_CURSOR_COLOR = COLOR_WHITE;
constexpr COLORREF DEFAULT_CURSOR_HEIGHT = 25;

constexpr COLORREF DEFAULT_SHADOW_COLOR = OPACITY_OPAQUE | COLOR_BLACK;
Loading