mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-04 08:46:09 +00:00
Cyclic Color Change in Palettes
Made Change Color: Increment/Decrement Foreground/Background methods cyclic instead of clamped. At last palette element, incrementing selected color returns to first element. At first palette element, decrementing color returns to last element.
This commit is contained in:
parent
dd2d226264
commit
edb9f89456
@ -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