diff --git a/src/app/ui/editor/moving_pixels_state.cpp b/src/app/ui/editor/moving_pixels_state.cpp index d41dbf0dc..8122391d7 100644 --- a/src/app/ui/editor/moving_pixels_state.cpp +++ b/src/app/ui/editor/moving_pixels_state.cpp @@ -52,6 +52,7 @@ #include "ui/view.h" #include +#include namespace app { @@ -63,6 +64,8 @@ MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMo , m_observingEditor(false) , m_discarded(false) , m_renderTimer(50) + , m_oldSpritePos(std::numeric_limits::min(), + std::numeric_limits::min()) { // MovingPixelsState needs a selection tool to avoid problems // sharing the extra cel between the drawing cursor preview and the @@ -367,14 +370,21 @@ bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg) // If there is a button pressed if (m_pixelsMovement->isDragging()) { - m_renderTimer.start(); - m_pixelsMovement->setFastMode(true); - // Auto-scroll gfx::Point mousePos = editor->autoScroll(msg, AutoScroll::MouseDir); // Get the position of the mouse in the sprite gfx::Point spritePos = editor->screenToEditor(mousePos); + if (spritePos == m_oldSpritePos) { + // Avoid redrawing everything if the position in the canvas didn't change. + // TODO remove this if we add support for anti-aliasing in the + // transformations + return true; + } + m_oldSpritePos = spritePos; + + m_renderTimer.start(); + m_pixelsMovement->setFastMode(true); // Get the customization for the pixels movement (snap to grid, angle snap, etc.). KeyContext keyContext = KeyContext::Normal; diff --git a/src/app/ui/editor/moving_pixels_state.h b/src/app/ui/editor/moving_pixels_state.h index f7854cd8d..2671a5126 100644 --- a/src/app/ui/editor/moving_pixels_state.h +++ b/src/app/ui/editor/moving_pixels_state.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2020 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -95,6 +95,11 @@ namespace app { ui::Timer m_renderTimer; + // Position of the mouse in the canvas to avoid redrawing when the + // mouse position changes (only we redraw when the canvas position + // changes). + gfx::Point m_oldSpritePos; + obs::connection m_ctxConn; obs::connection m_opaqueConn; obs::connection m_transparentConn;