[apps/shared] Create ZoomCurveViewController:

SimpleInteractiveCurveViewController inherits from
ZoomCurveViewController
This commit is contained in:
Émilie Feral
2020-03-23 12:27:11 +01:00
parent 7d48d4e7c4
commit 52b6508d6c
5 changed files with 60 additions and 27 deletions

View File

@@ -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 \
)

View File

@@ -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())) {

View File

@@ -1,21 +1,17 @@
#ifndef SHARED_SIMPLE_INTERACTIVE_CURVE_VIEW_CONTROLLER_H
#define SHARED_SIMPLE_INTERACTIVE_CURVE_VIEW_CONTROLLER_H
#include <escher/view_controller.h>
#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;
};

View File

@@ -0,0 +1,23 @@
#include "zoom_curve_view_controller.h"
#include <cmath>
#include <assert.h>
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;
}
}

View File

@@ -0,0 +1,30 @@
#ifndef SHARED_ZOOM_CURVE_VIEW_CONTROLLER_H
#define SHARED_ZOOM_CURVE_VIEW_CONTROLLER_H
#include <escher/view_controller.h>
#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