Add tests for 'eraser' in 'Replace Color Mode'

To make the eraser work in 'Replace Color Mode' within the tests,
was implemented the possibility of using the right button in
the creation of the point vector.

During testing with UI available it was observed that the 'bg' color
was copied from the 'fg'. Changed this to be compatible with the way
the default value of 'fg' is assigned when it is not specified.
This last modification resulted in errors during 'tilemap.lua' due to
incompatibility of the type of 'bg' color. This was corrected
considering the color type of 'fg' color.

During testing with UI available, it was also found that the command
'app.range.tiles = { 1 }' did not finish assigning the tile picks to
the activeSite, then 'assert(1, #app.range.tiles)' was failing.
This was fixed too.
This commit is contained in:
Gaspar Capello 2024-07-04 15:28:56 -03:00
parent 6a836a918b
commit f715038c5d
3 changed files with 77 additions and 3 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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