mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-01 00:23:35 +00:00
Add option to create color gradients in the ColorBar
This commit is contained in:
parent
5f46ffc5e0
commit
ca1ebf02b5
@ -252,6 +252,7 @@ void ColorBar::onPaletteButtonClick()
|
|||||||
Menu menu;
|
Menu menu;
|
||||||
MenuItem
|
MenuItem
|
||||||
rev("Reverse Colors"),
|
rev("Reverse Colors"),
|
||||||
|
grd("Gradient"),
|
||||||
hue("Sort by Hue"),
|
hue("Sort by Hue"),
|
||||||
sat("Sort by Saturation"),
|
sat("Sort by Saturation"),
|
||||||
bri("Sort by Brightness"),
|
bri("Sort by Brightness"),
|
||||||
@ -259,6 +260,7 @@ void ColorBar::onPaletteButtonClick()
|
|||||||
asc("Ascending"),
|
asc("Ascending"),
|
||||||
des("Descending");
|
des("Descending");
|
||||||
menu.addChild(&rev);
|
menu.addChild(&rev);
|
||||||
|
menu.addChild(&grd);
|
||||||
menu.addChild(new ui::Separator("", JI_HORIZONTAL));
|
menu.addChild(new ui::Separator("", JI_HORIZONTAL));
|
||||||
menu.addChild(&hue);
|
menu.addChild(&hue);
|
||||||
menu.addChild(&sat);
|
menu.addChild(&sat);
|
||||||
@ -272,6 +274,7 @@ void ColorBar::onPaletteButtonClick()
|
|||||||
else des.setSelected(true);
|
else des.setSelected(true);
|
||||||
|
|
||||||
rev.Click.connect(Bind<void>(&ColorBar::onReverseColors, this));
|
rev.Click.connect(Bind<void>(&ColorBar::onReverseColors, this));
|
||||||
|
grd.Click.connect(Bind<void>(&ColorBar::onGradient, this));
|
||||||
hue.Click.connect(Bind<void>(&ColorBar::onSortBy, this, SortPaletteBy::HUE));
|
hue.Click.connect(Bind<void>(&ColorBar::onSortBy, this, SortPaletteBy::HUE));
|
||||||
sat.Click.connect(Bind<void>(&ColorBar::onSortBy, this, SortPaletteBy::SATURATION));
|
sat.Click.connect(Bind<void>(&ColorBar::onSortBy, this, SortPaletteBy::SATURATION));
|
||||||
bri.Click.connect(Bind<void>(&ColorBar::onSortBy, this, SortPaletteBy::VALUE));
|
bri.Click.connect(Bind<void>(&ColorBar::onSortBy, this, SortPaletteBy::VALUE));
|
||||||
@ -360,6 +363,11 @@ void ColorBar::applyRemap(const doc::Remap& remap, const doc::Palette* newPalett
|
|||||||
m_remap->merge(remap);
|
m_remap->merge(remap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPalette(newPalette, actionText);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorBar::setPalette(const doc::Palette* newPalette, const std::string& actionText)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
ContextWriter writer(UIContext::instance(), 500);
|
ContextWriter writer(UIContext::instance(), 500);
|
||||||
Sprite* sprite = writer.sprite();
|
Sprite* sprite = writer.sprite();
|
||||||
@ -373,6 +381,9 @@ void ColorBar::applyRemap(const doc::Remap& remap, const doc::Palette* newPalett
|
|||||||
catch (base::Exception& e) {
|
catch (base::Exception& e) {
|
||||||
Console::showException(e);
|
Console::showException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_current_palette(newPalette, false);
|
||||||
|
getManager()->invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBar::onPaletteViewChangeSize(int boxsize)
|
void ColorBar::onPaletteViewChangeSize(int boxsize)
|
||||||
@ -458,9 +469,6 @@ void ColorBar::onReverseColors()
|
|||||||
|
|
||||||
Palette newPalette(*get_current_palette(), remap);
|
Palette newPalette(*get_current_palette(), remap);
|
||||||
applyRemap(remap, &newPalette, "Reverse Colors");
|
applyRemap(remap, &newPalette, "Reverse Colors");
|
||||||
|
|
||||||
set_current_palette(&newPalette, false);
|
|
||||||
getManager()->invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBar::onSortBy(SortPaletteBy channel)
|
void ColorBar::onSortBy(SortPaletteBy channel)
|
||||||
@ -517,11 +525,19 @@ void ColorBar::onSortBy(SortPaletteBy channel)
|
|||||||
// Create a new palette and apply the remap. This is the final new
|
// Create a new palette and apply the remap. This is the final new
|
||||||
// palette for the sprite.
|
// palette for the sprite.
|
||||||
Palette newPalette(palette, remapOrig);
|
Palette newPalette(palette, remapOrig);
|
||||||
|
|
||||||
applyRemap(remapOrig, &newPalette, "Sort Colors");
|
applyRemap(remapOrig, &newPalette, "Sort Colors");
|
||||||
|
}
|
||||||
|
|
||||||
set_current_palette(&newPalette, false);
|
void ColorBar::onGradient()
|
||||||
getManager()->invalidate();
|
{
|
||||||
|
int index1, index2;
|
||||||
|
if (!m_paletteView.getSelectedRange(index1, index2))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Palette newPalette(*get_current_palette());
|
||||||
|
newPalette.makeHorzRamp(index1, index2);
|
||||||
|
|
||||||
|
setPalette(&newPalette, "Gradient");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBar::setAscending(bool ascending)
|
void ColorBar::setAscending(bool ascending)
|
||||||
|
@ -68,6 +68,7 @@ namespace app {
|
|||||||
void onPickSpectrum(const app::Color& color, ui::MouseButtons buttons);
|
void onPickSpectrum(const app::Color& color, ui::MouseButtons buttons);
|
||||||
void onReverseColors();
|
void onReverseColors();
|
||||||
void onSortBy(doc::SortPaletteBy channel);
|
void onSortBy(doc::SortPaletteBy channel);
|
||||||
|
void onGradient();
|
||||||
void setAscending(bool ascending);
|
void setAscending(bool ascending);
|
||||||
|
|
||||||
// PaletteViewDelegate impl
|
// PaletteViewDelegate impl
|
||||||
@ -78,6 +79,7 @@ namespace app {
|
|||||||
private:
|
private:
|
||||||
void destroyRemap();
|
void destroyRemap();
|
||||||
void applyRemap(const doc::Remap& remap, const doc::Palette* newPalette, const std::string& actionText);
|
void applyRemap(const doc::Remap& remap, const doc::Palette* newPalette, const std::string& actionText);
|
||||||
|
void setPalette(const doc::Palette* newPalette, const std::string& actionText);
|
||||||
|
|
||||||
class ScrollableView : public ui::View {
|
class ScrollableView : public ui::View {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user