diff --git a/apps/apps_container.h b/apps/apps_container.h index d03e90b4e..5e8ac0803 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -2,7 +2,7 @@ #define APPS_CONTAINER_H #include "home/app.h" -#include "graph/graph_app.h" +#include "graph/app.h" #include "probability/app.h" #define USE_PIC_VIEW_APP 0 @@ -21,7 +21,7 @@ public: private: static constexpr int k_numberOfApps = 3; Home::App m_homeApp; - GraphApp m_graphApp; + Graph::App m_graphApp; Probability::App m_probabilityApp; #if USE_PIC_VIEW_APP PicViewApp m_picViewApp; diff --git a/apps/graph/Makefile b/apps/graph/Makefile index 8420668d8..d5968e56a 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -1,5 +1,5 @@ app_objs += $(addprefix apps/graph/,\ - graph_app.o\ + app.o\ even_odd_cell.o\ evaluate_context.o\ function.o\ diff --git a/apps/graph/graph_app.cpp b/apps/graph/app.cpp similarity index 75% rename from apps/graph/graph_app.cpp rename to apps/graph/app.cpp index eee96079d..a17bf1539 100644 --- a/apps/graph/graph_app.cpp +++ b/apps/graph/app.cpp @@ -1,10 +1,12 @@ -#include "graph_app.h" +#include "app.h" #include "graph_icon.h" -GraphApp::GraphApp(Context * context) : - App("Graph", ImageStore::GraphIcon), - m_functionStore(Graph::FunctionStore()), - m_evaluateContext(Graph::EvaluateContext(context)), +namespace Graph { + +App::App(::Context * context) : + ::App("Graph", ImageStore::GraphIcon), + m_functionStore(FunctionStore()), + m_evaluateContext(EvaluateContext(context)), m_listController(ListController(nullptr, &m_functionStore)), m_listStackViewController(StackViewController(&m_tabViewController, &m_listController)), m_graphController(GraphController(nullptr, &m_functionStore, &m_evaluateContext)), @@ -13,7 +15,7 @@ GraphApp::GraphApp(Context * context) : m_tabViewController(&m_inputViewController, &m_listStackViewController, &m_graphController, &m_valuesStackViewController), m_inputViewController(this, &m_tabViewController) { - Graph::Function * function = m_functionStore.addEmptyFunction(); + Function * function = m_functionStore.addEmptyFunction(); function->setContent("(x-1)*(x+1)*x"); function = m_functionStore.addEmptyFunction(); function->setContent("x*x"); @@ -27,10 +29,12 @@ GraphApp::GraphApp(Context * context) : function->setContent("1/(1+1/(1/x))"); } -ViewController * GraphApp::rootViewController() { +ViewController * App::rootViewController() { return &m_inputViewController; } -InputViewController * GraphApp::inputViewController() { +InputViewController * App::inputViewController() { return &m_inputViewController; } + +} diff --git a/apps/graph/graph_app.h b/apps/graph/app.h similarity index 75% rename from apps/graph/graph_app.h rename to apps/graph/app.h index 341d70a6b..3ff9c9dfb 100644 --- a/apps/graph/graph_app.h +++ b/apps/graph/app.h @@ -1,5 +1,5 @@ -#ifndef GRAPH_GRAPH_APP_H -#define GRAPH_GRAPH_APP_H +#ifndef GRAPH_APP_H +#define GRAPH_APP_H #include #include "function_store.h" @@ -8,15 +8,17 @@ #include "list/list_controller.h" #include "values/values_controller.h" -class GraphApp : public ::App { +namespace Graph { + +class App : public ::App { public: - GraphApp(Context * context); + App(::Context * context); InputViewController * inputViewController(); protected: ViewController * rootViewController() override; private: - Graph::FunctionStore m_functionStore; - Graph::EvaluateContext m_evaluateContext; + FunctionStore m_functionStore; + EvaluateContext m_evaluateContext; ListController m_listController; StackViewController m_listStackViewController; GraphController m_graphController; @@ -26,4 +28,6 @@ private: InputViewController m_inputViewController; }; +} + #endif diff --git a/apps/graph/evaluate_context.cpp b/apps/graph/evaluate_context.cpp index b5d947e7f..ea871f5ca 100644 --- a/apps/graph/evaluate_context.cpp +++ b/apps/graph/evaluate_context.cpp @@ -1,17 +1,19 @@ #include "evaluate_context.h" #include -Graph::EvaluateContext::EvaluateContext(::Context * parentContext) : +namespace Graph { + +EvaluateContext::EvaluateContext(::Context * parentContext) : m_xValue(Float(0.0f)), m_context(parentContext) { } -void Graph::EvaluateContext::setOverridenValueForSymbolX(float f) { +void EvaluateContext::setOverridenValueForSymbolX(float f) { m_xValue = Float(f); } -const Expression * Graph::EvaluateContext::operator[](const char * symbolName) const { +const Expression * EvaluateContext::operator[](const char * symbolName) const { if (strcmp("x", symbolName) == 0) { return &m_xValue; } else { @@ -19,3 +21,5 @@ const Expression * Graph::EvaluateContext::operator[](const char * symbolName) c return context[symbolName]; } } + +} diff --git a/apps/graph/even_odd_cell.cpp b/apps/graph/even_odd_cell.cpp index 6c46c4c0a..f3b7ff255 100644 --- a/apps/graph/even_odd_cell.cpp +++ b/apps/graph/even_odd_cell.cpp @@ -1,5 +1,7 @@ #include "even_odd_cell.h" +namespace Graph { + constexpr KDColor EvenOddCell::k_evenLineBackgroundColor; constexpr KDColor EvenOddCell::k_oddLineBackgroundColor; constexpr KDColor EvenOddCell::k_selectedLineBackgroundColor; @@ -38,3 +40,4 @@ void EvenOddCell::drawRect(KDContext * ctx, KDRect rect) const { ctx->fillRect(rect, background); } +} diff --git a/apps/graph/even_odd_cell.h b/apps/graph/even_odd_cell.h index bef02c8de..5969cdd5f 100644 --- a/apps/graph/even_odd_cell.h +++ b/apps/graph/even_odd_cell.h @@ -3,6 +3,8 @@ #include +namespace Graph { + class EvenOddCell : public ChildlessView { public: EvenOddCell(); @@ -21,4 +23,6 @@ private: bool m_even; }; +} + #endif diff --git a/apps/graph/function.cpp b/apps/graph/function.cpp index 09e6055e8..cd43159c8 100644 --- a/apps/graph/function.cpp +++ b/apps/graph/function.cpp @@ -1,7 +1,9 @@ #include "function.h" #include -Graph::Function::Function(const char * text, KDColor color) : +namespace Graph { + +Function::Function(const char * text, KDColor color) : m_name(text), m_color(color), m_expression(nullptr), @@ -10,7 +12,7 @@ Graph::Function::Function(const char * text, KDColor color) : { } -void Graph::Function::setContent(const char * c) { +void Function::setContent(const char * c) { strlcpy(m_text, c, sizeof(m_text)); if (m_expression != nullptr) { delete m_expression; @@ -22,11 +24,11 @@ void Graph::Function::setContent(const char * c) { m_layout = expression()->createLayout(); } -void Graph::Function::setColor(KDColor color) { +void Function::setColor(KDColor color) { m_color = color; } -Graph::Function::~Function() { +Function::~Function() { if (m_layout != nullptr) { delete m_layout; } @@ -35,31 +37,33 @@ Graph::Function::~Function() { } } -const char * Graph::Function::text() { +const char * Function::text() { return m_text; } -const char * Graph::Function::name() { +const char * Function::name() { return m_name; } -Expression * Graph::Function::expression() { +Expression * Function::expression() { return m_expression; } -ExpressionLayout * Graph::Function::layout() { +ExpressionLayout * Function::layout() { return m_layout; } -bool Graph::Function::isActive() { +bool Function::isActive() { return m_active; } -void Graph::Function::setActive(bool active) { +void Function::setActive(bool active) { m_active = active; } -float Graph::Function::evaluateAtAbscissa(float x, Graph::EvaluateContext * context) { +float Function::evaluateAtAbscissa(float x, EvaluateContext * context) { context->setOverridenValueForSymbolX(x); return m_expression->approximate(*context); } + +} diff --git a/apps/graph/function_store.cpp b/apps/graph/function_store.cpp index ccdbc2263..754eb1db8 100644 --- a/apps/graph/function_store.cpp +++ b/apps/graph/function_store.cpp @@ -3,21 +3,23 @@ extern "C" { #include } -constexpr int Graph::FunctionStore::k_numberOfDefaultColors; -constexpr KDColor Graph::FunctionStore::k_defaultColors[k_numberOfDefaultColors]; -constexpr const char * Graph::FunctionStore::k_functionNames[k_maxNumberOfFunctions]; +namespace Graph { -Graph::FunctionStore::FunctionStore() : +constexpr int FunctionStore::k_numberOfDefaultColors; +constexpr KDColor FunctionStore::k_defaultColors[k_numberOfDefaultColors]; +constexpr const char * FunctionStore::k_functionNames[k_maxNumberOfFunctions]; + +FunctionStore::FunctionStore() : m_numberOfFunctions(0) { } -Graph::Function * Graph::FunctionStore::functionAtIndex(int i) { +Function * FunctionStore::functionAtIndex(int i) { assert(i>=0 && i=0 && ifillRect(rect, KDColorRed); } + +} diff --git a/apps/graph/graph/cursor_view.h b/apps/graph/graph/cursor_view.h index f27ee5f9c..cab368585 100644 --- a/apps/graph/graph/cursor_view.h +++ b/apps/graph/graph/cursor_view.h @@ -3,10 +3,13 @@ #include +namespace Graph { class CursorView : public ChildlessView { public: using ChildlessView::ChildlessView; void drawRect(KDContext * ctx, KDRect rect) const override; }; +} + #endif diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index f2aeec265..20f74d949 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -1,7 +1,9 @@ #include "graph_controller.h" #include -GraphController::GraphController(Responder * parentResponder, Graph::FunctionStore * functionStore, Graph::EvaluateContext * evaluateContext) : +namespace Graph { + +GraphController::GraphController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext) : HeaderViewController(parentResponder, &m_view), m_view(GraphView(functionStore, evaluateContext)), m_headerSelected(false), @@ -65,3 +67,5 @@ bool GraphController::handleEvent(Ion::Events::Event event) { } } } + +} diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index 026fedb84..5a86e2b16 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -6,9 +6,10 @@ #include "../function_store.h" #include "../evaluate_context.h" +namespace Graph { class GraphController : public HeaderViewController { public: - GraphController(Responder * parentResponder, Graph::FunctionStore * functionStore, Graph::EvaluateContext * evaluateContext); + GraphController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext); const char * title() const override; bool handleEvent(Ion::Events::Event event) override; @@ -24,4 +25,6 @@ private: Button m_displayButton; }; +} + #endif diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 661ceb592..9ec9733c1 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -1,13 +1,15 @@ #include "graph_view.h" #include +namespace Graph { + constexpr KDColor kAxisColor = KDColor(0x000000); constexpr KDColor kMainGridColor = KDColor(0xCCCCCC); constexpr KDColor kSecondaryGridColor = KDColor(0xEEEEEE); constexpr int kNumberOfMainGridLines = 5; constexpr int kNumberOfSecondaryGridLines = 4; -GraphView::GraphView(Graph::FunctionStore * functionStore, Graph::EvaluateContext * evaluateContext) : +GraphView::GraphView(FunctionStore * functionStore, EvaluateContext * evaluateContext) : #if GRAPH_VIEW_IS_TILED TiledView(), #else @@ -162,7 +164,7 @@ void GraphView::drawFunction(KDContext * ctx, KDRect rect) const { for (KDCoordinate px = rect.x()-stampSize; pxnumberOfFunctions(); i++) { - Graph::Function * f = m_functionStore->functionAtIndex(i); + Function * f = m_functionStore->functionAtIndex(i); if (f->isActive()) { float y = f->evaluateAtAbscissa(x, m_evaluateContext); KDCoordinate py = floatToPixel(Axis::Vertical, y); @@ -222,3 +224,5 @@ void GraphView::drawFunction(KDRect rect) const { } } #endif + +} diff --git a/apps/graph/graph/graph_view.h b/apps/graph/graph/graph_view.h index 459933925..33c4a36da 100644 --- a/apps/graph/graph/graph_view.h +++ b/apps/graph/graph/graph_view.h @@ -8,6 +8,8 @@ #define GRAPH_VIEW_IS_TILED 1 +namespace Graph { + class GraphView : public #if GRAPH_VIEW_IS_TILED TiledView @@ -16,7 +18,7 @@ class GraphView : public #endif { public: - GraphView(Graph::FunctionStore * functionStore, Graph::EvaluateContext * evaluateContext); + GraphView(FunctionStore * functionStore, EvaluateContext * evaluateContext); #if GRAPH_VIEW_IS_TILED KDColor * tile() const override; @@ -67,8 +69,10 @@ private: float m_yMin; float m_yMax; - Graph::FunctionStore * m_functionStore; - Graph::EvaluateContext * m_evaluateContext; + FunctionStore * m_functionStore; + EvaluateContext * m_evaluateContext; }; +} + #endif diff --git a/apps/graph/list/function_cell.cpp b/apps/graph/list/function_cell.cpp index a53b241d2..88ec995ae 100644 --- a/apps/graph/list/function_cell.cpp +++ b/apps/graph/list/function_cell.cpp @@ -1,5 +1,7 @@ #include "function_cell.h" +namespace Graph { + constexpr KDColor FunctionCell::k_desactiveTextColor; FunctionCell::FunctionCell() : @@ -8,11 +10,13 @@ FunctionCell::FunctionCell() : { } -void FunctionCell::setFunction(Graph::Function * f) { +void FunctionCell::setFunction(Function * f) { m_function = f; markRectAsDirty(bounds()); } -Graph::Function * FunctionCell::function() { +Function * FunctionCell::function() { return m_function; } + +} diff --git a/apps/graph/list/function_cell.h b/apps/graph/list/function_cell.h index a0eaa4b56..e29e6e64b 100644 --- a/apps/graph/list/function_cell.h +++ b/apps/graph/list/function_cell.h @@ -5,16 +5,20 @@ #include "../function.h" #include "../even_odd_cell.h" +namespace Graph { + class FunctionCell : public EvenOddCell { public: FunctionCell(); - void setFunction(Graph::Function * f); - Graph::Function * function(); + void setFunction(Function * f); + Function * function(); static constexpr KDColor k_desactiveTextColor = KDColor(0x646464); protected: - Graph::Function * m_function; + Function * m_function; }; +} + #endif diff --git a/apps/graph/list/function_expression_view.cpp b/apps/graph/list/function_expression_view.cpp index b6f1cf707..cc96889a7 100644 --- a/apps/graph/list/function_expression_view.cpp +++ b/apps/graph/list/function_expression_view.cpp @@ -1,5 +1,7 @@ #include "function_expression_view.h" +namespace Graph { + FunctionExpressionView::FunctionExpressionView() : FunctionCell() { @@ -17,3 +19,5 @@ void FunctionExpressionView::drawRect(KDContext * ctx, KDRect rect) const { KDPoint origin(0, 0.5f*(m_frame.height() - expressionSize.height())); m_function->layout()->draw(ctx, origin, text, background); } + +} diff --git a/apps/graph/list/function_expression_view.h b/apps/graph/list/function_expression_view.h index 173773bd2..e25346e02 100644 --- a/apps/graph/list/function_expression_view.h +++ b/apps/graph/list/function_expression_view.h @@ -4,6 +4,8 @@ #include #include "function_cell.h" +namespace Graph { + class FunctionCell; class FunctionExpressionView : public FunctionCell { @@ -12,4 +14,6 @@ public: void drawRect(KDContext * ctx, KDRect rect) const override; }; +} + #endif diff --git a/apps/graph/list/function_name_view.cpp b/apps/graph/list/function_name_view.cpp index 17aa29301..65509fb92 100644 --- a/apps/graph/list/function_name_view.cpp +++ b/apps/graph/list/function_name_view.cpp @@ -1,6 +1,8 @@ #include "function_name_view.h" #include "../function_store.h" +namespace Graph { + constexpr KDColor FunctionNameView::k_separatorColor; FunctionNameView::FunctionNameView() : @@ -32,5 +34,7 @@ void FunctionNameView::drawRect(KDContext * ctx, KDRect rect) const { KDPoint origin(0.5f*(k_colorIndicatorThickness + m_frame.width() - 4*textSize.width()), baseline-textSize.height()+0.5f*(m_frame.height() - expressionSize.height())); ctx->drawString(functionName, origin, functionNameColor, background); - ctx->drawString(Graph::Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), textColor, background); + ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), textColor, background); +} + } diff --git a/apps/graph/list/function_name_view.h b/apps/graph/list/function_name_view.h index fc27c66a7..ddeb4b86f 100644 --- a/apps/graph/list/function_name_view.h +++ b/apps/graph/list/function_name_view.h @@ -4,6 +4,7 @@ #include #include "function_cell.h" +namespace Graph { class FunctionNameView : public FunctionCell { public: @@ -16,4 +17,6 @@ private: constexpr static KDColor k_separatorColor = KDColor(0xEFF2F4); }; +} + #endif diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index c19339b81..95e647c9a 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -1,8 +1,10 @@ #include "list_controller.h" -#include "../graph_app.h" +#include "../app.h" #include -ListController::ListController(Responder * parentResponder, Graph::FunctionStore * functionStore) : +namespace Graph { + +ListController::ListController(Responder * parentResponder, FunctionStore * functionStore) : HeaderViewController(parentResponder, &m_tableView), m_tableView(TableView(this)), m_activeCellx(0), @@ -31,7 +33,7 @@ int ListController::numberOfColumns() { }; KDCoordinate ListController::rowHeight(int j) { - Graph::Function * function = m_functionStore->functionAtIndex(j); + Function * function = m_functionStore->functionAtIndex(j); KDCoordinate functionSize = function->layout()->size().height(); return functionSize + k_verticalFunctionMargin; } @@ -125,20 +127,20 @@ void ListController::didBecomeFirstResponder() { } } -void ListController::configureFunction(Graph::Function * function) { +void ListController::configureFunction(Function * function) { StackViewController * stack = ((StackViewController *)parentResponder()); m_parameterController.setFunction(function); stack->push(&m_parameterController); } void ListController::editExpression(FunctionExpressionView * functionCell) { - GraphApp * myApp = (GraphApp *)app(); + App * myApp = (App *)app(); InputViewController * inputController = myApp->inputViewController(); const char * initialTextContent = functionCell->function()->text(); inputController->edit(this, initialTextContent, functionCell, [](void * context, void * sender){ FunctionExpressionView * myCell = (FunctionExpressionView *) context; - Graph::Function * myFunction = myCell->function(); + Function * myFunction = myCell->function(); InputViewController * myInputViewController = (InputViewController *)sender; const char * textBody = myInputViewController->textBody(); myFunction->setContent(textBody); @@ -225,3 +227,4 @@ void ListController::willDisplayCellAtLocation(View * cell, int i, int j) { myCell->setEven(j%2 == 0); } +} \ No newline at end of file diff --git a/apps/graph/list/list_controller.h b/apps/graph/list/list_controller.h index 9f6ba5bc1..67bf76460 100644 --- a/apps/graph/list/list_controller.h +++ b/apps/graph/list/list_controller.h @@ -7,9 +7,11 @@ #include "function_expression_view.h" #include "parameter_controller.h" +namespace Graph { + class ListController : public HeaderViewController, public TableViewDataSource { public: - ListController(Responder * parentResponder, Graph::FunctionStore * functionStore); + ListController(Responder * parentResponder, FunctionStore * functionStore); void setActiveCell(int i, int j); @@ -30,7 +32,7 @@ public: View * reusableCell(int index, int type) override; int reusableCellCount(int type) override; int typeAtLocation(int i, int j) override; - void configureFunction(Graph::Function * function); + void configureFunction(Function * function); void editExpression(FunctionExpressionView * functionCell); private: @@ -46,8 +48,10 @@ private: int m_activeCellx; int m_activeCelly; KDCoordinate m_manualScrolling; - Graph::FunctionStore * m_functionStore; + FunctionStore * m_functionStore; ParameterController m_parameterController; }; +} + #endif diff --git a/apps/graph/list/parameter_controller.cpp b/apps/graph/list/parameter_controller.cpp index 8a9c33e50..fef33f7c9 100644 --- a/apps/graph/list/parameter_controller.cpp +++ b/apps/graph/list/parameter_controller.cpp @@ -1,7 +1,9 @@ #include "parameter_controller.h" #include -ParameterController::ParameterController(Responder * parentResponder, Graph::FunctionStore * functionStore) : +namespace Graph { + +ParameterController::ParameterController(Responder * parentResponder, FunctionStore * functionStore) : ViewController(parentResponder), m_colorCell(TableViewCell((char*)"Couleur de la fonction")), m_enableCell(SwitchTableViewCell((char*)"Activer/Desactiver")), @@ -47,7 +49,7 @@ void ParameterController::setActiveCell(int index) { } -void ParameterController::setFunction(Graph::Function * function) { +void ParameterController::setFunction(Function * function) { m_function = function; } @@ -117,3 +119,5 @@ int ParameterController::reusableCellCount() { KDCoordinate ParameterController::cellHeight() { return 35; } + +} diff --git a/apps/graph/list/parameter_controller.h b/apps/graph/list/parameter_controller.h index d71de9e12..5e8661e4d 100644 --- a/apps/graph/list/parameter_controller.h +++ b/apps/graph/list/parameter_controller.h @@ -5,14 +5,16 @@ #include "../function.h" #include "../function_store.h" +namespace Graph { + class ParameterController : public ViewController, public ListViewDataSource { public: - ParameterController(Responder * parentResponder, Graph::FunctionStore * functionStore); + ParameterController(Responder * parentResponder, FunctionStore * functionStore); View * view() override; const char * title() const override; bool handleEvent(Ion::Events::Event event) override; - void setFunction(Graph::Function * function); + void setFunction(Function * function); void didBecomeFirstResponder() override; void setActiveCell(int index); @@ -29,8 +31,10 @@ private: TableViewCell m_deleteCell; ListView m_listView; int m_activeCell; - Graph::Function * m_function; - Graph::FunctionStore * m_functionStore; + Function * m_function; + FunctionStore * m_functionStore; }; +} + #endif diff --git a/apps/graph/values/interval.cpp b/apps/graph/values/interval.cpp index d124028a6..7b86d2148 100644 --- a/apps/graph/values/interval.cpp +++ b/apps/graph/values/interval.cpp @@ -1,14 +1,16 @@ #include "interval.h" #include -Graph::Interval::Interval(float start, float end, float step) : +namespace Graph { + +Interval::Interval(float start, float end, float step) : m_start(start), m_end(end), m_step(step) { } -int Graph::Interval::numberOfElements() { +int Interval::numberOfElements() { if (m_start > m_end) { return 0; } else { @@ -16,7 +18,9 @@ int Graph::Interval::numberOfElements() { } } -float Graph::Interval::element(int i) { +float Interval::element(int i) { assert(i >= 0 && i < numberOfElements()); return m_start + i*m_step; -} \ No newline at end of file +} + +} diff --git a/apps/graph/values/title_cell.cpp b/apps/graph/values/title_cell.cpp index 362d91d69..75e43649e 100644 --- a/apps/graph/values/title_cell.cpp +++ b/apps/graph/values/title_cell.cpp @@ -1,6 +1,8 @@ #include "title_cell.h" #include "../function_store.h" +namespace Graph { + TitleCell::TitleCell() : EvenOddCell(), m_text(nullptr) @@ -18,5 +20,7 @@ void TitleCell::drawRect(KDContext * ctx, KDRect rect) const { KDSize textSize = KDText::stringSize(m_text); KDPoint origin(0.5f*(m_frame.width() - textSize.width()), 0.5f*(m_frame.height() - textSize.height())); ctx->drawString(m_text, origin, KDColorBlack, background); - ctx->drawString(Graph::Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), KDColorBlack, background); + ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), KDColorBlack, background); +} + } diff --git a/apps/graph/values/title_cell.h b/apps/graph/values/title_cell.h index 59a8c2088..f94308500 100644 --- a/apps/graph/values/title_cell.h +++ b/apps/graph/values/title_cell.h @@ -4,6 +4,7 @@ #include #include "../even_odd_cell.h" +namespace Graph { class TitleCell : public EvenOddCell { public: TitleCell(); @@ -14,4 +15,6 @@ protected: char * m_text; }; +} + #endif diff --git a/apps/graph/values/value_cell.cpp b/apps/graph/values/value_cell.cpp index 557705c25..f52b9b7fc 100644 --- a/apps/graph/values/value_cell.cpp +++ b/apps/graph/values/value_cell.cpp @@ -1,6 +1,8 @@ #include "value_cell.h" #include "float_to_string.h" +namespace Graph { + ValueCell::ValueCell() : EvenOddCell() { @@ -19,3 +21,5 @@ void ValueCell::drawRect(KDContext * ctx, KDRect rect) const { KDPoint origin(m_frame.width() - textSize.width(), 0.5f*(m_frame.height() - textSize.height())); ctx->drawString(m_buffer, origin, KDColorBlack, background); } + +} diff --git a/apps/graph/values/value_cell.h b/apps/graph/values/value_cell.h index ab31f96c1..708743a7b 100644 --- a/apps/graph/values/value_cell.h +++ b/apps/graph/values/value_cell.h @@ -4,6 +4,7 @@ #include #include "../even_odd_cell.h" +namespace Graph { class ValueCell : public EvenOddCell { public: ValueCell(); @@ -15,4 +16,6 @@ protected: char m_buffer[14]; }; +} + #endif diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 21754a448..2120b50cc 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -1,14 +1,16 @@ #include "values_controller.h" #include -ValuesController::ValuesController(Responder * parentResponder, Graph::FunctionStore * functionStore, Graph::EvaluateContext * evaluateContext) : +namespace Graph { + +ValuesController::ValuesController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext) : HeaderViewController(parentResponder, &m_tableView), m_tableView(TableView(this, k_topMargin, k_rightMargin, k_bottomMargin, k_leftMargin)), m_activeCellX(0), m_activeCellY(-1), m_functionStore(functionStore), m_evaluateContext(evaluateContext), - m_interval(Graph::Interval(-1.0f, 1.0f, 0.25f)), + m_interval(Interval(-1.0f, 1.0f, 0.25f)), m_parameterController(ValuesParameterController(this)), m_setIntervalButton(Button(this, "Regler l'intervalle",Invocation([](void * context, void * sender) { ValuesController * valuesController = (ValuesController *) context; @@ -84,11 +86,7 @@ int ValuesController::indexFromCumulatedWidth(KDCoordinate offsetX) { } int ValuesController::indexFromCumulatedHeight(KDCoordinate offsetY) { - int index = 0; - while (index*k_cellHeight <= offsetY) { - index++; - } - return index-1; + return (offsetY-1) / k_cellHeight; } void ValuesController::setActiveCell(int i, int j) { @@ -206,7 +204,7 @@ void ValuesController::willDisplayCellAtLocation(View * cell, int i, int j) { if (i == 0) { myCell->setText("x"); } else { - Graph::Function * function = m_functionStore->activeFunctionAtIndex(i-1); + Function * function = m_functionStore->activeFunctionAtIndex(i-1); myCell->setText(function->name()); } } else { @@ -214,7 +212,7 @@ void ValuesController::willDisplayCellAtLocation(View * cell, int i, int j) { if (i == 0){ myCell->setFloat(m_interval.element(j-1)); } else { - Graph::Function * function = m_functionStore->activeFunctionAtIndex(i-1); + Function * function = m_functionStore->activeFunctionAtIndex(i-1); float x = m_interval.element(j-1); myCell->setFloat(function->evaluateAtAbscissa(x, m_evaluateContext)); } @@ -222,3 +220,4 @@ void ValuesController::willDisplayCellAtLocation(View * cell, int i, int j) { } } +} diff --git a/apps/graph/values/values_controller.h b/apps/graph/values/values_controller.h index b9ef3b33d..52a123a64 100644 --- a/apps/graph/values/values_controller.h +++ b/apps/graph/values/values_controller.h @@ -9,9 +9,11 @@ #include "interval.h" #include "values_parameter_controller.h" +namespace Graph { + class ValuesController : public HeaderViewController, public TableViewDataSource { public: - ValuesController(Responder * parentResponder, Graph::FunctionStore * functionStore, Graph::EvaluateContext * evaluateContext); + ValuesController(Responder * parentResponder, FunctionStore * functionStore, EvaluateContext * evaluateContext); void setActiveCell(int i, int j); @@ -54,11 +56,13 @@ private: TableView m_tableView; int m_activeCellX; int m_activeCellY; - Graph::FunctionStore * m_functionStore; - Graph::EvaluateContext * m_evaluateContext; - Graph::Interval m_interval; + FunctionStore * m_functionStore; + EvaluateContext * m_evaluateContext; + Interval m_interval; ValuesParameterController m_parameterController; Button m_setIntervalButton; }; +} + #endif diff --git a/apps/graph/values/values_parameter_controller.cpp b/apps/graph/values/values_parameter_controller.cpp index 908de9d5a..a527e039b 100644 --- a/apps/graph/values/values_parameter_controller.cpp +++ b/apps/graph/values/values_parameter_controller.cpp @@ -1,6 +1,8 @@ #include "values_parameter_controller.h" #include +namespace Graph { + ValuesParameterController::ValuesParameterController(Responder * parentResponder) : ViewController(parentResponder), m_intervalStartCell(TableViewCell((char*)"X Debut")), @@ -70,3 +72,5 @@ int ValuesParameterController::reusableCellCount() { KDCoordinate ValuesParameterController::cellHeight() { return 35; } + +} diff --git a/apps/graph/values/values_parameter_controller.h b/apps/graph/values/values_parameter_controller.h index 9f85e744b..c6b862d0f 100644 --- a/apps/graph/values/values_parameter_controller.h +++ b/apps/graph/values/values_parameter_controller.h @@ -3,6 +3,7 @@ #include +namespace Graph { class ValuesParameterController : public ViewController, public ListViewDataSource { public: ValuesParameterController(Responder * parentResponder); @@ -26,4 +27,6 @@ private: int m_activeCell; }; +} + #endif