mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +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 onPalChange();
|
||||
void resetRelativeInfo();
|
||||
void getPicks(PalettePicks& picks);
|
||||
|
||||
app::Color::Type m_type;
|
||||
Box m_vbox;
|
||||
@ -315,9 +316,8 @@ void PaletteEntryEditor::setColor(const app::Color& color)
|
||||
if (!m_disableHexUpdate)
|
||||
m_hexColorEntry.setColor(color);
|
||||
|
||||
PaletteView* palette_editor = ColorBar::instance()->getPaletteView();
|
||||
PalettePicks entries;
|
||||
palette_editor->getSelectedEntries(entries);
|
||||
getPicks(entries);
|
||||
int i, j, i2;
|
||||
|
||||
// Find the first selected entry
|
||||
@ -459,9 +459,8 @@ void PaletteEntryEditor::onRelativeButtonClick(Event& ev)
|
||||
|
||||
void PaletteEntryEditor::setPaletteEntry(const app::Color& color)
|
||||
{
|
||||
PaletteView* palView = ColorBar::instance()->getPaletteView();
|
||||
PalettePicks entries;
|
||||
palView->getSelectedEntries(entries);
|
||||
getPicks(entries);
|
||||
|
||||
color_t new_pal_color = doc::rgba(color.getRed(),
|
||||
color.getGreen(),
|
||||
@ -476,13 +475,9 @@ void PaletteEntryEditor::setPaletteEntry(const app::Color& color)
|
||||
|
||||
void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel channel, const app::Color& color)
|
||||
{
|
||||
PaletteView* palView = ColorBar::instance()->getPaletteView();
|
||||
PalettePicks entries;
|
||||
palView->getSelectedEntries(entries);
|
||||
|
||||
int begSel, endSel;
|
||||
if (!palView->getSelectedRange(begSel, endSel))
|
||||
return;
|
||||
getPicks(entries);
|
||||
int picksCount = entries.picks();
|
||||
|
||||
uint32_t src_color;
|
||||
int r, g, b;
|
||||
@ -502,7 +497,7 @@ void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel ch
|
||||
|
||||
case app::Color::RgbType:
|
||||
// Modify one entry
|
||||
if (begSel == endSel) {
|
||||
if (picksCount == 1) {
|
||||
r = color.getRed();
|
||||
g = color.getGreen();
|
||||
b = color.getBlue();
|
||||
@ -528,7 +523,7 @@ void PaletteEntryEditor::setAbsolutePaletteEntryChannel(ColorSliders::Channel ch
|
||||
Hsv hsv;
|
||||
|
||||
// Modify one entry
|
||||
if (begSel == endSel) {
|
||||
if (picksCount == 1) {
|
||||
hsv.hue(color.getHue());
|
||||
hsv.saturation(double(color.getSaturation()) / 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)
|
||||
{
|
||||
PaletteView* palView = ColorBar::instance()->getPaletteView();
|
||||
PalettePicks entries;
|
||||
palView->getSelectedEntries(entries);
|
||||
getPicks(entries);
|
||||
|
||||
// Update modified delta
|
||||
m_relDeltas[channel] = delta;
|
||||
@ -723,6 +717,17 @@ void PaletteEntryEditor::resetRelativeInfo()
|
||||
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()
|
||||
{
|
||||
return new PaletteEditorCommand;
|
||||
|
@ -482,7 +482,7 @@ void ColorBar::onBgColorButtonChange(const app::Color& color)
|
||||
void ColorBar::onColorButtonChange(const app::Color& color)
|
||||
{
|
||||
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)
|
||||
|
@ -133,7 +133,7 @@ void ColorSelector::setColor(const app::Color& color, SetColorOptions options)
|
||||
|
||||
if (color.getType() == app::Color::IndexType) {
|
||||
m_colorPalette.deselect();
|
||||
m_colorPalette.selectColor(color.getIndex(), false);
|
||||
m_colorPalette.selectColor(color.getIndex());
|
||||
}
|
||||
|
||||
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);
|
||||
if (i >= 0 && i < 256) {
|
||||
m_colorPalette.deselect();
|
||||
m_colorPalette.selectColor(i, false);
|
||||
m_colorPalette.selectColor(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ void PaletteView::deselect()
|
||||
this->invalidate();
|
||||
}
|
||||
|
||||
void PaletteView::selectColor(int index, bool startRange)
|
||||
void PaletteView::selectColor(int index)
|
||||
{
|
||||
ASSERT(index >= 0 && index < Palette::MaxColors);
|
||||
|
||||
@ -114,9 +114,6 @@ void PaletteView::selectColor(int index, bool startRange)
|
||||
m_currentEntry = index;
|
||||
m_rangeAnchor = index;
|
||||
|
||||
if (startRange)
|
||||
m_selectedEntries[index] = true;
|
||||
|
||||
update_scroll(m_currentEntry);
|
||||
invalidate();
|
||||
}
|
||||
@ -318,8 +315,10 @@ bool PaletteView::onProcessMessage(Message* msg)
|
||||
|
||||
if (msg->type() == kMouseMoveMessage)
|
||||
selectRange(m_rangeAnchor, idx);
|
||||
else
|
||||
selectColor(idx, true);
|
||||
else {
|
||||
selectColor(idx);
|
||||
m_selectedEntries[idx] = true;
|
||||
}
|
||||
|
||||
// Emit signal
|
||||
if (m_delegate)
|
||||
|
@ -47,7 +47,7 @@ namespace app {
|
||||
void setColumns(int columns);
|
||||
|
||||
void deselect();
|
||||
void selectColor(int index, bool startRange);
|
||||
void selectColor(int index);
|
||||
void selectRange(int index1, int index2);
|
||||
|
||||
int getSelectedEntry() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user