Fix preview with selection tools in tiles mode

This commit is contained in:
David Capello 2020-08-26 12:30:48 -03:00
parent e5bfccbcd2
commit 4eeaad5a69
4 changed files with 36 additions and 17 deletions

View File

@ -446,9 +446,18 @@ public:
gfx::Rect rc(x1, y, x2-x1+1, 1);
// For tile point shape, the point shape is done in "tiles"
// coordinatse, but we want the selection in "canvas" coordinates.
if (loop->getPointShape()->isTile())
rc = loop->getGrid().tileToCanvas(rc);
// coordinates, but we want the selection in canvas/pixels
// coordinates.
if (loop->getPointShape()->isTile()) {
const Grid& grid = loop->getGrid();
rc = grid.tileToCanvas(rc);
if (!m_modify_selection) {
// For feedback purposes, the coordinates must be relative to
// the getDstImage() and not in absolute sprite canvas
// coordinates.
rc.offset(-grid.origin());
}
}
if (m_modify_selection) {
int modifiers = int(loop->getModifiers());

View File

@ -512,6 +512,9 @@ public:
// pixels. See ExpandCelCanvas::commit() for details about this flag.
(getController()->isFreehand() ?
ExpandCelCanvas::UseModifiedRegionAsUndoInfo:
ExpandCelCanvas::None) |
(!m_tilesMode || m_ink->isSelection() ?
ExpandCelCanvas::PixelsBounds:
ExpandCelCanvas::None)));
if (!m_floodfillSrcImage)
@ -550,11 +553,7 @@ public:
// Setup the new grid of ExpandCelCanvas which can be displaced to
// match the new temporal cel position (m_celOrigin).
m_grid = m_expandCelCanvas->getGrid();
if (m_tilesMode)
m_celOrigin = m_grid.origin();
else
m_celOrigin = m_expandCelCanvas->getCel()->position();
m_celOrigin = m_expandCelCanvas->getCel()->position();
m_mask = m_document->mask();
m_maskOrigin = (!m_mask->isEmpty() ? gfx::Point(m_mask->bounds().x-m_celOrigin.x,
@ -768,9 +767,8 @@ tools::ToolLoop* create_tool_loop(
if (params.ink->isSelection() &&
!params.tool->getPointShape(
button != tools::Pointer::Left ? 1: 0)->isFloodFill()) {
// TODO improve the selection preview without using a preview
// image (e.g. we could use a gfx::Path)
site.layer(nullptr);
// Don't call site.layer(nullptr) because we want to keep the
// site.layer() to know if we are in a tilemap layer
}
else {
Layer* layer = site.layer();

View File

@ -118,7 +118,8 @@ ExpandCelCanvas::ExpandCelCanvas(
m_origCelPos = m_cel->position();
// Region to draw
gfx::Rect celBounds = (m_celCreated ? m_sprite->bounds(): m_cel->bounds());
gfx::Rect celBounds = (m_celCreated ? m_sprite->bounds():
m_cel->bounds());
gfx::Rect spriteBounds(0, 0,
m_sprite->width(),
@ -131,20 +132,28 @@ ExpandCelCanvas::ExpandCelCanvas(
m_bounds = spriteBounds;
}
if (m_tilemapMode == TilemapMode::Tiles) {
if ((m_tilemapMode == TilemapMode::Tiles) ||
((m_flags & PixelsBounds) == PixelsBounds)) {
// Bounds of the canvas in tiles.
m_bounds = m_grid.canvasToTile(m_bounds);
// New tiles bounds in pixels coordinates.
gfx::Rect newBoundsFromTiles = m_grid.tileToCanvas(m_bounds);
// As the grid origin depends on the current cel position (see
// Site::grid()), and we're going to modify the m_cel position
// temporarily, we need to adjust the grid to the new temporal
// grid origin matching the new m_dstImage position.
auto newCelPosition = m_grid.tileToCanvas(m_bounds.origin());
m_grid.origin(newCelPosition);
m_grid.origin(newBoundsFromTiles.origin());
// The origin of m_bounds must be in canvas position
m_bounds.setOrigin(newCelPosition);
if ((m_flags & PixelsBounds) == PixelsBounds) {
m_bounds = newBoundsFromTiles;
}
else {
// Bounds for the new cel which is a tilemap
m_bounds.setOrigin(newBoundsFromTiles.origin());
}
}
// We have to adjust the cel position to match the m_dstImage

View File

@ -47,6 +47,9 @@ namespace app {
None = 0,
NeedsSource = 1,
UseModifiedRegionAsUndoInfo = 2,
// Use tiles mode but with pixels bounds in dst image (e.g. for
// selection preview)
PixelsBounds = 4,
};
ExpandCelCanvas(Site site, Layer* layer,