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
This commit is contained in:
David Capello 2020-01-13 15:01:45 -03:00
parent cd598e5539
commit d5f0e3189c
5 changed files with 18 additions and 19 deletions

View File

@ -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);
}
}

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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());