diff --git a/src/app/script/app_object.cpp b/src/app/script/app_object.cpp index db6d6417f..778d60b3a 100644 --- a/src/app/script/app_object.cpp +++ b/src/app/script/app_object.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2023 Igara Studio S.A. +// Copyright (C) 2018-2024 Igara Studio S.A. // Copyright (C) 2015-2018 David Capello // // This program is distributed under the terms of @@ -365,6 +365,9 @@ int App_useTool(lua_State* L) type = lua_getfield(L, 1, "bgColor"); if (type != LUA_TNIL) params.bg = convert_args_into_color(L, -1); + else if (params.fg.getType() == + Preferences::instance().colorBar.bgColor().getType()) + params.bg = Preferences::instance().colorBar.bgColor(); else params.bg = params.fg; lua_pop(L, 1); @@ -476,6 +479,13 @@ int App_useTool(lua_State* L) bool first = true; lua_pushnil(L); + tools::ToolBox* toolbox = App::instance()->toolBox(); + const bool isSelectionInk = + (params.ink == toolbox->getInkById(tools::WellKnownInks::Selection)); + const tools::Pointer::Button button = + (!isSelectionInk ? (buttonIdx == 0 ? tools::Pointer::Button::Left : + tools::Pointer::Button::Right) : + tools::Pointer::Button::Left); while (lua_next(L, -2) != 0) { gfx::Point pt = convert_args_into_point(L, -1); @@ -483,7 +493,7 @@ int App_useTool(lua_State* L) pt, // TODO configurable params tools::Vec2(0.0f, 0.0f), - tools::Pointer::Button::Left, + button, tools::Pointer::Type::Unknown, 0.0f); if (first) { diff --git a/src/app/ui_context.cpp b/src/app/ui_context.cpp index 018ce8259..888c02f93 100644 --- a/src/app/ui_context.cpp +++ b/src/app/ui_context.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2023 Igara Studio S.A. +// Copyright (C) 2019-2024 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -366,6 +366,14 @@ void UIContext::onGetActiveSite(Site* site) const colorBar->getPaletteView()->getSelectedEntries(picks); site->selectedColors(picks); } + else if (colorBar && + colorBar->getTilesView()->getSelectedEntriesCount() > 0) { + site->focus(Site::InColorBar); + + doc::PalettePicks picks; + colorBar->getTilesView()->getSelectedEntries(picks); + site->selectedTiles(picks); + } else { site->focus(Site::InEditor); } diff --git a/tests/scripts/inks.lua b/tests/scripts/inks.lua index 9cf3e9ca0..8dd11b334 100644 --- a/tests/scripts/inks.lua +++ b/tests/scripts/inks.lua @@ -331,4 +331,60 @@ do { 1, 0, 1, 0, 2, 0, 1, 0, 1}) +end + +---------------------------------------------------------------------- +-- Tests for Eraser Tool with Indexed image + background layer + +-- mask color present in the palette +---------------------------------------------------------------------- +do + local s = Sprite(3, 3, ColorMode.INDEXED) + local p = s.palettes[1] + p:setColor(0, Color{ r=0 , g=0 , b=0 , a=255 }) + p:setColor(1, Color{ r=255, g=0 , b=0 , a=255 }) + p:setColor(2, Color{ r=0 , g=255, b=0 , a=255 }) + p:setColor(3, Color{ r=0 , g=0 , b=255, a=255 }) + p:setColor(4, Color{ r=255, g=255, b=0 , a=255 }) + p:setColor(5, Color{ r=255, g=255, b=255, a=255 }) + p:setColor(6, Color{ r=0 , g=0 , b=0 , a=0 }) + + app.fgColor = 0 + app.bgColor = 0 + app.command.BackgroundFromLayer() + s.transparentColor = 6 + array_to_pixels({ 0, 0, 0, + 0, 0, 0, + 0, 0, 0 }, app.activeImage) + + app.fgColor = 1 + app.bgColor = 6 + app.useTool{ tool='pencil', + points={ Point(0, 0), Point(2, 0)} } + app.useTool{ tool='pencil', + color=2, + points={ Point(0, 1), Point(2, 1)} } + app.useTool{ tool='pencil', + color=3, + points={ Point(0, 2), Point(2, 2)} } + array_to_pixels({ 1, 1, 1, + 2, 2, 2, + 3, 3, 3 }, app.activeImage) + + app.fgColor = 2 + app.bgColor = 6 + app.useTool{ tool='eraser', + button=MouseButton.LEFT, + points={ Point(0, 0), Point(0, 2) } } + expect_img(app.activeImage, + { 0, 1, 1, + 0, 2, 2, + 0, 3, 3 }) + + app.useTool{ tool='eraser', + button=MouseButton.RIGHT, + points={ Point(1, 0), Point(1, 2) } } + expect_img(app.activeImage, + { 0, 1, 1, + 0, 0, 2, + 0, 3, 3 }) end \ No newline at end of file