mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-21 14:50:44 +01:00
[apps/graph] add methods to handle function names and colors.
Change-Id: Ic11f2dd6bd9cb473b436d5e7769e2660c173c733
This commit is contained in:
@@ -3,8 +3,9 @@ extern "C" {
|
||||
#include <assert.h>
|
||||
}
|
||||
|
||||
constexpr int Graph::FunctionStore::numberOfDefaultColors;
|
||||
constexpr KDColor Graph::FunctionStore::defaultColors[numberOfDefaultColors];
|
||||
constexpr int Graph::FunctionStore::k_numberOfDefaultColors;
|
||||
constexpr KDColor Graph::FunctionStore::defaultColors[k_numberOfDefaultColors];
|
||||
constexpr const char * Graph::FunctionStore::functionNames[k_maxNumberOfFunctions];
|
||||
|
||||
Graph::FunctionStore::FunctionStore() :
|
||||
m_numberOfFunctions(0)
|
||||
@@ -18,10 +19,9 @@ Graph::Function * Graph::FunctionStore::functionAtIndex(int i) {
|
||||
|
||||
Graph::Function * Graph::FunctionStore::addEmptyFunction() {
|
||||
assert(m_numberOfFunctions < k_maxNumberOfFunctions);
|
||||
Graph::Function addedFunction = Function();
|
||||
addedFunction.setColor(defaultColors[numberOfFunctions()%numberOfDefaultColors]);
|
||||
addedFunction.setName("f(x)");
|
||||
addedFunction.setActive(true);
|
||||
const char * name = firstAvailableName();
|
||||
KDColor color = firstAvailableColor();
|
||||
Graph::Function addedFunction = Function(name, color);
|
||||
m_functions[m_numberOfFunctions] = addedFunction;
|
||||
Function * result = &m_functions[m_numberOfFunctions];
|
||||
m_numberOfFunctions++;
|
||||
@@ -43,3 +43,35 @@ void Graph::FunctionStore::removeFunction(Function * f) {
|
||||
int Graph::FunctionStore::numberOfFunctions() {
|
||||
return m_numberOfFunctions;
|
||||
}
|
||||
|
||||
const char * Graph::FunctionStore::firstAvailableName() {
|
||||
for (int k = 0; k < k_maxNumberOfFunctions; k++) {
|
||||
int j = 0;
|
||||
while (j < m_numberOfFunctions) {
|
||||
if (m_functions[j].name() == functionNames[k]) {
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (j == m_numberOfFunctions) {
|
||||
return functionNames[k];
|
||||
}
|
||||
}
|
||||
return functionNames[0];
|
||||
}
|
||||
|
||||
const KDColor Graph::FunctionStore::firstAvailableColor() {
|
||||
for (int k = 0; k < k_numberOfDefaultColors; k++) {
|
||||
int j = 0;
|
||||
while (j < m_numberOfFunctions) {
|
||||
if (m_functions[j].color() == defaultColors[k]) {
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (j == m_numberOfFunctions) {
|
||||
return defaultColors[k];
|
||||
}
|
||||
}
|
||||
return defaultColors[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user