mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps] Factorize scrolling speed for long repetition
Change-Id: I5fcfaf04e418942664641c4b1cd044cda7f5aebb
This commit is contained in:
committed by
Émilie Feral
parent
241a217f58
commit
b60c67ff88
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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<ContinuousFunction> 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<double> xy = function->evaluateXYAtParameter(t, App::app()->localContext());
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<SequenceStore *>(Shared::FunctionGraphController::functionStore()); }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -59,6 +59,7 @@ bool isAlphaActive();
|
||||
bool isLockActive();
|
||||
void setLongRepetition(bool longRepetition);
|
||||
bool isLongRepetition();
|
||||
int longRepetitionScrollSpeed();
|
||||
void updateModifiersFromEvent(Event e);
|
||||
void didPressNewKey();
|
||||
|
||||
|
||||
@@ -41,6 +41,10 @@ bool isLongRepetition() {
|
||||
return sLongRepetition;
|
||||
}
|
||||
|
||||
int longRepetitionScrollSpeed() {
|
||||
return sLongRepetition ? 5 : 1;
|
||||
};
|
||||
|
||||
void setShiftAlphaStatus(ShiftAlphaStatus s) {
|
||||
sShiftAlphaStatus = s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user