diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml
index 37eb4a7..fb42d06 100644
--- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml
+++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml
@@ -424,6 +424,18 @@
+
+
+
TracingValueChangedEvent += ref new TracingValueChangedEventHandler(this, &GraphingCalculator::OnTracePointChanged);
+ // Update where the pointer value is (ie: where the user cursor from keyboard inputs moves the point to)
+ GraphingControl->PointerValueChangedEvent += ref new PointerValueChangedEventHandler(this, &GraphingCalculator::OnPointerPointChanged);
+
// OemMinus and OemAdd aren't declared in the VirtualKey enum, we can't add this accelerator XAML-side
auto virtualKey = ref new KeyboardAccelerator();
virtualKey->Key = (VirtualKey)187; //OemMinus key
@@ -177,6 +180,13 @@ void GraphingCalculator::OnTracePointChanged(Windows::Foundation::Point newPoint
PositionGraphPopup();
}
+void CalculatorApp::GraphingCalculator::OnPointerPointChanged(Windows::Foundation::Point newPoint)
+{
+ // Move the pointer glyph to where it is supposed to be.
+ // because the glyph is centered and has some spacing, to get the point to properly line up with the glyph, move the x point over 2 px
+ TracePointer->Margin = Thickness(newPoint.X - 2, newPoint.Y, 0, 0);
+}
+
GraphingCalculatorViewModel ^ GraphingCalculator::ViewModel::get()
{
return m_viewModel;
@@ -479,6 +489,8 @@ void CalculatorApp::GraphingCalculator::ActiveTracing_Checked(Platform::Object ^
this, &CalculatorApp::GraphingCalculator::ActiveTracing_KeyUp);
KeyboardShortcutManager::IgnoreEscape(false);
+
+ TracePointer->Visibility = ::Visibility::Visible;
}
void CalculatorApp::GraphingCalculator::ActiveTracing_Unchecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
@@ -495,6 +507,8 @@ void CalculatorApp::GraphingCalculator::ActiveTracing_Unchecked(Platform::Object
m_activeTracingKeyUpToken.Value = 0;
}
KeyboardShortcutManager::HonorEscape();
+
+ TracePointer->Visibility = ::Visibility::Collapsed;
}
void CalculatorApp::GraphingCalculator::ActiveTracing_KeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args)
diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h
index 54b45db..8ade897 100644
--- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h
+++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.h
@@ -55,6 +55,7 @@ public ref class GraphingCalculator sealed : public Windows::UI::Xaml::Data::INo
void OnShowTracePopupChanged(bool newValue);
void OnTracePointChanged(Windows::Foundation::Point newPoint);
+ void OnPointerPointChanged(Windows::Foundation::Point newPoint);
private:
void OnDataRequested(
Windows::ApplicationModel::DataTransfer::DataTransferManager ^ sender,
diff --git a/src/GraphControl/Control/Grapher.cpp b/src/GraphControl/Control/Grapher.cpp
index 405a705..9ce43d8 100644
--- a/src/GraphControl/Control/Grapher.cpp
+++ b/src/GraphControl/Control/Grapher.cpp
@@ -844,6 +844,7 @@ void Grapher::HandleTracingMovementTick(Object ^ sender, Object ^ e)
else
{
ActiveTraceCursorPosition = curPos;
+ PointerValueChangedEvent(curPos);
}
}
diff --git a/src/GraphControl/Control/Grapher.h b/src/GraphControl/Control/Grapher.h
index fa84aec..7f2949c 100644
--- a/src/GraphControl/Control/Grapher.h
+++ b/src/GraphControl/Control/Grapher.h
@@ -20,6 +20,8 @@ public
public
delegate void TracingValueChangedEventHandler(Windows::Foundation::Point value);
+public
+ delegate void PointerValueChangedEventHandler(Windows::Foundation::Point value);
[Windows::UI::Xaml::Markup::ContentPropertyAttribute(Name = L"Equations")] public ref class Grapher sealed
: public Windows::UI::Xaml::Controls::Control,
@@ -27,6 +29,7 @@ public
{
public:
event TracingValueChangedEventHandler ^ TracingValueChangedEvent;
+ event PointerValueChangedEventHandler ^ PointerValueChangedEvent;
event TracingChangedEventHandler ^ TracingChangedEvent;
virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler ^ PropertyChanged;
diff --git a/src/GraphControl/DirectX/ActiveTracingPointRenderer.cpp b/src/GraphControl/DirectX/ActiveTracingPointRenderer.cpp
deleted file mode 100644
index 66e986c..0000000
--- a/src/GraphControl/DirectX/ActiveTracingPointRenderer.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-#include "pch.h"
-#include "ActiveTracingPointRenderer.h"
-#include "DirectXHelper.h"
-
-using namespace D2D1;
-using namespace GraphControl::DX;
-using namespace std;
-using namespace Windows::Foundation;
-
-namespace
-{
- const ColorF c_DefaultPointColor = ColorF::Red;
- constexpr float c_ActiveTracingPointRadius = 2;
-}
-
-ActiveTracingPointRenderer::ActiveTracingPointRenderer(DeviceResources* deviceResources)
- : m_deviceResources{ deviceResources }
- , m_color{ c_DefaultPointColor }
-
-{
- m_RoundedRect.rect.bottom = 0;
- m_RoundedRect.rect.left = 0;
- m_RoundedRect.rect.right = 10;
- m_RoundedRect.rect.top = 10;
- m_width = (int)(m_RoundedRect.rect.right - m_RoundedRect.rect.left);
- m_height = (int)(m_RoundedRect.rect.top - m_RoundedRect.rect.bottom);
- m_RoundedRect.radiusX = c_ActiveTracingPointRadius;
- m_RoundedRect.radiusY = c_ActiveTracingPointRadius;
-
- CreateDeviceDependentResources();
-}
-
-void ActiveTracingPointRenderer::CreateDeviceDependentResources()
-{
- CreateBrush();
-}
-
-void ActiveTracingPointRenderer::ReleaseDeviceDependentResources()
-{
- m_brush.Reset();
-}
-
-void ActiveTracingPointRenderer::Render(const Point& location)
-{
- // We want to center this around the location
- if (ID2D1DeviceContext* context = m_deviceResources->GetD2DDeviceContext())
- {
- m_RoundedRect.rect.bottom = location.Y - m_height / 2;
- m_RoundedRect.rect.left = location.X - m_width / 2;
- m_RoundedRect.rect.top = m_RoundedRect.rect.bottom + m_height;
- m_RoundedRect.rect.right = m_RoundedRect.rect.left + m_width;
-
- context->BeginDraw();
- context->FillRoundedRectangle(m_RoundedRect, m_brush.Get());
-
- // Ignore D2DERR_RECREATE_TARGET here. This error indicates that the device
- // is lost. It will be handled during the next call to Present.
- HRESULT hr = context->EndDraw();
- if (hr != D2DERR_RECREATE_TARGET)
- {
- ThrowIfFailed(hr);
- }
- }
-}
-
-void ActiveTracingPointRenderer::SetColor(const ColorF& color)
-{
- m_color = color;
- CreateBrush();
-}
-
-void ActiveTracingPointRenderer::CreateBrush()
-{
- m_brush.Reset();
- ThrowIfFailed(
- m_deviceResources->GetD2DDeviceContext()->CreateSolidColorBrush(m_color, &m_brush)
- );
-}
diff --git a/src/GraphControl/DirectX/ActiveTracingPointRenderer.h b/src/GraphControl/DirectX/ActiveTracingPointRenderer.h
deleted file mode 100644
index a6c3702..0000000
--- a/src/GraphControl/DirectX/ActiveTracingPointRenderer.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-#pragma once
-
-namespace GraphControl::DX
-{
- class DeviceResources;
-
- class ActiveTracingPointRenderer
- {
- public:
- ActiveTracingPointRenderer(DeviceResources* deviceResources);
-
- void CreateDeviceDependentResources();
- void ReleaseDeviceDependentResources();
- void Render(const Windows::Foundation::Point& location);
-
- void SetColor(const D2D1::ColorF& color);
-
- private:
- void CreateBrush();
-
- private:
- DeviceResources* const m_deviceResources;
-
- D2D1::ColorF m_color;
- D2D1_ROUNDED_RECT m_RoundedRect;
- int m_width;
- int m_height;
-
- // Resources related to rendering.
- Microsoft::WRL::ComPtr m_brush;
- };
-}
diff --git a/src/GraphControl/DirectX/RenderMain.cpp b/src/GraphControl/DirectX/RenderMain.cpp
index bb832b7..ace5ae4 100644
--- a/src/GraphControl/DirectX/RenderMain.cpp
+++ b/src/GraphControl/DirectX/RenderMain.cpp
@@ -37,7 +37,6 @@ namespace GraphControl::DX
, m_TraceValue(Point(0, 0))
, m_TraceLocation(Point(0, 0))
, m_Tracing(false)
- , m_ActiveTracingPointRenderer{ &m_deviceResources }
{
// Register to be notified if the Device is lost or recreated
m_deviceResources.RegisterDeviceNotify(this);
@@ -177,8 +176,6 @@ namespace GraphControl::DX
{
// Active tracing takes over for draw nearest point input from the mouse pointer.
trackPoint = m_activeTracingPointerLocation;
-
- m_ActiveTracingPointRenderer.Render(m_activeTracingPointerLocation);
}
int formulaId;
diff --git a/src/GraphControl/DirectX/RenderMain.h b/src/GraphControl/DirectX/RenderMain.h
index b9ff322..7524e2e 100644
--- a/src/GraphControl/DirectX/RenderMain.h
+++ b/src/GraphControl/DirectX/RenderMain.h
@@ -7,7 +7,6 @@
#include "DeviceResources.h"
#include "NearestPointRenderer.h"
-#include "ActiveTracingPointRenderer.h"
#include "IGraph.h"
// Renders Direct2D and 3D content on the screen.
@@ -67,7 +66,6 @@ namespace GraphControl::DX
if (m_activeTracingPointerLocation != newValue)
{
m_activeTracingPointerLocation = newValue;
- m_ActiveTracingPointRenderer.Render(m_activeTracingPointerLocation);
RunRenderPass();
}
}
@@ -123,7 +121,6 @@ namespace GraphControl::DX
private:
DX::DeviceResources m_deviceResources;
NearestPointRenderer m_nearestPointRenderer;
- ActiveTracingPointRenderer m_ActiveTracingPointRenderer;
// Cached Graph object with Renderer property.
std::shared_ptr m_graph = nullptr;
diff --git a/src/GraphControl/GraphControl.vcxproj b/src/GraphControl/GraphControl.vcxproj
index b3db688..d7c9f3b 100644
--- a/src/GraphControl/GraphControl.vcxproj
+++ b/src/GraphControl/GraphControl.vcxproj
@@ -285,7 +285,6 @@
-
@@ -299,7 +298,6 @@
-
@@ -326,4 +324,4 @@
-
+
\ No newline at end of file
diff --git a/src/GraphControl/GraphControl.vcxproj.filters b/src/GraphControl/GraphControl.vcxproj.filters
index 99bf6dd..2b7c4e9 100644
--- a/src/GraphControl/GraphControl.vcxproj.filters
+++ b/src/GraphControl/GraphControl.vcxproj.filters
@@ -28,9 +28,6 @@
DirectX
-
- DirectX
-
Models
@@ -54,9 +51,6 @@
DirectX
-
- DirectX
-
@@ -77,7 +71,5 @@
-
-
\ No newline at end of file