Update color picker (#668)
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
@@ -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<Windows::UI::Color>(GetValue(s_lineColorProperty));
|
||||
return static_cast<Windows::UI::Xaml::Media::SolidColorBrush^>(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;
|
||||
};
|
||||
}
|
||||
|
@@ -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<GraphControl::Equation ^>
|
||||
{
|
||||
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<GraphControl::Equation ^> ^ 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<GraphControl::Equation ^> ^ 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<GraphControl::Equation ^> ^ m_vector;
|
||||
std::vector<Windows::Foundation::EventRegistrationToken> m_tokens;
|
||||
};
|
||||
}
|
||||
|
@@ -39,17 +39,17 @@ namespace
|
||||
// Translate the pointer position to the [-1, 1] bounds.
|
||||
__inline pair<double, double> 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<String^, double>());
|
||||
this->SetValue(VariablesProperty, ref new Map<String ^, double>());
|
||||
|
||||
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<SolidColorBrush^>(this->Background))
|
||||
if (auto backgroundBrush = safe_cast<SolidColorBrush ^>(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<SolidColorBrush^>(this->Background))
|
||||
if (auto backgroundBrush = safe_cast<SolidColorBrush ^>(this->Background))
|
||||
{
|
||||
this->UnregisterPropertyChangedCallback(BackgroundProperty, m_tokenBackgroundColorChanged.Value);
|
||||
}
|
||||
@@ -127,7 +123,7 @@ namespace GraphControl
|
||||
|
||||
void Grapher::OnApplyTemplate()
|
||||
{
|
||||
auto swapChainPanel = dynamic_cast<SwapChainPanel^>(GetTemplateChild(StringReference(s_templateKey_SwapChainPanel)));
|
||||
auto swapChainPanel = dynamic_cast<SwapChainPanel ^>(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<String^, double>::typeid,
|
||||
IObservableMap<String ^, double>::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<Grapher^>(obj);
|
||||
auto self = static_cast<Grapher ^>(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<SolidColorBrush^>(obj);
|
||||
auto brush = static_cast<SolidColorBrush ^>(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<InspectingDataSource^, DataSourceChangedEventArgs>(this, &Grapher::OnDataSourceChanged);
|
||||
m_tokenDataSourceChanged = m_dataSource->DataSourceChanged +=
|
||||
ref new TypedEventHandler<InspectingDataSource ^, DataSourceChangedEventArgs>(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<Equation^>(EquationTemplate->LoadContent());
|
||||
auto eq = safe_cast<Equation ^>(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<Equation^>(EquationTemplate->LoadContent());
|
||||
auto eq = safe_cast<Equation ^>(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<EquationCollection^>(args->OldValue))
|
||||
if (auto older = static_cast<EquationCollection ^>(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<EquationCollection^>(args->NewValue))
|
||||
if (auto newer = static_cast<EquationCollection ^>(args->NewValue))
|
||||
{
|
||||
m_tokenEquationsChanged =
|
||||
newer->VectorChanged += ref new VectorChangedEventHandler<Equation^>(this, &Grapher::OnEquationsVectorChanged);
|
||||
m_tokenEquationsChanged = newer->VectorChanged += ref new VectorChangedEventHandler<Equation ^>(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<Equation^>^ sender, IVectorChangedEventArgs^ event)
|
||||
void Grapher::OnEquationsVectorChanged(IObservableVector<Equation ^> ^ 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"<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><mi>show2d</mi><mfenced separators=\"\">";
|
||||
|
||||
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<String^, double>();
|
||||
auto updatedVariables = ref new Map<String ^, double>();
|
||||
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<Equation^>& validEqs)
|
||||
void Grapher::UpdateGraphOptions(IGraphingOptions& options, const vector<Equation ^>& validEqs)
|
||||
{
|
||||
options.SetForceProportional(ForceProportionalAxes);
|
||||
|
||||
@@ -482,24 +487,20 @@ namespace GraphControl
|
||||
{
|
||||
vector<Graphing::Color> 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<Equation^> Grapher::GetValidEquations()
|
||||
vector<Equation ^> Grapher::GetValidEquations()
|
||||
{
|
||||
vector<Equation^> validEqs;
|
||||
vector<Equation ^> 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<Graphing::IBitmap> BitmapOut;
|
||||
bool hasSomeMissingDataOut = false;
|
||||
HRESULT hr = E_FAIL;
|
||||
hr = renderer->GetBitmap(BitmapOut, hasSomeMissingDataOut);
|
||||
@@ -676,9 +676,9 @@ namespace GraphControl
|
||||
auto arr = ref new Array<BYTE>(&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
|
||||
|
@@ -159,6 +159,7 @@ namespace GraphControl
|
||||
void OnEquationsChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args);
|
||||
void OnEquationsVectorChanged(Windows::Foundation::Collections::IObservableVector<GraphControl::Equation ^> ^sender, Windows::Foundation::Collections::IVectorChangedEventArgs^ event);
|
||||
void OnEquationChanged();
|
||||
void OnEquationStyleChanged();
|
||||
|
||||
void UpdateGraph();
|
||||
void UpdateGraphOptions(Graphing::IGraphingOptions& options, const std::vector<Equation^>& 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;
|
||||
|
Reference in New Issue
Block a user