Add support to pick tiles with eyedropper

This commit is contained in:
David Capello 2020-06-25 19:47:58 -03:00
parent d0c95cf46f
commit d0ab7d720c
2 changed files with 32 additions and 13 deletions

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -126,24 +126,41 @@ void ColorPicker::pickColor(const Site& site,
// Pick from the composed image // Pick from the composed image
case FromComposition: { case FromComposition: {
m_color = app::Color::fromImage(
sprite->pixelFormat(),
render::get_sprite_pixel(sprite, pos.x, pos.y,
site.frame(), proj,
Preferences::instance().experimental.newBlend()));
doc::CelList cels; doc::CelList cels;
sprite->pickCels(pos.x, pos.y, site.frame(), kOpacityThreshold, sprite->pickCels(pos.x, pos.y, site.frame(), kOpacityThreshold,
sprite->allVisibleLayers(), cels); sprite->allVisibleLayers(), cels);
if (!cels.empty()) if (!cels.empty())
m_layer = cels.front()->layer(); m_layer = cels.front()->layer();
if (site.tilemapMode() == TilemapMode::Tiles) {
if (!cels.empty()) {
gfx::Point tilePos = site.grid().canvasToTile(gfx::Point(pos));
m_color = app::Color::fromIndex(
doc::get_pixel(cels.front()->image(), tilePos.x, tilePos.y));
}
}
else if (site.tilemapMode() == TilemapMode::Pixels) {
m_color = app::Color::fromImage(
sprite->pixelFormat(),
render::get_sprite_pixel(sprite, pos.x, pos.y,
site.frame(), proj,
Preferences::instance().experimental.newBlend()));
}
break; break;
} }
// Pick from the current layer // Pick from the current layer
case FromActiveLayer: { case FromActiveLayer: {
const Cel* cel = site.cel(); const Cel* cel = site.cel();
if (cel) { if (!cel)
return;
if (site.tilemapMode() == TilemapMode::Tiles) {
gfx::Point tilePos = site.grid().canvasToTile(gfx::Point(pos));
m_color = app::Color::fromIndex(
doc::get_pixel(cel->image(), tilePos.x, tilePos.y));
}
else if (site.tilemapMode() == TilemapMode::Pixels) {
doc::color_t imageColor; doc::color_t imageColor;
if (!get_cel_pixel(cel, pos.x, pos.y, if (!get_cel_pixel(cel, pos.x, pos.y,
site.frame(), imageColor)) site.frame(), imageColor))

View File

@ -1,4 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -8,22 +9,18 @@
#include "config.h" #include "config.h"
#endif #endif
#include "app/app.h"
#include "app/color.h" #include "app/color.h"
#include "app/color_picker.h" #include "app/color_picker.h"
#include "app/commands/cmd_eyedropper.h" #include "app/commands/cmd_eyedropper.h"
#include "app/commands/commands.h" #include "app/commands/commands.h"
#include "app/commands/params.h" #include "app/commands/params.h"
#include "app/modules/editors.h" #include "app/context.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/site.h" #include "app/site.h"
#include "app/tools/tool.h" #include "app/tools/tool.h"
#include "app/tools/tool_box.h" #include "app/tools/tool_box.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui_context.h"
#include "doc/image.h"
#include "doc/sprite.h"
#include "ui/manager.h" #include "ui/manager.h"
#include "ui/system.h" #include "ui/system.h"
@ -65,6 +62,11 @@ void EyedropperCommand::pickSample(const Site& site,
app::Color picked = picker.color(); app::Color picked = picker.color();
if (site.tilemapMode() == TilemapMode::Tiles) {
color = app::Color::fromIndex(picked.getIndex());
return;
}
switch (channel) { switch (channel) {
case app::gen::EyedropperChannel::COLOR_ALPHA: case app::gen::EyedropperChannel::COLOR_ALPHA:
color = picked; color = picked;