From d5f0e3189c2605931ba38a6ac75f973dcfe55e40 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 13 Jan 2020 15:01:45 -0300 Subject: [PATCH] Fix bug drawing and zooming with the mouse wheel or pinch gesture The mouse position jumps from one side to other when we zoom because there were an intermediate scroll change event where the mouse position is converted using the old zoom. Fixed regressiong from 951fb7c35784d3e5b0aba86e340aed9edbd2456d Fixed bug https://community.aseprite.org/t/4587 --- src/app/ui/color_bar.cpp | 6 +++--- src/app/ui/doc_view.cpp | 4 ++-- src/app/ui/editor/editor.cpp | 12 ++++++------ src/app/ui/editor/editor.h | 4 ++-- src/ui/view.cpp | 11 +++++------ 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index 3d48a9578..5641a41d6 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -1080,8 +1080,8 @@ void ColorBar::onTimerTick() // Redraw just the current editor else { m_redrawAll = true; - if (current_editor != NULL) - current_editor->updateEditor(); + if (current_editor) + current_editor->updateEditor(true); } } diff --git a/src/app/ui/doc_view.cpp b/src/app/ui/doc_view.cpp index 94ab1be7a..da7d201cc 100644 --- a/src/app/ui/doc_view.cpp +++ b/src/app/ui/doc_view.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -371,7 +371,7 @@ bool DocView::onProcessMessage(Message* msg) void DocView::onGeneralUpdate(DocEvent& ev) { if (m_editor->isVisible()) - m_editor->updateEditor(); + m_editor->updateEditor(true); } void DocView::onSpritePixelsModified(DocEvent& ev) diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index bcd9df684..f616b06a2 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -483,7 +483,7 @@ void Editor::setScrollAndZoomToFitScreen() } } - updateEditor(); + updateEditor(false); setEditorScroll( gfx::Point( m_padding.x - vp.w/2 + m_proj.applyX(canvas.w)/2, @@ -503,9 +503,9 @@ void Editor::setEditorZoom(const render::Zoom& zoom) Editor::ZoomBehavior::CENTER); } -void Editor::updateEditor() +void Editor::updateEditor(const bool restoreScrollPos) { - View::getView(this)->updateView(false); + View::getView(this)->updateView(restoreScrollPos); } void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& spriteRectToDraw, int dx, int dy) @@ -1477,7 +1477,7 @@ void Editor::centerInSpritePoint(const gfx::Point& spritePos) m_padding.x - (vp.w/2) + m_proj.applyX(1)/2 + m_proj.applyX(spritePos.x), m_padding.y - (vp.h/2) + m_proj.applyY(1)/2 + m_proj.applyY(spritePos.y)); - updateEditor(); + updateEditor(false); setEditorScroll(scroll); invalidate(); } @@ -2360,7 +2360,7 @@ void Editor::setZoomAndCenterInMouse(const Zoom& zoom, setZoom(zoom); if ((m_proj.zoom() != zoom) || (screenPos != view->viewScroll())) { - updateEditor(); + updateEditor(false); setEditorScroll(scrollPos); } } diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index 04dbf11dc..c0ea363ce 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -160,7 +160,7 @@ namespace app { void setEditorZoom(const render::Zoom& zoom); // Updates the Editor's view. - void updateEditor(); + void updateEditor(const bool restoreScrollPos); // Draws the sprite taking care of the whole clipping region. void drawSpriteClipped(const gfx::Region& updateRegion); diff --git a/src/ui/view.cpp b/src/ui/view.cpp index ba4196e49..1d53cffc3 100644 --- a/src/ui/view.cpp +++ b/src/ui/view.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. @@ -151,6 +151,9 @@ void View::setViewScroll(const Point& pt) onSetViewScroll(pt); } +// If restoreScrollPos=false it means that the caller of +// updateView(false) will then update the view scroll position +// manually. void View::updateView(const bool restoreScrollPos) { Widget* vw = UI_FIRST_WIDGET(m_viewport.children()); @@ -169,16 +172,12 @@ void View::updateView(const bool restoreScrollPos) setScrollableSize(m_viewport.calculateNeededSize(), false); m_viewport.setBounds(m_viewport.bounds()); - if (restoreScrollPos || - // Force restoring the old scroll position if we are out of - // bounds in the viewport limits. - scroll != limitScrollPosToViewport(scroll)) { + if (restoreScrollPos) { if (vw) setViewScroll(scroll); else setViewScroll(Point(0, 0)); } - ASSERT(viewScroll() == limitScrollPosToViewport(viewScroll())); if (Widget* child = attachedWidget()) { updateAttachedWidgetBounds(viewScroll());