mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 22:21:12 +00:00
Use DelayedMouseMove for MovingCelState too (#3119)
This commit is contained in:
parent
26c1a94b83
commit
06cfbd794e
@ -20,8 +20,8 @@ DelayedMouseMove::DelayedMouseMove(DelayedMouseMoveDelegate* delegate,
|
||||
: m_delegate(delegate)
|
||||
, m_editor(editor)
|
||||
, m_timer(interval)
|
||||
, m_spritePos(std::numeric_limits<int>::min(),
|
||||
std::numeric_limits<int>::min())
|
||||
, m_spritePos(std::numeric_limits<double>::min(),
|
||||
std::numeric_limits<double>::min())
|
||||
{
|
||||
ASSERT(m_delegate);
|
||||
m_timer.Tick.connect([this] { commitMouseMove(); });
|
||||
@ -63,10 +63,10 @@ void DelayedMouseMove::commitMouseMove()
|
||||
m_delegate->onCommitMouseMove(m_editor, spritePos());
|
||||
}
|
||||
|
||||
const gfx::Point& DelayedMouseMove::spritePos() const
|
||||
const gfx::PointF& DelayedMouseMove::spritePos() const
|
||||
{
|
||||
ASSERT(m_spritePos.x != std::numeric_limits<int>::min() &&
|
||||
m_spritePos.y != std::numeric_limits<int>::min());
|
||||
ASSERT(m_spritePos.x != std::numeric_limits<double>::min() &&
|
||||
m_spritePos.y != std::numeric_limits<double>::min());
|
||||
return m_spritePos;
|
||||
}
|
||||
|
||||
@ -75,13 +75,10 @@ bool DelayedMouseMove::updateSpritePos(const ui::MouseMessage* msg)
|
||||
// The autoScroll() function controls the "infinite scroll" when we
|
||||
// touch the viewport borders.
|
||||
const gfx::Point mousePos = m_editor->autoScroll(msg, AutoScroll::MouseDir);
|
||||
const gfx::Point spritePos = m_editor->screenToEditor(mousePos);
|
||||
const gfx::PointF spritePos = m_editor->screenToEditorF(mousePos);
|
||||
|
||||
// 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.
|
||||
if (m_spritePos != spritePos) {
|
||||
m_spritePos = spritePos;
|
||||
return true;
|
||||
|
@ -24,7 +24,7 @@ namespace app {
|
||||
public:
|
||||
virtual ~DelayedMouseMoveDelegate() { }
|
||||
virtual void onCommitMouseMove(Editor* editor,
|
||||
const gfx::Point& spritePos) = 0;
|
||||
const gfx::PointF& spritePos) = 0;
|
||||
};
|
||||
|
||||
// Helper class to group several onMouseMove() calls into one
|
||||
@ -45,7 +45,7 @@ namespace app {
|
||||
bool onMouseMove(const ui::MouseMessage* msg);
|
||||
void onMouseUp(const ui::MouseMessage* msg);
|
||||
|
||||
const gfx::Point& spritePos() const;
|
||||
const gfx::PointF& spritePos() const;
|
||||
|
||||
private:
|
||||
void commitMouseMove();
|
||||
@ -58,7 +58,7 @@ namespace app {
|
||||
// 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_spritePos;
|
||||
gfx::PointF m_spritePos;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -239,7 +239,7 @@ bool DrawingState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
// Update velocity sensor.
|
||||
m_velocity.updateWithScreenPoint(msg->position());
|
||||
|
||||
m_lastPointer = tools::Pointer(m_delayedMouseMove.spritePos(),
|
||||
m_lastPointer = tools::Pointer(gfx::Point(m_delayedMouseMove.spritePos()),
|
||||
m_velocity.velocity(),
|
||||
button_from_msg(msg),
|
||||
msg->pointerType(),
|
||||
@ -253,7 +253,7 @@ bool DrawingState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
}
|
||||
|
||||
void DrawingState::onCommitMouseMove(Editor* editor,
|
||||
const gfx::Point& spritePos)
|
||||
const gfx::PointF& spritePos)
|
||||
{
|
||||
if (m_toolLoop &&
|
||||
!m_toolLoop->isCanceled()) {
|
||||
|
@ -65,7 +65,7 @@ namespace app {
|
||||
|
||||
// DelayedMouseMoveDelegate impl
|
||||
void onCommitMouseMove(Editor* editor,
|
||||
const gfx::Point& spritePos) override;
|
||||
const gfx::PointF& spritePos) override;
|
||||
|
||||
Editor* m_editor;
|
||||
DrawingType m_type;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2020-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2020-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -80,10 +80,11 @@ MovingCelCollect::MovingCelCollect(Editor* editor, Layer* layer)
|
||||
}
|
||||
|
||||
MovingCelState::MovingCelState(Editor* editor,
|
||||
MouseMessage* msg,
|
||||
const MouseMessage* msg,
|
||||
const HandleType handle,
|
||||
const MovingCelCollect& collect)
|
||||
: m_reader(UIContext::instance(), 500)
|
||||
, m_delayedMouseMove(this, editor, 5)
|
||||
, m_cel(nullptr)
|
||||
, m_celList(collect.celList())
|
||||
, m_celOffset(0.0, 0.0)
|
||||
@ -128,6 +129,8 @@ MovingCelState::MovingCelState(Editor* editor,
|
||||
document->setMaskVisible(false);
|
||||
document->generateMaskBoundaries();
|
||||
}
|
||||
|
||||
m_delayedMouseMove.onMouseDown(msg);
|
||||
}
|
||||
|
||||
void MovingCelState::onBeforePopState(Editor* editor)
|
||||
@ -138,6 +141,8 @@ void MovingCelState::onBeforePopState(Editor* editor)
|
||||
|
||||
bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg)
|
||||
{
|
||||
m_delayedMouseMove.onMouseUp(msg);
|
||||
|
||||
Doc* document = editor->document();
|
||||
bool modified = restoreCelStartPosition();
|
||||
|
||||
@ -209,9 +214,15 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg)
|
||||
|
||||
bool MovingCelState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
{
|
||||
const gfx::Point mousePos = editor->autoScroll(msg, AutoScroll::MouseDir);
|
||||
const gfx::PointF newCursorPos = editor->screenToEditorF(mousePos);
|
||||
m_delayedMouseMove.onMouseMove(msg);
|
||||
|
||||
// Use StandbyState implementation
|
||||
return StandbyState::onMouseMove(editor, msg);
|
||||
}
|
||||
|
||||
void MovingCelState::onCommitMouseMove(Editor* editor,
|
||||
const gfx::PointF& newCursorPos)
|
||||
{
|
||||
switch (m_handle) {
|
||||
|
||||
case MovePixelsHandle:
|
||||
@ -271,9 +282,6 @@ bool MovingCelState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
|
||||
// Redraw the new cel position.
|
||||
editor->invalidate();
|
||||
|
||||
// Use StandbyState implementation
|
||||
return StandbyState::onMouseMove(editor, msg);
|
||||
}
|
||||
|
||||
bool MovingCelState::onKeyDown(Editor* editor, KeyMessage* msg)
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2021 Igara Studio S.A.
|
||||
// Copyright (C) 2021-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -12,6 +12,7 @@
|
||||
#include "app/ui/editor/standby_state.h"
|
||||
|
||||
#include "app/context_access.h"
|
||||
#include "app/ui/editor/delayed_mouse_move.h"
|
||||
#include "app/ui/editor/handle_type.h"
|
||||
#include "doc/cel_list.h"
|
||||
|
||||
@ -38,10 +39,11 @@ namespace app {
|
||||
CelList m_celList;
|
||||
};
|
||||
|
||||
class MovingCelState : public StandbyState {
|
||||
class MovingCelState : public StandbyState
|
||||
, DelayedMouseMoveDelegate {
|
||||
public:
|
||||
MovingCelState(Editor* editor,
|
||||
ui::MouseMessage* msg,
|
||||
const ui::MouseMessage* msg,
|
||||
const HandleType handle,
|
||||
const MovingCelCollect& collect);
|
||||
|
||||
@ -59,7 +61,12 @@ namespace app {
|
||||
// ContextObserver
|
||||
void onBeforeCommandExecution(CommandExecutionEvent& ev);
|
||||
|
||||
// DelayedMouseMoveDelegate impl
|
||||
void onCommitMouseMove(Editor* editor,
|
||||
const gfx::PointF& spritePos) override;
|
||||
|
||||
ContextReader m_reader;
|
||||
DelayedMouseMove m_delayedMouseMove;
|
||||
Cel* m_cel;
|
||||
CelList m_celList;
|
||||
std::vector<gfx::RectF> m_celStarts;
|
||||
|
@ -389,7 +389,7 @@ bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
}
|
||||
|
||||
void MovingPixelsState::onCommitMouseMove(Editor* editor,
|
||||
const gfx::Point& spritePos)
|
||||
const gfx::PointF& spritePos)
|
||||
{
|
||||
m_pixelsMovement->setFastMode(true);
|
||||
|
||||
@ -446,7 +446,7 @@ void MovingPixelsState::onCommitMouseMove(Editor* editor,
|
||||
transfHandles->invalidateHandles(m_editor, m_pixelsMovement->getTransformation());
|
||||
|
||||
// Drag the image to that position
|
||||
m_pixelsMovement->moveImage(spritePos, moveModifier);
|
||||
m_pixelsMovement->moveImage(gfx::Point(spritePos), moveModifier);
|
||||
|
||||
m_editor->updateStatusBar();
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ namespace app {
|
||||
private:
|
||||
// DelayedMouseMoveDelegate impl
|
||||
void onCommitMouseMove(Editor* editor,
|
||||
const gfx::Point& spritePos) override;
|
||||
const gfx::PointF& spritePos) override;
|
||||
|
||||
void onTransparentColorChange();
|
||||
void onRenderTimer();
|
||||
|
Loading…
x
Reference in New Issue
Block a user