Fix losing sprite center when we change zoom

This issue is pretty common when we change the zoom and the cursor is
outside the canvas, we lost the center of the sprite or the canvas
goes more far and far away. I've seen this problem on streamers and
myself using the program. Hoping to do a little of improvement in this
area with this patch.
This commit is contained in:
David Capello 2019-04-28 21:27:05 -03:00
parent b768d99743
commit d0962eb737

View File

@ -52,6 +52,7 @@
#include "app/ui_context.h"
#include "base/bind.h"
#include "base/chrono.h"
#include "base/clamp.h"
#include "base/convert_to.h"
#include "doc/conversion_to_surface.h"
#include "doc/doc.h"
@ -2187,6 +2188,12 @@ void Editor::setZoomAndCenterInMouse(const Zoom& zoom,
screenPos = mousePos;
break;
}
// Limit zooming screen position to the visible sprite bounds
gfx::Rect visibleBounds = editorToScreen(getVisibleSpriteBounds());
screenPos.x = base::clamp(screenPos.x, visibleBounds.x, visibleBounds.x2()-1);
screenPos.y = base::clamp(screenPos.y, visibleBounds.y, visibleBounds.y2()-1);
spritePos = screenToEditor(screenPos);
if (zoomBehavior == ZoomBehavior::MOUSE) {