diff --git a/apps/shared/Makefile b/apps/shared/Makefile index 83210f1da..080529995 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -34,6 +34,7 @@ app_objs += $(addprefix apps/shared/,\ parameter_text_field_delegate.o\ range_parameter_controller.o\ regular_table_view_data_source.o\ + simple_interactive_curve_view_controller.o\ store_controller.o\ store_parameter_controller.o\ tab_table_controller.o\ diff --git a/apps/shared/interactive_curve_view_controller.cpp b/apps/shared/interactive_curve_view_controller.cpp index acb44ceb0..c74586da7 100644 --- a/apps/shared/interactive_curve_view_controller.cpp +++ b/apps/shared/interactive_curve_view_controller.cpp @@ -8,9 +8,8 @@ using namespace Poincare; namespace Shared { InteractiveCurveViewController::InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion) : - ViewController(parentResponder), + SimpleInteractiveCurveViewController(parentResponder, interactiveRange, curveView, cursor), ButtonRowDelegate(header, nullptr), - m_cursor(cursor), m_cursorView(), m_modelVersion(modelVersion), m_rangeVersion(rangeVersion), @@ -38,10 +37,6 @@ const char * InteractiveCurveViewController::title() { return I18n::translate(I18n::Message::GraphTab); } -View * InteractiveCurveViewController::view() { - return curveView(); -} - bool InteractiveCurveViewController::handleEvent(Ion::Events::Event event) { if (!curveView()->isMainViewSelected()) { if (event == Ion::Events::Down) { @@ -59,25 +54,9 @@ bool InteractiveCurveViewController::handleEvent(Ion::Events::Event event) { } return false; } - if (event == Ion::Events::Plus) { - interactiveCurveViewRange()->zoom(2.0f/3.0f, m_cursor->x(), m_cursor->y()); - curveView()->reload(); + if (SimpleInteractiveCurveViewController::handleEvent(event)) { return true; } - if (event == Ion::Events::Minus) { - interactiveCurveViewRange()->zoom(3.0f/2.0f, m_cursor->x(), m_cursor->y()); - curveView()->reload(); - return true; - } - if (event == Ion::Events::Left || event == Ion::Events::Right) { - int direction = event == Ion::Events::Left ? -1 : 1; - if (moveCursorHorizontally(direction)) { - reloadBannerView(); - curveView()->reload(); - return true; - } - return false; - } if (event == Ion::Events::Down || event == Ion::Events::Up) { int direction = event == Ion::Events::Down ? -1 : 1; if (moveCursorVertically(direction)) { diff --git a/apps/shared/interactive_curve_view_controller.h b/apps/shared/interactive_curve_view_controller.h index a1f239dd8..2cd5301a2 100644 --- a/apps/shared/interactive_curve_view_controller.h +++ b/apps/shared/interactive_curve_view_controller.h @@ -1,10 +1,7 @@ #ifndef SHARED_INTERACTIVE_CURVE_VIEW_CONTROLLER_H #define SHARED_INTERACTIVE_CURVE_VIEW_CONTROLLER_H -#include -#include "interactive_curve_view_range.h" -#include "curve_view_cursor.h" -#include "curve_view.h" +#include "simple_interactive_curve_view_controller.h" #include "cursor_view.h" #include "ok_view.h" #include "banner_view.h" @@ -13,10 +10,9 @@ namespace Shared { -class InteractiveCurveViewController : public ViewController, public ButtonRowDelegate, public AlternateEmptyViewDelegate { +class InteractiveCurveViewController : public SimpleInteractiveCurveViewController, public ButtonRowDelegate, public AlternateEmptyViewDelegate { public: InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion); - View * view() override; const char * title() override; bool handleEvent(Ion::Events::Event event) override; void didBecomeFirstResponder() override; @@ -35,25 +31,16 @@ public: void didEnterResponderChain(Responder * previousFirstResponder) override; void willExitResponderChain(Responder * nextFirstResponder) override; protected: - constexpr static float k_numberOfCursorStepsInGradUnit = 5.0f; virtual BannerView * bannerView() = 0; virtual bool handleEnter() = 0; Responder * tabController() const; virtual StackViewController * stackController() const; - virtual void reloadBannerView() = 0; virtual void initRangeParameters() = 0; virtual void initCursorParameters() = 0; - /* the result of moveCursorVertically/Horizontally means: - * false -> the cursor cannot move in this direction - * true -> the cursor moved */ - virtual bool moveCursorHorizontally(int direction) = 0; virtual bool moveCursorVertically(int direction) = 0; virtual uint32_t modelVersion() = 0; virtual uint32_t rangeVersion() = 0; - virtual InteractiveCurveViewRange * interactiveCurveViewRange() = 0; - virtual CurveView * curveView() = 0; virtual bool isCursorVisible() = 0; - CurveViewCursor * m_cursor; CursorView m_cursorView; OkView m_okView; private: diff --git a/apps/shared/simple_interactive_curve_view_controller.cpp b/apps/shared/simple_interactive_curve_view_controller.cpp new file mode 100644 index 000000000..c465993eb --- /dev/null +++ b/apps/shared/simple_interactive_curve_view_controller.cpp @@ -0,0 +1,46 @@ +#include "simple_interactive_curve_view_controller.h" +#include +#include + +using namespace Poincare; + +namespace Shared { + +SimpleInteractiveCurveViewController::SimpleInteractiveCurveViewController(Responder * parentResponder,InteractiveCurveViewRange * interactiveRange, CurveView * curveView, 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); + } + if (event == Ion::Events::Left || event == Ion::Events::Right) { + return handleLeftRightEvent(event); + } + return false; +} + +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)) { + reloadBannerView(); + curveView()->reload(); + return true; + } + return false; +} + +} diff --git a/apps/shared/simple_interactive_curve_view_controller.h b/apps/shared/simple_interactive_curve_view_controller.h new file mode 100644 index 000000000..90d12b3b2 --- /dev/null +++ b/apps/shared/simple_interactive_curve_view_controller.h @@ -0,0 +1,35 @@ +#ifndef SHARED_SIMPLE_INTERACTIVE_CURVE_VIEW_CONTROLLER_H +#define SHARED_SIMPLE_INTERACTIVE_CURVE_VIEW_CONTROLLER_H + +#include +#include "interactive_curve_view_range.h" +#include "curve_view_cursor.h" +#include "curve_view.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: + SimpleInteractiveCurveViewController(Responder * parentResponder, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor); + View * view() override; + bool handleEvent(Ion::Events::Event event) override; +protected: + constexpr static float k_numberOfCursorStepsInGradUnit = 5.0f; + virtual bool handleZoom(Ion::Events::Event event); + virtual bool handleLeftRightEvent(Ion::Events::Event event); + virtual void reloadBannerView() {}; + /* the result of moveCursorVertically/Horizontally means: + * false -> the cursor cannot move in this direction + * true -> the cursor moved */ + virtual bool moveCursorHorizontally(int direction) { return false; }; + virtual InteractiveCurveViewRange * interactiveCurveViewRange() = 0; + virtual CurveView * curveView() = 0; + CurveViewCursor * m_cursor; +}; + +} + +#endif