mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-12 16:14:10 +00:00
Fix zoom behavior when the zoom is changed from the center
This commit is contained in:
parent
bfaf8a5921
commit
3d29adcbdf
@ -347,8 +347,9 @@ void Editor::setEditorScroll(const gfx::Point& scroll, bool blit_valid_rgn)
|
||||
|
||||
void Editor::setEditorZoom(Zoom zoom)
|
||||
{
|
||||
setZoomAndCenterInMouse(zoom,
|
||||
ui::get_mouse_position(), Editor::kCofiguredZoomBehavior);
|
||||
setZoomAndCenterInMouse(
|
||||
zoom, ui::get_mouse_position(),
|
||||
Editor::ZoomBehavior::CENTER);
|
||||
}
|
||||
|
||||
void Editor::updateEditor()
|
||||
@ -1445,43 +1446,33 @@ void Editor::setZoomAndCenterInMouse(Zoom zoom,
|
||||
{
|
||||
View* view = View::getView(this);
|
||||
Rect vp = view->getViewportBounds();
|
||||
bool centerMouse = false;
|
||||
|
||||
switch (zoomBehavior) {
|
||||
case kCofiguredZoomBehavior:
|
||||
centerMouse = UIContext::instance()->settings()->getCenterOnZoom();
|
||||
break;
|
||||
case kCenterOnZoom:
|
||||
centerMouse = true;
|
||||
break;
|
||||
case kDontCenterOnZoom:
|
||||
centerMouse = false;
|
||||
break;
|
||||
}
|
||||
|
||||
hideDrawingCursor();
|
||||
gfx::Point spritePos = screenToEditor(mousePos);
|
||||
gfx::Point mid;
|
||||
|
||||
if (centerMouse) {
|
||||
mid.x = vp.x+vp.w/2;
|
||||
mid.y = vp.y+vp.h/2;
|
||||
}
|
||||
else {
|
||||
mid.x = mousePos.x;
|
||||
mid.y = mousePos.y;
|
||||
gfx::Point screenPos;
|
||||
gfx::Point spritePos;
|
||||
switch (zoomBehavior) {
|
||||
case ZoomBehavior::CENTER:
|
||||
screenPos = gfx::Point(vp.x + vp.w/2,
|
||||
vp.y + vp.h/2);
|
||||
break;
|
||||
case ZoomBehavior::MOUSE:
|
||||
screenPos = mousePos;
|
||||
break;
|
||||
}
|
||||
spritePos = screenToEditor(screenPos);
|
||||
|
||||
spritePos.x = m_offset_x - (mid.x - vp.x) + (zoom.apply(1)/2) + zoom.apply(spritePos.x);
|
||||
spritePos.y = m_offset_y - (mid.y - vp.y) + (zoom.apply(1)/2) + zoom.apply(spritePos.y);
|
||||
gfx::Point scrollPos(
|
||||
m_offset_x - (screenPos.x-vp.x) + zoom.apply(spritePos.x+zoom.remove(1)/2) + zoom.apply(1)/2,
|
||||
m_offset_y - (screenPos.y-vp.y) + zoom.apply(spritePos.y+zoom.remove(1)/2) + zoom.apply(1)/2);
|
||||
|
||||
if ((m_zoom != zoom) || (m_cursorEditor != mid)) {
|
||||
if ((m_zoom != zoom) || (screenPos != view->getViewScroll())) {
|
||||
bool blit_valid_rgn = (m_zoom == zoom);
|
||||
|
||||
m_zoom = zoom;
|
||||
|
||||
updateEditor();
|
||||
setEditorScroll(spritePos, blit_valid_rgn);
|
||||
setEditorScroll(scrollPos, blit_valid_rgn);
|
||||
}
|
||||
showDrawingCursor();
|
||||
}
|
||||
|
@ -72,10 +72,9 @@ namespace app {
|
||||
kShowOnionskin | kShowOutside | kShowDecorators),
|
||||
};
|
||||
|
||||
enum ZoomBehavior {
|
||||
kCofiguredZoomBehavior,
|
||||
kCenterOnZoom,
|
||||
kDontCenterOnZoom,
|
||||
enum class ZoomBehavior {
|
||||
CENTER, // Zoom from center (don't change center of the editor)
|
||||
MOUSE, // Zoom from cursor
|
||||
};
|
||||
|
||||
Editor(Document* document, EditorFlags flags = kDefaultEditorFlags);
|
||||
|
@ -114,8 +114,9 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
|
||||
}
|
||||
|
||||
if (editor->zoom() != zoom) {
|
||||
editor->setZoomAndCenterInMouse(zoom,
|
||||
mouseMsg->position(), Editor::kDontCenterOnZoom);
|
||||
editor->setZoomAndCenterInMouse(
|
||||
zoom, mouseMsg->position(),
|
||||
Editor::ZoomBehavior::CENTER);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -53,8 +53,8 @@ bool ZoomingState::onMouseUp(Editor* editor, MouseMessage* msg)
|
||||
else if (msg->right())
|
||||
zoom.out();
|
||||
|
||||
editor->setZoomAndCenterInMouse(zoom,
|
||||
msg->position(), Editor::kCofiguredZoomBehavior);
|
||||
editor->setZoomAndCenterInMouse(
|
||||
zoom, msg->position(), Editor::ZoomBehavior::MOUSE);
|
||||
}
|
||||
|
||||
editor->backToPreviousState();
|
||||
@ -71,8 +71,8 @@ bool ZoomingState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
scale = 1.0 / -(scale-2.0);
|
||||
zoom = render::Zoom::fromScale(scale);
|
||||
|
||||
editor->setZoomAndCenterInMouse(zoom,
|
||||
m_startPos, Editor::kDontCenterOnZoom);
|
||||
editor->setZoomAndCenterInMouse(
|
||||
zoom, m_startPos, Editor::ZoomBehavior::MOUSE);
|
||||
|
||||
m_moved = true;
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user