mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
Show selected fg/bg items in the tiles view
This commit is contained in:
parent
963602444f
commit
d164458c24
@ -283,6 +283,8 @@ ColorBar::ColorBar(int align, TooltipManager* tooltipManager)
|
||||
m_buttons.ItemChange.connect([this]{ onPaletteButtonClick(); });
|
||||
m_tilesButton.ItemChange.connect([this]{ onTilesButtonClick(); });
|
||||
m_tilesButton.RightClick.connect([this]{ onTilesButtonRightClick(); });
|
||||
m_fgTile.Change.connect(&ColorBar::onFgTileButtonChange, this);
|
||||
m_bgTile.Change.connect(&ColorBar::onBgTileButtonChange, this);
|
||||
m_tilesetModeButtons.ItemChange.connect([this]{ onTilesetModeButtonClick(); });
|
||||
|
||||
InitTheme.connect(
|
||||
@ -948,6 +950,13 @@ void ColorBar::onRemapTilesButtonClick()
|
||||
}
|
||||
}
|
||||
|
||||
bool ColorBar::onIsPaletteViewActive(PaletteView* paletteView) const
|
||||
{
|
||||
return
|
||||
(paletteView == &m_paletteView && m_tilemapMode == TilemapMode::Pixels) ||
|
||||
(paletteView == &m_tilesView && m_tilemapMode == TilemapMode::Tiles);
|
||||
}
|
||||
|
||||
void ColorBar::onPaletteViewIndexChange(int index, ui::MouseButton button)
|
||||
{
|
||||
COLOR_BAR_TRACE("ColorBar::onPaletteViewIndexChange(%d)\n", index);
|
||||
@ -1082,6 +1091,16 @@ app::Color ColorBar::onPaletteViewGetBackgroundIndex()
|
||||
return getBgColor();
|
||||
}
|
||||
|
||||
doc::tile_index ColorBar::onPaletteViewGetForegroundTile()
|
||||
{
|
||||
return doc::tile_geti(getFgTile());
|
||||
}
|
||||
|
||||
doc::tile_index ColorBar::onPaletteViewGetBackgroundTile()
|
||||
{
|
||||
return doc::tile_geti(getBgTile());
|
||||
}
|
||||
|
||||
void ColorBar::onTilesViewClearTiles(const doc::PalettePicks& _picks)
|
||||
{
|
||||
// Copy the collection of selected tiles because in case that the
|
||||
@ -1236,7 +1255,9 @@ void ColorBar::onFgTileChangeFromPreferences()
|
||||
return;
|
||||
|
||||
base::ScopedValue<bool> sync(m_fromPref, true, false);
|
||||
m_fgTile.setTile(Preferences::instance().colorBar.fgTile());
|
||||
auto tile = Preferences::instance().colorBar.fgTile();
|
||||
m_fgTile.setTile(tile);
|
||||
m_tilesView.selectColor(tile);
|
||||
}
|
||||
|
||||
void ColorBar::onBgTileChangeFromPreferences()
|
||||
@ -1245,7 +1266,9 @@ void ColorBar::onBgTileChangeFromPreferences()
|
||||
return;
|
||||
|
||||
base::ScopedValue<bool> sync(m_fromPref, true, false);
|
||||
m_bgTile.setTile(Preferences::instance().colorBar.bgTile());
|
||||
auto tile = Preferences::instance().colorBar.bgTile();
|
||||
m_bgTile.setTile(tile);
|
||||
m_tilesView.selectColor(tile);
|
||||
}
|
||||
|
||||
void ColorBar::onFgColorButtonBeforeChange(app::Color& color)
|
||||
@ -1339,6 +1362,18 @@ void ColorBar::onColorButtonChange(const app::Color& color)
|
||||
m_wheel->selectColor(color);
|
||||
}
|
||||
|
||||
void ColorBar::onFgTileButtonChange(doc::tile_t tile)
|
||||
{
|
||||
if (!m_fromPref)
|
||||
Preferences::instance().colorBar.fgTile(tile);
|
||||
}
|
||||
|
||||
void ColorBar::onBgTileButtonChange(doc::tile_t tile)
|
||||
{
|
||||
if (!m_fromPref)
|
||||
Preferences::instance().colorBar.bgTile(tile);
|
||||
}
|
||||
|
||||
void ColorBar::onPickSpectrum(const app::Color& color, ui::MouseButton button)
|
||||
{
|
||||
// Change to pixels mode automatically
|
||||
|
@ -143,6 +143,8 @@ namespace app {
|
||||
void onFgColorButtonChange(const app::Color& color);
|
||||
void onBgColorButtonChange(const app::Color& color);
|
||||
void onColorButtonChange(const app::Color& color);
|
||||
void onFgTileButtonChange(doc::tile_t tile);
|
||||
void onBgTileButtonChange(doc::tile_t tile);
|
||||
void onPickSpectrum(const app::Color& color, ui::MouseButton button);
|
||||
void onReverseColors();
|
||||
void onSortBy(doc::SortPaletteBy channel);
|
||||
@ -152,12 +154,15 @@ namespace app {
|
||||
void setAscending(bool ascending);
|
||||
|
||||
// PaletteViewDelegate impl
|
||||
bool onIsPaletteViewActive(PaletteView* paletteView) const override;
|
||||
void onPaletteViewIndexChange(int index, ui::MouseButton button) override;
|
||||
void onPaletteViewModification(const doc::Palette* newPalette, PaletteViewModification mod) override;
|
||||
void onPaletteViewChangeSize(PaletteView* paletteView, int boxsize) override;
|
||||
void onPaletteViewPasteColors(const Palette* fromPal, const doc::PalettePicks& from, const doc::PalettePicks& to) override;
|
||||
app::Color onPaletteViewGetForegroundIndex() override;
|
||||
app::Color onPaletteViewGetBackgroundIndex() override;
|
||||
doc::tile_index onPaletteViewGetForegroundTile() override;
|
||||
doc::tile_index onPaletteViewGetBackgroundTile() override;
|
||||
void onTilesViewClearTiles(const doc::PalettePicks& picks) override;
|
||||
void onTilesViewResize(const int newSize) override;
|
||||
void onTilesViewDragAndDrop(doc::Tileset* tileset,
|
||||
|
@ -503,7 +503,9 @@ app::Color PaletteView::getColorByPosition(const gfx::Point& pos)
|
||||
{
|
||||
gfx::Point relPos = pos - bounds().origin();
|
||||
for (int i=0; i<m_adapter->size(); ++i) {
|
||||
if (getPaletteEntryBounds(i).contains(relPos))
|
||||
auto box = getPaletteEntryBounds(i);
|
||||
box.inflate(childSpacing());
|
||||
if (box.contains(relPos))
|
||||
return app::Color::fromIndex(i);
|
||||
}
|
||||
return app::Color::fromMask();
|
||||
@ -513,7 +515,9 @@ doc::tile_t PaletteView::getTileByPosition(const gfx::Point& pos)
|
||||
{
|
||||
gfx::Point relPos = pos - bounds().origin();
|
||||
for (int i=0; i<m_adapter->size(); ++i) {
|
||||
if (getPaletteEntryBounds(i).contains(relPos))
|
||||
auto box = getPaletteEntryBounds(i);
|
||||
box.inflate(childSpacing());
|
||||
if (box.contains(relPos))
|
||||
return doc::tile(i, 0);
|
||||
}
|
||||
return doc::notile;
|
||||
@ -791,12 +795,22 @@ void PaletteView::onPaint(ui::PaintEvent& ev)
|
||||
const bool dragging = (m_state == State::DRAGGING_OUTLINE && hotColor);
|
||||
const bool resizing = (m_state == State::RESIZING_PALETTE && hotColor);
|
||||
|
||||
if (m_style == FgBgColors && m_delegate) {
|
||||
fgIndex = findExactIndex(m_delegate->onPaletteViewGetForegroundIndex());
|
||||
bgIndex = findExactIndex(m_delegate->onPaletteViewGetBackgroundIndex());
|
||||
if (m_delegate) {
|
||||
switch (m_style) {
|
||||
|
||||
if (current_editor && current_editor->sprite()->pixelFormat() == IMAGE_INDEXED)
|
||||
transparentIndex = current_editor->sprite()->transparentColor();
|
||||
case FgBgColors:
|
||||
fgIndex = findExactIndex(m_delegate->onPaletteViewGetForegroundIndex());
|
||||
bgIndex = findExactIndex(m_delegate->onPaletteViewGetBackgroundIndex());
|
||||
|
||||
if (current_editor && current_editor->sprite()->pixelFormat() == IMAGE_INDEXED)
|
||||
transparentIndex = current_editor->sprite()->transparentColor();
|
||||
break;
|
||||
|
||||
case FgBgTiles:
|
||||
fgIndex = m_delegate->onPaletteViewGetForegroundTile();
|
||||
bgIndex = m_delegate->onPaletteViewGetBackgroundTile();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g->fillRect(theme->colors.editorFace(), bounds);
|
||||
@ -826,28 +840,38 @@ void PaletteView::onPaint(ui::PaintEvent& ev)
|
||||
m_adapter->drawEntry(g, theme, i + idxOffset, i + boxOffset,
|
||||
childSpacing(), box, negColor);
|
||||
const int boxsize = boxSizePx();
|
||||
const int scale = guiscale();
|
||||
|
||||
switch (m_style) {
|
||||
if (!m_delegate || m_delegate->onIsPaletteViewActive(this)) {
|
||||
switch (m_style) {
|
||||
|
||||
case SelectOneColor:
|
||||
if (m_currentEntry == i)
|
||||
g->fillRect(negColor, gfx::Rect(box.center(), gfx::Size(guiscale(), guiscale())));
|
||||
break;
|
||||
case SelectOneColor:
|
||||
if (m_currentEntry == i)
|
||||
g->fillRect(negColor, gfx::Rect(box.center(), gfx::Size(scale, scale)));
|
||||
break;
|
||||
|
||||
case FgBgColors:
|
||||
if (fgIndex == i) {
|
||||
for (int i=0; i<int(boxsize/2); ++i)
|
||||
g->drawHLine(negColor, box.x, box.y+i, int(boxsize/2)-i);
|
||||
}
|
||||
case FgBgColors:
|
||||
case FgBgTiles:
|
||||
if (fgIndex == i) {
|
||||
for (int i=0; i<int(boxsize/2); i += scale) {
|
||||
g->fillRect(negColor,
|
||||
gfx::Rect(box.x, box.y+i, int(boxsize/2)-i, scale));
|
||||
}
|
||||
}
|
||||
|
||||
if (bgIndex == i) {
|
||||
for (int i=0; i<int(boxsize/4); ++i)
|
||||
g->drawHLine(negColor, box.x+box.w-(i+1), box.y+box.h-int(boxsize/4)+i, i+1);
|
||||
}
|
||||
if (bgIndex == i) {
|
||||
for (int i=0; i<int(boxsize/4); i += scale) {
|
||||
g->fillRect(negColor,
|
||||
gfx::Rect(box.x+box.w-(i+scale),
|
||||
box.y+box.h-int(boxsize/4)+i,
|
||||
i+scale, scale));
|
||||
}
|
||||
}
|
||||
|
||||
if (transparentIndex == i)
|
||||
g->fillRect(negColor, gfx::Rect(box.center(), gfx::Size(guiscale(), guiscale())));
|
||||
break;
|
||||
if (transparentIndex == i)
|
||||
g->fillRect(negColor, gfx::Rect(box.center(), gfx::Size(scale, scale)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ namespace app {
|
||||
class PaletteViewDelegate {
|
||||
public:
|
||||
virtual ~PaletteViewDelegate() { }
|
||||
virtual bool onIsPaletteViewActive(PaletteView* paletteView) const { return false; }
|
||||
virtual void onPaletteViewIndexChange(int index, ui::MouseButton button) { }
|
||||
virtual void onPaletteViewModification(const doc::Palette* newPalette, PaletteViewModification mod) { }
|
||||
virtual void onPaletteViewChangeSize(PaletteView* paletteView, int boxsize) { }
|
||||
@ -50,6 +51,8 @@ namespace app {
|
||||
const doc::Palette* fromPal, const doc::PalettePicks& from, const doc::PalettePicks& to) { }
|
||||
virtual app::Color onPaletteViewGetForegroundIndex() { return app::Color::fromMask(); }
|
||||
virtual app::Color onPaletteViewGetBackgroundIndex() { return app::Color::fromMask(); }
|
||||
virtual doc::tile_index onPaletteViewGetForegroundTile() { return -1; }
|
||||
virtual doc::tile_index onPaletteViewGetBackgroundTile() { return -1; }
|
||||
virtual void onTilesViewClearTiles(const doc::PalettePicks& tiles) { }
|
||||
virtual void onTilesViewResize(const int newSize) { }
|
||||
virtual void onTilesViewDragAndDrop(doc::Tileset* tileset,
|
||||
|
Loading…
x
Reference in New Issue
Block a user