mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-04 08:46:09 +00:00
Merge branch 'cyclic-change-color-2'
This commit is contained in:
commit
4c6835c439
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user