diff --git a/apps/shared/Makefile b/apps/shared/Makefile index 98e4a8fe6..1185cf65a 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -78,6 +78,7 @@ app_shared_src = $(addprefix apps/shared/,\ values_parameter_controller.cpp \ vertical_cursor_view.cpp \ xy_banner_view.cpp\ + zoom_curve_view_controller.cpp \ zoom_parameter_controller.cpp \ ) diff --git a/apps/shared/simple_interactive_curve_view_controller.cpp b/apps/shared/simple_interactive_curve_view_controller.cpp index 46a4673b1..374ce26a9 100644 --- a/apps/shared/simple_interactive_curve_view_controller.cpp +++ b/apps/shared/simple_interactive_curve_view_controller.cpp @@ -6,16 +6,6 @@ using namespace Poincare; namespace Shared { -SimpleInteractiveCurveViewController::SimpleInteractiveCurveViewController(Responder * parentResponder, CurveViewCursor * cursor) : - ViewController(parentResponder), - m_cursor(cursor) -{ -} - -View * SimpleInteractiveCurveViewController::view() { - return curveView(); -} - bool SimpleInteractiveCurveViewController::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::Plus || event == Ion::Events::Minus) { return handleZoom(event); @@ -36,13 +26,6 @@ bool SimpleInteractiveCurveViewController::textFieldDidReceiveEvent(TextField * return TextFieldDelegate::textFieldDidReceiveEvent(textField, event); } -bool SimpleInteractiveCurveViewController::handleZoom(Ion::Events::Event event) { - float ratio = event == Ion::Events::Plus ? 2.0f/3.0f : 3.0f/2.0f; - interactiveCurveViewRange()->zoom(ratio, m_cursor->x(), m_cursor->y()); - curveView()->reload(); - return true; -} - bool SimpleInteractiveCurveViewController::handleLeftRightEvent(Ion::Events::Event event) { int direction = event == Ion::Events::Left ? -1 : 1; if (moveCursorHorizontally(direction, Ion::Events::isLongRepetition())) { diff --git a/apps/shared/simple_interactive_curve_view_controller.h b/apps/shared/simple_interactive_curve_view_controller.h index fd30d2998..7827e649b 100644 --- a/apps/shared/simple_interactive_curve_view_controller.h +++ b/apps/shared/simple_interactive_curve_view_controller.h @@ -1,21 +1,17 @@ #ifndef SHARED_SIMPLE_INTERACTIVE_CURVE_VIEW_CONTROLLER_H #define SHARED_SIMPLE_INTERACTIVE_CURVE_VIEW_CONTROLLER_H -#include #include "text_field_delegate.h" -#include "interactive_curve_view_range.h" -#include "curve_view_cursor.h" -#include "curve_view.h" +#include "zoom_curve_view_controller.h" namespace Shared { /* SimpleInteractiveCurveViewController is a View controller with a cursor that * can handles zoom in/out and left and right events. */ -class SimpleInteractiveCurveViewController : public ViewController, public TextFieldDelegate { +class SimpleInteractiveCurveViewController : public ZoomCurveViewController, public TextFieldDelegate { public: - SimpleInteractiveCurveViewController(Responder * parentResponder, CurveViewCursor * cursor); - View * view() override; + SimpleInteractiveCurveViewController(Responder * parentResponder, CurveViewCursor * cursor) : ZoomCurveViewController(parentResponder), m_cursor(cursor) {} bool handleEvent(Ion::Events::Event event) override; bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override; protected: @@ -24,15 +20,15 @@ protected: virtual float cursorTopMarginRatio() { return 0.07f; } // (cursorHeight/2)/(graphViewHeight-1) virtual float cursorBottomMarginRatio() = 0; // (cursorHeight/2+bannerHeight)/(graphViewHeight-1) constexpr static float k_numberOfCursorStepsInGradUnit = 5.0f; - virtual bool handleZoom(Ion::Events::Event event); + // ZoomCurveViewController + float xFocus() override { return m_cursor->x(); } + float yFocus() override { return m_cursor->y(); } virtual bool handleLeftRightEvent(Ion::Events::Event event); virtual void reloadBannerView() = 0; /* 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 InteractiveCurveViewRange * interactiveCurveViewRange() = 0; - virtual CurveView * curveView() = 0; virtual bool handleEnter() = 0; CurveViewCursor * m_cursor; }; diff --git a/apps/shared/zoom_curve_view_controller.cpp b/apps/shared/zoom_curve_view_controller.cpp new file mode 100644 index 000000000..45c25078d --- /dev/null +++ b/apps/shared/zoom_curve_view_controller.cpp @@ -0,0 +1,23 @@ +#include "zoom_curve_view_controller.h" +#include +#include + +using namespace Poincare; + +namespace Shared { + +bool ZoomCurveViewController::handleEvent(Ion::Events::Event event) { + if (event == Ion::Events::Plus || event == Ion::Events::Minus) { + return handleZoom(event); + } + return false; +} + +bool ZoomCurveViewController::handleZoom(Ion::Events::Event event) { + float ratio = event == Ion::Events::Plus ? 2.0f/3.0f : 3.0f/2.0f; + interactiveCurveViewRange()->zoom(ratio, xFocus(), yFocus()); + curveView()->reload(); + return true; +} + +} diff --git a/apps/shared/zoom_curve_view_controller.h b/apps/shared/zoom_curve_view_controller.h new file mode 100644 index 000000000..97698ae76 --- /dev/null +++ b/apps/shared/zoom_curve_view_controller.h @@ -0,0 +1,30 @@ +#ifndef SHARED_ZOOM_CURVE_VIEW_CONTROLLER_H +#define SHARED_ZOOM_CURVE_VIEW_CONTROLLER_H + +#include +#include "interactive_curve_view_range.h" +#include "curve_view_cursor.h" +#include "curve_view.h" + +namespace Shared { + +/* ZoomCurveViewController is a View controller with a cursor that can handles + * zoom in/out events. */ + +class ZoomCurveViewController : public ViewController { +public: + ZoomCurveViewController(Responder * parentResponder) : ViewController(parentResponder) {} + View * view() override { return curveView(); } + bool handleEvent(Ion::Events::Event event) override; +protected: + virtual bool handleZoom(Ion::Events::Event event); + virtual InteractiveCurveViewRange * interactiveCurveViewRange() = 0; + virtual CurveView * curveView() = 0; + virtual float xFocus() = 0; + virtual float yFocus() = 0; + CurveViewCursor * m_cursor; +}; + +} + +#endif