mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 03:44:16 +00:00
Fix palette editor for one entry (non-selected range)
This fix the most common behavior where we are capable of use eyedropper to pick just one color, and modify it with the editor.
This commit is contained in:
parent
442d8c624a
commit
300a5cc1cb
@ -85,6 +85,7 @@ private:
|
|||||||
void updateColorBar();
|
void updateColorBar();
|
||||||
void onPalChange();
|
void onPalChange();
|
||||||
void resetRelativeInfo();
|
void resetRelativeInfo();
|
||||||
|
void getPicks(PalettePicks& picks);
|
||||||
|
|
||||||
app::Color::Type m_type;
|
app::Color::Type m_type;
|
||||||
Box m_vbox;
|
Box m_vbox;
|
||||||
@ -315,9 +316,8 @@ void PaletteEntryEditor::setColor(const app::Color& color)
|
|||||||
if (!m_disableHexUpdate)
|
if (!m_disableHexUpdate)
|
||||||
m_hexColorEntry.setColor(color);
|
m_hexColorEntry.setColor(color);
|
||||||
|
|
||||||
PaletteView* palette_editor = ColorBar::instance()->getPaletteView();
|
|
||||||
PalettePicks entries;
|
PalettePicks entries;
|
||||||
palette_editor->getSelectedEntries(entries);
|
getPicks(entries);
|
||||||
int i, j, i2;
|
int i, j, i2;
|
||||||
|
|
||||||
// Find the first selected entry
|
// Find the first selected entry
|
||||||
@ -459,9 +459,8 @@ void PaletteEntryEditor::onRelativeButtonClick(Event& ev)
|
|||||||
|
|
||||||
void PaletteEntryEditor::setPaletteEntry(const app::Color& color)
|
void PaletteEntryEditor::setPaletteEntry(const app::Color& color)
|
||||||
{
|
{
|
||||||
PaletteView* palView = ColorBar::instance()->getPaletteView();
|
|
||||||
PalettePicks entries;
|
PalettePicks entries;
|
||||||
palView->getSelectedEntries(entries);
|
getPicks(entries);
|
||||||
|
|
||||||
color_t new_pal_color = doc::rgba(color.getRed(),
|
color_t new_pal_color = doc::rgba(color.getRed(),
|
||||||
color.getGreen(),
|
color.getGreen(),
|
||||||
@ -476,13 +475,9 @@ void PaletteEntryEditor::setPaletteEntry(const app::Color& color)
|
|||||||
|
|
||||||
void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel channel, const app::Color& color)
|
void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel channel, const app::Color& color)
|
||||||
{
|
{
|
||||||
PaletteView* palView = ColorBar::instance()->getPaletteView();
|
|
||||||
PalettePicks entries;
|
PalettePicks entries;
|
||||||
palView->getSelectedEntries(entries);
|
getPicks(entries);
|
||||||
|
int picksCount = entries.picks();
|
||||||
int begSel, endSel;
|
|
||||||
if (!palView->getSelectedRange(begSel, endSel))
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint32_t src_color;
|
uint32_t src_color;
|
||||||
int r, g, b;
|
int r, g, b;
|
||||||
@ -502,7 +497,7 @@ void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel ch
|
|||||||
|
|
||||||
case app::Color::RgbType:
|
case app::Color::RgbType:
|
||||||
// Modify one entry
|
// Modify one entry
|
||||||
if (begSel == endSel) {
|
if (picksCount == 1) {
|
||||||
r = color.getRed();
|
r = color.getRed();
|
||||||
g = color.getGreen();
|
g = color.getGreen();
|
||||||
b = color.getBlue();
|
b = color.getBlue();
|
||||||
@ -528,7 +523,7 @@ void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel ch
|
|||||||
Hsv hsv;
|
Hsv hsv;
|
||||||
|
|
||||||
// Modify one entry
|
// Modify one entry
|
||||||
if (begSel == endSel) {
|
if (picksCount == 1) {
|
||||||
hsv.hue(color.getHue());
|
hsv.hue(color.getHue());
|
||||||
hsv.saturation(double(color.getSaturation()) / 100.0);
|
hsv.saturation(double(color.getSaturation()) / 100.0);
|
||||||
hsv.value(double(color.getValue()) / 100.0);
|
hsv.value(double(color.getValue()) / 100.0);
|
||||||
@ -567,9 +562,8 @@ void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel ch
|
|||||||
|
|
||||||
void PaletteEntryEditor::setRelativePaletteEntryChannel(ColorSliders::Channel channel, int delta)
|
void PaletteEntryEditor::setRelativePaletteEntryChannel(ColorSliders::Channel channel, int delta)
|
||||||
{
|
{
|
||||||
PaletteView* palView = ColorBar::instance()->getPaletteView();
|
|
||||||
PalettePicks entries;
|
PalettePicks entries;
|
||||||
palView->getSelectedEntries(entries);
|
getPicks(entries);
|
||||||
|
|
||||||
// Update modified delta
|
// Update modified delta
|
||||||
m_relDeltas[channel] = delta;
|
m_relDeltas[channel] = delta;
|
||||||
@ -723,6 +717,17 @@ void PaletteEntryEditor::resetRelativeInfo()
|
|||||||
m_relDeltas.clear();
|
m_relDeltas.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaletteEntryEditor::getPicks(PalettePicks& picks)
|
||||||
|
{
|
||||||
|
PaletteView* palView = ColorBar::instance()->getPaletteView();
|
||||||
|
palView->getSelectedEntries(picks);
|
||||||
|
if (picks.picks() == 0) {
|
||||||
|
int i = palView->getSelectedEntry();
|
||||||
|
if (i >= 0 && i < picks.size())
|
||||||
|
picks[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Command* CommandFactory::createPaletteEditorCommand()
|
Command* CommandFactory::createPaletteEditorCommand()
|
||||||
{
|
{
|
||||||
return new PaletteEditorCommand;
|
return new PaletteEditorCommand;
|
||||||
|
@ -482,7 +482,7 @@ void ColorBar::onBgColorButtonChange(const app::Color& color)
|
|||||||
void ColorBar::onColorButtonChange(const app::Color& color)
|
void ColorBar::onColorButtonChange(const app::Color& color)
|
||||||
{
|
{
|
||||||
if (color.getType() == app::Color::IndexType)
|
if (color.getType() == app::Color::IndexType)
|
||||||
m_paletteView.selectColor(color.getIndex(), false);
|
m_paletteView.selectColor(color.getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBar::onPickSpectrum(const app::Color& color, ui::MouseButtons buttons)
|
void ColorBar::onPickSpectrum(const app::Color& color, ui::MouseButtons buttons)
|
||||||
|
@ -133,7 +133,7 @@ void ColorSelector::setColor(const app::Color& color, SetColorOptions options)
|
|||||||
|
|
||||||
if (color.getType() == app::Color::IndexType) {
|
if (color.getType() == app::Color::IndexType) {
|
||||||
m_colorPalette.deselect();
|
m_colorPalette.deselect();
|
||||||
m_colorPalette.selectColor(color.getIndex(), false);
|
m_colorPalette.selectColor(color.getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_rgbSliders.setColor(m_color);
|
m_rgbSliders.setColor(m_color);
|
||||||
@ -306,7 +306,7 @@ void ColorSelector::findBestfitIndex(const app::Color& color)
|
|||||||
int i = get_current_palette()->findBestfit(r, g, b);
|
int i = get_current_palette()->findBestfit(r, g, b);
|
||||||
if (i >= 0 && i < 256) {
|
if (i >= 0 && i < 256) {
|
||||||
m_colorPalette.deselect();
|
m_colorPalette.deselect();
|
||||||
m_colorPalette.selectColor(i, false);
|
m_colorPalette.selectColor(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ void PaletteView::deselect()
|
|||||||
this->invalidate();
|
this->invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaletteView::selectColor(int index, bool startRange)
|
void PaletteView::selectColor(int index)
|
||||||
{
|
{
|
||||||
ASSERT(index >= 0 && index < Palette::MaxColors);
|
ASSERT(index >= 0 && index < Palette::MaxColors);
|
||||||
|
|
||||||
@ -114,9 +114,6 @@ void PaletteView::selectColor(int index, bool startRange)
|
|||||||
m_currentEntry = index;
|
m_currentEntry = index;
|
||||||
m_rangeAnchor = index;
|
m_rangeAnchor = index;
|
||||||
|
|
||||||
if (startRange)
|
|
||||||
m_selectedEntries[index] = true;
|
|
||||||
|
|
||||||
update_scroll(m_currentEntry);
|
update_scroll(m_currentEntry);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
@ -318,8 +315,10 @@ bool PaletteView::onProcessMessage(Message* msg)
|
|||||||
|
|
||||||
if (msg->type() == kMouseMoveMessage)
|
if (msg->type() == kMouseMoveMessage)
|
||||||
selectRange(m_rangeAnchor, idx);
|
selectRange(m_rangeAnchor, idx);
|
||||||
else
|
else {
|
||||||
selectColor(idx, true);
|
selectColor(idx);
|
||||||
|
m_selectedEntries[idx] = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Emit signal
|
// Emit signal
|
||||||
if (m_delegate)
|
if (m_delegate)
|
||||||
|
@ -47,7 +47,7 @@ namespace app {
|
|||||||
void setColumns(int columns);
|
void setColumns(int columns);
|
||||||
|
|
||||||
void deselect();
|
void deselect();
|
||||||
void selectColor(int index, bool startRange);
|
void selectColor(int index);
|
||||||
void selectRange(int index1, int index2);
|
void selectRange(int index1, int index2);
|
||||||
|
|
||||||
int getSelectedEntry() const;
|
int getSelectedEntry() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user