Fix pattern Fill does not "Align to Destination" (fix #2528)

This commit is contained in:
Gaspar Capello 2023-09-15 16:21:30 -03:00 committed by David Capello
parent ba99f41d82
commit aca8621bff
2 changed files with 66 additions and 6 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -1144,10 +1144,21 @@ public:
}
void prepareForPointShape(ToolLoop* loop, bool firstPoint, int x, int y) override {
if ((m_patternAlign == BrushPattern::ALIGNED_TO_DST && firstPoint) ||
(m_patternAlign == BrushPattern::PAINT_BRUSH)) {
m_u = ((m_brush->patternOrigin().x % loop->sprite()->width()) - loop->getCelOrigin().x) % m_width;
m_v = ((m_brush->patternOrigin().y % loop->sprite()->height()) - loop->getCelOrigin().y) % m_height;
if (m_patternAlign != BrushPattern::ALIGNED_TO_SRC) {
// Case: during painting process with PaintBucket Tool
if (loop->getPointShape()->isFloodFill()) {
m_u = x - m_brush->bounds().w / 2;
m_v = y - m_brush->bounds().h / 2;
}
// Case: during brush preview of PaintBucket Tool
else if (loop->getController()->isOnePoint()) {
m_u = m_brush->bounds().w / 2;
m_v = m_brush->bounds().h / 2;
}
else {
m_u = ((m_brush->patternOrigin().x % loop->sprite()->width()) - loop->getCelOrigin().x) % m_width;
m_v = ((m_brush->patternOrigin().y % loop->sprite()->height()) - loop->getCelOrigin().y) % m_height;
}
}
}

View File

@ -1,4 +1,4 @@
-- Copyright (C) 2020-2022 Igara Studio S.A.
-- Copyright (C) 2020-2023 Igara Studio S.A.
--
-- This file is released under the terms of the MIT license.
-- Read LICENSE.txt for more information.
@ -283,3 +283,52 @@ do
2, 2 })
end
----------------------------------------------------------------------
-- Tests for Paint Bucket Tool with image brush and
-- pattern alignment SRC (ORIGIN) vs DST (TARGET)
----------------------------------------------------------------------
do
local s = Sprite(3, 3, ColorMode.INDEXED)
array_to_pixels({ 0, 0, 0,
0, 0, 0,
0, 0, 0 }, app.activeImage)
local brushImage = Image(2, 2, ColorMode.INDEXED)
array_to_pixels({ 0, 1,
2, 0 }, brushImage)
brush = Brush{
image=brushImage,
pattern=BrushPattern.ORIGIN
}
app.useTool{ tool="paint_bucket", brush=brush, points={ Point(0, 0) } }
expect_img(app.activeImage,
{ 0, 1, 0,
2, 0, 2,
0, 1, 0 })
app.undo()
app.useTool{ tool="paint_bucket", brush=brush, points={ Point(1, 0) } }
expect_img(app.activeImage,
{ 0, 1, 0,
2, 0, 2,
0, 1, 0 })
app.undo()
brush = Brush{
image=brushImage,
pattern=BrushPattern.TARGET
}
app.useTool{ tool="paint_bucket", brush=brush, points={ Point(1, 1) } }
expect_img(app.activeImage,
{ 0, 1, 0,
2, 0, 2,
0, 1, 0 })
app.undo()
app.useTool{ tool="paint_bucket", brush=brush, points={ Point(2, 1) } }
expect_img(app.activeImage,
{ 1, 0, 1,
0, 2, 0,
1, 0, 1})
end