[Horus] Model move within a category
This commit is contained in:
@@ -95,6 +95,33 @@ class ModelsCategory: public std::list<ModelCell *>
|
||||
remove(model);
|
||||
}
|
||||
|
||||
void moveModel(ModelCell * model, int8_t step)
|
||||
{
|
||||
ModelsCategory::iterator current = begin();
|
||||
for (; current != end(); current++) {
|
||||
if (*current == model) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ModelsCategory::iterator new_position = current;
|
||||
if (step > 0) {
|
||||
while (step >= 0 && new_position != end()) {
|
||||
new_position++;
|
||||
step--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (step < 0 && new_position != begin()) {
|
||||
new_position--;
|
||||
step++;
|
||||
}
|
||||
}
|
||||
|
||||
insert(new_position, 1, *current);
|
||||
erase(current);
|
||||
}
|
||||
|
||||
void save(FIL * file)
|
||||
{
|
||||
f_puts("[", file);
|
||||
@@ -130,6 +157,7 @@ class ModelsList
|
||||
categories.clear();
|
||||
currentCategory = NULL;
|
||||
currentModel = NULL;
|
||||
modelsCount = 0;
|
||||
}
|
||||
|
||||
bool load()
|
||||
@@ -159,6 +187,7 @@ class ModelsList
|
||||
currentCategory = category;
|
||||
currentModel = model;
|
||||
}
|
||||
modelsCount += 1;
|
||||
}
|
||||
}
|
||||
f_close(&file);
|
||||
@@ -221,12 +250,14 @@ class ModelsList
|
||||
ModelCell * addModel(ModelsCategory * category, const char * name)
|
||||
{
|
||||
ModelCell * result = category->addModel(name);
|
||||
modelsCount++;
|
||||
save();
|
||||
return result;
|
||||
}
|
||||
|
||||
void removeCategory(ModelsCategory * category)
|
||||
{
|
||||
modelsCount -= category->size();
|
||||
delete category;
|
||||
categories.remove(category);
|
||||
}
|
||||
@@ -234,12 +265,20 @@ class ModelsList
|
||||
void removeModel(ModelsCategory * category, ModelCell * model)
|
||||
{
|
||||
category->removeModel(model);
|
||||
modelsCount--;
|
||||
save();
|
||||
}
|
||||
|
||||
void moveModel(ModelsCategory * category, ModelCell * model, int8_t step)
|
||||
{
|
||||
category->moveModel(model, step);
|
||||
save();
|
||||
}
|
||||
|
||||
std::list<ModelsCategory *> categories;
|
||||
ModelsCategory * currentCategory;
|
||||
ModelCell * currentModel;
|
||||
unsigned int modelsCount;
|
||||
|
||||
protected:
|
||||
FIL file;
|
||||
|
||||
Reference in New Issue
Block a user