diff --git a/apps/graph/graph/calculation_graph_controller.cpp b/apps/graph/graph/calculation_graph_controller.cpp index a68dc5156..b5849d74d 100644 --- a/apps/graph/graph/calculation_graph_controller.cpp +++ b/apps/graph/graph/calculation_graph_controller.cpp @@ -64,7 +64,7 @@ bool CalculationGraphController::handleEnter() { return true; } -bool CalculationGraphController::moveCursorHorizontally(int direction, bool fast) { +bool CalculationGraphController::moveCursorHorizontally(int direction, int scrollspeed) { if (!m_isActive) { return false; } diff --git a/apps/graph/graph/calculation_graph_controller.h b/apps/graph/graph/calculation_graph_controller.h index 14f5cc797..4bf7a9fa5 100644 --- a/apps/graph/graph/calculation_graph_controller.h +++ b/apps/graph/graph/calculation_graph_controller.h @@ -31,7 +31,7 @@ protected: bool m_isActive; private: bool handleEnter() override; - bool moveCursorHorizontally(int direction, bool fast = false) override; + bool moveCursorHorizontally(int direction, int scrollSpeed = 1) override; Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } Shared::CurveView * curveView() override { return m_graphView; } }; diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index cc9dbb93a..3ef644d21 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -165,9 +165,9 @@ void GraphController::reloadBannerView() { reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, record); } -bool GraphController::moveCursorHorizontally(int direction, bool fast) { +bool GraphController::moveCursorHorizontally(int direction, int scrollSpeed) { Ion::Storage::Record record = functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor()); - return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, record, fast); + return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, record, scrollSpeed); } int GraphController::nextCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const { diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index 84240fcd3..abc05b8c8 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -27,7 +27,7 @@ private: void selectFunctionWithCursor(int functionIndex) override; BannerView * bannerView() override { return &m_bannerView; } void reloadBannerView() override; - bool moveCursorHorizontally(int direction, bool fast = false) override; + bool moveCursorHorizontally(int direction, int scrollSpeed = 1) override; int nextCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const override; double defaultCursorT(Ion::Storage::Record record) override; Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } diff --git a/apps/graph/graph/graph_controller_helper.cpp b/apps/graph/graph/graph_controller_helper.cpp index ad42ac727..90785d29a 100644 --- a/apps/graph/graph/graph_controller_helper.cpp +++ b/apps/graph/graph/graph_controller_helper.cpp @@ -10,7 +10,7 @@ using namespace Poincare; namespace Graph { -bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, bool fast) { +bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, int scrollSpeed) { ExpiringPointer function = App::app()->functionStore()->modelForRecord(record); double tCursorPosition = cursor->t(); double t = tCursorPosition; @@ -27,10 +27,7 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso function = App::app()->functionStore()->modelForRecord(record); // Reload the expiring pointer double dir = (direction > 0 ? 1.0 : -1.0); double step = function->plotType() == ContinuousFunction::PlotType::Cartesian ? range->xGridUnit()/numberOfStepsInGradUnit : (tMax-tMin)/k_definitionDomainDivisor; - if (fast) { - // TODO Navigate quicker the longer the user presses? (slow start) - step *= 5.0; - } + step *= scrollSpeed; t += dir * step; t = std::max(tMin, std::min(tMax, t)); Coordinate2D xy = function->evaluateXYAtParameter(t, App::app()->localContext()); diff --git a/apps/graph/graph/graph_controller_helper.h b/apps/graph/graph/graph_controller_helper.h index dcc6daf02..b0e131497 100644 --- a/apps/graph/graph/graph_controller_helper.h +++ b/apps/graph/graph/graph_controller_helper.h @@ -11,7 +11,7 @@ class App; class GraphControllerHelper { protected: - bool privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, bool fast = false); + bool privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record, int scrollSpeed = 1); void reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, Ion::Storage::Record record); virtual BannerView * bannerView() = 0; private: diff --git a/apps/graph/graph/tangent_graph_controller.cpp b/apps/graph/graph/tangent_graph_controller.cpp index f3cacdbcb..afc41f941 100644 --- a/apps/graph/graph/tangent_graph_controller.cpp +++ b/apps/graph/graph/tangent_graph_controller.cpp @@ -90,7 +90,7 @@ void TangentGraphController::reloadBannerView() { m_bannerView->reload(); } -bool TangentGraphController::moveCursorHorizontally(int direction, bool fast) { +bool TangentGraphController::moveCursorHorizontally(int direction, int scrollSpeed) { return privateMoveCursorHorizontally(m_cursor, direction, m_graphRange, k_numberOfCursorStepsInGradUnit, m_record); } diff --git a/apps/graph/graph/tangent_graph_controller.h b/apps/graph/graph/tangent_graph_controller.h index e75947a05..eed6d6379 100644 --- a/apps/graph/graph/tangent_graph_controller.h +++ b/apps/graph/graph/tangent_graph_controller.h @@ -24,7 +24,7 @@ private: Shared::CurveView * curveView() override { return m_graphView; } BannerView * bannerView() override { return m_bannerView; }; void reloadBannerView() override; - bool moveCursorHorizontally(int direction, bool fast = false) override; + bool moveCursorHorizontally(int direction, int scrollSpeed = 1) override; bool handleEnter() override; GraphView * m_graphView; BannerView * m_bannerView; diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index eceb6906a..519713002 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -219,7 +219,7 @@ void GraphController::reloadBannerView() { m_bannerView.reload(); } -bool GraphController::moveCursorHorizontally(int direction, bool fast) { +bool GraphController::moveCursorHorizontally(int direction, int scrollSpeed) { double x; double y; if (*m_selectedDotIndex >= 0) { @@ -235,10 +235,7 @@ bool GraphController::moveCursorHorizontally(int direction, bool fast) { } *m_selectedDotIndex = dotSelected; } else { - double step = direction * m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit; - if (fast) { - step *= 5.0; - } + double step = direction * scrollSpeed * m_store->xGridUnit()/k_numberOfCursorStepsInGradUnit; x = m_cursor->x() + step; y = yValue(*m_selectedSeriesIndex, x, globalContext()); } diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h index d81680c18..73c1d99fb 100644 --- a/apps/regression/graph_controller.h +++ b/apps/regression/graph_controller.h @@ -25,7 +25,7 @@ public: int selectedSeriesIndex() const { return *m_selectedSeriesIndex; } // moveCursorHorizontally and Vertically are public to be used in tests - bool moveCursorHorizontally(int direction, bool fast = false) override; + bool moveCursorHorizontally(int direction, int scrollSpeed = 1) override; bool moveCursorVertically(int direction) override; private: diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index cad4979f8..76a7d771a 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -79,13 +79,13 @@ bool GraphController::handleEnter() { return FunctionGraphController::handleEnter(); } -bool GraphController::moveCursorHorizontally(int direction, bool fast) { +bool GraphController::moveCursorHorizontally(int direction, int scrollSpeed) { double xCursorPosition = std::round(m_cursor->x()); if (direction < 0 && xCursorPosition <= 0) { return false; } // The cursor moves by step that is larger than 1 and than a pixel's width. - const int step = std::ceil(m_view.pixelWidth()) * (fast ? 5 : 1); + const int step = std::ceil(m_view.pixelWidth()) * scrollSpeed; double x = direction > 0 ? xCursorPosition + step: xCursorPosition - step; if (x < 0.0) { diff --git a/apps/sequence/graph/graph_controller.h b/apps/sequence/graph/graph_controller.h index 2177bc230..b08a2b3ce 100644 --- a/apps/sequence/graph/graph_controller.h +++ b/apps/sequence/graph/graph_controller.h @@ -25,7 +25,7 @@ public: private: Shared::XYBannerView * bannerView() override { return &m_bannerView; } bool handleEnter() override; - bool moveCursorHorizontally(int direction, bool fast = false) override; + bool moveCursorHorizontally(int direction, int scrollSpeed = 1) override; double defaultCursorT(Ion::Storage::Record record) override; CurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } SequenceStore * functionStore() const override { return static_cast(Shared::FunctionGraphController::functionStore()); } diff --git a/apps/shared/simple_interactive_curve_view_controller.cpp b/apps/shared/simple_interactive_curve_view_controller.cpp index 374ce26a9..bf1354c1e 100644 --- a/apps/shared/simple_interactive_curve_view_controller.cpp +++ b/apps/shared/simple_interactive_curve_view_controller.cpp @@ -28,7 +28,7 @@ bool SimpleInteractiveCurveViewController::textFieldDidReceiveEvent(TextField * bool SimpleInteractiveCurveViewController::handleLeftRightEvent(Ion::Events::Event event) { int direction = event == Ion::Events::Left ? -1 : 1; - if (moveCursorHorizontally(direction, Ion::Events::isLongRepetition())) { + if (moveCursorHorizontally(direction, Ion::Events::longRepetitionScrollSpeed())) { interactiveCurveViewRange()->panToMakePointVisible( m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio diff --git a/apps/shared/simple_interactive_curve_view_controller.h b/apps/shared/simple_interactive_curve_view_controller.h index 7827e649b..8bf2c7715 100644 --- a/apps/shared/simple_interactive_curve_view_controller.h +++ b/apps/shared/simple_interactive_curve_view_controller.h @@ -28,7 +28,7 @@ protected: /* the result of moveCursorVertically/Horizontally means: * false -> the cursor cannot move in this direction * true -> the cursor moved */ - virtual bool moveCursorHorizontally(int direction, bool fast = false) { return false; } + virtual bool moveCursorHorizontally(int direction, int scrollSpeed = 1) { return false; } virtual bool handleEnter() = 0; CurveViewCursor * m_cursor; }; diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index d3ba86fa6..19e1b0c67 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -59,6 +59,7 @@ bool isAlphaActive(); bool isLockActive(); void setLongRepetition(bool longRepetition); bool isLongRepetition(); +int longRepetitionScrollSpeed(); void updateModifiersFromEvent(Event e); void didPressNewKey(); diff --git a/ion/src/shared/events_modifier.cpp b/ion/src/shared/events_modifier.cpp index db7e24d43..b97b5376e 100644 --- a/ion/src/shared/events_modifier.cpp +++ b/ion/src/shared/events_modifier.cpp @@ -41,6 +41,10 @@ bool isLongRepetition() { return sLongRepetition; } +int longRepetitionScrollSpeed() { + return sLongRepetition ? 5 : 1; +}; + void setShiftAlphaStatus(ShiftAlphaStatus s) { sShiftAlphaStatus = s; }