Minor refactor from ui::MouseMessage -> tools::Pointer

This commit is contained in:
David Capello 2020-08-31 19:02:34 -03:00
parent b1c0d80356
commit 291ebc6a38
5 changed files with 24 additions and 21 deletions

View File

@ -144,7 +144,7 @@ bool DrawingState::onMouseDown(Editor* editor, MouseMessage* msg)
// checkStartDrawingStraightLine() with the right-button.
if (recreateLoop && isCanceled) {
ASSERT(!m_toolLoopManager);
checkStartDrawingStraightLine(editor, msg);
checkStartDrawingStraightLine(editor, &pointer);
}
return true;
@ -154,6 +154,8 @@ bool DrawingState::onMouseUp(Editor* editor, MouseMessage* msg)
{
ASSERT(m_toolLoopManager != NULL);
tools::Pointer pointer = pointer_from_msg(editor, msg, m_velocity.velocity());
// Selection tools with Replace mode are cancelled with a simple click.
// ("one point" controller selection tool i.e. the magic wand, and
// selection tools with Add or Subtract mode aren't cancelled with
@ -167,8 +169,7 @@ bool DrawingState::onMouseUp(Editor* editor, MouseMessage* msg)
m_type == DrawingType::SelectTiles ||
(editor->getToolLoopModifiers() != tools::ToolLoopModifiers::kReplaceSelection &&
editor->getToolLoopModifiers() != tools::ToolLoopModifiers::kIntersectSelection)) {
m_lastPointer = pointer_from_msg(editor, msg,
m_velocity.velocity());
m_lastPointer = pointer;
// Notify the release of the mouse button to the tool loop
// manager. This is the correct way to say "the user finishes the
@ -191,7 +192,7 @@ bool DrawingState::onMouseUp(Editor* editor, MouseMessage* msg)
// button, if the Shift key is pressed, the whole ToolLoop starts
// again.
if (Preferences::instance().editor.straightLinePreview())
checkStartDrawingStraightLine(editor, msg);
checkStartDrawingStraightLine(editor, &pointer);
return true;
}

View File

@ -1689,11 +1689,11 @@ doc::tile_t Editor::getTileByPosition(const gfx::Point& mousePos)
return doc::tile_i_notile;
}
bool Editor::startStraightLineWithFreehandTool(const ui::MouseMessage* msg)
bool Editor::startStraightLineWithFreehandTool(const tools::Pointer* pointer)
{
tools::Tool* tool = App::instance()->activeToolManager()->selectedTool();
// TODO add support for more buttons (X1, X2, etc.)
int i = (msg && msg->right() ? 1: 0);
int i = (pointer && pointer->button() == tools::Pointer::Button::Right ? 1: 0);
return
(isActive() &&
(hasMouse() || hasCapture()) &&

View File

@ -63,6 +63,7 @@ namespace app {
namespace tools {
class Ink;
class Pointer;
class Tool;
}
@ -292,7 +293,7 @@ namespace app {
// Returns true if the Shift key to draw straight lines with a
// freehand tool is pressed.
bool startStraightLineWithFreehandTool(const ui::MouseMessage* msg);
bool startStraightLineWithFreehandTool(const tools::Pointer* pointer);
// Functions to handle the set of selected slices.
bool isSliceSelected(const doc::Slice* slice) const;

View File

@ -324,10 +324,12 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
// Start the Tool-Loop
if (layer && (layer->isImage() || clickedInk->isSelection())) {
tools::Pointer pointer = pointer_from_msg(editor, msg);
// Shift+click on Pencil tool starts a line onMouseDown() when the
// preview (onKeyDown) is disabled.
if (!Preferences::instance().editor.straightLinePreview() &&
checkStartDrawingStraightLine(editor, msg)) {
checkStartDrawingStraightLine(editor, &pointer)) {
// Send first mouse down to draw the straight line and start the
// freehand mode.
editor->getState()->onMouseDown(editor, msg);
@ -344,7 +346,7 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
startDrawingState(editor,
DrawingType::Regular,
pointer_from_msg(editor, msg));
pointer);
// Restore layer edges
if (layerEdges)
@ -667,13 +669,13 @@ DrawingState* StandbyState::startDrawingState(
}
bool StandbyState::checkStartDrawingStraightLine(Editor* editor,
const ui::MouseMessage* msg)
const tools::Pointer* pointer)
{
// Start line preview with shift key
if (canCheckStartDrawingStraightLine() &&
editor->startStraightLineWithFreehandTool(msg)) {
editor->startStraightLineWithFreehandTool(pointer)) {
tools::Pointer::Button pointerButton =
(msg ? button_from_msg(msg): tools::Pointer::Left);
(pointer ? pointer->button(): tools::Pointer::Left);
DrawingState* drawingState =
startDrawingState(editor,
@ -682,17 +684,16 @@ bool StandbyState::checkStartDrawingStraightLine(Editor* editor,
editor->document()->lastDrawingPoint(),
tools::Vec2(0.0f, 0.0f),
pointerButton,
msg ? msg->pointerType(): PointerType::Unknown,
msg ? msg->pressure(): 0.0f));
pointer ? pointer->type(): PointerType::Unknown,
pointer ? pointer->pressure(): 0.0f));
if (drawingState) {
drawingState->sendMovementToToolLoop(
tools::Pointer(
editor->screenToEditor(msg ? msg->position():
ui::get_mouse_position()),
pointer ? pointer->point(): editor->screenToEditor(ui::get_mouse_position()),
tools::Vec2(0.0f, 0.0f),
pointerButton,
msg ? msg->pointerType(): tools::Pointer::Type::Unknown,
msg ? msg->pressure(): 0.0f));
pointer ? pointer->type(): tools::Pointer::Type::Unknown,
pointer ? pointer->pressure(): 0.0f));
return true;
}
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -20,7 +20,6 @@ namespace app {
namespace tools {
class Ink;
class Pointer;
class Command;
}
class DrawingState;
@ -55,7 +54,8 @@ namespace app {
protected:
void callEyedropper(Editor* editor, const ui::MouseMessage* msg);
bool checkStartDrawingStraightLine(Editor* editor, const ui::MouseMessage* msg);
bool checkStartDrawingStraightLine(Editor* editor,
const tools::Pointer* pointer);
virtual bool canCheckStartDrawingStraightLine() { return true; }
class Decorator : public EditorDecorator {