diff --git a/apps/graph/app.cpp b/apps/graph/app.cpp index 40d00f345..01ea5285d 100644 --- a/apps/graph/app.cpp +++ b/apps/graph/app.cpp @@ -23,7 +23,7 @@ const Image * App::Descriptor::icon() { App::Snapshot::Snapshot() : Shared::FunctionApp::Snapshot::Snapshot(), m_functionStore(), - m_graphRange(&m_cursor) + m_graphRange() { } diff --git a/apps/graph/graph/graph_controller_helper.h b/apps/graph/graph/graph_controller_helper.h index f6c300cf9..acec972a7 100644 --- a/apps/graph/graph/graph_controller_helper.h +++ b/apps/graph/graph/graph_controller_helper.h @@ -2,9 +2,8 @@ #define GRAPH_GRAPH_CONTROLLER_HELPER_H #include "banner_view.h" -#include "../../shared/text_field_delegate_app.h" +#include "../../shared/curve_view_cursor.h" #include "../../shared/interactive_curve_view_range.h" -#include "../cartesian_function_store.h" namespace Graph { diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index 1134106c9..1c6d36efb 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -28,7 +28,6 @@ GraphController::GraphController(Responder * parentResponder, InputEventHandlerD for (int i = 0; i < Store::k_numberOfSeries; i++) { m_modelType[i] = (Model::Type) -1; } - m_store->setCursor(m_cursor); m_store->setDelegate(this); } @@ -349,10 +348,6 @@ uint32_t GraphController::rangeVersion() { return m_store->rangeChecksum(); } -bool GraphController::isCursorVisible() { - return interactiveCurveViewRange()->isCursorVisible(cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); -} - bool GraphController::closestCurveIndexIsSuitable(int newIndex, int currentIndex) const { return newIndex != currentIndex && !m_store->seriesIsEmpty(newIndex); } diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h index c3e14ee27..49bc1076e 100644 --- a/apps/regression/graph_controller.h +++ b/apps/regression/graph_controller.h @@ -44,7 +44,6 @@ private: void initCursorParameters() override; uint32_t modelVersion() override; uint32_t rangeVersion() override; - bool isCursorVisible() override; bool closestCurveIndexIsSuitable(int newIndex, int currentIndex) const override; double yValue(int curveIndex, double x, Poincare::Context * context) const override; bool suitableYValue(double y) const override; diff --git a/apps/regression/store.cpp b/apps/regression/store.cpp index 5e342a999..683849169 100644 --- a/apps/regression/store.cpp +++ b/apps/regression/store.cpp @@ -17,7 +17,7 @@ static_assert(Model::k_numberOfModels == 9, "Number of models changed, Regressio static_assert(Store::k_numberOfSeries == 3, "Number of series changed, Regression::Store() needs to adapt (m_seriesChecksum)"); Store::Store() : - InteractiveCurveViewRange(nullptr), + InteractiveCurveViewRange(), DoublePairStore(), m_seriesChecksum{0, 0, 0}, m_angleUnit(Poincare::Preferences::AngleUnit::Degree) diff --git a/apps/sequence/app.cpp b/apps/sequence/app.cpp index f2e1f42c2..b40a26c19 100644 --- a/apps/sequence/app.cpp +++ b/apps/sequence/app.cpp @@ -21,7 +21,7 @@ const Image * App::Descriptor::icon() { App::Snapshot::Snapshot() : Shared::FunctionApp::Snapshot::Snapshot(), m_sequenceStore(), - m_graphRange(&m_cursor) + m_graphRange() { } diff --git a/apps/sequence/graph/curve_view_range.cpp b/apps/sequence/graph/curve_view_range.cpp index 444422906..821a152cd 100644 --- a/apps/sequence/graph/curve_view_range.cpp +++ b/apps/sequence/graph/curve_view_range.cpp @@ -8,8 +8,8 @@ using namespace Poincare; namespace Sequence { -CurveViewRange::CurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate) : - InteractiveCurveViewRange(cursor, delegate) +CurveViewRange::CurveViewRange(InteractiveCurveViewRangeDelegate * delegate) : + InteractiveCurveViewRange(delegate) { m_xMin = -k_displayLeftMarginRatio * m_xMax; } diff --git a/apps/sequence/graph/curve_view_range.h b/apps/sequence/graph/curve_view_range.h index ac9316220..cb50fb502 100644 --- a/apps/sequence/graph/curve_view_range.h +++ b/apps/sequence/graph/curve_view_range.h @@ -7,7 +7,7 @@ namespace Sequence { class CurveViewRange : public Shared::InteractiveCurveViewRange { public: - CurveViewRange(Shared::CurveViewCursor * cursor, Shared::InteractiveCurveViewRangeDelegate * delegate = nullptr); + CurveViewRange(Shared::InteractiveCurveViewRangeDelegate * delegate = nullptr); void roundAbscissa() override; void normalize() override; void setTrigonometric() override; diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index 56776141e..ab1b09d8d 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -148,10 +148,6 @@ uint32_t FunctionGraphController::rangeVersion() { return interactiveCurveViewRange()->rangeChecksum(); } -bool FunctionGraphController::isCursorVisible() { - return interactiveCurveViewRange()->isCursorVisible(cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); -} - bool FunctionGraphController::closestCurveIndexIsSuitable(int newIndex, int currentIndex) const { return newIndex != currentIndex; } diff --git a/apps/shared/function_graph_controller.h b/apps/shared/function_graph_controller.h index 189ebc09d..bf43ca2df 100644 --- a/apps/shared/function_graph_controller.h +++ b/apps/shared/function_graph_controller.h @@ -40,7 +40,6 @@ private: CurveView * curveView() override; uint32_t modelVersion() override; uint32_t rangeVersion() override; - bool isCursorVisible() override; bool closestCurveIndexIsSuitable(int newIndex, int currentIndex) const override; double yValue(int curveIndex, double x, Poincare::Context * context) const override; int numberOfCurves() const override; diff --git a/apps/shared/interactive_curve_view_controller.cpp b/apps/shared/interactive_curve_view_controller.cpp index 4ddb006a6..1c34e476a 100644 --- a/apps/shared/interactive_curve_view_controller.cpp +++ b/apps/shared/interactive_curve_view_controller.cpp @@ -194,6 +194,17 @@ StackViewController * InteractiveCurveViewController::stackController() const{ return (StackViewController *)(parentResponder()->parentResponder()->parentResponder()); } +bool InteractiveCurveViewController::isCursorVisible() { + InteractiveCurveViewRange * range = interactiveCurveViewRange(); + float xRange = range->xMax() - range->xMin(); + float yRange = range->yMax() - range->yMin(); + return + m_cursor->x() >= range->xMin() + k_cursorLeftMarginRatio * xRange && + m_cursor->x() <= range->xMax() - k_cursorRightMarginRatio * xRange && + m_cursor->y() >= range->yMin() + cursorBottomMarginRatio() * yRange && + m_cursor->y() <= range->yMax() - cursorTopMarginRatio() * yRange; +} + int InteractiveCurveViewController::closestCurveIndexVertically(bool goingUp, int currentCurveIndex, Poincare::Context * context) const { double x = m_cursor->x(); double y = m_cursor->y(); diff --git a/apps/shared/interactive_curve_view_controller.h b/apps/shared/interactive_curve_view_controller.h index a6871bb9b..c1b9fc029 100644 --- a/apps/shared/interactive_curve_view_controller.h +++ b/apps/shared/interactive_curve_view_controller.h @@ -37,7 +37,7 @@ protected: virtual bool moveCursorVertically(int direction) = 0; virtual uint32_t modelVersion() = 0; virtual uint32_t rangeVersion() = 0; - virtual bool isCursorVisible() = 0; + bool isCursorVisible(); // Closest vertical curve helper int closestCurveIndexVertically(bool goingUp, int currentSelectedCurve, Poincare::Context * context) const; diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index 7bf8f63eb..bb5ef39a5 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -208,12 +208,6 @@ void InteractiveCurveViewRange::panToMakePointVisible(float x, float y, float to } } -bool InteractiveCurveViewRange::isCursorVisible(float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation) { - float xRange = m_xMax - m_xMin; - float yRange = m_yMax - m_yMin; - return m_cursor->x() >= m_xMin + leftMarginRation*xRange && m_cursor->x() <= m_xMax - rightMarginRatio*xRange && m_cursor->y() >= m_yMin + bottomMarginRation*yRange && m_cursor->y() <= m_yMax - topMarginRatio*yRange; -} - float InteractiveCurveViewRange::clipped(float x, bool isMax) { float maxF = isMax ? k_upperMaxFloat : k_lowerMaxFloat; float minF = isMax ? -k_lowerMaxFloat : -k_upperMaxFloat; diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index 6ea5cb4ef..fc695ccd7 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -3,7 +3,6 @@ #include #include "memoized_curve_view_range.h" -#include "curve_view_cursor.h" #include "interactive_curve_view_range_delegate.h" #include #include @@ -13,15 +12,13 @@ namespace Shared { class InteractiveCurveViewRange : public MemoizedCurveViewRange { public: constexpr static float k_minFloat = 1E-4f; - InteractiveCurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate = nullptr) : + InteractiveCurveViewRange(InteractiveCurveViewRangeDelegate * delegate = nullptr) : MemoizedCurveViewRange(), m_yAuto(true), - m_delegate(delegate), - m_cursor(cursor) + m_delegate(delegate) {} void setDelegate(InteractiveCurveViewRangeDelegate * delegate) { m_delegate = delegate; } - void setCursor(CurveViewCursor * cursor) { m_cursor = cursor; } uint32_t rangeChecksum() override; bool yAuto() const { return m_yAuto; } @@ -42,7 +39,6 @@ public: virtual void setDefault(); void centerAxisAround(Axis axis, float position); void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation); - bool isCursorVisible(float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation); protected: bool m_yAuto; /* In normalized settings, we put each axis so that 1cm = 2 units. For now, @@ -64,7 +60,6 @@ private: constexpr static float k_lowerMaxFloat = 9E+7f; constexpr static float k_maxRatioPositionRange = 1E5f; void notifyRangeChange(); - CurveViewCursor * m_cursor; }; static_assert(InteractiveCurveViewRange::k_minFloat >= FLT_EPSILON, "InteractiveCurveViewRange's minimal float range is lower than float precision, it might draw uglily curves such as cos(x)^2+sin(x)^2");