Passive & Active tracing (#638)

* Plumebd with data transfer

* Getting mainpage to talk to getbitmap.  moving share callbacks from mainpage to graphingcalculator

* Trying to get bitmap from renderer.

* work

* Share worked

* cleanups

* Cleanups progressing

* Share working, need loc for title string and user notification incase of a failure.  Then add the equations key.

* More cleanup, now using share icon image and resources for strings.  Still need to do the graph equation key.

* Change share to html based start.

* Key working, with UL but going to try changing to table.

* Fix a html formating error, generating a new UL for each equation.

* Switched over to a table for equation key and have color block formating

* Updates from PR feedback, using Graphing::IBitmap abstraction.

* Update src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h

Fixed

Co-Authored-By: Pepe Rivera <joseartrivera@gmail.com>

* PR Updates.

* Add variables to the graph key.

* eod

* Passive graph value tracing working.

* Basic active tracing cursor working.

* Move active tracing from graphingcalculator to grapher to save some hops.
Also block tracking of the active tracing key's when in the EquationTextBox.

* Active tracing working, need to put button on screen for activation.

* Added active tracing control button (placeholder image)

* Eod

* Popup trace value now tracks the highlighted point.

* Popup skined

* PR Updates.

* Update certificate thumbnail so VS2019 doesn't have a build error.

* PR comments in process.

* PR Updates

* PR Updates, change tracing value to use tooltip static resource so we automatically change depending on system values.  And changed text formatting of the value to be generic (x,y) value.

* PR updates, changed how we detect who has focus so we don't eat keys when not in active tracing.

* Additional filtering for the Key Up/Down in the grapher.
This commit is contained in:
David Shoemaker
2019-10-04 12:24:43 -07:00
committed by Stephanie Anderl
parent 7864fe6413
commit 18f80a89db
12 changed files with 742 additions and 160 deletions

View File

@@ -13,6 +13,7 @@ using namespace Windows::Foundation::Collections;
using namespace Windows::Storage::Streams;
using namespace Windows::System;
using namespace Windows::UI;
using namespace Windows::UI::Core;
using namespace Windows::UI::Input;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
@@ -54,6 +55,7 @@ namespace GraphControl
Grapher::Grapher()
: m_solver{ IMathSolver::CreateMathSolver() }
, m_graph{ m_solver->CreateGrapher() }
, m_Moving{ false }
{
m_solver->ParsingOptions().SetFormatType(FormatType::MathML);
@@ -67,6 +69,10 @@ namespace GraphControl
this->ManipulationMode = ManipulationModes::TranslateX | ManipulationModes::TranslateY | ManipulationModes::TranslateInertia | ManipulationModes::Scale
| ManipulationModes::ScaleInertia;
auto cw = CoreWindow::GetForCurrentThread();
cw->KeyDown += ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &Grapher::OnCoreKeyDown);
cw->KeyUp += ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &Grapher::OnCoreKeyUp);
}
void Grapher::OnLoaded(Object ^ sender, RoutedEventArgs ^ args)
@@ -126,6 +132,7 @@ namespace GraphControl
auto swapChainPanel = dynamic_cast<SwapChainPanel ^>(GetTemplateChild(StringReference(s_templateKey_SwapChainPanel)));
if (swapChainPanel)
{
swapChainPanel->AllowFocusOnInteraction = true;
m_renderMain = ref new RenderMain(swapChainPanel);
}
@@ -535,12 +542,27 @@ namespace GraphControl
}
}
void Grapher::UpdateTracingChanged()
{
if (m_renderMain->Tracing || m_renderMain->ActiveTracing)
{
TracingChangedEvent(true);
TracingValueChangedEvent(m_renderMain->TraceValue);
}
else
{
TracingChangedEvent(false);
}
}
void Grapher::OnPointerMoved(PointerRoutedEventArgs ^ e)
{
if (m_renderMain)
{
PointerPoint ^ currPoint = e->GetCurrentPoint(/* relativeTo */ this);
m_renderMain->PointerLocation = currPoint->Position;
UpdateTracingChanged();
e->Handled = true;
}
@@ -551,6 +573,11 @@ namespace GraphControl
if (m_renderMain)
{
m_renderMain->DrawNearestPoint = false;
if (ActiveTracing == false)
{
// IF we are active tracing we never want to hide the popup..
TracingChangedEvent(false);
}
e->Handled = true;
}
}
@@ -699,3 +726,175 @@ namespace GraphControl
return outputStream;
}
}
void Grapher::OnCoreKeyUp(CoreWindow ^ sender, KeyEventArgs ^ e)
{
// We don't want to react to keyboard input unless the graph control has the focus.
// NOTE: you can't select the graph control from the mouse for focus but you can tab to it.
GraphControl::Grapher ^ gcHasFocus = dynamic_cast<GraphControl::Grapher ^>(FocusManager::GetFocusedElement());
if (gcHasFocus == nullptr || gcHasFocus != this)
{
// Not a graphingCalculator control so we don't want the input.
return;
}
switch (e->VirtualKey)
{
case VirtualKey::Left:
case VirtualKey::Right:
case VirtualKey::Down:
case VirtualKey::Up:
case VirtualKey::Shift:
{
HandleKey(false, e->VirtualKey);
}
break;
}
}
void Grapher::OnCoreKeyDown(CoreWindow ^ sender, KeyEventArgs ^ e)
{
// We don't want to react to any keys when we are not in the graph control
GraphControl::Grapher ^ gcHasFocus = dynamic_cast<GraphControl::Grapher ^>(FocusManager::GetFocusedElement());
if (gcHasFocus == nullptr || gcHasFocus != this)
{
// Not a graphingCalculator control so we don't want the input.
return;
}
switch (e->VirtualKey)
{
case VirtualKey::Left:
case VirtualKey::Right:
case VirtualKey::Down:
case VirtualKey::Up:
case VirtualKey::Shift:
{
HandleKey(true, e->VirtualKey);
}
break;
}
}
void Grapher::HandleKey(bool keyDown, VirtualKey key)
{
int pressedKeys = 0;
if (key == VirtualKey::Left)
{
m_KeysPressed[KeysPressedSlots::Left] = keyDown;
if (keyDown)
{
pressedKeys++;
}
}
if (key == VirtualKey::Right)
{
m_KeysPressed[KeysPressedSlots::Right] = keyDown;
if (keyDown)
{
pressedKeys++;
}
}
if (key == VirtualKey::Up)
{
m_KeysPressed[KeysPressedSlots::Up] = keyDown;
if (keyDown)
{
pressedKeys++;
}
}
if (key == VirtualKey::Down)
{
m_KeysPressed[KeysPressedSlots::Down] = keyDown;
if (keyDown)
{
pressedKeys++;
}
}
if (key == VirtualKey::Shift)
{
m_KeysPressed[KeysPressedSlots::Accelerator] = keyDown;
}
if (pressedKeys > 0 && !m_Moving)
{
m_Moving = true;
// Key(s) we care about, so ensure we are ticking our timer (and that we have one to tick)
if (m_TracingTrackingTimer == nullptr)
{
m_TracingTrackingTimer = ref new DispatcherTimer();
m_TracingTrackingTimer->Tick += ref new EventHandler<Object ^>(this, &Grapher::HandleTracingMovementTick);
TimeSpan ts;
ts.Duration = 100000; // .1 second
m_TracingTrackingTimer->Interval = ts;
auto i = m_TracingTrackingTimer->Interval;
}
m_TracingTrackingTimer->Start();
}
}
void Grapher::HandleTracingMovementTick(Object ^ sender, Object ^ e)
{
int delta = 5;
int liveKeys = 0;
if (m_KeysPressed[KeysPressedSlots::Accelerator])
{
delta = 1;
}
auto curPos = ActiveTraceCursorPosition;
if (m_KeysPressed[KeysPressedSlots::Left])
{
liveKeys++;
curPos.X -= delta;
if (curPos.X < 0)
{
curPos.X = 0;
}
}
if (m_KeysPressed[KeysPressedSlots::Right])
{
liveKeys++;
curPos.X += delta;
if (curPos.X > ActualWidth - delta)
{
curPos.X = (float)ActualWidth - delta; // TODO change this to deal with size of cursor
}
}
if (m_KeysPressed[KeysPressedSlots::Up])
{
liveKeys++;
curPos.Y -= delta;
if (curPos.Y < 0)
{
curPos.Y = 0;
}
}
if (m_KeysPressed[KeysPressedSlots::Down])
{
liveKeys++;
curPos.Y += delta;
if (curPos.Y > ActualHeight - delta)
{
curPos.Y = (float)ActualHeight - delta; // TODO change this to deal with size of cursor
}
}
if (liveKeys == 0)
{
m_Moving = false;
// Non of the keys we care about are being hit any longer so shut down our timer
m_TracingTrackingTimer->Stop();
}
else
{
ActiveTraceCursorPosition = curPos;
}
}

View File

@@ -9,15 +9,24 @@
namespace GraphControl
{
[Windows::UI::Xaml::Markup::ContentPropertyAttribute(Name = L"Equations")]
public ref class Grapher sealed : public Windows::UI::Xaml::Controls::Control
public
delegate void TracingChangedEventHandler(bool newValue);
public
delegate void TracingValueChangedEventHandler(Windows::Foundation::Point value);
[Windows::UI::Xaml::Markup::ContentPropertyAttribute(Name = L"Equations")] public ref class Grapher sealed : public Windows::UI::Xaml::Controls::Control
{
public:
event TracingValueChangedEventHandler ^ TracingValueChangedEvent;
event TracingChangedEventHandler ^ TracingChangedEvent;
public:
Grapher();
static void RegisterDependencyProperties();
#pragma region Windows::UI::Xaml::DataTemplate^ EquationTemplate DependencyProperty
#pragma region Windows::UI::Xaml::DataTemplate ^ EquationTemplate DependencyProperty
static property Windows::UI::Xaml::DependencyProperty^ EquationTemplateProperty
{
Windows::UI::Xaml::DependencyProperty^ get()
@@ -37,9 +46,9 @@ namespace GraphControl
SetValue(s_equationTemplateProperty, value);
}
}
#pragma endregion
#pragma endregion
#pragma region Platform::Object^ EquationsSource DependencyProperty
#pragma region Platform::Object ^ EquationsSource DependencyProperty
static property Windows::UI::Xaml::DependencyProperty^ EquationsSourceProperty
{
Windows::UI::Xaml::DependencyProperty^ get()
@@ -59,9 +68,9 @@ namespace GraphControl
SetValue(s_equationsSourceProperty, value);
}
}
#pragma endregion
#pragma endregion
#pragma region GraphControl::EquationCollection^ Equations DependencyProperty
#pragma region GraphControl::EquationCollection ^ Equations DependencyProperty
static property Windows::UI::Xaml::DependencyProperty^ EquationsProperty
{
Windows::UI::Xaml::DependencyProperty^ get()
@@ -77,9 +86,9 @@ namespace GraphControl
return static_cast< GraphControl::EquationCollection^ >(GetValue(s_equationsProperty));
}
}
#pragma endregion
#pragma endregion
#pragma region Windows::Foundation::Collections::IObservableMap<Platform::String^, double>^ Variables DependencyProperty
#pragma region Windows::Foundation::Collections::IObservableMap < Platform::String ^, double> ^ Variables DependencyProperty
static property Windows::UI::Xaml::DependencyProperty^ VariablesProperty
{
Windows::UI::Xaml::DependencyProperty^ get()
@@ -100,9 +109,9 @@ namespace GraphControl
SetValue(s_variablesProperty, value);
}
}
#pragma endregion
#pragma endregion
#pragma region Windows::UI::Xaml::DataTemplate^ ForceProportionalAxes DependencyProperty
#pragma region Windows::UI::Xaml::DataTemplate ^ ForceProportionalAxes DependencyProperty
static property Windows::UI::Xaml::DependencyProperty^ ForceProportionalAxesTemplateProperty
{
Windows::UI::Xaml::DependencyProperty^ get()
@@ -122,52 +131,103 @@ namespace GraphControl
SetValue(s_forceProportionalAxesTemplateProperty, value);
}
}
#pragma endregion
#pragma endregion
event Windows::Foundation::EventHandler<Windows::Foundation::Collections::IMap<Platform::String^, double>^>^ VariablesUpdated;
// Pass active tracing turned on or off down to the renderer
property bool ActiveTracing
{
bool get()
{
return m_renderMain->ActiveTracing;
}
void set(bool value)
{
m_renderMain->ActiveTracing = value;
UpdateTracingChanged();
}
}
void SetVariable(Platform::String^ variableName, double newValue);
void ZoomFromCenter(double scale);
void ResetGrid();
property Windows::Foundation::Point TraceValue
{
Windows::Foundation::Point get()
{
return m_renderMain->TraceValue;
}
}
property Windows::Foundation::Point TraceLocation
{
Windows::Foundation::Point get()
{
return m_renderMain->TraceLocation;
}
}
property Windows::Foundation::Point ActiveTraceCursorPosition
{
Windows::Foundation::Point get()
{
return m_renderMain->ActiveTraceCursorPosition;
}
void set(Windows::Foundation::Point newValue)
{
if (m_renderMain->ActiveTraceCursorPosition != newValue)
{
m_renderMain->ActiveTraceCursorPosition = newValue;
UpdateTracingChanged();
}
}
}
event Windows::Foundation::EventHandler<Windows::Foundation::Collections::IMap<Platform::String ^, double> ^> ^ VariablesUpdated;
void SetVariable(Platform::String ^ variableName, double newValue);
protected:
#pragma region Control Overrides
#pragma region Control Overrides
void OnApplyTemplate() override;
void OnPointerEntered(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
void OnPointerMoved(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
void OnPointerExited(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
void OnPointerWheelChanged(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
void OnPointerPressed(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
void OnPointerReleased(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
void OnPointerCanceled(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
void OnManipulationDelta(Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs^ e) override;
#pragma endregion
void OnPointerEntered(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
void OnPointerMoved(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
void OnPointerExited(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
void OnPointerWheelChanged(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
void OnPointerPressed(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
void OnPointerReleased(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
void OnPointerCanceled(Windows::UI::Xaml::Input::PointerRoutedEventArgs ^ e) override;
void OnManipulationDelta(Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs ^ e) override;
#pragma endregion
private:
void OnLoaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ args);
void OnUnloaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ args);
void OnLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ args);
void OnUnloaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ args);
static void OnCustomDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject^ obj, Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args);
void OnDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject^ obj, Windows::UI::Xaml::DependencyProperty^ p);
static void OnCustomDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject ^ obj, Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args);
void OnDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject ^ obj, Windows::UI::Xaml::DependencyProperty ^ p);
void OnEquationTemplateChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args);
void OnEquationTemplateChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args);
void OnEquationsSourceChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args);
void OnDataSourceChanged(GraphControl::InspectingDataSource^ sender, GraphControl::DataSourceChangedEventArgs args);
void OnEquationsSourceChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args);
void OnDataSourceChanged(GraphControl::InspectingDataSource ^ sender, GraphControl::DataSourceChangedEventArgs args);
void OnEquationsChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args);
void OnEquationsVectorChanged(Windows::Foundation::Collections::IObservableVector<GraphControl::Equation ^> ^sender, Windows::Foundation::Collections::IVectorChangedEventArgs^ event);
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);
std::vector<Equation^> GetValidEquations();
void UpdateGraphOptions(Graphing::IGraphingOptions& options, const std::vector<Equation ^>& validEqs);
std::vector<Equation ^> GetValidEquations();
void SetGraphArgs();
void UpdateVariables();
void OnForceProportionalAxesChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args);
void OnForceProportionalAxesChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args);
void OnBackgroundColorChanged(const Windows::UI::Color& color);
@@ -177,29 +237,52 @@ namespace GraphControl
void ScaleRange(double centerX, double centerY, double scale);
void OnCoreKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ e);
void OnCoreKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ e);
void UpdateTracingChanged();
void HandleTracingMovementTick(Object ^ sender, Object ^ e);
void HandleKey(bool keyDown, Windows::System::VirtualKey key);
private:
DX::RenderMain^ m_renderMain = nullptr;
DX::RenderMain ^ m_renderMain = nullptr;
static Windows::UI::Xaml::DependencyProperty^ s_equationTemplateProperty;
static Windows::UI::Xaml::DependencyProperty ^ s_equationTemplateProperty;
static Windows::UI::Xaml::DependencyProperty^ s_equationsSourceProperty;
InspectingDataSource^ m_dataSource;
static Windows::UI::Xaml::DependencyProperty ^ s_equationsSourceProperty;
InspectingDataSource ^ m_dataSource;
Windows::Foundation::EventRegistrationToken m_tokenDataSourceChanged;
static Windows::UI::Xaml::DependencyProperty^ s_equationsProperty;
static Windows::UI::Xaml::DependencyProperty^ s_variablesProperty;
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;
static Windows::UI::Xaml::DependencyProperty ^ s_forceProportionalAxesTemplateProperty;
Windows::Foundation::EventRegistrationToken m_tokenBackgroundColorChanged;
const std::unique_ptr<Graphing::IMathSolver> m_solver;
const std::shared_ptr<Graphing::IGraph> m_graph;
public:
Windows::Storage::Streams::RandomAccessStreamReference^ GetGraphBitmapStream();
bool m_tracingTracking;
enum KeysPressedSlots
{
Left,
Right,
Down,
Up,
Accelerator
};
bool m_KeysPressed[5];
bool m_Moving;
Windows::UI::Xaml::DispatcherTimer ^ m_TracingTrackingTimer;
public:
Windows::Storage::Streams::RandomAccessStreamReference ^ GetGraphBitmapStream();
};
}