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/EquationInputArea.xaml.cpp b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp
index 3d993d3d8..a3c0e5ad7 100644
--- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp
+++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp
@@ -1,7 +1,5 @@
#include "pch.h"
#include "EquationInputArea.xaml.h"
-#include "CalcViewModel/Common/KeyboardShortcutManager.h"
-#include "Controls/EquationTextBox.h"
using namespace CalculatorApp;
using namespace CalculatorApp::Common;
@@ -13,25 +11,14 @@ using namespace Windows::System;
using namespace Windows::UI;
using namespace Windows::UI::ViewManagement;
using namespace Windows::UI::Xaml;
+using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Input;
+using namespace GraphControl;
namespace
{
- const Color accentColor = (ref new UISettings())->GetColorValue(UIColorType::Accent);
- const Color lineColors[] = {
- accentColor,
- Colors::DarkOrange,
- Colors::MediumPurple,
- Colors::ForestGreen,
- Colors::BlueViolet,
- Colors::DarkRed,
- Colors::LightGoldenrodYellow,
- Colors::DarkOliveGreen
- };
- const size_t lineColorsSize = std::size(lineColors);
-
StringReference EquationsPropertyName(L"Equations");
}
@@ -65,8 +52,6 @@ void EquationInputArea::AddEquationButton_Click(Object^ sender, RoutedEventArgs^
void EquationInputArea::AddNewEquation()
{
auto eq = ref new EquationViewModel();
- eq->LineColor = GetNextLineColor();
-
Equations->Append(eq);
}
@@ -85,15 +70,9 @@ void EquationInputArea::InputTextBox_Submitted(Object ^ sender, RoutedEventArgs
auto tb = static_cast(sender);
auto eq = static_cast(tb->DataContext);
eq->Expression = tb->GetEquationText();
+ FocusManager::TryMoveFocus(::FocusNavigationDirection::Left);
}
-Color EquationInputArea::GetNextLineColor()
-{
- m_lastLineColorIndex = (m_lastLineColorIndex + 1) % lineColorsSize;
- return lineColors[m_lastLineColorIndex];
-}
-
-
void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object^ sender, RoutedEventArgs^ e)
{
auto tb = static_cast(sender);
@@ -104,3 +83,15 @@ void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object^ sender, Rout
Equations->RemoveAt(index);
}
}
+
+void EquationInputArea::EquationTextBoxLoaded(Object ^ sender, RoutedEventArgs ^ e)
+{
+ auto tb = static_cast(sender);
+ auto eq = static_cast(tb->DataContext);
+
+ auto colorChooser = static_cast(tb->ColorChooserFlyout->Content);
+
+ m_lastLineColorIndex = (m_lastLineColorIndex + 1) % colorChooser->AvailableColors->Size;
+
+ eq->LineColor = colorChooser->AvailableColors->GetAt(m_lastLineColorIndex);
+}
diff --git a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h
index 2da5170fc..924473109 100644
--- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h
+++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h
@@ -3,6 +3,9 @@
#include "Views/GraphingCalculator/EquationInputArea.g.h"
#include "CalcViewModel/Common/Utils.h"
#include "CalcViewModel/GraphingCalculator/EquationViewModel.h"
+#include "EquationStylePanelControl.xaml.h"
+#include "CalcViewModel/Common/KeyboardShortcutManager.h"
+#include "Controls/EquationTextBox.h"
namespace CalculatorApp
{
@@ -25,10 +28,9 @@ namespace CalculatorApp
void InputTextBox_LostFocus(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void InputTextBox_Submitted(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
- Windows::UI::Color GetNextLineColor();
-
private:
int m_lastLineColorIndex;
void EquationTextBox_RemoveButtonClicked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
+ void EquationTextBoxLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
};
}
diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml
index 67ce13bab..c7776f886 100644
--- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml
+++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml
@@ -365,18 +365,23 @@
-
-
+
+
+
+
+
-
-
+
+
+
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"