From bb718b07c756c0033f7fa8f37d2d6e93c5d268d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 20 Mar 2017 10:51:23 +0100 Subject: [PATCH] [apps/sequence] Clip default range initialisation to 0 on X range for sequences Change-Id: I501a397ce3016ba605bd9aca950b87a2ca295000 --- apps/sequence/graph/curve_view_range.cpp | 51 ++++++++++++++++++++ apps/sequence/graph/curve_view_range.h | 3 ++ apps/shared/interactive_curve_view_range.cpp | 4 +- apps/shared/interactive_curve_view_range.h | 8 +-- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/apps/sequence/graph/curve_view_range.cpp b/apps/sequence/graph/curve_view_range.cpp index 14b3f94b3..9c8404725 100644 --- a/apps/sequence/graph/curve_view_range.cpp +++ b/apps/sequence/graph/curve_view_range.cpp @@ -1,6 +1,10 @@ #include "curve_view_range.h" +#include +#include +#include using namespace Shared; +using namespace Poincare; namespace Sequence { @@ -10,6 +14,53 @@ CurveViewRange::CurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRan m_xMin = -k_displayLeftMarginRatio*m_xMax; } +void CurveViewRange::roundAbscissa() { + float xMin = m_xMin; + float xMax = m_xMax; + m_xMin = roundf((xMin+xMax)/2) - (float)Ion::Display::Width/2.0f; + m_xMax = roundf((xMin+xMax)/2) + (float)Ion::Display::Width/2.0f-1.0f; + if (m_xMin < 0.0f) { + m_xMin = -k_displayLeftMarginRatio*(float)Ion::Display::Width; + m_xMax = m_xMin+(float)Ion::Display::Width; + } + m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); + if (m_delegate) { + m_delegate->didChangeRange(this); + } +} + +void CurveViewRange::normalize() { + float xMin = m_xMin; + float xMax = m_xMax; + float yMin = m_yMin; + float yMax = m_yMax; + m_xMin = (xMin+xMax)/2 - 5.3f; + m_xMax = (xMin+xMax)/2 + 5.3f; + if (m_xMin < 0.0f) { + m_xMin = -k_displayLeftMarginRatio*2.0f*5.3f; + m_xMax = m_xMin + 2.0f*5.3f; + } + m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); + m_yAuto = false; + m_yMin = (yMin+yMax)/2 - 3.1f; + m_yMax = (yMin+yMax)/2 + 3.1f; + m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax); +} + +void CurveViewRange::setTrigonometric() { + m_xMin = -k_displayLeftMarginRatio*21.0f; + m_xMax = 21.0f; + if (Preferences::sharedPreferences()->angleUnit() == Expression::AngleUnit::Degree) { + m_xMin = -k_displayLeftMarginRatio*1200; + m_xMax = 1200; + } + m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); + m_yAuto = false; + m_yMin = -1.6f; + m_yMax = 1.6f; + m_yGridUnit = computeGridUnit(Axis::Y, m_yMin, m_yMax); +} + void CurveViewRange::setDefault() { m_xMax = 10.0f; 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 023035d95..57c45203e 100644 --- a/apps/sequence/graph/curve_view_range.h +++ b/apps/sequence/graph/curve_view_range.h @@ -8,6 +8,9 @@ namespace Sequence { class CurveViewRange : public Shared::InteractiveCurveViewRange { public: CurveViewRange(Shared::CurveViewCursor * cursor, Shared::InteractiveCurveViewRangeDelegate * delegate); + void roundAbscissa() override; + void normalize() override; + void setTrigonometric() override; void setDefault() override; private: constexpr static float k_displayLeftMarginRatio = 0.05f; diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index 535194590..5dff2c023 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -12,8 +12,8 @@ namespace Shared { InteractiveCurveViewRange::InteractiveCurveViewRange(CurveViewCursor * cursor, InteractiveCurveViewRangeDelegate * delegate) : MemoizedCurveViewRange(), m_yAuto(true), - m_cursor(cursor), - m_delegate(delegate) + m_delegate(delegate), + m_cursor(cursor) { } diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index 2aebff7fe..6272f402c 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -25,18 +25,18 @@ public: // Window void zoom(float ratio); void panWithVector(float x, float y); - void roundAbscissa(); - void normalize(); - void setTrigonometric(); + virtual void roundAbscissa(); + virtual void normalize(); + virtual void setTrigonometric(); virtual void setDefault(); void centerAxisAround(Axis axis, float position); void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation); protected: bool m_yAuto; + InteractiveCurveViewRangeDelegate * m_delegate; private: constexpr static float k_minFloat = 1E-8f; CurveViewCursor * m_cursor; - InteractiveCurveViewRangeDelegate * m_delegate; }; typedef void (InteractiveCurveViewRange::*ParameterSetterPointer)(float);