Fix eyedropper to use the real mouse position received in messages

Instead of the global mouse position, we can use the more proper
mouse position receive in editor messages.
This commit is contained in:
David Capello 2018-03-16 12:26:38 -03:00
parent 7b49bf295f
commit 072e223ec5
5 changed files with 39 additions and 23 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2017 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -183,11 +183,22 @@ void EyedropperCommand::onLoadParams(const Params& params)
void EyedropperCommand::onExecute(Context* context)
{
Widget* widget = ui::Manager::getDefault()->getMouse();
gfx::Point mousePos = ui::get_mouse_position();
Widget* widget = ui::Manager::getDefault()->pick(mousePos);
if (!widget || widget->type() != editor_type())
return;
Editor* editor = static_cast<Editor*>(widget);
executeOnMousePos(context, editor, mousePos, !m_background);
}
void EyedropperCommand::executeOnMousePos(Context* context,
Editor* editor,
const gfx::Point& mousePos,
const bool foreground)
{
ASSERT(editor);
Sprite* sprite = editor->sprite();
if (!sprite)
return;
@ -199,24 +210,24 @@ void EyedropperCommand::onExecute(Context* context)
}
// Pixel position to get
gfx::PointF pixelPos = editor->screenToEditorF(ui::get_mouse_position());
gfx::PointF pixelPos = editor->screenToEditorF(mousePos);
// Start with fg/bg color
DisableColorBarEditMode disable;
Preferences& pref = Preferences::instance();
app::Color color =
m_background ? pref.colorBar.bgColor():
pref.colorBar.fgColor();
foreground ? pref.colorBar.fgColor():
pref.colorBar.bgColor();
pickSample(editor->getSite(),
pixelPos,
editor->projection(),
color);
if (m_background)
pref.colorBar.bgColor(color);
else
if (foreground)
pref.colorBar.fgColor(color);
else
pref.colorBar.bgColor(color);
}
Command* CommandFactory::createEyedropperCommand()

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -10,6 +10,7 @@
#include "app/color.h"
#include "app/commands/command.h"
#include "gfx/point.h"
namespace doc {
class Site;
@ -20,6 +21,7 @@ namespace render {
}
namespace app {
class Editor;
class EyedropperCommand : public Command {
public:
@ -32,6 +34,11 @@ namespace app {
const render::Projection& proj,
app::Color& color);
void executeOnMousePos(Context* context,
Editor* editor,
const gfx::Point& mousePos,
const bool foreground);
protected:
void onLoadParams(const Params& params) override;
void onExecute(Context* context) override;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2017 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -245,7 +245,7 @@ bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg)
// Call the eyedropper command
tools::Ink* clickedInk = editor->getCurrentEditorInk();
if (clickedInk->isEyedropper()) {
callEyedropper(editor);
callEyedropper(editor, msg);
return true;
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2017 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -209,7 +209,7 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
// Call the eyedropper command
if (clickedInk->isEyedropper()) {
editor->captureMouse();
callEyedropper(editor);
callEyedropper(editor, msg);
return true;
}
@ -360,7 +360,7 @@ bool StandbyState::onMouseMove(Editor* editor, MouseMessage* msg)
tools::Ink* clickedInk = editor->getCurrentEditorInk();
if (clickedInk->isEyedropper() &&
editor->hasCapture()) {
callEyedropper(editor);
callEyedropper(editor, msg);
}
}
@ -733,20 +733,18 @@ void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleT
}
}
void StandbyState::callEyedropper(Editor* editor)
void StandbyState::callEyedropper(Editor* editor, const ui::MouseMessage* msg)
{
tools::Ink* clickedInk = editor->getCurrentEditorInk();
if (!clickedInk->isEyedropper())
return;
Command* eyedropper_cmd =
Commands::instance()->byId(CommandId::Eyedropper());
EyedropperCommand* eyedropper =
(EyedropperCommand*)Commands::instance()->byId(CommandId::Eyedropper());
bool fg = (static_cast<tools::PickInk*>(clickedInk)->target() == tools::PickInk::Fg);
Params params;
params.set("target", fg ? "foreground": "background");
UIContext::instance()->executeCommand(eyedropper_cmd, params);
eyedropper->executeOnMousePos(UIContext::instance(), editor,
msg->position(), fg);
}
void StandbyState::onPivotChange(Editor* editor)

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2017 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -49,7 +49,7 @@ namespace app {
void startSelectionTransformation(Editor* editor, const gfx::Point& move, double angle);
protected:
void callEyedropper(Editor* editor);
void callEyedropper(Editor* editor, const ui::MouseMessage* msg);
bool checkStartDrawingStraightLine(Editor* editor, const ui::MouseMessage* msg);
class Decorator : public EditorDecorator {