/*++ Copyright (c) Microsoft Corporation Licensed under the MIT license. Module Name: - Appearances Abstract: - The classes defined in this module are responsible for encapsulating the appearance settings of profiles and presenting them in the settings UI Author(s): - Pankaj Bhojwani - May 2021 --*/ #pragma once #include "Font.g.h" #include "Appearances.g.h" #include "AppearanceViewModel.g.h" #include "Utils.h" #include "ViewModelHelpers.h" #include "SettingContainer.h" namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { struct FontComparator { bool operator()(const Font& lhs, const Font& rhs) const { return lhs.LocalizedName() < rhs.LocalizedName(); } }; struct Font : FontT { public: Font(std::wstring name, std::wstring localizedName) : _Name{ name }, _LocalizedName{ localizedName } {}; hstring ToString() { return _LocalizedName; } WINRT_PROPERTY(hstring, Name); WINRT_PROPERTY(hstring, LocalizedName); }; struct AppearanceViewModel : AppearanceViewModelT, ViewModelHelper { public: AppearanceViewModel(const Model::AppearanceConfig& appearance); void SetFontWeightFromDouble(double fontWeight) { FontWeight(winrt::Microsoft::Terminal::Settings::Editor::Converters::DoubleToFontWeight(fontWeight)); } void SetBackgroundImageOpacityFromPercentageValue(double percentageValue) { BackgroundImageOpacity(winrt::Microsoft::Terminal::Settings::Editor::Converters::PercentageValueToPercentage(percentageValue)); } void SetBackgroundImagePath(winrt::hstring path) { BackgroundImagePath(path); } // background image bool UseDesktopBGImage(); void UseDesktopBGImage(const bool useDesktop); bool BackgroundImageSettingsVisible(); Windows::Foundation::Collections::IMapView Schemes() { return _Schemes; } void Schemes(const Windows::Foundation::Collections::IMapView& val) { _Schemes = val; } WINRT_PROPERTY(bool, IsDefault, false); WINRT_PROPERTY(IHostedInWindow, WindowRoot, nullptr); // These settings are not defined in AppearanceConfig, so we grab them // from the source profile itself. The reason we still want them in the // AppearanceViewModel is so we can continue to have the 'Text' grouping // we currently have in xaml, since that grouping has some settings that // are defined in AppearanceConfig and some that are not. OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), FontFace); OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), FontSize); OBSERVABLE_PROJECTED_SETTING(_appearance.SourceProfile().FontInfo(), FontWeight); OBSERVABLE_PROJECTED_SETTING(_appearance, RetroTerminalEffect); OBSERVABLE_PROJECTED_SETTING(_appearance, CursorShape); OBSERVABLE_PROJECTED_SETTING(_appearance, CursorHeight); OBSERVABLE_PROJECTED_SETTING(_appearance, ColorSchemeName); OBSERVABLE_PROJECTED_SETTING(_appearance, BackgroundImagePath); OBSERVABLE_PROJECTED_SETTING(_appearance, BackgroundImageOpacity); OBSERVABLE_PROJECTED_SETTING(_appearance, BackgroundImageStretchMode); OBSERVABLE_PROJECTED_SETTING(_appearance, BackgroundImageAlignment); OBSERVABLE_PROJECTED_SETTING(_appearance, IntenseTextStyle); OBSERVABLE_PROJECTED_SETTING(_appearance, AdjustIndistinguishableColors); private: Model::AppearanceConfig _appearance; winrt::hstring _lastBgImagePath; Windows::Foundation::Collections::IMapView _Schemes; }; struct Appearances : AppearancesT { public: Appearances(); // font face Windows::Foundation::IInspectable CurrentFontFace() const; // CursorShape visibility logic bool IsVintageCursor() const; Model::ColorScheme CurrentColorScheme(); void CurrentColorScheme(const Model::ColorScheme& val); bool UsingMonospaceFont() const noexcept; bool ShowAllFonts() const noexcept; void ShowAllFonts(const bool& value); fire_and_forget BackgroundImage_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); void BIAlignment_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); void FontFace_SelectionChanged(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs const& e); // manually bind FontWeight Windows::Foundation::IInspectable CurrentFontWeight() const; void CurrentFontWeight(const Windows::Foundation::IInspectable& enumEntry); bool IsCustomFontWeight(); WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, FontWeightList); GETSET_BINDABLE_ENUM_SETTING(CursorShape, Microsoft::Terminal::Core::CursorStyle, Appearance, CursorShape); WINRT_PROPERTY(Windows::Foundation::Collections::IObservableVector, ColorSchemeList, nullptr); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); DEPENDENCY_PROPERTY(Editor::AppearanceViewModel, Appearance); WINRT_PROPERTY(Editor::ProfileViewModel, SourceProfile, nullptr); GETSET_BINDABLE_ENUM_SETTING(BackgroundImageStretchMode, Windows::UI::Xaml::Media::Stretch, Appearance, BackgroundImageStretchMode); GETSET_BINDABLE_ENUM_SETTING(IntenseTextStyle, Microsoft::Terminal::Settings::Model::IntenseStyle, Appearance, IntenseTextStyle); private: bool _ShowAllFonts; void _UpdateBIAlignmentControl(const int32_t val); std::array _BIAlignmentButtons; Windows::Foundation::Collections::IMap _FontWeightMap; Editor::EnumEntry _CustomFontWeight{ nullptr }; Windows::UI::Xaml::Data::INotifyPropertyChanged::PropertyChanged_revoker _ViewModelChangedRevoker; static void _ViewModelChanged(Windows::UI::Xaml::DependencyObject const& d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs const& e); void _UpdateWithNewViewModel(); }; }; namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation { BASIC_FACTORY(Appearances); }