diff --git a/src/CalcViewModel/CalcViewModel.vcxproj.filters b/src/CalcViewModel/CalcViewModel.vcxproj.filters index 4810f72fd..3251ab940 100644 --- a/src/CalcViewModel/CalcViewModel.vcxproj.filters +++ b/src/CalcViewModel/CalcViewModel.vcxproj.filters @@ -1,26 +1,12 @@  - - {1daab7c4-63f6-4266-a259-f34acad66d09} - - - {8d4edf06-c312-4312-978a-b6c2beb8295a} - - - {0184f727-b8aa-4af8-a699-63f1b56e7853} - - - {cf7dca32-9727-4f98-83c3-1c0ca7dd1e0c} - - - - + @@ -72,9 +58,6 @@ Common - - Common\Automation - Common\Automation @@ -87,46 +70,49 @@ Common\Automation - + + Common\Automation + + DataLoaders DataLoaders - - DataLoaders + + GraphingCalculator GraphingCalculator - - - GraphingCalculator - + + + DataLoaders + - - + + - - Common - Common Common - + Common - + + Common + + Common @@ -159,22 +145,25 @@ Common + + Common + Common Common - + Common Common - + Common - + Common @@ -186,11 +175,8 @@ Common - - Common\Automation - - - Common\Automation + + Common Common\Automation @@ -204,11 +190,11 @@ Common\Automation - - DataLoaders + + Common\Automation - - DataLoaders + + Common\Automation DataLoaders @@ -219,29 +205,40 @@ DataLoaders - - Common - DataLoaders - + DataLoaders - - Common + + GraphingCalculator GraphingCalculator - - GraphingCalculator + + DataLoaders + DataLoaders - + + + + {98717b14-c8c7-4fb6-9861-abb9124b34f0} + + + {07311281-a1fd-4dd9-baef-007f159e33ed} + + + {14ddcbc1-10a4-4940-ad53-3a751b9ebea0} + + + {b017a5e6-6d25-4799-a517-99f88d65b82f} + \ No newline at end of file diff --git a/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp b/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp index 222966982..c09ff7684 100644 --- a/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp +++ b/src/CalcViewModel/GraphingCalculator/EquationViewModel.cpp @@ -7,9 +7,8 @@ using namespace Windows::UI::Xaml; namespace CalculatorApp::ViewModel { EquationViewModel::EquationViewModel() - : m_LineColor{ Colors::Transparent }, - m_KeyGraphFeaturesVisibility{ ::Visibility::Collapsed }, - m_Expression{ "" } + : m_LineColor{ nullptr }, m_KeyGraphFeaturesVisibility{ ::Visibility::Collapsed } + , m_Expression{ "" } { } } diff --git a/src/CalcViewModel/GraphingCalculator/EquationViewModel.h b/src/CalcViewModel/GraphingCalculator/EquationViewModel.h index 50d23df16..ce0d37e9a 100644 --- a/src/CalcViewModel/GraphingCalculator/EquationViewModel.h +++ b/src/CalcViewModel/GraphingCalculator/EquationViewModel.h @@ -11,7 +11,7 @@ namespace CalculatorApp::ViewModel OBSERVABLE_OBJECT(); OBSERVABLE_PROPERTY_RW(Platform::String^, Expression); - OBSERVABLE_PROPERTY_RW(Windows::UI::Color, LineColor); + OBSERVABLE_PROPERTY_RW(Windows::UI::Xaml::Media::SolidColorBrush ^, LineColor); OBSERVABLE_PROPERTY_RW(Windows::UI::Xaml::Visibility, KeyGraphFeaturesVisibility); }; } diff --git a/src/Calculator/App.xaml b/src/Calculator/App.xaml index 6f25c2bd8..b3c8b5807 100644 --- a/src/Calculator/App.xaml +++ b/src/Calculator/App.xaml @@ -46,8 +46,28 @@ FallbackColor="{ThemeResource SystemChromeMediumColor}" TintColor="{ThemeResource SystemChromeLowColor}" TintOpacity="0.7"/> + + + + + + + + + + + + + + + + + + + + 0,0,0,0 @@ -85,6 +105,25 @@ TintOpacity="0.7"/> + + + + + + + + + + + + + + + + + + + 0,1,0,0 @@ -106,8 +145,28 @@ + - + + + + + + + + + + + + + + + + + + + + @@ -1147,7 +1206,7 @@ - + @@ -1176,183 +1235,6 @@ - + + + + + + + + + + + + + + + + diff --git a/src/Calculator/EquationStylePanelControl.xaml.cpp b/src/Calculator/EquationStylePanelControl.xaml.cpp new file mode 100644 index 000000000..e75862b40 --- /dev/null +++ b/src/Calculator/EquationStylePanelControl.xaml.cpp @@ -0,0 +1,92 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "pch.h" +#include "EquationStylePanelControl.xaml.h" + +using namespace CalculatorApp; + +using namespace Platform; +using namespace Platform::Collections; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Controls::Primitives; +using namespace Windows::UI::Xaml::Data; +using namespace Windows::UI::Xaml::Input; +using namespace Windows::UI::Xaml::Media; +using namespace Windows::UI::Xaml::Navigation; +using namespace Windows::UI::Xaml::Shapes; + +DEPENDENCY_PROPERTY_INITIALIZATION(EquationStylePanelControl, SelectedColor); + +EquationStylePanelControl::EquationStylePanelControl() +{ + InitializeComponent(); + InitializeAvailableColors(); +} + +void EquationStylePanelControl::InitializeAvailableColors() +{ + // TODO: Handle dynamically switching these to high contrast equivalents + m_AvailableColors = ref new Vector(); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush1"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush2"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush3"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush4"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush5"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush6"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush7"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush8"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush9"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush10"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush11"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush12"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush13"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush14"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush15"))); + m_AvailableColors->Append(safe_cast(Application::Current->Resources->Lookup(L"EquationBrush16"))); +} + +void EquationStylePanelControl::SelectionChanged(Object ^ /*sender */, SelectionChangedEventArgs ^ e) +{ + if (e->AddedItems->Size > 0) + { + SelectedColor = static_cast(e->AddedItems->GetAt(0)); + } +} + +void EquationStylePanelControl::OnSelectedColorPropertyChanged(SolidColorBrush ^ /*oldColor*/, SolidColorBrush ^ newColor) +{ + SelectColor(newColor); +} + +void EquationStylePanelControl::ColorChooserLoaded(Object ^ sender, RoutedEventArgs ^ e) +{ + SelectColor(SelectedColor); +} + +void EquationStylePanelControl::SelectColor(SolidColorBrush ^ selectedColor) +{ + for (auto item : ColorChooser->Items->GetView()) + { + auto brush = static_cast(item); + auto gridViewItem = dynamic_cast(ColorChooser->ContainerFromItem(brush)); + + if (!gridViewItem) + { + continue; + } + + if (brush->Color == selectedColor->Color) + { + gridViewItem->IsSelected = true; + } + else + { + gridViewItem->IsSelected = false; + } + } +} diff --git a/src/Calculator/EquationStylePanelControl.xaml.h b/src/Calculator/EquationStylePanelControl.xaml.h new file mode 100644 index 000000000..055795e44 --- /dev/null +++ b/src/Calculator/EquationStylePanelControl.xaml.h @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#pragma once + +#include "EquationStylePanelControl.g.h" +#include "CalcViewModel/Common/Utils.h" + +namespace CalculatorApp +{ + [Windows::Foundation::Metadata::WebHostHidden] public ref class EquationStylePanelControl sealed + { + public: + EquationStylePanelControl(); + DEPENDENCY_PROPERTY_OWNER(EquationStylePanelControl); + + DEPENDENCY_PROPERTY_WITH_CALLBACK(Windows::UI::Xaml::Media::SolidColorBrush ^, SelectedColor); + + property Windows::Foundation::Collections::IVector^ AvailableColors + { + Windows::Foundation::Collections::IVector^ get() { + return m_AvailableColors; + } + } + + private: + void InitializeAvailableColors(); + void SelectionChanged(Platform::Object ^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^ e); + void OnSelectedColorPropertyChanged(Windows::UI::Xaml::Media::SolidColorBrush ^ oldValue, Windows::UI::Xaml::Media::SolidColorBrush ^ newValue); + void ColorChooserLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); + void SelectColor(Windows::UI::Xaml::Media::SolidColorBrush ^ selectedColor); + + Windows::Foundation::Collections::IVector^ m_AvailableColors; + }; +} diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw index afbc6786d..335f59ad0 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -3527,4 +3527,8 @@ Max Label text for the max text box + + Line Color + Label for the Line Color section of the style picker + diff --git a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml index a8e74b9b8..48e08965c 100644 --- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml +++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml @@ -3,80 +3,59 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:CalculatorApp.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="using:CalculatorApp" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:CalculatorApp.ViewModel" d:DesignHeight="300" d:DesignWidth="400" mc:Ignorable="d"> - - - - - + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp index bc828d778..f9f10fc5f 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp @@ -92,7 +92,7 @@ void GraphingCalculator::OnDataRequested(DataTransferManager^ sender, DataReques for (unsigned i = 0; i < equations->Size; i++) { auto expression = equations->GetAt(i)->Expression->Data(); - auto color = equations->GetAt(i)->LineColor; + auto color = equations->GetAt(i)->LineColor->Color; if (equations->GetAt(i)->Expression->Length() == 0) { @@ -204,11 +204,11 @@ void GraphingCalculator::SubmitTextbox(TextBox^ sender) } else if (sender->Name == "MaxTextBox") { - variableViewModel->Step = validateDouble(sender->Text, variableViewModel->Step); + variableViewModel->Max = validateDouble(sender->Text, variableViewModel->Max); } else if (sender->Name == "StepTextBox") { - variableViewModel->Max = validateDouble(sender->Text, variableViewModel->Max); + variableViewModel->Step = validateDouble(sender->Text, variableViewModel->Step); } } diff --git a/src/GraphControl/Control/Equation.cpp b/src/GraphControl/Control/Equation.cpp index 959543cf3..a5072dfa1 100644 --- a/src/GraphControl/Control/Equation.cpp +++ b/src/GraphControl/Control/Equation.cpp @@ -6,6 +6,7 @@ using namespace std; using namespace Windows::UI; using namespace Windows::UI::ViewManagement; using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Media; namespace GraphControl { @@ -41,14 +42,13 @@ namespace GraphControl { // Default line color should be the user's accent color auto uiSettings = ref new UISettings(); - Color accentColor = uiSettings->GetColorValue(UIColorType::Accent); s_lineColorProperty = DependencyProperty::Register( EquationProperties::LineColor, - Color::typeid, + SolidColorBrush::typeid, Equation::typeid, ref new PropertyMetadata( - accentColor, + nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged))); } } diff --git a/src/GraphControl/Control/Equation.h b/src/GraphControl/Control/Equation.h index 29f059242..7ee4df9af 100644 --- a/src/GraphControl/Control/Equation.h +++ b/src/GraphControl/Control/Equation.h @@ -4,22 +4,23 @@ namespace GraphControl { namespace EquationProperties { - extern Platform::String^ Expression; - extern Platform::String^ LineColor; + extern Platform::String ^ Expression; + extern Platform::String ^ LineColor; } ref class Equation; - delegate void PropertyChangedEventHandler(Equation^ sender, Platform::String^ propertyName); + delegate void PropertyChangedEventHandler(Equation ^ sender, Platform::String ^ propertyName); - [Windows::UI::Xaml::Data::Bindable] - public ref class Equation sealed : public Windows::UI::Xaml::FrameworkElement + [Windows::UI::Xaml::Data::Bindable] public ref class Equation sealed : public Windows::UI::Xaml::FrameworkElement { public: - Equation() {} + Equation() + { + } static void RegisterDependencyProperties(); - #pragma region Platform::String^ Expression DependencyProperty +#pragma region Platform::String ^ Expression DependencyProperty static property Windows::UI::Xaml::DependencyProperty^ ExpressionProperty { Windows::UI::Xaml::DependencyProperty^ get() @@ -38,9 +39,9 @@ namespace GraphControl SetValue(s_expressionProperty, value); } } - #pragma endregion +#pragma endregion - #pragma region Windows::UI::Color LineColor DependencyProperty +#pragma region Windows::UI::Xaml::Media::SolidColorBrush ^ LineColor DependencyProperty static property Windows::UI::Xaml::DependencyProperty^ LineColorProperty { Windows::UI::Xaml::DependencyProperty^ get() @@ -48,18 +49,22 @@ namespace GraphControl return s_lineColorProperty; } } - property Windows::UI::Color LineColor + property Windows::UI::Xaml::Media::SolidColorBrush^ LineColor { - Windows::UI::Color get() + Windows::UI::Xaml::Media::SolidColorBrush^ get() { - return static_cast(GetValue(s_lineColorProperty)); + return static_cast(GetValue(s_lineColorProperty)); } - void set(Windows::UI::Color value) + void set(Windows::UI::Xaml::Media::SolidColorBrush^ value) { - SetValue(s_lineColorProperty, value); + if (value == nullptr || LineColor == nullptr || (value->Color.A != LineColor->Color.A) || (value->Color.R != LineColor->Color.R) || (value->Color.G != LineColor->Color.G) + || (value->Color.B != LineColor->Color.B)) + { + SetValue(s_lineColorProperty, value); + } } } - #pragma endregion +#pragma endregion internal: event PropertyChangedEventHandler^ PropertyChanged; @@ -67,14 +72,14 @@ namespace GraphControl std::wstring GetRequest(); private: - static void OnCustomDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject^ obj, Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args); + static void OnCustomDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject ^ obj, Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args); std::wstring GetRequestHeader(); std::wstring GetExpression(); std::wstring GetLineColor(); private: - static Windows::UI::Xaml::DependencyProperty^ s_expressionProperty; - static Windows::UI::Xaml::DependencyProperty^ s_lineColorProperty; + static Windows::UI::Xaml::DependencyProperty ^ s_expressionProperty; + static Windows::UI::Xaml::DependencyProperty ^ s_lineColorProperty; }; } diff --git a/src/GraphControl/Control/EquationCollection.h b/src/GraphControl/Control/EquationCollection.h index 92a0eed0e..c6b86ab66 100644 --- a/src/GraphControl/Control/EquationCollection.h +++ b/src/GraphControl/Control/EquationCollection.h @@ -6,21 +6,22 @@ namespace GraphControl { delegate void EquationChangedEventHandler(); - public ref class EquationCollection sealed : public Windows::Foundation::Collections::IObservableVector< GraphControl::Equation^ > +public + ref class EquationCollection sealed : public Windows::Foundation::Collections::IObservableVector { public: virtual ~EquationCollection() { } - #pragma region IIterable +#pragma region IIterable virtual Windows::Foundation::Collections::IIterator< GraphControl::Equation^ >^ First() { return m_vector->First(); } - #pragma endregion +#pragma endregion - #pragma region IVector +#pragma region IVector virtual property unsigned int Size { unsigned int get() @@ -29,12 +30,11 @@ namespace GraphControl } } - virtual void Append(GraphControl::Equation^ value) + virtual void Append(GraphControl::Equation ^ value) { m_vector->Append(value); m_tokens.emplace_back( - value->PropertyChanged += ref new GraphControl::PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged) - ); + value->PropertyChanged += ref new GraphControl::PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged)); } virtual void Clear() @@ -49,12 +49,10 @@ namespace GraphControl m_tokens.clear(); } - virtual GraphControl::Equation^ GetAt(unsigned int index) - { - return m_vector->GetAt(index); - } + virtual GraphControl::Equation + ^ GetAt(unsigned int index) { return m_vector->GetAt(index); } - virtual unsigned int GetMany(unsigned int startIndex, Platform::WriteOnlyArray< GraphControl::Equation^ >^ items) + virtual unsigned int GetMany(unsigned int startIndex, Platform::WriteOnlyArray ^ items) { return m_vector->GetMany(startIndex, items); } @@ -69,13 +67,11 @@ namespace GraphControl return m_vector->IndexOf(value, index); } - virtual void InsertAt(unsigned int index, GraphControl::Equation^ value) + virtual void InsertAt(unsigned int index, GraphControl::Equation ^ value) { m_vector->InsertAt(index, value); m_tokens.insert( - m_tokens.begin() + index, - value->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged) - ); + m_tokens.begin() + index, value->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged)); } virtual void RemoveAt(unsigned int index) @@ -98,7 +94,7 @@ namespace GraphControl m_vector->RemoveAtEnd(); } - virtual void ReplaceAll(const Platform::Array< GraphControl::Equation^ >^ items) + virtual void ReplaceAll(const Platform::Array ^ items) { auto size = m_vector->Size; for (auto i = 0u; i < size; i++) @@ -116,17 +112,16 @@ namespace GraphControl m_vector->ReplaceAll(items); } - virtual void SetAt(unsigned int index, GraphControl::Equation^ value) + virtual void SetAt(unsigned int index, GraphControl::Equation ^ value) { m_vector->GetAt(index)->PropertyChanged -= m_tokens[index]; m_vector->SetAt(index, value); - m_tokens[index] = - value->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged); + m_tokens[index] = value->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged); } - #pragma endregion +#pragma endregion - #pragma region IObservableVector +#pragma region IObservableVector virtual event Windows::Foundation::Collections::VectorChangedEventHandler< GraphControl::Equation^ >^ VectorChanged { Windows::Foundation::EventRegistrationToken add(Windows::Foundation::Collections::VectorChangedEventHandler< GraphControl::Equation^ >^ handler) @@ -139,7 +134,7 @@ namespace GraphControl m_vector->VectorChanged -= token; } } - #pragma endregion +#pragma endregion internal: EquationCollection() : @@ -147,16 +142,24 @@ namespace GraphControl { } - event EquationChangedEventHandler^ EquationChanged; + event EquationChangedEventHandler ^ EquationChanged; + event EquationChangedEventHandler ^ EquationStyleChanged; private: - void OnEquationPropertyChanged(GraphControl::Equation^, Platform::String^ propertyName) + void OnEquationPropertyChanged(GraphControl::Equation ^, Platform::String ^ propertyName) { - EquationChanged(); + if (propertyName == L"LineColor") + { + EquationStyleChanged(); + } + else + { + EquationChanged(); + } } private: - Platform::Collections::Vector< GraphControl::Equation^ >^ m_vector; + Platform::Collections::Vector ^ m_vector; std::vector m_tokens; }; } diff --git a/src/GraphControl/Control/Grapher.cpp b/src/GraphControl/Control/Grapher.cpp index 814a2c780..1f5513124 100644 --- a/src/GraphControl/Control/Grapher.cpp +++ b/src/GraphControl/Control/Grapher.cpp @@ -39,17 +39,17 @@ namespace // Translate the pointer position to the [-1, 1] bounds. __inline pair PointerPositionToGraphPosition(double posX, double posY, double width, double height) { - return make_pair(( 2 * posX / width - 1 ), ( 1 - 2 * posY / height )); + return make_pair((2 * posX / width - 1), (1 - 2 * posY / height)); } } namespace GraphControl { - DependencyProperty^ Grapher::s_equationTemplateProperty; - DependencyProperty^ Grapher::s_equationsProperty; - DependencyProperty^ Grapher::s_equationsSourceProperty; - DependencyProperty^ Grapher::s_variablesProperty; - DependencyProperty^ Grapher::s_forceProportionalAxesTemplateProperty; + DependencyProperty ^ Grapher::s_equationTemplateProperty; + DependencyProperty ^ Grapher::s_equationsProperty; + DependencyProperty ^ Grapher::s_equationsSourceProperty; + DependencyProperty ^ Grapher::s_variablesProperty; + DependencyProperty ^ Grapher::s_forceProportionalAxesTemplateProperty; Grapher::Grapher() : m_solver{ IMathSolver::CreateMathSolver() } @@ -60,33 +60,29 @@ namespace GraphControl DefaultStyleKey = StringReference(s_defaultStyleKey); this->SetValue(EquationsProperty, ref new EquationCollection()); - this->SetValue(VariablesProperty, ref new Map()); + this->SetValue(VariablesProperty, ref new Map()); 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; + this->ManipulationMode = ManipulationModes::TranslateX | ManipulationModes::TranslateY | ManipulationModes::TranslateInertia | ManipulationModes::Scale + | ManipulationModes::ScaleInertia; } - void Grapher::OnLoaded(Object^ sender, RoutedEventArgs^ args) + void Grapher::OnLoaded(Object ^ sender, RoutedEventArgs ^ args) { - if (auto backgroundBrush = safe_cast(this->Background)) + if (auto backgroundBrush = safe_cast(this->Background)) { - m_tokenBackgroundColorChanged.Value = - backgroundBrush->RegisterPropertyChangedCallback(SolidColorBrush::ColorProperty, ref new DependencyPropertyChangedCallback(this, &Grapher::OnDependencyPropertyChanged)); + m_tokenBackgroundColorChanged.Value = backgroundBrush->RegisterPropertyChangedCallback( + SolidColorBrush::ColorProperty, ref new DependencyPropertyChangedCallback(this, &Grapher::OnDependencyPropertyChanged)); OnBackgroundColorChanged(backgroundBrush->Color); } } - void Grapher::OnUnloaded(Object^ sender, RoutedEventArgs^ args) + void Grapher::OnUnloaded(Object ^ sender, RoutedEventArgs ^ args) { - if (auto backgroundBrush = safe_cast(this->Background)) + if (auto backgroundBrush = safe_cast(this->Background)) { this->UnregisterPropertyChangedCallback(BackgroundProperty, m_tokenBackgroundColorChanged.Value); } @@ -127,7 +123,7 @@ namespace GraphControl void Grapher::OnApplyTemplate() { - auto swapChainPanel = dynamic_cast(GetTemplateChild(StringReference(s_templateKey_SwapChainPanel))); + auto swapChainPanel = dynamic_cast(GetTemplateChild(StringReference(s_templateKey_SwapChainPanel))); if (swapChainPanel) { m_renderMain = ref new RenderMain(swapChainPanel); @@ -144,9 +140,7 @@ namespace GraphControl StringReference(s_propertyName_Equations), EquationCollection::typeid, Grapher::typeid, - ref new PropertyMetadata( - nullptr, - ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); + ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); } if (!s_equationsSourceProperty) @@ -155,9 +149,7 @@ namespace GraphControl StringReference(s_propertyName_EquationsSource), Object::typeid, Grapher::typeid, - ref new PropertyMetadata( - nullptr, - ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); + ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); } if (!s_equationTemplateProperty) @@ -166,37 +158,31 @@ namespace GraphControl StringReference(s_propertyName_EquationTemplate), DataTemplate::typeid, Grapher::typeid, - ref new PropertyMetadata( - nullptr, - ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); + ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); } if (!s_variablesProperty) { s_variablesProperty = DependencyProperty::Register( StringReference(s_propertyName_Variables), - IObservableMap::typeid, + IObservableMap::typeid, Grapher::typeid, - ref new PropertyMetadata( - nullptr, - ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); + ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); } if (!s_forceProportionalAxesTemplateProperty) { s_forceProportionalAxesTemplateProperty = DependencyProperty::Register( StringReference(s_propertyName_ForceProportionalAxes), - bool::typeid, + bool ::typeid, Grapher::typeid, - ref new PropertyMetadata( - true, - ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); + ref new PropertyMetadata(true, ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged))); } } - void Grapher::OnCustomDependencyPropertyChanged(DependencyObject^ obj, DependencyPropertyChangedEventArgs^ args) + void Grapher::OnCustomDependencyPropertyChanged(DependencyObject ^ obj, DependencyPropertyChangedEventArgs ^ args) { - auto self = static_cast(obj); + auto self = static_cast(obj); if (self) { if (args->Property == EquationsProperty) @@ -218,21 +204,21 @@ namespace GraphControl } } - void Grapher::OnDependencyPropertyChanged(DependencyObject^ obj, DependencyProperty^ p) + void Grapher::OnDependencyPropertyChanged(DependencyObject ^ obj, DependencyProperty ^ p) { if (p == SolidColorBrush::ColorProperty) { - auto brush = static_cast(obj); + auto brush = static_cast(obj); OnBackgroundColorChanged(brush->Color); } } - void Grapher::OnEquationTemplateChanged(DependencyPropertyChangedEventArgs^ args) + void Grapher::OnEquationTemplateChanged(DependencyPropertyChangedEventArgs ^ args) { SyncEquationsWithItemsSource(); } - void Grapher::OnEquationsSourceChanged(DependencyPropertyChangedEventArgs^ args) + void Grapher::OnEquationsSourceChanged(DependencyPropertyChangedEventArgs ^ args) { if (m_dataSource && m_tokenDataSourceChanged.Value != 0) { @@ -242,14 +228,14 @@ namespace GraphControl m_dataSource = args->NewValue ? ref new InspectingDataSource(args->NewValue) : nullptr; if (m_dataSource) { - m_tokenDataSourceChanged = - m_dataSource->DataSourceChanged += ref new TypedEventHandler(this, &Grapher::OnDataSourceChanged); + m_tokenDataSourceChanged = m_dataSource->DataSourceChanged += + ref new TypedEventHandler(this, &Grapher::OnDataSourceChanged); } SyncEquationsWithItemsSource(); } - void Grapher::OnDataSourceChanged(InspectingDataSource^ sender, DataSourceChangedEventArgs args) + void Grapher::OnDataSourceChanged(InspectingDataSource ^ sender, DataSourceChangedEventArgs args) { switch (args.Action) { @@ -276,7 +262,7 @@ namespace GraphControl { for (int i = index + count - 1; i >= index; i--) { - auto eq = safe_cast(EquationTemplate->LoadContent()); + auto eq = safe_cast(EquationTemplate->LoadContent()); eq->DataContext = m_dataSource->GetAt(i); Equations->InsertAt(index, eq); @@ -299,7 +285,7 @@ namespace GraphControl auto size = m_dataSource->GetSize(); for (auto i = 0u; i < size; i++) { - auto eq = safe_cast(EquationTemplate->LoadContent()); + auto eq = safe_cast(EquationTemplate->LoadContent()); eq->DataContext = m_dataSource->GetAt(i); Equations->Append(eq); @@ -307,9 +293,9 @@ namespace GraphControl } } - void Grapher::OnEquationsChanged(DependencyPropertyChangedEventArgs^ args) + void Grapher::OnEquationsChanged(DependencyPropertyChangedEventArgs ^ args) { - if (auto older = static_cast(args->OldValue)) + if (auto older = static_cast(args->OldValue)) { if (m_tokenEquationsChanged.Value != 0) { @@ -321,21 +307,27 @@ namespace GraphControl older->EquationChanged -= m_tokenEquationChanged; m_tokenEquationChanged.Value = 0; } + + if (m_tokenEquationStyleChanged.Value != 0) + { + older->EquationStyleChanged -= m_tokenEquationStyleChanged; + m_tokenEquationStyleChanged.Value = 0; + } } - if (auto newer = static_cast(args->NewValue)) + if (auto newer = static_cast(args->NewValue)) { - m_tokenEquationsChanged = - newer->VectorChanged += ref new VectorChangedEventHandler(this, &Grapher::OnEquationsVectorChanged); + m_tokenEquationsChanged = newer->VectorChanged += ref new VectorChangedEventHandler(this, &Grapher::OnEquationsVectorChanged); + + m_tokenEquationChanged = newer->EquationChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationChanged); - m_tokenEquationChanged = - newer->EquationChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationChanged); + m_tokenEquationStyleChanged = newer->EquationStyleChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationStyleChanged); } UpdateGraph(); } - void Grapher::OnEquationsVectorChanged(IObservableVector^ sender, IVectorChangedEventArgs^ event) + void Grapher::OnEquationsVectorChanged(IObservableVector ^ sender, IVectorChangedEventArgs ^ event) { if (event->CollectionChange == ::CollectionChange::ItemInserted || event->CollectionChange == ::CollectionChange::ItemChanged) { @@ -356,6 +348,19 @@ namespace GraphControl UpdateGraph(); } + void Grapher::OnEquationStyleChanged() + { + if (m_graph) + { + UpdateGraphOptions(m_graph->GetOptions(), GetValidEquations()); + } + + if (m_renderMain) + { + m_renderMain->RunRenderPass(); + } + } + void Grapher::UpdateGraph() { if (m_renderMain && m_graph != nullptr) @@ -368,7 +373,7 @@ namespace GraphControl ss << L"show2d"; int numValidEquations = 0; - for (Equation^ eq : validEqs) + for (Equation ^ eq : validEqs) { if (numValidEquations++ > 0) { @@ -423,7 +428,7 @@ namespace GraphControl void Grapher::UpdateVariables() { - auto updatedVariables = ref new Map(); + auto updatedVariables = ref new Map(); if (m_graph) { auto graphVariables = m_graph->GetVariables(); @@ -449,7 +454,7 @@ namespace GraphControl VariablesUpdated(this, Variables); } - void Grapher::SetVariable(Platform::String^ variableName, double newValue) + void Grapher::SetVariable(Platform::String ^ variableName, double newValue) { if (Variables->HasKey(variableName)) { @@ -474,7 +479,7 @@ namespace GraphControl } } - void Grapher::UpdateGraphOptions(IGraphingOptions& options, const vector& validEqs) + void Grapher::UpdateGraphOptions(IGraphingOptions& options, const vector& validEqs) { options.SetForceProportional(ForceProportionalAxes); @@ -482,24 +487,20 @@ namespace GraphControl { vector graphColors; graphColors.reserve(validEqs.size()); - for (Equation^ eq : validEqs) + for (Equation ^ eq : validEqs) { - auto lineColor = eq->LineColor; - graphColors.emplace_back( - lineColor.R, - lineColor.G, - lineColor.B, - lineColor.A); + auto lineColor = eq->LineColor->Color; + graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A); } options.SetGraphColors(graphColors); } } - vector Grapher::GetValidEquations() + vector Grapher::GetValidEquations() { - vector validEqs; + vector validEqs; - for (Equation^ eq : Equations) + for (Equation ^ eq : Equations) { if (!eq->Expression->IsEmpty()) { @@ -510,7 +511,7 @@ namespace GraphControl return validEqs; } - void Grapher::OnForceProportionalAxesChanged(DependencyPropertyChangedEventArgs^ args) + void Grapher::OnForceProportionalAxesChanged(DependencyPropertyChangedEventArgs ^ args) { UpdateGraph(); } @@ -523,7 +524,7 @@ namespace GraphControl } } - void Grapher::OnPointerEntered(PointerRoutedEventArgs^ e) + void Grapher::OnPointerEntered(PointerRoutedEventArgs ^ e) { if (m_renderMain) { @@ -534,18 +535,18 @@ namespace GraphControl } } - void Grapher::OnPointerMoved(PointerRoutedEventArgs^ e) + void Grapher::OnPointerMoved(PointerRoutedEventArgs ^ e) { if (m_renderMain) { - PointerPoint^ currPoint = e->GetCurrentPoint(/* relativeTo */ this); + PointerPoint ^ currPoint = e->GetCurrentPoint(/* relativeTo */ this); m_renderMain->PointerLocation = currPoint->Position; e->Handled = true; } } - void Grapher::OnPointerExited(PointerRoutedEventArgs^ e) + void Grapher::OnPointerExited(PointerRoutedEventArgs ^ e) { if (m_renderMain) { @@ -554,9 +555,9 @@ namespace GraphControl } } - void Grapher::OnPointerWheelChanged(PointerRoutedEventArgs^ e) + void Grapher::OnPointerWheelChanged(PointerRoutedEventArgs ^ e) { - PointerPoint^ currentPointer = e->GetCurrentPoint(/*relative to*/ this); + PointerPoint ^ currentPointer = e->GetCurrentPoint(/*relative to*/ this); double delta = currentPointer->Properties->MouseWheelDelta; @@ -582,24 +583,24 @@ namespace GraphControl e->Handled = true; } - void Grapher::OnPointerPressed(PointerRoutedEventArgs^ e) + void Grapher::OnPointerPressed(PointerRoutedEventArgs ^ e) { // Set the pointer capture to the element being interacted with so that only it // will fire pointer-related events CapturePointer(e->Pointer); } - void Grapher::OnPointerReleased(PointerRoutedEventArgs^ e) + void Grapher::OnPointerReleased(PointerRoutedEventArgs ^ e) { ReleasePointerCapture(e->Pointer); } - void Grapher::OnPointerCanceled(PointerRoutedEventArgs^ e) + void Grapher::OnPointerCanceled(PointerRoutedEventArgs ^ e) { ReleasePointerCapture(e->Pointer); } - void Grapher::OnManipulationDelta(ManipulationDeltaRoutedEventArgs^ e) + void Grapher::OnManipulationDelta(ManipulationDeltaRoutedEventArgs ^ e) { if (m_renderMain != nullptr && m_graph != nullptr) { @@ -656,16 +657,15 @@ namespace GraphControl } } - - RandomAccessStreamReference^ Grapher::GetGraphBitmapStream() + RandomAccessStreamReference ^ Grapher::GetGraphBitmapStream() { - RandomAccessStreamReference^ outputStream; + RandomAccessStreamReference ^ outputStream; if (m_renderMain != nullptr && m_graph != nullptr) { if (auto renderer = m_graph->GetRenderer()) { - std::shared_ptr < Graphing::IBitmap> BitmapOut; + std::shared_ptr BitmapOut; bool hasSomeMissingDataOut = false; HRESULT hr = E_FAIL; hr = renderer->GetBitmap(BitmapOut, hasSomeMissingDataOut); @@ -676,9 +676,9 @@ namespace GraphControl auto arr = ref new Array(&byteVector[0], (unsigned int)byteVector.size()); // create a memory stream wrapper - InMemoryRandomAccessStream^ stream = ref new InMemoryRandomAccessStream(); + InMemoryRandomAccessStream ^ stream = ref new InMemoryRandomAccessStream(); - // Get a writer to transfer the data + // Get a writer to transfer the data auto writer = ref new DataWriter(stream->GetOutputStreamAt(0)); // write the data diff --git a/src/GraphControl/Control/Grapher.h b/src/GraphControl/Control/Grapher.h index 9178ac96e..45a21388a 100644 --- a/src/GraphControl/Control/Grapher.h +++ b/src/GraphControl/Control/Grapher.h @@ -159,6 +159,7 @@ namespace GraphControl void OnEquationsChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args); void OnEquationsVectorChanged(Windows::Foundation::Collections::IObservableVector ^sender, Windows::Foundation::Collections::IVectorChangedEventArgs^ event); void OnEquationChanged(); + void OnEquationStyleChanged(); void UpdateGraph(); void UpdateGraphOptions(Graphing::IGraphingOptions& options, const std::vector& validEqs); @@ -188,6 +189,7 @@ namespace GraphControl static Windows::UI::Xaml::DependencyProperty^ s_equationsProperty; static Windows::UI::Xaml::DependencyProperty^ s_variablesProperty; Windows::Foundation::EventRegistrationToken m_tokenEquationsChanged; + Windows::Foundation::EventRegistrationToken m_tokenEquationStyleChanged; Windows::Foundation::EventRegistrationToken m_tokenEquationChanged; static Windows::UI::Xaml::DependencyProperty^ s_forceProportionalAxesTemplateProperty;