Merge branch 'cyclic-change-color-2'

This commit is contained in:
David Capello 2021-09-01 10:40:32 -03:00
commit 4c6835c439

View File

@ -75,15 +75,20 @@ void ChangeColorCommand::onExecute(Context* context)
// do nothing
break;
case IncrementIndex: {
int index = color.getIndex();
if (index < get_current_palette()->size()-1)
color = app::Color::fromIndex(index+1);
const int palSize = get_current_palette()->size();
if (palSize >= 1) {
// Seems safe to assume getIndex() will return a
// positive number, so use truncation modulo.
color = app::Color::fromIndex((color.getIndex() + 1) % palSize);
}
break;
}
case DecrementIndex: {
int index = color.getIndex();
if (index > 0)
color = app::Color::fromIndex(index-1);
const int palSize = get_current_palette()->size();
if (palSize >= 1) {
// Floor modulo.
color = app::Color::fromIndex(((color.getIndex() - 1) % palSize + palSize) % palSize);
}
break;
}
}