From 3942662c9d40b9d06d86a91ad9728e296fa1f75b Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Fri, 20 Dec 2019 10:56:01 -0800 Subject: [PATCH] High Contrast support for Graphing Calculator (#878) * Equation Control - High contrast * tweak * Update graph colors when users switch from one high contrast mode to another * decrease opacity of reveal borders --- src/Calculator/App.xaml | 459 +-------------- src/Calculator/Resources/en-US/Resources.resw | 16 +- .../GraphingCalculator/EquationInputArea.xaml | 540 ++++++++++++++++++ .../GraphingCalculator.xaml | 33 +- src/GraphControl/Control/Grapher.cpp | 66 +-- src/GraphControl/Control/Grapher.h | 17 +- 6 files changed, 609 insertions(+), 522 deletions(-) diff --git a/src/Calculator/App.xaml b/src/Calculator/App.xaml index 4930120..9e91566 100644 --- a/src/Calculator/App.xaml +++ b/src/Calculator/App.xaml @@ -3,7 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="using:CalculatorApp.Controls" xmlns:common="using:CalculatorApp.Common" - xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)" xmlns:local="using:CalculatorApp"> @@ -15,8 +14,6 @@ 0,0,0,0 0 - 0.3 - 0.5 #FF000000 #FF2B2B2B #FF858585 @@ -69,22 +66,9 @@ FallbackColor="{ThemeResource SystemChromeMediumColor}" TintColor="{ThemeResource SystemChromeLowColor}" TintOpacity="0.7"/> - - - + Dark - - - - - - - @@ -108,8 +92,6 @@ 0 #FFF2F2F2 #FFE0E0E0 - 0.2 - 0.4 #FF858585 @@ -165,19 +147,8 @@ FallbackColor="{ThemeResource SystemChromeMediumColor}" TintColor="{ThemeResource SystemChromeLowColor}" TintOpacity="0.8"/> - - - - - - - - - + Light - @@ -198,8 +169,6 @@ 0,1,0,0 2 - 1.0 - 1.0 @@ -224,21 +193,12 @@ - - - - - - - - - - + Dark - + @@ -1628,75 +1588,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml index fe5c112..37eb4a7 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml @@ -11,10 +11,8 @@ x:Name="Control" DataContextChanged="GraphingCalculator_DataContextChanged" mc:Ignorable="d"> - - 4,4,0,0 0,0,4,4 4,0,0,4 0,4,4,0 + 0 0 0 0 + - - - - - + VariablesUpdated="GraphingControl_VariablesUpdated"/> + Style="{ThemeResource GraphControlCommandPanel}"> + Style="{ThemeResource GraphControlCommandPanel}"> Loaded += ref new RoutedEventHandler(this, &Grapher::OnLoaded); - this->Unloaded += ref new RoutedEventHandler(this, &Grapher::OnUnloaded); - this->ManipulationMode = ManipulationModes::TranslateX | ManipulationModes::TranslateY | ManipulationModes::TranslateInertia | ManipulationModes::Scale | ManipulationModes::ScaleInertia; @@ -79,25 +78,6 @@ namespace GraphControl auto& formatOptions = m_solver->FormatOptions(); } - void Grapher::OnLoaded(Object ^ sender, RoutedEventArgs ^ args) - { - if (auto backgroundBrush = safe_cast(this->Background)) - { - m_tokenBackgroundColorChanged.Value = backgroundBrush->RegisterPropertyChangedCallback( - SolidColorBrush::ColorProperty, ref new DependencyPropertyChangedCallback(this, &Grapher::OnDependencyPropertyChanged)); - - OnBackgroundColorChanged(backgroundBrush->Color); - } - } - - void Grapher::OnUnloaded(Object ^ sender, RoutedEventArgs ^ args) - { - if (auto backgroundBrush = safe_cast(this->Background)) - { - this->UnregisterPropertyChangedCallback(BackgroundProperty, m_tokenBackgroundColorChanged.Value); - } - } - void Grapher::ZoomFromCenter(double scale) { ScaleRange(0, 0, scale); @@ -138,20 +118,12 @@ namespace GraphControl { swapChainPanel->AllowFocusOnInteraction = true; m_renderMain = ref new RenderMain(swapChainPanel); + m_renderMain->BackgroundColor = GraphBackground; } TryUpdateGraph(); } - void Grapher::OnDependencyPropertyChanged(DependencyObject ^ obj, DependencyProperty ^ p) - { - if (p == SolidColorBrush::ColorProperty) - { - auto brush = static_cast(obj); - OnBackgroundColorChanged(brush->Color); - } - } - void Grapher::OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue) { if (oldValue != nullptr) @@ -512,14 +484,6 @@ namespace GraphControl TryUpdateGraph(); } - void Grapher::OnBackgroundColorChanged(const Windows::UI::Color& color) - { - if (m_renderMain) - { - m_renderMain->BackgroundColor = color; - } - } - void Grapher::OnPointerEntered(PointerRoutedEventArgs ^ e) { if (m_renderMain) @@ -894,3 +858,27 @@ String ^ Grapher::ConvertToLinear(String ^ mmlString) return ref new String(linearExpression.c_str()); } + +void Grapher::OnAxesColorPropertyChanged(Windows::UI::Color /*oldValue*/, Windows::UI::Color newValue) +{ + if (m_graph) + { + auto axesColor = Graphing::Color(newValue.R, newValue.G, newValue.B, newValue.A); + m_graph->GetOptions().SetAxisColor(axesColor); + m_graph->GetOptions().SetFontColor(axesColor); + } +} + +void Grapher::OnGraphBackgroundPropertyChanged(Windows::UI::Color /*oldValue*/, Windows::UI::Color newValue) +{ + if (m_renderMain) + { + m_renderMain->BackgroundColor = newValue; + } + if (m_graph) + { + auto color = Graphing::Color(newValue.R, newValue.G, newValue.B, newValue.A); + m_graph->GetOptions().SetBackColor(color); + m_graph->GetOptions().SetBoxColor(color); + } +} diff --git a/src/GraphControl/Control/Grapher.h b/src/GraphControl/Control/Grapher.h index f09f3e7..fa84aec 100644 --- a/src/GraphControl/Control/Grapher.h +++ b/src/GraphControl/Control/Grapher.h @@ -21,7 +21,9 @@ public public delegate void TracingValueChangedEventHandler(Windows::Foundation::Point value); - [Windows::UI::Xaml::Markup::ContentPropertyAttribute(Name = L"Equations")] public ref class Grapher sealed : public Windows::UI::Xaml::Controls::Control, public Windows::UI::Xaml::Data::INotifyPropertyChanged + [Windows::UI::Xaml::Markup::ContentPropertyAttribute(Name = L"Equations")] public ref class Grapher sealed + : public Windows::UI::Xaml::Controls::Control, + public Windows::UI::Xaml::Data::INotifyPropertyChanged { public: event TracingValueChangedEventHandler ^ TracingValueChangedEvent; @@ -38,8 +40,10 @@ public Variables, SINGLE_ARG(ref new Platform::Collections::Map())); DEPENDENCY_PROPERTY_R_WITH_DEFAULT_AND_CALLBACK(GraphControl::EquationCollection ^, Equations, nullptr); - // Pass active tracing turned on or off down to the renderer + DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, AxesColor, Windows::UI::Colors::Transparent); + DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Windows::UI::Color, GraphBackground, Windows::UI::Colors::Transparent); + // Pass active tracing turned on or off down to the renderer property bool ActiveTracing { bool get() @@ -115,13 +119,10 @@ public #pragma endregion private: - void OnLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ args); - void OnUnloaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ args); - void OnForceProportionalAxesPropertyChanged(bool oldValue, bool newValue); void OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue); - void OnDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject ^ obj, Windows::UI::Xaml::DependencyProperty ^ p); - + void OnAxesColorPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue); + void OnGraphBackgroundPropertyChanged(Windows::UI::Color oldValue, Windows::UI::Color newValue); void OnEquationChanged(Equation ^ equation); void OnEquationStyleChanged(Equation ^ equation); void OnEquationLineEnabledChanged(Equation ^ equation); @@ -133,8 +134,6 @@ public std::shared_ptr GetGraph(GraphControl::Equation ^ equation); void UpdateVariables(); - void OnBackgroundColorChanged(const Windows::UI::Color& color); - void ScaleRange(double centerX, double centerY, double scale); void OnCoreKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ e);