diff --git a/apps/graph/function.cpp b/apps/graph/function.cpp index 8fd58c604..4e23cb7c5 100644 --- a/apps/graph/function.cpp +++ b/apps/graph/function.cpp @@ -7,8 +7,9 @@ Graph::Function::Function() : { } -Graph::Function::Function(const char * text) : +Graph::Function::Function(const char * text, KDColor color) : m_text(text), // FIXME: Copy !! + m_color(color), m_expression(nullptr), m_layout(nullptr) { diff --git a/apps/graph/function.h b/apps/graph/function.h index d8b8056b5..764516858 100644 --- a/apps/graph/function.h +++ b/apps/graph/function.h @@ -2,19 +2,22 @@ #define GRAPH_FUNCTION_H #include +#include namespace Graph { class Function { public: Function(); - Function(const char * text); + Function(const char * text, KDColor m_color); ~Function(); // Delete expression and layout, if needed const char * text(); + KDColor color() const { return m_color; } Expression * expression(); ExpressionLayout * layout(); private: const char * m_text; + KDColor m_color; Expression * m_expression; ExpressionLayout * m_layout; }; diff --git a/apps/graph/function_store.cpp b/apps/graph/function_store.cpp index 291b6d137..5c2d0c277 100644 --- a/apps/graph/function_store.cpp +++ b/apps/graph/function_store.cpp @@ -3,6 +3,11 @@ extern "C" { #include } +constexpr int numberOfDefaultColors = 3; +constexpr KDColor defaultColors[numberOfDefaultColors] = { + KDColorRed, KDColorGreen, KDColorBlue +}; + Graph::FunctionStore::FunctionStore() : m_numberOfFunctions(0) { @@ -15,7 +20,7 @@ Graph::Function * Graph::FunctionStore::functionAtIndex(int i) { void Graph::FunctionStore::pushFunction(const char * functionText) { assert(m_numberOfFunctions < k_maxNumberOfFunctions); - m_functions[m_numberOfFunctions++] = Function(functionText); + m_functions[m_numberOfFunctions++] = Function(functionText, defaultColors[m_numberOfFunctions%numberOfDefaultColors]); } int Graph::FunctionStore::numberOfFunctions() { diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index b965f6dee..d8c9dd61b 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -168,7 +168,7 @@ void GraphView::drawFunction(KDContext * ctx, KDRect rect) const { float y = f->expression()->approximate(plotContext); KDCoordinate py = floatToPixel(Axis::Vertical, y); KDRect stampRect(px, py, stampSize, stampSize); - ctx->fillRectWithMask(stampRect, KDColorRed, mask, workingBuffer); + ctx->fillRectWithMask(stampRect, f->color(), mask, workingBuffer); } } }