interactive_curve_view_controller.cpp
5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "interactive_curve_view_controller.h"
#include "text_field_delegate_app.h"
#include <cmath>
#include <assert.h>
using namespace Poincare;
namespace Shared {
InteractiveCurveViewController::InteractiveCurveViewController(Responder * parentResponder, ButtonRowController * header, InteractiveCurveViewRange * interactiveRange, CurveView * curveView, CurveViewCursor * cursor, uint32_t * modelVersion, uint32_t * rangeVersion) :
SimpleInteractiveCurveViewController(parentResponder, interactiveRange, curveView, cursor),
ButtonRowDelegate(header, nullptr),
m_modelVersion(modelVersion),
m_rangeVersion(rangeVersion),
m_rangeParameterController(this, interactiveRange),
m_zoomParameterController(this, interactiveRange, curveView),
m_rangeButton(this, I18n::Message::Axis, Invocation([](void * context, void * sender) {
InteractiveCurveViewController * graphController = (InteractiveCurveViewController *) context;
StackViewController * stack = graphController->stackController();
stack->push(graphController->rangeParameterController());
}, this), KDText::FontSize::Small),
m_zoomButton(this, I18n::Message::Zoom, Invocation([](void * context, void * sender) {
InteractiveCurveViewController * graphController = (InteractiveCurveViewController *) context;
StackViewController * stack = graphController->stackController();
stack->push(graphController->zoomParameterController());
}, this), KDText::FontSize::Small),
m_defaultInitialisationButton(this, I18n::Message::Initialization, Invocation([](void * context, void * sender) {
InteractiveCurveViewController * graphController = (InteractiveCurveViewController *) context;
StackViewController * stack = graphController->stackController();
stack->push(graphController->initialisationParameterController());
}, this), KDText::FontSize::Small)
{
}
const char * InteractiveCurveViewController::title() {
return I18n::translate(I18n::Message::GraphTab);
}
bool InteractiveCurveViewController::handleEvent(Ion::Events::Event event) {
if (!curveView()->isMainViewSelected()) {
if (event == Ion::Events::Down) {
header()->setSelectedButton(-1);
curveView()->selectMainView(true);
app()->setFirstResponder(this);
reloadBannerView();
curveView()->reload();
return true;
}
if (event == Ion::Events::Up) {
header()->setSelectedButton(-1);
app()->setFirstResponder(tabController());
return true;
}
return false;
}
if (SimpleInteractiveCurveViewController::handleEvent(event)) {
return true;
}
if (event == Ion::Events::Down || event == Ion::Events::Up) {
int direction = event == Ion::Events::Down ? -1 : 1;
if (moveCursorVertically(direction)) {
reloadBannerView();
curveView()->reload();
return true;
}
if (event == Ion::Events::Down) {
return false;
}
curveView()->selectMainView(false);
header()->setSelectedButton(0);
return true;
}
return false;
}
void InteractiveCurveViewController::didBecomeFirstResponder() {
if (!curveView()->isMainViewSelected()) {
header()->setSelectedButton(0);
}
}
ViewController * InteractiveCurveViewController::rangeParameterController() {
return &m_rangeParameterController;
}
ViewController * InteractiveCurveViewController::zoomParameterController() {
return &m_zoomParameterController;
}
int InteractiveCurveViewController::numberOfButtons(ButtonRowController::Position) const {
if (isEmpty()) {
return 0;
}
return 3;
}
Button * InteractiveCurveViewController::buttonAtIndex(int index, ButtonRowController::Position position) const {
const Button * buttons[3] = {&m_rangeButton, &m_zoomButton, &m_defaultInitialisationButton};
return (Button *)buttons[index];
}
Responder * InteractiveCurveViewController::defaultController() {
return tabController();
}
void InteractiveCurveViewController::viewWillAppear() {
uint32_t newModelVersion = modelVersion();
if (*m_modelVersion != newModelVersion) {
*m_modelVersion = newModelVersion;
initRangeParameters();
/* Warning: init cursor parameter before reloading banner view. Indeed,
* reloading banner view needs an updated cursor to load the right data. */
initCursorParameters();
}
uint32_t newRangeVersion = rangeVersion();
if (*m_rangeVersion != newRangeVersion) {
*m_rangeVersion = newRangeVersion;
if (!isCursorVisible()) {
initCursorParameters();
}
}
curveView()->setOkView(&m_okView);
if (!curveView()->isMainViewSelected()) {
curveView()->selectMainView(true);
header()->setSelectedButton(-1);
}
reloadBannerView();
curveView()->reload();
}
void InteractiveCurveViewController::viewDidDisappear() {
*m_rangeVersion = rangeVersion();
}
void InteractiveCurveViewController::didEnterResponderChain(Responder * previousFirstResponder) {
reloadBannerView();
curveView()->reload();
}
void InteractiveCurveViewController::willExitResponderChain(Responder * nextFirstResponder) {
if (nextFirstResponder == nullptr || nextFirstResponder == tabController()) {
curveView()->selectMainView(false);
header()->setSelectedButton(-1);
curveView()->reload();
}
}
Responder * InteractiveCurveViewController::tabController() const{
return (stackController()->parentResponder());
}
StackViewController * InteractiveCurveViewController::stackController() const{
return (StackViewController *)(parentResponder()->parentResponder()->parentResponder());
}
}