mirror of https://github.com/aseprite/aseprite.git
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:
parent
7b49bf295f
commit
072e223ec5
|
|
@ -1,5 +1,5 @@
|
||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2017 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
// the End-User License Agreement for Aseprite.
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
@ -183,11 +183,22 @@ void EyedropperCommand::onLoadParams(const Params& params)
|
||||||
|
|
||||||
void EyedropperCommand::onExecute(Context* context)
|
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())
|
if (!widget || widget->type() != editor_type())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Editor* editor = static_cast<Editor*>(widget);
|
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();
|
Sprite* sprite = editor->sprite();
|
||||||
if (!sprite)
|
if (!sprite)
|
||||||
return;
|
return;
|
||||||
|
|
@ -199,24 +210,24 @@ void EyedropperCommand::onExecute(Context* context)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pixel position to get
|
// Pixel position to get
|
||||||
gfx::PointF pixelPos = editor->screenToEditorF(ui::get_mouse_position());
|
gfx::PointF pixelPos = editor->screenToEditorF(mousePos);
|
||||||
|
|
||||||
// Start with fg/bg color
|
// Start with fg/bg color
|
||||||
DisableColorBarEditMode disable;
|
DisableColorBarEditMode disable;
|
||||||
Preferences& pref = Preferences::instance();
|
Preferences& pref = Preferences::instance();
|
||||||
app::Color color =
|
app::Color color =
|
||||||
m_background ? pref.colorBar.bgColor():
|
foreground ? pref.colorBar.fgColor():
|
||||||
pref.colorBar.fgColor();
|
pref.colorBar.bgColor();
|
||||||
|
|
||||||
pickSample(editor->getSite(),
|
pickSample(editor->getSite(),
|
||||||
pixelPos,
|
pixelPos,
|
||||||
editor->projection(),
|
editor->projection(),
|
||||||
color);
|
color);
|
||||||
|
|
||||||
if (m_background)
|
if (foreground)
|
||||||
pref.colorBar.bgColor(color);
|
|
||||||
else
|
|
||||||
pref.colorBar.fgColor(color);
|
pref.colorBar.fgColor(color);
|
||||||
|
else
|
||||||
|
pref.colorBar.bgColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command* CommandFactory::createEyedropperCommand()
|
Command* CommandFactory::createEyedropperCommand()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2016 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
// the End-User License Agreement for Aseprite.
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "app/color.h"
|
#include "app/color.h"
|
||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
|
#include "gfx/point.h"
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
class Site;
|
class Site;
|
||||||
|
|
@ -20,6 +21,7 @@ namespace render {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
class Editor;
|
||||||
|
|
||||||
class EyedropperCommand : public Command {
|
class EyedropperCommand : public Command {
|
||||||
public:
|
public:
|
||||||
|
|
@ -32,6 +34,11 @@ namespace app {
|
||||||
const render::Projection& proj,
|
const render::Projection& proj,
|
||||||
app::Color& color);
|
app::Color& color);
|
||||||
|
|
||||||
|
void executeOnMousePos(Context* context,
|
||||||
|
Editor* editor,
|
||||||
|
const gfx::Point& mousePos,
|
||||||
|
const bool foreground);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onLoadParams(const Params& params) override;
|
void onLoadParams(const Params& params) override;
|
||||||
void onExecute(Context* context) override;
|
void onExecute(Context* context) override;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2017 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
// the End-User License Agreement for Aseprite.
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
@ -245,7 +245,7 @@ bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg)
|
||||||
// Call the eyedropper command
|
// Call the eyedropper command
|
||||||
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
||||||
if (clickedInk->isEyedropper()) {
|
if (clickedInk->isEyedropper()) {
|
||||||
callEyedropper(editor);
|
callEyedropper(editor, msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2017 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
// the End-User License Agreement for Aseprite.
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
@ -209,7 +209,7 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
|
||||||
// Call the eyedropper command
|
// Call the eyedropper command
|
||||||
if (clickedInk->isEyedropper()) {
|
if (clickedInk->isEyedropper()) {
|
||||||
editor->captureMouse();
|
editor->captureMouse();
|
||||||
callEyedropper(editor);
|
callEyedropper(editor, msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,7 +360,7 @@ bool StandbyState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||||
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
||||||
if (clickedInk->isEyedropper() &&
|
if (clickedInk->isEyedropper() &&
|
||||||
editor->hasCapture()) {
|
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();
|
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
||||||
if (!clickedInk->isEyedropper())
|
if (!clickedInk->isEyedropper())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Command* eyedropper_cmd =
|
EyedropperCommand* eyedropper =
|
||||||
Commands::instance()->byId(CommandId::Eyedropper());
|
(EyedropperCommand*)Commands::instance()->byId(CommandId::Eyedropper());
|
||||||
bool fg = (static_cast<tools::PickInk*>(clickedInk)->target() == tools::PickInk::Fg);
|
bool fg = (static_cast<tools::PickInk*>(clickedInk)->target() == tools::PickInk::Fg);
|
||||||
|
|
||||||
Params params;
|
eyedropper->executeOnMousePos(UIContext::instance(), editor,
|
||||||
params.set("target", fg ? "foreground": "background");
|
msg->position(), fg);
|
||||||
|
|
||||||
UIContext::instance()->executeCommand(eyedropper_cmd, params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandbyState::onPivotChange(Editor* editor)
|
void StandbyState::onPivotChange(Editor* editor)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2017 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
// the End-User License Agreement for Aseprite.
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
@ -49,7 +49,7 @@ namespace app {
|
||||||
void startSelectionTransformation(Editor* editor, const gfx::Point& move, double angle);
|
void startSelectionTransformation(Editor* editor, const gfx::Point& move, double angle);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void callEyedropper(Editor* editor);
|
void callEyedropper(Editor* editor, const ui::MouseMessage* msg);
|
||||||
bool checkStartDrawingStraightLine(Editor* editor, const ui::MouseMessage* msg);
|
bool checkStartDrawingStraightLine(Editor* editor, const ui::MouseMessage* msg);
|
||||||
|
|
||||||
class Decorator : public EditorDecorator {
|
class Decorator : public EditorDecorator {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue