diff --git a/apps/graph/Makefile b/apps/graph/Makefile index 44f6d9344..94fd50153 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -4,8 +4,8 @@ app_objs += $(addprefix apps/graph/,\ function.o\ function_store.o\ function_title_cell.o\ - graph/axis_interval.o\ - graph/axis_parameter_controller.o\ + graph/graph_window.o\ + graph/window_parameter_controller.o\ graph/cursor_view.o\ graph/curve_parameter_controller.o\ graph/goto_parameter_controller.o\ diff --git a/apps/graph/graph/axis_parameter_controller.cpp b/apps/graph/graph/axis_parameter_controller.cpp deleted file mode 100644 index 97be87422..000000000 --- a/apps/graph/graph/axis_parameter_controller.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "axis_parameter_controller.h" -#include - -namespace Graph { - -AxisParameterController::AxisParameterController(Responder * parentResponder, AxisInterval * axisInterval, GraphView * graphView) : - FloatParameterController(parentResponder), - m_axisInterval(axisInterval), - m_yAutoCell(SwitchMenuListCell((char*)"Y auto")), - m_graphView(graphView) -{ - m_axisCells[0].setText("Xmin"); - m_axisCells[1].setText("Xmax"); - m_axisCells[2].setText("Ymin"); - m_axisCells[3].setText("Ymax"); - -} - -ExpressionTextFieldDelegate * AxisParameterController::textFieldDelegate() { - ExpressionTextFieldDelegate * myApp = (ExpressionTextFieldDelegate *)app(); - return myApp; -} - -const char * AxisParameterController::title() const { - return "Axes"; -} - -void AxisParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) { - if (index == 2) { - SwitchView * switchView = (SwitchView *)m_yAutoCell.accessoryView(); - switchView->setState(m_axisInterval->yAuto()); - return; - } - if (index == 3 || index == 4) { - if (m_axisInterval->yAuto()) { - m_axisCells[index-1].setTextColor(Palette::DesactiveTextColor); - } else { - m_axisCells[index-1].setTextColor(KDColorBlack); - } - } - FloatParameterController::willDisplayCellForIndex(cell, index); -} - -bool AxisParameterController::handleEvent(Ion::Events::Event event) { - m_graphView->initCursorPosition(); - if (activeCell() == 2) { - if (event == Ion::Events::OK) { - m_axisInterval->setYAuto(!m_axisInterval->yAuto()); - m_selectableTableView.reloadData(); - return true; - } - return false; - } - if (m_axisInterval->yAuto() && (activeCell() == 3 || activeCell() == 4)) { - return false; - } - return FloatParameterController::handleEvent(event); -} - -float AxisParameterController::parameterAtIndex(int index) { - switch (index) { - case 0: - return m_axisInterval->xMin(); - case 1: - return m_axisInterval->xMax(); - case 3: - return m_axisInterval->yMin(); - case 4: - return m_axisInterval->yMax(); - default: - assert(false); - return 0.0f; - } -} - -void AxisParameterController::setParameterAtIndex(int parameterIndex, float f) { - switch(parameterIndex) { - case 0: - m_axisInterval->setXMin(f); - break; - case 1: - m_axisInterval->setXMax(f); - break; - case 3: - m_axisInterval->setYMin(f); - break; - case 4: - m_axisInterval->setYMax(f); - break; - default: - assert(false); - } -} - -int AxisParameterController::numberOfRows() { - return k_numberOfTextCell+1; -}; - -TableViewCell * AxisParameterController::reusableCell(int index) { - if (index == 2) { - return &m_yAutoCell; - } - int cellIndex = index > 2 ? index - 1 : index; - assert(cellIndex >= 0); - assert(cellIndex < k_numberOfTextCell); - return &m_axisCells[cellIndex]; -} - -int AxisParameterController::reusableCellCount() { - return k_numberOfTextCell+1; -} - -} diff --git a/apps/graph/graph/goto_parameter_controller.h b/apps/graph/graph/goto_parameter_controller.h index c62efc60f..615f0c2bd 100644 --- a/apps/graph/graph/goto_parameter_controller.h +++ b/apps/graph/graph/goto_parameter_controller.h @@ -2,7 +2,6 @@ #define GRAPH_GRAPH_GOTO_PARAMETER_CONTROLLER_H #include -#include "axis_interval.h" #include "graph_view.h" #include "../../float_parameter_controller.h" diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 22360a2ac..7ab6f98e6 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -8,16 +8,16 @@ namespace Graph { GraphController::GraphController(Responder * parentResponder, FunctionStore * functionStore, HeaderViewController * header) : ViewController(parentResponder), HeaderViewDelegate(header), - m_view(GraphView(functionStore, &m_axisInterval)), - m_axisInterval(functionStore), - m_axisParameterController(AxisParameterController(this, &m_axisInterval, &m_view)), - m_zoomParameterController(ZoomParameterController(this, &m_axisInterval, &m_view)), - m_initialisationParameterController(InitialisationParameterController(this, &m_axisInterval, &m_view)), + m_view(GraphView(functionStore, &m_graphWindow)), + m_graphWindow(functionStore), + m_windowParameterController(WindowParameterController(this, &m_graphWindow, &m_view)), + m_zoomParameterController(ZoomParameterController(this, &m_graphWindow, &m_view)), + m_initialisationParameterController(InitialisationParameterController(this, &m_graphWindow, &m_view)), m_curveParameterController(CurveParameterController(&m_view)), - m_axisButton(this, "Axes", Invocation([](void * context, void * sender) { + m_windowButton(this, "Axes", Invocation([](void * context, void * sender) { GraphController * graphController = (GraphController *) context; StackViewController * stack = graphController->stackController(); - stack->push(graphController->axisParameterController()); + stack->push(graphController->windowParameterController()); }, this)), m_zoomButton(this, "Zoom", Invocation([](void * context, void * sender) { GraphController * graphController = (GraphController *) context; @@ -70,8 +70,8 @@ StackViewController * GraphController::stackController() const{ return (StackViewController *)(parentResponder()->parentResponder()->parentResponder()); } -ViewController * GraphController::axisParameterController() { - return &m_axisParameterController; +ViewController * GraphController::windowParameterController() { + return &m_windowParameterController; } ViewController * GraphController::zoomParameterController() { @@ -89,7 +89,7 @@ int GraphController::numberOfButtons() const { Button * GraphController::buttonAtIndex(int index) { switch (index) { case 0: - return &m_axisButton; + return &m_windowButton; case 1: return &m_zoomButton; case 2: @@ -105,12 +105,12 @@ void GraphController::didBecomeFirstResponder() { App * graphApp = (Graph::App *)app(); m_view.setContext(graphApp->evaluateContext()); } - if (m_axisInterval.context() == nullptr) { + if (m_graphWindow.context() == nullptr) { App * graphApp = (Graph::App *)app(); - m_axisInterval.setContext(graphApp->evaluateContext()); + m_graphWindow.setContext(graphApp->evaluateContext()); } - // if new functions were added to the store, the axis interval needs to be refresh - m_axisInterval.computeYaxes(); + // if new functions were added to the store, the window parameters need to be refresh + m_graphWindow.computeYaxes(); headerViewController()->setSelectedButton(-1); m_headerSelected = false; @@ -137,29 +137,29 @@ bool GraphController::handleEvent(Ion::Events::Event event) { return headerViewController()->handleEvent(event); } else { if (event == Ion::Events::Plus) { - float xMin = m_axisInterval.xMin(); - float xMax = m_axisInterval.xMax(); - float yMin = m_axisInterval.yMin(); - float yMax = m_axisInterval.yMax(); - m_axisInterval.setXMin((xMax+xMin)/2.0f - fabsf(xMax-xMin)/3.0f); - m_axisInterval.setXMax((xMax+xMin)/2.0f + fabsf(xMax-xMin)/3.0f); - m_axisInterval.setYAuto(false); - m_axisInterval.setYMin((yMax+yMin)/2.0f - fabsf(yMax-yMin)/3.0f); - m_axisInterval.setYMax((yMax+yMin)/2.0f + fabsf(yMax-yMin)/3.0f); + float xMin = m_graphWindow.xMin(); + float xMax = m_graphWindow.xMax(); + float yMin = m_graphWindow.yMin(); + float yMax = m_graphWindow.yMax(); + m_graphWindow.setXMin((xMax+xMin)/2.0f - fabsf(xMax-xMin)/3.0f); + m_graphWindow.setXMax((xMax+xMin)/2.0f + fabsf(xMax-xMin)/3.0f); + m_graphWindow.setYAuto(false); + m_graphWindow.setYMin((yMax+yMin)/2.0f - fabsf(yMax-yMin)/3.0f); + m_graphWindow.setYMax((yMax+yMin)/2.0f + fabsf(yMax-yMin)/3.0f); m_view.initCursorPosition(); m_view.reload(); return true; } if (event == Ion::Events::Minus) { - float xMin = m_axisInterval.xMin(); - float xMax = m_axisInterval.xMax(); - float yMin = m_axisInterval.yMin(); - float yMax = m_axisInterval.yMax(); - m_axisInterval.setXMin((xMax+xMin)/2.0f - 3.0f*fabsf(xMax-xMin)/4.0f); - m_axisInterval.setXMax((xMax+xMin)/2.0f + 3.0f*fabsf(xMax-xMin)/4.0f); - m_axisInterval.setYAuto(false); - m_axisInterval.setYMin((yMax+yMin)/2.0f - 3.0f*fabsf(yMax-yMin)/4.0f); - m_axisInterval.setYMax((yMax+yMin)/2.0f + 3.0f*fabsf(yMax-yMin)/4.0f); + float xMin = m_graphWindow.xMin(); + float xMax = m_graphWindow.xMax(); + float yMin = m_graphWindow.yMin(); + float yMax = m_graphWindow.yMax(); + m_graphWindow.setXMin((xMax+xMin)/2.0f - 3.0f*fabsf(xMax-xMin)/4.0f); + m_graphWindow.setXMax((xMax+xMin)/2.0f + 3.0f*fabsf(xMax-xMin)/4.0f); + m_graphWindow.setYAuto(false); + m_graphWindow.setYMin((yMax+yMin)/2.0f - 3.0f*fabsf(yMax-yMin)/4.0f); + m_graphWindow.setYMax((yMax+yMin)/2.0f + 3.0f*fabsf(yMax-yMin)/4.0f); m_view.initCursorPosition(); m_view.reload(); return true; diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index c0e61671f..e3ca11174 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -3,8 +3,8 @@ #include #include "graph_view.h" -#include "axis_interval.h" -#include "axis_parameter_controller.h" +#include "graph_window.h" +#include "window_parameter_controller.h" #include "curve_parameter_controller.h" #include "initialisation_parameter_controller.h" #include "zoom_parameter_controller.h" @@ -18,7 +18,7 @@ public: View * view() override; bool handleEvent(Ion::Events::Event event) override; void didBecomeFirstResponder() override; - ViewController * axisParameterController(); + ViewController * windowParameterController(); ViewController * zoomParameterController(); ViewController * initialisationParameterController(); @@ -34,12 +34,12 @@ private: StackViewController * stackController() const; GraphView m_view; bool m_headerSelected; - AxisInterval m_axisInterval; - AxisParameterController m_axisParameterController; + GraphWindow m_graphWindow; + WindowParameterController m_windowParameterController; ZoomParameterController m_zoomParameterController; InitialisationParameterController m_initialisationParameterController; CurveParameterController m_curveParameterController; - Button m_axisButton; + Button m_windowButton; Button m_zoomButton; Button m_defaultInitialisationButton; FunctionStore * m_functionStore; diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 1697d7e6b..82eeae890 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -7,13 +7,13 @@ namespace Graph { constexpr KDColor GraphView::k_gridColor; -GraphView::GraphView(FunctionStore * functionStore, AxisInterval * axisInterval) : +GraphView::GraphView(FunctionStore * functionStore, GraphWindow * graphWindow) : CurveView(), m_cursorView(CursorView()), m_xCursorPosition(-1.0f), m_yCursorPosition(-1.0f), m_visibleCursor(true), - m_axisInterval(axisInterval), + m_graphWindow(graphWindow), m_functionStore(functionStore), m_evaluateContext(nullptr) { @@ -48,7 +48,7 @@ void GraphView::reload() { } float GraphView::scale(Axis axis) const { - return (axis == Axis::Horizontal ? m_axisInterval->xScale() : m_axisInterval->yScale()); + return (axis == Axis::Horizontal ? m_graphWindow->xScale() : m_graphWindow->yScale()); } char * GraphView::label(Axis axis, int index) const { @@ -66,13 +66,13 @@ float GraphView::xCursorPosition() { void GraphView::setXCursorPosition(float xPosition, Function * function) { float xRange = max(Axis::Horizontal) - min(Axis::Horizontal); float yRange = max(Axis::Horizontal) - min(Axis::Horizontal); - m_axisInterval->setXMin(xPosition - xRange/2.0f); - m_axisInterval->setXMax(xPosition + xRange/2.0f); + m_graphWindow->setXMin(xPosition - xRange/2.0f); + m_graphWindow->setXMax(xPosition + xRange/2.0f); m_xCursorPosition = floatToPixel(Axis::Horizontal, xPosition); float yPosition = function->evaluateAtAbscissa(xPosition, m_evaluateContext); - m_axisInterval->setYAuto(false); - m_axisInterval->setYMin(yPosition - yRange/2.0f); - m_axisInterval->setYMax(yPosition + yRange/2.0f); + m_graphWindow->setYAuto(false); + m_graphWindow->setYMin(yPosition - yRange/2.0f); + m_graphWindow->setYMax(yPosition + yRange/2.0f); m_yCursorPosition = floatToPixel(Axis::Vertical, yPosition); reload(); } @@ -96,14 +96,14 @@ void GraphView::moveCursorHorizontally(KDCoordinate xOffset) { m_xCursorPosition = m_xCursorPosition + xOffset; if (!outsideWindow && m_xCursorPosition < k_cursorMarginToBorder) { float xRange = max(Axis::Horizontal) - min(Axis::Horizontal); - m_axisInterval->setXMin(pixelToFloat(Axis::Horizontal, floorf(m_xCursorPosition)-k_cursorMarginToBorder)); - m_axisInterval->setXMax(min(Axis::Horizontal) + xRange); + m_graphWindow->setXMin(pixelToFloat(Axis::Horizontal, floorf(m_xCursorPosition)-k_cursorMarginToBorder)); + m_graphWindow->setXMax(min(Axis::Horizontal) + xRange); m_xCursorPosition = m_xCursorPosition - floorf(m_xCursorPosition) + k_cursorMarginToBorder; } if (!outsideWindow && m_xCursorPosition > bounds().width() - k_cursorMarginToBorder) { float xRange = max(Axis::Horizontal) - min(Axis::Horizontal); - m_axisInterval->setXMax(pixelToFloat(Axis::Horizontal, ceilf(m_xCursorPosition)+k_cursorMarginToBorder)); - m_axisInterval->setXMin(max(Axis::Horizontal) - xRange); + m_graphWindow->setXMax(pixelToFloat(Axis::Horizontal, ceilf(m_xCursorPosition)+k_cursorMarginToBorder)); + m_graphWindow->setXMin(max(Axis::Horizontal) - xRange); m_xCursorPosition = bounds().width() - k_cursorMarginToBorder - ceilf(m_xCursorPosition) + m_xCursorPosition; } Function * f = m_functionStore->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); @@ -111,14 +111,14 @@ void GraphView::moveCursorHorizontally(KDCoordinate xOffset) { m_yCursorPosition = floatToPixel(Axis::Vertical, ordinate); if (!outsideWindow && m_yCursorPosition < k_cursorMarginToBorder) { float yRange = max(Axis::Vertical) - min(Axis::Vertical); - m_axisInterval->setYMax(pixelToFloat(Axis::Vertical, floorf(m_yCursorPosition)-k_cursorMarginToBorder)); - m_axisInterval->setYMin(max(Axis::Vertical) - yRange); + m_graphWindow->setYMax(pixelToFloat(Axis::Vertical, floorf(m_yCursorPosition)-k_cursorMarginToBorder)); + m_graphWindow->setYMin(max(Axis::Vertical) - yRange); m_yCursorPosition = m_yCursorPosition - floorf(m_yCursorPosition) + k_cursorMarginToBorder; } if (!outsideWindow && m_yCursorPosition > bounds().height() - k_cursorMarginToBorder) { float yRange = max(Axis::Vertical) - min(Axis::Vertical); - m_axisInterval->setYMin(pixelToFloat(Axis::Vertical, ceilf(m_yCursorPosition)+k_cursorMarginToBorder)); - m_axisInterval->setYMax(min(Axis::Vertical) + yRange); + m_graphWindow->setYMin(pixelToFloat(Axis::Vertical, ceilf(m_yCursorPosition)+k_cursorMarginToBorder)); + m_graphWindow->setYMax(min(Axis::Vertical) + yRange); m_yCursorPosition = bounds().height() - k_cursorMarginToBorder - ceilf(m_yCursorPosition) + m_yCursorPosition; } reload(); @@ -201,18 +201,18 @@ void GraphView::drawGridLines(KDContext * ctx, KDRect rect, Axis axis, float ste } void GraphView::drawGrid(KDContext * ctx, KDRect rect) const { - drawGridLines(ctx, rect, Axis::Horizontal, m_axisInterval->xScale(), k_gridColor); - drawGridLines(ctx, rect, Axis::Vertical, m_axisInterval->yScale(), k_gridColor); + drawGridLines(ctx, rect, Axis::Horizontal, m_graphWindow->xScale(), k_gridColor); + drawGridLines(ctx, rect, Axis::Vertical, m_graphWindow->yScale(), k_gridColor); } float GraphView::min(Axis axis) const { assert(axis == Axis::Horizontal || axis == Axis::Vertical); - return (axis == Axis::Horizontal ? m_axisInterval->xMin() : m_axisInterval->yMin()); + return (axis == Axis::Horizontal ? m_graphWindow->xMin() : m_graphWindow->yMin()); } float GraphView::max(Axis axis) const { assert(axis == Axis::Horizontal || axis == Axis::Vertical); - return (axis == Axis::Horizontal ? m_axisInterval->xMax() : m_axisInterval->yMax()); + return (axis == Axis::Horizontal ? m_graphWindow->xMax() : m_graphWindow->yMax()); } float GraphView::evaluateExpressionAtAbscissa(Expression * expression, float abscissa) const { diff --git a/apps/graph/graph/graph_view.h b/apps/graph/graph/graph_view.h index 12657cf3e..98a45b198 100644 --- a/apps/graph/graph/graph_view.h +++ b/apps/graph/graph/graph_view.h @@ -3,7 +3,7 @@ #include #include "cursor_view.h" -#include "axis_interval.h" +#include "graph_window.h" #include "../../curve_view.h" #include "../../constant.h" #include "../function_store.h" @@ -13,7 +13,7 @@ namespace Graph { class GraphView : public CurveView { public: - GraphView(FunctionStore * functionStore, AxisInterval * axisInterval); + GraphView(FunctionStore * functionStore, GraphWindow * graphWindow); void drawRect(KDContext * ctx, KDRect rect) const override; float xPixelCursorPosition(); @@ -54,7 +54,7 @@ private: char m_xLabels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode]; char m_yLabels[k_maxNumberOfYLabels][Constant::FloatBufferSizeInScientificMode]; - AxisInterval * m_axisInterval; + GraphWindow * m_graphWindow; FunctionStore * m_functionStore; EvaluateContext * m_evaluateContext; }; diff --git a/apps/graph/graph/axis_interval.cpp b/apps/graph/graph/graph_window.cpp similarity index 76% rename from apps/graph/graph/axis_interval.cpp rename to apps/graph/graph/graph_window.cpp index a88314af1..ec2001ee5 100644 --- a/apps/graph/graph/axis_interval.cpp +++ b/apps/graph/graph/graph_window.cpp @@ -1,4 +1,4 @@ -#include "axis_interval.h" +#include "graph_window.h" #include "../../constant.h" #include #include @@ -7,7 +7,7 @@ namespace Graph { -AxisInterval::AxisInterval(FunctionStore * functionStore) : +GraphWindow::GraphWindow(FunctionStore * functionStore) : m_xMin(-10.0f), m_xMax(10.0f), m_yMin(-10.0f), @@ -20,62 +20,62 @@ AxisInterval::AxisInterval(FunctionStore * functionStore) : { } -float AxisInterval::xMin() { +float GraphWindow::xMin() { return m_xMin; } -float AxisInterval::xMax() { +float GraphWindow::xMax() { return m_xMax; } -float AxisInterval::yMin() { +float GraphWindow::yMin() { return m_yMin; } -float AxisInterval::yMax() { +float GraphWindow::yMax() { return m_yMax; } -bool AxisInterval::yAuto() { +bool GraphWindow::yAuto() { return m_yAuto; } -float AxisInterval::xScale() { +float GraphWindow::xScale() { return m_xScale; } -float AxisInterval::yScale() { +float GraphWindow::yScale() { return m_yScale; } -void AxisInterval::setXMin(float xMin) { +void GraphWindow::setXMin(float xMin) { m_xMin = xMin; computeYaxes(); computeXScale(); } -void AxisInterval::setXMax(float xMax) { +void GraphWindow::setXMax(float xMax) { m_xMax = xMax; computeYaxes(); computeXScale(); } -void AxisInterval::setYMin(float yMin) { +void GraphWindow::setYMin(float yMin) { m_yMin = yMin; computeYScale(); } -void AxisInterval::setYMax(float yMax) { +void GraphWindow::setYMax(float yMax) { m_yMax = yMax; computeYScale(); } -void AxisInterval::setYAuto(bool yAuto) { +void GraphWindow::setYAuto(bool yAuto) { m_yAuto = yAuto; computeYaxes(); } -void AxisInterval::computeYaxes() { +void GraphWindow::computeYaxes() { if (!m_yAuto) { return; } @@ -104,7 +104,7 @@ void AxisInterval::computeYaxes() { computeYScale(); } -void AxisInterval::computeXScale() { +void GraphWindow::computeXScale() { int a = 0; int b = 0; float d = m_xMax - m_xMin; @@ -123,7 +123,7 @@ void AxisInterval::computeXScale() { m_xScale = a*powf(10,b); } -void AxisInterval::computeYScale() { +void GraphWindow::computeYScale() { int a = 0; int b = 0; float d = m_yMax - m_yMin; @@ -142,11 +142,11 @@ void AxisInterval::computeYScale() { m_yScale = a*powf(10,b); } -Context * AxisInterval::context() { +Context * GraphWindow::context() { return m_evaluateContext; } -void AxisInterval::setContext(Context * context) { +void GraphWindow::setContext(Context * context) { m_evaluateContext = (EvaluateContext *)context; } diff --git a/apps/graph/graph/axis_interval.h b/apps/graph/graph/graph_window.h similarity index 92% rename from apps/graph/graph/axis_interval.h rename to apps/graph/graph/graph_window.h index a54691d47..7162b59a5 100644 --- a/apps/graph/graph/axis_interval.h +++ b/apps/graph/graph/graph_window.h @@ -6,9 +6,9 @@ namespace Graph { -class AxisInterval { +class GraphWindow { public: - AxisInterval(FunctionStore * functionStore); + GraphWindow(FunctionStore * functionStore); float xMin(); float xMax(); float yMin(); diff --git a/apps/graph/graph/initialisation_parameter_controller.cpp b/apps/graph/graph/initialisation_parameter_controller.cpp index cba5a3054..349359681 100644 --- a/apps/graph/graph/initialisation_parameter_controller.cpp +++ b/apps/graph/graph/initialisation_parameter_controller.cpp @@ -4,11 +4,11 @@ namespace Graph { -InitialisationParameterController::InitialisationParameterController(Responder * parentResponder, AxisInterval * axisInterval, GraphView * graphView) : +InitialisationParameterController::InitialisationParameterController(Responder * parentResponder, GraphWindow * graphWindow, GraphView * graphView) : ViewController(parentResponder), m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin, Metric::BottomMargin, Metric::LeftMargin)), - m_axisInterval(axisInterval), + m_graphWindow(graphWindow), m_graphView(graphView) { m_cells[0].setText("Trigonometrique"); @@ -36,36 +36,36 @@ bool InitialisationParameterController::handleEvent(Ion::Events::Event event) { switch (m_selectableTableView.selectedRow()) { case 0: // TODO: if mode == degree, xmin = -600, xmax = 600 - m_axisInterval->setXMin(-10.5f); - m_axisInterval->setXMax(10.5f); - m_axisInterval->setYAuto(false); - m_axisInterval->setYMin(-1.6f); - m_axisInterval->setYMax(1.6f); + m_graphWindow->setXMin(-10.5f); + m_graphWindow->setXMax(10.5f); + m_graphWindow->setYAuto(false); + m_graphWindow->setYMin(-1.6f); + m_graphWindow->setYMax(1.6f); break; case 1: { - float xMin = m_axisInterval->xMin(); - float xMax =m_axisInterval->xMax(); - m_axisInterval->setXMin(roundf((xMin+xMax)/2) - 160.0f); - m_axisInterval->setXMax(roundf((xMin+xMax)/2) + 159.0f); + float xMin = m_graphWindow->xMin(); + float xMax =m_graphWindow->xMax(); + m_graphWindow->setXMin(roundf((xMin+xMax)/2) - 160.0f); + m_graphWindow->setXMax(roundf((xMin+xMax)/2) + 159.0f); break; } case 2: { - float xMin = m_axisInterval->xMin(); - float xMax =m_axisInterval->xMax(); - float yMin = m_axisInterval->yMin(); - float yMax =m_axisInterval->yMax(); - m_axisInterval->setXMin((xMin+xMax)/2 - 5.3f); - m_axisInterval->setXMax((xMin+xMax)/2 + 5.3f); - m_axisInterval->setYMin((yMin+yMax)/2 - 3.1f); - m_axisInterval->setYMax((yMin+yMax)/2 + 3.1f); + float xMin = m_graphWindow->xMin(); + float xMax =m_graphWindow->xMax(); + float yMin = m_graphWindow->yMin(); + float yMax =m_graphWindow->yMax(); + m_graphWindow->setXMin((xMin+xMax)/2 - 5.3f); + m_graphWindow->setXMax((xMin+xMax)/2 + 5.3f); + m_graphWindow->setYMin((yMin+yMax)/2 - 3.1f); + m_graphWindow->setYMax((yMin+yMax)/2 + 3.1f); break; } case 3: - m_axisInterval->setXMin(-10.0f); - m_axisInterval->setXMax(10.0f); - m_axisInterval->setYAuto(true); + m_graphWindow->setXMin(-10.0f); + m_graphWindow->setXMax(10.0f); + m_graphWindow->setYAuto(true); break; default: return false; diff --git a/apps/graph/graph/initialisation_parameter_controller.h b/apps/graph/graph/initialisation_parameter_controller.h index 0a97c3be5..28f7b35f7 100644 --- a/apps/graph/graph/initialisation_parameter_controller.h +++ b/apps/graph/graph/initialisation_parameter_controller.h @@ -2,14 +2,14 @@ #define GRAPH_GRAPH_INITIALISATION_PARAMETER_CONTROLLER_H #include -#include "axis_interval.h" +#include "graph_window.h" #include "graph_view.h" namespace Graph { class InitialisationParameterController : public ViewController, public SimpleListViewDataSource { public: - InitialisationParameterController(Responder * parentResponder, AxisInterval * axisInterval, GraphView * graphView); + InitialisationParameterController(Responder * parentResponder, GraphWindow * graphWindow, GraphView * graphView); View * view() override; const char * title() const override; bool handleEvent(Ion::Events::Event event) override; @@ -22,7 +22,7 @@ private: constexpr static int k_totalNumberOfCells = 4; MenuListCell m_cells[k_totalNumberOfCells]; SelectableTableView m_selectableTableView; - AxisInterval * m_axisInterval; + GraphWindow * m_graphWindow; GraphView * m_graphView; }; diff --git a/apps/graph/graph/window_parameter_controller.cpp b/apps/graph/graph/window_parameter_controller.cpp new file mode 100644 index 000000000..fe4fe4070 --- /dev/null +++ b/apps/graph/graph/window_parameter_controller.cpp @@ -0,0 +1,112 @@ +#include "window_parameter_controller.h" +#include + +namespace Graph { + +WindowParameterController::WindowParameterController(Responder * parentResponder, GraphWindow * graphWindow, GraphView * graphView) : + FloatParameterController(parentResponder), + m_graphWindow(graphWindow), + m_yAutoCell(SwitchMenuListCell((char*)"Y auto")), + m_graphView(graphView) +{ + m_windowCells[0].setText("Xmin"); + m_windowCells[1].setText("Xmax"); + m_windowCells[2].setText("Ymin"); + m_windowCells[3].setText("Ymax"); +} + +ExpressionTextFieldDelegate * WindowParameterController::textFieldDelegate() { + ExpressionTextFieldDelegate * myApp = (ExpressionTextFieldDelegate *)app(); + return myApp; +} + +const char * WindowParameterController::title() const { + return "Axes"; +} + +void WindowParameterController::willDisplayCellForIndex(TableViewCell * cell, int index) { + if (index == 2) { + SwitchView * switchView = (SwitchView *)m_yAutoCell.accessoryView(); + switchView->setState(m_graphWindow->yAuto()); + return; + } + if (index == 3 || index == 4) { + if (m_graphWindow->yAuto()) { + m_windowCells[index-1].setTextColor(Palette::DesactiveTextColor); + } else { + m_windowCells[index-1].setTextColor(KDColorBlack); + } + } + FloatParameterController::willDisplayCellForIndex(cell, index); +} + +bool WindowParameterController::handleEvent(Ion::Events::Event event) { + m_graphView->initCursorPosition(); + if (activeCell() == 2) { + if (event == Ion::Events::OK) { + m_graphWindow->setYAuto(!m_graphWindow->yAuto()); + m_selectableTableView.reloadData(); + return true; + } + return false; + } + if (m_graphWindow->yAuto() && (activeCell() == 3 || activeCell() == 4)) { + return false; + } + return FloatParameterController::handleEvent(event); +} + +float WindowParameterController::parameterAtIndex(int index) { + switch (index) { + case 0: + return m_graphWindow->xMin(); + case 1: + return m_graphWindow->xMax(); + case 3: + return m_graphWindow->yMin(); + case 4: + return m_graphWindow->yMax(); + default: + assert(false); + return 0.0f; + } +} + +void WindowParameterController::setParameterAtIndex(int parameterIndex, float f) { + switch(parameterIndex) { + case 0: + m_graphWindow->setXMin(f); + break; + case 1: + m_graphWindow->setXMax(f); + break; + case 3: + m_graphWindow->setYMin(f); + break; + case 4: + m_graphWindow->setYMax(f); + break; + default: + assert(false); + } +} + +int WindowParameterController::numberOfRows() { + return k_numberOfTextCell+1; +}; + +TableViewCell * WindowParameterController::reusableCell(int index) { + if (index == 2) { + return &m_yAutoCell; + } + int cellIndex = index > 2 ? index - 1 : index; + assert(cellIndex >= 0); + assert(cellIndex < k_numberOfTextCell); + return &m_windowCells[cellIndex]; +} + +int WindowParameterController::reusableCellCount() { + return k_numberOfTextCell+1; +} + +} diff --git a/apps/graph/graph/axis_parameter_controller.h b/apps/graph/graph/window_parameter_controller.h similarity index 64% rename from apps/graph/graph/axis_parameter_controller.h rename to apps/graph/graph/window_parameter_controller.h index f5d2125bf..add2861e8 100644 --- a/apps/graph/graph/axis_parameter_controller.h +++ b/apps/graph/graph/window_parameter_controller.h @@ -1,15 +1,15 @@ -#ifndef GRAPH_GRAPH_AXIS_PARAMETER_CONTROLLER_H -#define GRAPH_GRAPH_AXIS_PARAMETER_CONTROLLER_H +#ifndef GRAPH_GRAPH_WINDOW_PARAMETER_CONTROLLER_H +#define GRAPH_GRAPH_WINDOW_PARAMETER_CONTROLLER_H #include -#include "axis_interval.h" +#include "graph_window.h" #include "graph_view.h" #include "../../float_parameter_controller.h" namespace Graph { -class AxisParameterController : public FloatParameterController { +class WindowParameterController : public FloatParameterController { public: - AxisParameterController(Responder * parentResponder, AxisInterval * axisInterval, GraphView * graphView); + WindowParameterController(Responder * parentResponder, GraphWindow * graphWindow, GraphView * graphView); ExpressionTextFieldDelegate * textFieldDelegate() override; const char * title() const override; int numberOfRows() override; @@ -21,8 +21,8 @@ private: float parameterAtIndex(int index) override; void setParameterAtIndex(int parameterIndex, float f) override; constexpr static int k_numberOfTextCell = 4; - AxisInterval * m_axisInterval; - EditableTextMenuListCell m_axisCells[k_numberOfTextCell]; + GraphWindow * m_graphWindow; + EditableTextMenuListCell m_windowCells[k_numberOfTextCell]; SwitchMenuListCell m_yAutoCell; GraphView * m_graphView; }; diff --git a/apps/graph/graph/zoom_parameter_controller.cpp b/apps/graph/graph/zoom_parameter_controller.cpp index 55aa769a0..4c24aa18f 100644 --- a/apps/graph/graph/zoom_parameter_controller.cpp +++ b/apps/graph/graph/zoom_parameter_controller.cpp @@ -8,10 +8,10 @@ constexpr KDColor ZoomParameterController::ContentView::LegendView::k_legendBack /* Zoom Parameter Controller */ -ZoomParameterController::ZoomParameterController(Responder * parentResponder, AxisInterval * axisInterval, GraphView * graphView) : +ZoomParameterController::ZoomParameterController(Responder * parentResponder, GraphWindow * graphWindow, GraphView * graphView) : ViewController(parentResponder), m_contentView(ContentView(graphView)), - m_axisInterval(axisInterval) + m_graphWindow(graphWindow) { } @@ -24,53 +24,53 @@ View * ZoomParameterController::view() { } bool ZoomParameterController::handleEvent(Ion::Events::Event event) { - float xMin = m_axisInterval->xMin(); - float xMax = m_axisInterval->xMax(); - float yMin = m_axisInterval->yMin(); - float yMax = m_axisInterval->yMax(); - m_axisInterval->setYAuto(false); + float xMin = m_graphWindow->xMin(); + float xMax = m_graphWindow->xMax(); + float yMin = m_graphWindow->yMin(); + float yMax = m_graphWindow->yMax(); + m_graphWindow->setYAuto(false); if (event == Ion::Events::Plus) { - m_axisInterval->setXMin((xMax+xMin)/2.0f - fabsf(xMax-xMin)/3.0f); - m_axisInterval->setXMax((xMax+xMin)/2.0f + fabsf(xMax-xMin)/3.0f); - m_axisInterval->setYMin((yMax+yMin)/2.0f - fabsf(yMax-yMin)/3.0f); - m_axisInterval->setYMax((yMax+yMin)/2.0f + fabsf(yMax-yMin)/3.0f); + m_graphWindow->setXMin((xMax+xMin)/2.0f - fabsf(xMax-xMin)/3.0f); + m_graphWindow->setXMax((xMax+xMin)/2.0f + fabsf(xMax-xMin)/3.0f); + m_graphWindow->setYMin((yMax+yMin)/2.0f - fabsf(yMax-yMin)/3.0f); + m_graphWindow->setYMax((yMax+yMin)/2.0f + fabsf(yMax-yMin)/3.0f); m_contentView.graphView()->initCursorPosition(); m_contentView.graphView()->reload(); return true; } if (event == Ion::Events::Minus) { - m_axisInterval->setXMin((xMax+xMin)/2.0f - 3.0f*fabsf(xMax-xMin)/4.0f); - m_axisInterval->setXMax((xMax+xMin)/2.0f + 3.0f*fabsf(xMax-xMin)/4.0f); - m_axisInterval->setYMin((yMax+yMin)/2.0f - 3.0f*fabsf(yMax-yMin)/4.0f); - m_axisInterval->setYMax((yMax+yMin)/2.0f + 3.0f*fabsf(yMax-yMin)/4.0f); + m_graphWindow->setXMin((xMax+xMin)/2.0f - 3.0f*fabsf(xMax-xMin)/4.0f); + m_graphWindow->setXMax((xMax+xMin)/2.0f + 3.0f*fabsf(xMax-xMin)/4.0f); + m_graphWindow->setYMin((yMax+yMin)/2.0f - 3.0f*fabsf(yMax-yMin)/4.0f); + m_graphWindow->setYMax((yMax+yMin)/2.0f + 3.0f*fabsf(yMax-yMin)/4.0f); m_contentView.graphView()->initCursorPosition(); m_contentView.graphView()->reload(); return true; } if (event == Ion::Events::Up) { - m_axisInterval->setYMin(yMin + m_axisInterval->yScale()); - m_axisInterval->setYMax(yMax + m_axisInterval->yScale()); + m_graphWindow->setYMin(yMin + m_graphWindow->yScale()); + m_graphWindow->setYMax(yMax + m_graphWindow->yScale()); m_contentView.graphView()->initCursorPosition(); m_contentView.graphView()->reload(); return true; } if (event == Ion::Events::Down) { - m_axisInterval->setYMin(yMin - m_axisInterval->yScale()); - m_axisInterval->setYMax(yMax - m_axisInterval->yScale()); + m_graphWindow->setYMin(yMin - m_graphWindow->yScale()); + m_graphWindow->setYMax(yMax - m_graphWindow->yScale()); m_contentView.graphView()->initCursorPosition(); m_contentView.graphView()->reload(); return true; } if (event == Ion::Events::Left) { - m_axisInterval->setXMin(xMin - m_axisInterval->xScale()); - m_axisInterval->setXMax(xMax - m_axisInterval->xScale()); + m_graphWindow->setXMin(xMin - m_graphWindow->xScale()); + m_graphWindow->setXMax(xMax - m_graphWindow->xScale()); m_contentView.graphView()->initCursorPosition(); m_contentView.graphView()->reload(); return true; } if (event == Ion::Events::Right) { - m_axisInterval->setXMin(xMin + m_axisInterval->xScale()); - m_axisInterval->setXMax(xMax + m_axisInterval->xScale()); + m_graphWindow->setXMin(xMin + m_graphWindow->xScale()); + m_graphWindow->setXMax(xMax + m_graphWindow->xScale()); m_contentView.graphView()->initCursorPosition(); m_contentView.graphView()->reload(); return true; diff --git a/apps/graph/graph/zoom_parameter_controller.h b/apps/graph/graph/zoom_parameter_controller.h index cbddf6f88..f620f0144 100644 --- a/apps/graph/graph/zoom_parameter_controller.h +++ b/apps/graph/graph/zoom_parameter_controller.h @@ -2,14 +2,14 @@ #define GRAPH_GRAPH_ZOOM_PARAMETER_CONTROLLER_H #include -#include "axis_interval.h" +#include "graph_window.h" #include "graph_view.h" namespace Graph { class ZoomParameterController : public ViewController { public: - ZoomParameterController(Responder * parentResponder, AxisInterval * axisInterval, GraphView * graphView); + ZoomParameterController(Responder * parentResponder, GraphWindow * graphWindow, GraphView * graphView); const char * title() const override; View * view() override; bool handleEvent(Ion::Events::Event event) override; @@ -41,7 +41,7 @@ private: constexpr static KDCoordinate k_legendHeight = 50; }; ContentView m_contentView; - AxisInterval * m_axisInterval; + GraphWindow * m_graphWindow; }; }