mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-03 21:46:20 +00:00
Don't alter pasted image position if it's off canvas (fix #1447)
Now we limit only one pixel inside the sprite bounds.
This commit is contained in:
parent
5e24be7ef7
commit
19f6dcfc58
@ -1351,17 +1351,25 @@ void Editor::setCustomizationDelegate(EditorCustomizationDelegate* delegate)
|
||||
m_customizationDelegate = delegate;
|
||||
}
|
||||
|
||||
Rect Editor::getViewportBounds()
|
||||
{
|
||||
return screenToEditor(View::getView(this)->viewportBounds());
|
||||
}
|
||||
|
||||
// Returns the visible area of the active sprite.
|
||||
Rect Editor::getVisibleSpriteBounds()
|
||||
{
|
||||
if (m_sprite)
|
||||
return getViewportBounds().createIntersection(m_sprite->bounds());
|
||||
|
||||
// This cannot happen, the sprite must be != nullptr. In old
|
||||
// Aseprite versions we were using one Editor to show multiple
|
||||
// sprites (switching the sprite inside the editor). Now we have one
|
||||
// (or more) editor(s) for each sprite.
|
||||
ASSERT(false);
|
||||
|
||||
// Return an empty rectangle if there is not a active sprite.
|
||||
if (!m_sprite) return Rect();
|
||||
|
||||
View* view = View::getView(this);
|
||||
Rect vp = view->viewportBounds();
|
||||
vp = screenToEditor(vp);
|
||||
|
||||
return vp.createIntersection(m_sprite->bounds());
|
||||
return Rect();
|
||||
}
|
||||
|
||||
// Changes the scroll to see the given point as the center of the editor.
|
||||
@ -2043,7 +2051,7 @@ void Editor::pasteImage(const Image* image, const Mask* mask)
|
||||
int x = mask->bounds().x;
|
||||
int y = mask->bounds().y;
|
||||
{
|
||||
const Rect visibleBounds = getVisibleSpriteBounds();
|
||||
const Rect visibleBounds = getViewportBounds();
|
||||
const Point maskCenter = mask->bounds().center();
|
||||
|
||||
// If the pasted image original location center point isn't
|
||||
@ -2066,9 +2074,9 @@ void Editor::pasteImage(const Image* image, const Mask* mask)
|
||||
y = MID(visibleBounds.y-image->height(), y, visibleBounds.y+visibleBounds.h-1);
|
||||
}
|
||||
|
||||
// Also we always limit the image inside the sprite's bounds.
|
||||
x = MID(0, x, sprite->width() - image->width());
|
||||
y = MID(0, y, sprite->height() - image->height());
|
||||
// Also we always limit the 1 image pixel inside the sprite's bounds.
|
||||
x = MID(-image->width()+1, x, sprite->width()-1);
|
||||
y = MID(-image->height()+1, y, sprite->height()-1);
|
||||
}
|
||||
|
||||
// Clear brush preview, as the extra cel will be replaced with the
|
||||
|
@ -172,6 +172,9 @@ namespace app {
|
||||
return m_customizationDelegate;
|
||||
}
|
||||
|
||||
// Returns the visible area of the viewport in sprite coordinates.
|
||||
gfx::Rect getViewportBounds();
|
||||
|
||||
// Returns the visible area of the active sprite.
|
||||
gfx::Rect getVisibleSpriteBounds();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2001-2015 David Capello
|
||||
// Copyright (c) 2001-2017 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -48,8 +48,8 @@ void write_mask(std::ostream& os, const Mask* mask)
|
||||
|
||||
Mask* read_mask(std::istream& is)
|
||||
{
|
||||
int x = read16(is); // Xpos
|
||||
int y = read16(is); // Ypos
|
||||
int x = int16_t(read16(is)); // Xpos (it's a signed int16 because we support negative mask coordinates)
|
||||
int y = int16_t(read16(is)); // Ypos
|
||||
int w = read16(is); // Width
|
||||
int h = read16(is); // Height
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user