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
This commit is contained in:
Rudy Huyn
2019-12-20 10:56:01 -08:00
committed by Eric Wong
parent 13e31799c9
commit 3942662c9d
6 changed files with 609 additions and 522 deletions

View File

@@ -29,6 +29,8 @@ using namespace GraphControl;
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, ForceProportionalAxes);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Variables);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Equations);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, AxesColor);
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, GraphBackground);
namespace
{
@@ -66,9 +68,6 @@ namespace GraphControl
DefaultStyleKey = StringReference(s_defaultStyleKey);
this->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<SolidColorBrush ^>(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<SolidColorBrush ^>(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<SolidColorBrush ^>(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);
}
}

View File

@@ -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<Platform::String ^, double>()));
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<Graphing::IGraph> 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);