mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/shared] Create ZoomCurveViewController:
SimpleInteractiveCurveViewController inherits from ZoomCurveViewController
This commit is contained in:
@@ -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 \
|
||||
)
|
||||
|
||||
|
||||
@@ -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())) {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
23
apps/shared/zoom_curve_view_controller.cpp
Normal file
23
apps/shared/zoom_curve_view_controller.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
30
apps/shared/zoom_curve_view_controller.h
Normal file
30
apps/shared/zoom_curve_view_controller.h
Normal 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
|
||||
Reference in New Issue
Block a user