mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
- Mouse wheel can be used to zoom in/out of the graph.
This commit is contained in:
parent
fdc65a7045
commit
c5bd06af90
2 changed files with 31 additions and 2 deletions
|
@ -417,4 +417,32 @@ namespace GraphControl
|
||||||
e->Handled = true;
|
e->Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Grapher::OnPointerWheelChanged(PointerRoutedEventArgs^ args)
|
||||||
|
{
|
||||||
|
PointerPoint^ currentPointer = args->GetCurrentPoint(/*relative to*/ this);
|
||||||
|
|
||||||
|
double delta = currentPointer->Properties->MouseWheelDelta;
|
||||||
|
|
||||||
|
// The maximum delta is 120 according to:
|
||||||
|
// https://docs.microsoft.com/en-us/uwp/api/windows.ui.input.pointerpointproperties.mousewheeldelta#Windows_UI_Input_PointerPointProperties_MouseWheelDelta
|
||||||
|
// Apply a dampening effect so that small mouse movements have a smoother zoom.
|
||||||
|
constexpr double scrollDamper = 0.15;
|
||||||
|
double scale = 1.0 + (abs(delta) / WHEEL_DELTA) * scrollDamper;
|
||||||
|
|
||||||
|
// positive delta if wheel scrolled away from the user
|
||||||
|
if (delta >= 0)
|
||||||
|
{
|
||||||
|
scale = 1.0 / scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For scaling, the graphing engine interprets x,y position between the range [-1, 1].
|
||||||
|
// Translate the pointer position to the [-1, 1] bounds.
|
||||||
|
double centerX = (currentPointer->Position.X - ActualWidth / 2) / (ActualWidth / 2);
|
||||||
|
double centerY = (ActualHeight / 2 - currentPointer->Position.Y) / (ActualHeight / 2);
|
||||||
|
|
||||||
|
ScaleRange(centerX, centerY, scale);
|
||||||
|
|
||||||
|
args->Handled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,7 @@ namespace GraphControl
|
||||||
void OnPointerEntered(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
|
void OnPointerEntered(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
|
||||||
void OnPointerMoved(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 OnPointerExited(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
|
||||||
|
void OnPointerWheelChanged(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -125,6 +126,7 @@ namespace GraphControl
|
||||||
void OnDataSourceChanged(GraphControl::InspectingDataSource^ sender, GraphControl::DataSourceChangedEventArgs args);
|
void OnDataSourceChanged(GraphControl::InspectingDataSource^ sender, GraphControl::DataSourceChangedEventArgs args);
|
||||||
|
|
||||||
void OnEquationsChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args);
|
void OnEquationsChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ args);
|
||||||
|
void OnEquationsVectorChanged(Windows::Foundation::Collections::IObservableVector<GraphControl::Equation ^> ^sender, Windows::Foundation::Collections::IVectorChangedEventArgs ^event);
|
||||||
void OnEquationChanged();
|
void OnEquationChanged();
|
||||||
|
|
||||||
void UpdateGraph();
|
void UpdateGraph();
|
||||||
|
@ -158,6 +160,5 @@ namespace GraphControl
|
||||||
|
|
||||||
const std::unique_ptr<Graphing::IMathSolver> m_solver;
|
const std::unique_ptr<Graphing::IMathSolver> m_solver;
|
||||||
const std::shared_ptr<Graphing::IGraph> m_graph;
|
const std::shared_ptr<Graphing::IGraph> m_graph;
|
||||||
void OnEquationsVectorChanged(Windows::Foundation::Collections::IObservableVector<GraphControl::Equation ^> ^sender, Windows::Foundation::Collections::IVectorChangedEventArgs ^event);
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue