diff --git a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp index 9784916..c89902d 100644 --- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp +++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp @@ -98,21 +98,28 @@ void EquationInputArea::AddNewEquation() void EquationInputArea::EquationTextBox_GotFocus(Object ^ sender, RoutedEventArgs ^ e) { KeyboardShortcutManager::HonorShortcuts(false); + + auto eq = GetViewModelFromEquationTextBox(sender); + if (eq != nullptr) + { + eq->GraphEquation->IsSelected = true; + } } void EquationInputArea::EquationTextBox_LostFocus(Object ^ sender, RoutedEventArgs ^ e) { KeyboardShortcutManager::HonorShortcuts(true); + + auto eq = GetViewModelFromEquationTextBox(sender); + if (eq != nullptr) + { + eq->GraphEquation->IsSelected = false; + } } void EquationInputArea::EquationTextBox_Submitted(Object ^ sender, MathRichEditBoxSubmission ^ submission) { - auto tb = static_cast(sender); - if (tb == nullptr) - { - return; - } - auto eq = static_cast(tb->DataContext); + auto eq = GetViewModelFromEquationTextBox(sender); if (eq == nullptr) { return; @@ -176,8 +183,7 @@ void EquationInputArea::FocusEquationTextBox(EquationViewModel ^ equation) void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, RoutedEventArgs ^ e) { - auto tb = static_cast(sender); - auto eq = static_cast(tb->DataContext); + auto eq = GetViewModelFromEquationTextBox(sender); unsigned int index; if (Equations->IndexOf(eq, &index)) @@ -206,15 +212,12 @@ void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, Rou void EquationInputArea::EquationTextBox_KeyGraphFeaturesButtonClicked(Object ^ sender, RoutedEventArgs ^ e) { - auto tb = static_cast(sender); - auto eq = static_cast(tb->DataContext); - KeyGraphFeaturesRequested(this, eq); + KeyGraphFeaturesRequested(this, GetViewModelFromEquationTextBox(sender)); } void EquationInputArea::EquationTextBox_EquationButtonClicked(Object ^ sender, RoutedEventArgs ^ e) { - auto tb = static_cast(sender); - auto eq = static_cast(tb->DataContext); + auto eq = GetViewModelFromEquationTextBox(sender); eq->IsLineEnabled = !eq->IsLineEnabled; } @@ -410,8 +413,21 @@ void EquationInputArea::VariableAreaTapped(Object ^ sender, TappedRoutedEventArg } } } - + void EquationInputArea::EquationTextBox_EquationFormatRequested(Object ^ sender, MathRichEditBoxFormatRequest ^ e) { EquationFormatRequested(sender, e); } + +EquationViewModel ^ EquationInputArea::GetViewModelFromEquationTextBox(Object ^ sender) +{ + auto tb = static_cast(sender); + if (tb == nullptr) + { + return nullptr; + } + + auto eq = static_cast(tb->DataContext); + + return eq; +} diff --git a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h index 20805f9..bc86845 100644 --- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h +++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h @@ -15,17 +15,18 @@ namespace CalculatorApp { - public ref class EquationInputArea sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged - { - public: - EquationInputArea(); +public + ref class EquationInputArea sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged + { + public: + EquationInputArea(); OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector ^, Equations); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector ^, Variables); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector ^, AvailableColors); - event Windows::Foundation::EventHandler^ KeyGraphFeaturesRequested; - event Windows::Foundation::EventHandler ^ EquationFormatRequested; + event Windows::Foundation::EventHandler ^ KeyGraphFeaturesRequested; + event Windows::Foundation::EventHandler ^ EquationFormatRequested; public: static Windows::UI::Xaml::Visibility ManageEditVariablesButtonVisibility(unsigned int numberOfVariables); @@ -37,20 +38,20 @@ namespace CalculatorApp ^ ToSolidColorBrush(Windows::UI::Color color) { return ref new Windows::UI::Xaml::Media::SolidColorBrush(color); } private: - void OnPropertyChanged(Platform::String^ propertyName); + void OnPropertyChanged(Platform::String ^ propertyName); void OnEquationsPropertyChanged(); void AddNewEquation(); - void EquationTextBox_GotFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void EquationTextBox_LostFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void EquationTextBox_GotFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); + void EquationTextBox_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void EquationTextBox_Submitted(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxSubmission ^ e); void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args); void ReloadAvailableColors(bool isHighContrast); void FocusEquationTextBox(ViewModel::EquationViewModel ^ equation); - void EquationTextBox_RemoveButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void EquationTextBox_RemoveButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void EquationTextBox_KeyGraphFeaturesButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void EquationTextBox_EquationButtonClicked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); void EquationTextBox_Loaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); @@ -65,6 +66,8 @@ namespace CalculatorApp void VariableAreaTapped(Platform::Object ^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e); void EquationTextBox_EquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ e); + CalculatorApp::ViewModel::EquationViewModel ^ GetViewModelFromEquationTextBox(Platform::Object ^ sender); + Windows::UI::ViewManagement::AccessibilitySettings ^ m_accessibilitySettings; int m_lastLineColorIndex; int m_lastFunctionLabelIndex; diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp index 24f05b3..0a64613 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cpp @@ -420,12 +420,14 @@ void GraphingCalculator::OnEquationKeyGraphFeaturesRequested(Object ^ sender, Eq auto keyGraphFeatureInfo = GraphingControl->AnalyzeEquation(equationViewModel->GraphEquation); equationViewModel->PopulateKeyGraphFeatures(keyGraphFeatureInfo); IsKeyGraphFeaturesVisible = true; + equationViewModel->GraphEquation->IsSelected = true; } } void GraphingCalculator::OnKeyGraphFeaturesClosed(Object ^ sender, RoutedEventArgs ^ e) { IsKeyGraphFeaturesVisible = false; + ViewModel->SelectedEquation->GraphEquation->IsSelected = false; } Visibility GraphingCalculator::ShouldDisplayPanel(bool isSmallState, bool isEquationModeActivated, bool isGraphPanel) diff --git a/src/GraphControl/Control/Grapher.cpp b/src/GraphControl/Control/Grapher.cpp index bb7c5a8..a1fca8e 100644 --- a/src/GraphControl/Control/Grapher.cpp +++ b/src/GraphControl/Control/Grapher.cpp @@ -179,6 +179,7 @@ namespace GraphControl { if (m_graph) { + m_graph->TryResetSelection(); UpdateGraphOptions(m_graph->GetOptions(), GetGraphableEquations()); } @@ -325,6 +326,13 @@ namespace GraphControl if (initResult != nullopt) { + auto graphedEquations = initResult.value(); + + for (int i = 0; i < validEqs.size(); i++) + { + validEqs[i]->GraphedEquation = graphedEquations[i]; + } + UpdateGraphOptions(m_graph->GetOptions(), validEqs); SetGraphArgs(m_graph); @@ -498,6 +506,11 @@ namespace GraphControl { auto lineColor = eq->LineColor; graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A); + + if (eq->IsSelected) + { + eq->GraphedEquation->TrySelectEquation(); + } } options.SetGraphColors(graphColors); } diff --git a/src/GraphControl/Models/Equation.cpp b/src/GraphControl/Models/Equation.cpp index 02be2cb..5446876 100644 --- a/src/GraphControl/Models/Equation.cpp +++ b/src/GraphControl/Models/Equation.cpp @@ -30,8 +30,7 @@ namespace GraphControl // Check for unicode characters of less than, less than or equal to, greater than and greater than or equal to. if (expr.find(L">><") != wstring_view::npos || expr.find(L"><<") != wstring_view::npos || expr.find(L">≥<") != wstring_view::npos || expr.find(L">≤<") != wstring_view::npos || expr.find(8805) != wstring_view::npos || expr.find(8804) != wstring_view::npos - || expr.find(L"><<") != wstring_view::npos - || expr.find(L">><") != wstring_view::npos) + || expr.find(L"><<") != wstring_view::npos || expr.find(L">><") != wstring_view::npos) { request = L"plotIneq2D"; } diff --git a/src/GraphControl/Models/Equation.h b/src/GraphControl/Models/Equation.h index cc404b7..baa66c7 100644 --- a/src/GraphControl/Models/Equation.h +++ b/src/GraphControl/Models/Equation.h @@ -17,6 +17,7 @@ namespace GraphControl OBSERVABLE_NAMED_PROPERTY_RW(bool, IsLineEnabled); OBSERVABLE_NAMED_PROPERTY_RW(bool, IsValidated); OBSERVABLE_NAMED_PROPERTY_RW(bool, HasGraphError); + OBSERVABLE_NAMED_PROPERTY_RW(bool, IsSelected); property Windows::UI::Color LineColor { @@ -32,10 +33,24 @@ namespace GraphControl bool IsGraphableEquation(); + internal: + property std::shared_ptr GraphedEquation + { + void set(std::shared_ptr graphedEquation) + { + m_graphedEquation = graphedEquation; + } + std::shared_ptr get() + { + return m_graphedEquation; + } + } + private: std::wstring GetExpression(); private: Windows::UI::Color m_LineColor; + std::shared_ptr m_graphedEquation; }; } diff --git a/src/GraphControl/Models/EquationCollection.h b/src/GraphControl/Models/EquationCollection.h index d1e1ba1..ad5c9c8 100644 --- a/src/GraphControl/Models/EquationCollection.h +++ b/src/GraphControl/Models/EquationCollection.h @@ -158,7 +158,7 @@ public { auto equation = static_cast(sender); auto propertyName = args->PropertyName; - if (propertyName == GraphControl::Equation::LineColorPropertyName) + if (propertyName == GraphControl::Equation::LineColorPropertyName || propertyName == GraphControl::Equation::IsSelectedPropertyName) { EquationStyleChanged(equation); }