mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-26 09:41:05 +00:00
Fix issue 188: Pick foreground color with right mouse button
This commit is contained in:
parent
d0a7831589
commit
9a15126682
@ -17,23 +17,27 @@
|
||||
<panel id="panel">
|
||||
<vbox id="section_general">
|
||||
<separator text="General" horizontal="true" />
|
||||
<grid columns="2">
|
||||
<hbox>
|
||||
<label text="Screen Scale:" />
|
||||
<combobox id="screen_scale" expansive="true" />
|
||||
</grid>
|
||||
<check text="Zoom with Scroll Wheel" id="wheel_zoom" />
|
||||
<combobox id="screen_scale" />
|
||||
</hbox>
|
||||
<check text="Show timeline automatically" id="autotimeline" tooltip="Show the timeline automatically when a new frame or layer is added." />
|
||||
</vbox>
|
||||
|
||||
<!-- Editor -->
|
||||
<vbox id="section_editor">
|
||||
<separator text="Editor" horizontal="true" />
|
||||
<check text="Zoom with Scroll Wheel" id="wheel_zoom" />
|
||||
<check text="Smooth auto-scroll" id="smooth" />
|
||||
<check text="Show scroll-bars in sprite editor" id="show_scrollbars" tooltip="Show scroll-bars in all sprite editors." />
|
||||
<grid columns="2">
|
||||
<label text="Cursor:" />
|
||||
<hbox>
|
||||
<label text="Right-click:" />
|
||||
<combobox id="right_click_behavior" expansive="true" />
|
||||
</hbox>
|
||||
<hbox>
|
||||
<label text="Cursor Color:" />
|
||||
<box id="cursor_color_box" /><!-- custom widget -->
|
||||
</grid>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
||||
<!-- Grid & background -->
|
||||
|
@ -87,6 +87,12 @@ public:
|
||||
screenScale()->addItem("4:1");
|
||||
screenScale()->setSelectedItemIndex(get_screen_scaling()-1);
|
||||
|
||||
// Right-click
|
||||
rightClickBehavior()->addItem("Paint with background color");
|
||||
rightClickBehavior()->addItem("Pick foreground color");
|
||||
rightClickBehavior()->addItem("Erase");
|
||||
rightClickBehavior()->setSelectedItemIndex((int)m_settings->getRightClickMode());
|
||||
|
||||
// Zoom with Scroll Wheel
|
||||
wheelZoom()->setSelected(m_settings->getZoomWithScrollWheel());
|
||||
|
||||
@ -135,6 +141,7 @@ public:
|
||||
|
||||
m_settings->setShowSpriteEditorScrollbars(showScrollbars()->isSelected());
|
||||
m_settings->setZoomWithScrollWheel(wheelZoom()->isSelected());
|
||||
m_settings->setRightClickMode(static_cast<RightClickMode>(rightClickBehavior()->getSelectedItemIndex()));
|
||||
|
||||
RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)checkedBgSize()->getSelectedItemIndex());
|
||||
RenderEngine::setCheckedBgZoom(checkedBgZoom()->isSelected());
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "app/settings/ink_type.h"
|
||||
#include "app/settings/rotation_algorithm.h"
|
||||
#include "app/settings/selection_mode.h"
|
||||
#include "app/settings/right_click_mode.h"
|
||||
#include "doc/settings.h"
|
||||
#include "gfx/point.h"
|
||||
#include "gfx/rect.h"
|
||||
@ -62,6 +63,7 @@ namespace app {
|
||||
// General settings
|
||||
virtual bool getZoomWithScrollWheel() = 0;
|
||||
virtual bool getShowSpriteEditorScrollbars() = 0;
|
||||
virtual RightClickMode getRightClickMode() = 0;
|
||||
virtual bool getGrabAlpha() = 0;
|
||||
virtual app::Color getFgColor() = 0;
|
||||
virtual app::Color getBgColor() = 0;
|
||||
@ -70,6 +72,7 @@ namespace app {
|
||||
|
||||
virtual void setZoomWithScrollWheel(bool state) = 0;
|
||||
virtual void setShowSpriteEditorScrollbars(bool state) = 0;
|
||||
virtual void setRightClickMode(RightClickMode mode) = 0;
|
||||
virtual void setGrabAlpha(bool state) = 0;
|
||||
virtual void setFgColor(const app::Color& color) = 0;
|
||||
virtual void setBgColor(const app::Color& color) = 0;
|
||||
|
@ -216,6 +216,8 @@ UISettingsImpl::UISettingsImpl()
|
||||
, m_zoomWithScrollWheel(get_config_bool("Options", "ZoomWithMouseWheel", true))
|
||||
, m_showSpriteEditorScrollbars(get_config_bool("Options", "ShowScrollbars", true))
|
||||
, m_grabAlpha(get_config_bool("Options", "GrabAlpha", false))
|
||||
, m_rightClickMode(static_cast<RightClickMode>(get_config_int("Options", "RightClickMode",
|
||||
static_cast<int>(RightClickMode::Default))))
|
||||
{
|
||||
m_colorSwatches = new app::ColorSwatches("Default");
|
||||
for (size_t i=0; i<16; ++i)
|
||||
@ -229,6 +231,7 @@ UISettingsImpl::~UISettingsImpl()
|
||||
set_config_bool("Options", "ZoomWithMouseWheel", m_zoomWithScrollWheel);
|
||||
set_config_bool("Options", "ShowScrollbars", m_showSpriteEditorScrollbars);
|
||||
set_config_bool("Options", "GrabAlpha", m_grabAlpha);
|
||||
set_config_int("Options", "RightClickMode", static_cast<int>(m_rightClickMode));
|
||||
|
||||
// Delete all tool settings.
|
||||
for (std::map<std::string, IToolSettings*>::iterator
|
||||
@ -277,6 +280,11 @@ bool UISettingsImpl::getShowSpriteEditorScrollbars()
|
||||
return m_showSpriteEditorScrollbars;
|
||||
}
|
||||
|
||||
RightClickMode UISettingsImpl::getRightClickMode()
|
||||
{
|
||||
return m_rightClickMode;
|
||||
}
|
||||
|
||||
bool UISettingsImpl::getGrabAlpha()
|
||||
{
|
||||
return m_grabAlpha;
|
||||
@ -317,6 +325,11 @@ void UISettingsImpl::setShowSpriteEditorScrollbars(bool state)
|
||||
notifyObservers<bool>(&GlobalSettingsObserver::onSetShowSpriteEditorScrollbars, state);
|
||||
}
|
||||
|
||||
void UISettingsImpl::setRightClickMode(RightClickMode mode)
|
||||
{
|
||||
m_rightClickMode = mode;
|
||||
}
|
||||
|
||||
void UISettingsImpl::setGrabAlpha(bool state)
|
||||
{
|
||||
m_grabAlpha = state;
|
||||
|
@ -49,6 +49,7 @@ namespace app {
|
||||
// ISettings implementation
|
||||
bool getZoomWithScrollWheel() override;
|
||||
bool getShowSpriteEditorScrollbars() override;
|
||||
RightClickMode getRightClickMode() override;
|
||||
bool getGrabAlpha() override;
|
||||
app::Color getFgColor() override;
|
||||
app::Color getBgColor() override;
|
||||
@ -57,6 +58,7 @@ namespace app {
|
||||
|
||||
void setZoomWithScrollWheel(bool state) override;
|
||||
void setShowSpriteEditorScrollbars(bool state) override;
|
||||
void setRightClickMode(RightClickMode mode) override;
|
||||
void setGrabAlpha(bool state) override;
|
||||
void setFgColor(const app::Color& color) override;
|
||||
void setBgColor(const app::Color& color) override;
|
||||
@ -93,6 +95,7 @@ namespace app {
|
||||
bool m_zoomWithScrollWheel;
|
||||
bool m_showSpriteEditorScrollbars;
|
||||
bool m_grabAlpha;
|
||||
RightClickMode m_rightClickMode;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
@ -46,6 +46,9 @@ namespace app {
|
||||
// is a effect so the Editor can display the cursor bounds)
|
||||
virtual bool isEffect() const { return false; }
|
||||
|
||||
// Returns true if this ink acts like an eraser
|
||||
virtual bool isEraser() const { return false; }
|
||||
|
||||
// Returns true if this ink picks colors from the image
|
||||
virtual bool isEyedropper() const { return false; }
|
||||
|
||||
|
@ -173,6 +173,7 @@ public:
|
||||
|
||||
bool isPaint() const { return true; }
|
||||
bool isEffect() const { return true; }
|
||||
bool isEraser() const { return true; }
|
||||
|
||||
void prepareInk(ToolLoop* loop)
|
||||
{
|
||||
|
@ -51,6 +51,8 @@ namespace tools {
|
||||
using namespace gfx;
|
||||
|
||||
const char* WellKnownTools::RectangularMarquee = "rectangular_marquee";
|
||||
const char* WellKnownTools::Eraser = "eraser";
|
||||
const char* WellKnownTools::Eyedropper = "eyedropper";
|
||||
|
||||
const char* WellKnownInks::Selection = "selection";
|
||||
const char* WellKnownInks::Paint = "paint";
|
||||
|
@ -33,6 +33,8 @@ namespace app {
|
||||
|
||||
namespace WellKnownTools {
|
||||
extern const char* RectangularMarquee;
|
||||
extern const char* Eraser;
|
||||
extern const char* Eyedropper;
|
||||
};
|
||||
|
||||
namespace WellKnownInks {
|
||||
|
@ -85,7 +85,7 @@ static int saved_pixel_n;
|
||||
static gfx::Region clipping_region;
|
||||
static gfx::Region old_clipping_region;
|
||||
|
||||
static void generate_cursor_boundaries();
|
||||
static void generate_cursor_boundaries(Editor* editor);
|
||||
|
||||
static void trace_thincross_pixels(ui::Graphics* g, Editor* editor, int x, int y, gfx::Color color, Editor::PixelDelegate pixel);
|
||||
static void trace_thickcross_pixels(ui::Graphics* g, Editor* editor, int x, int y, gfx::Color color, int thickness, Editor::PixelDelegate pixel);
|
||||
@ -156,16 +156,13 @@ static void on_brush_after_change()
|
||||
}
|
||||
}
|
||||
|
||||
static Brush* editor_get_current_brush()
|
||||
static Brush* editor_get_current_brush(Editor* editor)
|
||||
{
|
||||
// Create the current brush from settings
|
||||
tools::Tool* current_tool = UIContext::instance()
|
||||
->settings()
|
||||
->getCurrentTool();
|
||||
|
||||
tools::Tool* tool = editor->getCurrentEditorTool();
|
||||
IBrushSettings* brush_settings = UIContext::instance()
|
||||
->settings()
|
||||
->getToolSettings(current_tool)
|
||||
->getToolSettings(tool)
|
||||
->getBrush();
|
||||
|
||||
ASSERT(brush_settings != NULL);
|
||||
@ -235,22 +232,20 @@ void Editor::drawBrushPreview(int x, int y, bool refresh)
|
||||
screenToEditor(x, y, &x, &y);
|
||||
|
||||
// Get the current tool
|
||||
tools::Tool* current_tool = UIContext::instance()
|
||||
->settings()
|
||||
->getCurrentTool();
|
||||
tools::Tool* tool = getCurrentEditorTool();
|
||||
tools::Ink* ink = getCurrentEditorInk();
|
||||
|
||||
// Setup the cursor type debrushding of several factors (current tool,
|
||||
// foreground color, and layer transparency).
|
||||
color_t brush_color = get_brush_color(m_sprite, m_layer);
|
||||
color_t mask_color = m_sprite->transparentColor();
|
||||
|
||||
if (current_tool->getInk(0)->isSelection() ||
|
||||
current_tool->getInk(0)->isSlice()) {
|
||||
if (ink->isSelection() || ink->isSlice()) {
|
||||
cursor_type = CURSOR_THICKCROSS;
|
||||
}
|
||||
else if (
|
||||
// Use cursor bounds for inks that are effects (eraser, blur, etc.)
|
||||
(current_tool->getInk(0)->isEffect()) ||
|
||||
(ink->isEffect()) ||
|
||||
// or when the brush color is transparent and we are not in the background layer
|
||||
(m_layer && !m_layer->isBackground() &&
|
||||
brush_color == mask_color)) {
|
||||
@ -262,15 +257,15 @@ void Editor::drawBrushPreview(int x, int y, bool refresh)
|
||||
|
||||
// For cursor type 'bounds' we have to generate cursor boundaries
|
||||
if (cursor_type & CURSOR_BRUSHBOUNDS)
|
||||
generate_cursor_boundaries();
|
||||
generate_cursor_boundaries(this);
|
||||
|
||||
// Draw pixel/brush preview
|
||||
if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) {
|
||||
IToolSettings* tool_settings = UIContext::instance()
|
||||
->settings()
|
||||
->getToolSettings(current_tool);
|
||||
->getToolSettings(tool);
|
||||
|
||||
Brush* brush = editor_get_current_brush();
|
||||
Brush* brush = editor_get_current_brush(this);
|
||||
gfx::Rect brushBounds = brush->bounds();
|
||||
|
||||
// Create the extra cel to show the brush preview
|
||||
@ -342,7 +337,7 @@ void Editor::moveBrushPreview(int x, int y, bool refresh)
|
||||
}
|
||||
|
||||
if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) {
|
||||
Brush* brush = editor_get_current_brush();
|
||||
Brush* brush = editor_get_current_brush(this);
|
||||
gfx::Rect brushBounds = brush->bounds();
|
||||
gfx::Rect rc1(old_x+brushBounds.x, old_y+brushBounds.y, brushBounds.w, brushBounds.h);
|
||||
gfx::Rect rc2(new_x+brushBounds.x, new_y+brushBounds.y, brushBounds.w, brushBounds.h);
|
||||
@ -392,7 +387,7 @@ void Editor::clearBrushPreview(bool refresh)
|
||||
|
||||
// Clean pixel/brush preview
|
||||
if (cursor_type & CURSOR_THINCROSS && m_state->requireBrushPreview()) {
|
||||
Brush* brush = editor_get_current_brush();
|
||||
Brush* brush = editor_get_current_brush(this);
|
||||
gfx::Rect brushBounds = brush->bounds();
|
||||
|
||||
m_document->prepareExtraCel(x+brushBounds.x, y+brushBounds.y,
|
||||
@ -424,17 +419,15 @@ bool Editor::doesBrushPreviewNeedSubpixel()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void generate_cursor_boundaries()
|
||||
static void generate_cursor_boundaries(Editor* editor)
|
||||
{
|
||||
tools::Tool* current_tool = UIContext::instance()
|
||||
->settings()
|
||||
->getCurrentTool();
|
||||
tools::Tool* tool = editor->getCurrentEditorTool();
|
||||
|
||||
IBrushSettings* brush_settings = NULL;
|
||||
if (current_tool)
|
||||
if (tool)
|
||||
brush_settings = UIContext::instance()
|
||||
->settings()
|
||||
->getToolSettings(current_tool)
|
||||
->getToolSettings(tool)
|
||||
->getBrush();
|
||||
|
||||
if (cursor_bound.seg == NULL ||
|
||||
|
@ -143,6 +143,7 @@ Editor::Editor(Document* document, EditorFlags flags)
|
||||
, m_customizationDelegate(NULL)
|
||||
, m_docView(NULL)
|
||||
, m_flags(flags)
|
||||
, m_secondaryButton(false)
|
||||
{
|
||||
// Add the first state into the history.
|
||||
m_statesHistory.push(m_state);
|
||||
@ -732,14 +733,121 @@ gfx::Point Editor::controlInfiniteScroll(MouseMessage* msg)
|
||||
return mousePos;
|
||||
}
|
||||
|
||||
bool Editor::isCurrentToolAffectedByRightClickMode()
|
||||
{
|
||||
Context* context = UIContext::instance();
|
||||
tools::Tool* tool = context->settings()->getCurrentTool();
|
||||
|
||||
return
|
||||
(tool->getInk(0)->isPaint() || tool->getInk(0)->isEffect()) &&
|
||||
(!tool->getInk(0)->isEraser());
|
||||
}
|
||||
|
||||
tools::Tool* Editor::getCurrentEditorTool()
|
||||
{
|
||||
if (m_quicktool)
|
||||
return m_quicktool;
|
||||
else {
|
||||
UIContext* context = UIContext::instance();
|
||||
return context->settings()->getCurrentTool();
|
||||
|
||||
Context* context = UIContext::instance();
|
||||
tools::Tool* tool = context->settings()->getCurrentTool();
|
||||
|
||||
if (m_secondaryButton && isCurrentToolAffectedByRightClickMode()) {
|
||||
tools::ToolBox* toolbox = App::instance()->getToolBox();
|
||||
|
||||
switch (context->settings()->getRightClickMode()) {
|
||||
case RightClickMode::PaintBgColor:
|
||||
// Do nothing, use the current tool
|
||||
break;
|
||||
case RightClickMode::PickFgColor:
|
||||
tool = toolbox->getToolById(tools::WellKnownTools::Eyedropper);
|
||||
break;
|
||||
case RightClickMode::Erase:
|
||||
tool = toolbox->getToolById(tools::WellKnownTools::Eraser);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return tool;
|
||||
}
|
||||
|
||||
tools::Ink* Editor::getCurrentEditorInk()
|
||||
{
|
||||
Context* context = UIContext::instance();
|
||||
tools::Tool* tool = getCurrentEditorTool();
|
||||
tools::Ink* ink = tool->getInk(m_secondaryButton ? 1: 0);
|
||||
|
||||
if (m_quicktool)
|
||||
return ink;
|
||||
|
||||
tools::Tool* selectedTool = context->settings()->getCurrentTool();
|
||||
RightClickMode rightClickMode = context->settings()->getRightClickMode();
|
||||
|
||||
if (m_secondaryButton &&
|
||||
rightClickMode != RightClickMode::Default &&
|
||||
isCurrentToolAffectedByRightClickMode()) {
|
||||
tools::ToolBox* toolbox = App::instance()->getToolBox();
|
||||
|
||||
switch (rightClickMode) {
|
||||
case RightClickMode::Default:
|
||||
// Do nothing
|
||||
break;
|
||||
case RightClickMode::PickFgColor:
|
||||
ink = toolbox->getInkById(tools::WellKnownInks::PickFg);
|
||||
break;
|
||||
case RightClickMode::Erase:
|
||||
ink = toolbox->getInkById(tools::WellKnownInks::Eraser);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
IToolSettings* toolSettings = context->settings()->getToolSettings(tool);
|
||||
InkType inkType = toolSettings->getInkType();
|
||||
const char* id = NULL;
|
||||
|
||||
switch (inkType) {
|
||||
case kDefaultInk:
|
||||
// Do nothing
|
||||
break;
|
||||
case kOpaqueInk:
|
||||
id = tools::WellKnownInks::PaintOpaque;
|
||||
break;
|
||||
case kSetAlphaInk:
|
||||
id = tools::WellKnownInks::PaintSetAlpha;
|
||||
break;
|
||||
case kLockAlphaInk:
|
||||
id = tools::WellKnownInks::PaintLockAlpha;
|
||||
break;
|
||||
case kMergeInk:
|
||||
id = tools::WellKnownInks::Paint;
|
||||
break;
|
||||
case kShadingInk:
|
||||
id = tools::WellKnownInks::Shading;
|
||||
break;
|
||||
case kReplaceInk:
|
||||
if (!m_secondaryButton)
|
||||
id = tools::WellKnownInks::ReplaceBgWithFg;
|
||||
else
|
||||
id = tools::WellKnownInks::ReplaceFgWithBg;
|
||||
break;
|
||||
case kEraseInk:
|
||||
id = tools::WellKnownInks::Eraser;
|
||||
break;
|
||||
case kSelectionInk:
|
||||
id = tools::WellKnownInks::Selection;
|
||||
break;
|
||||
case kBlurInk:
|
||||
id = tools::WellKnownInks::Blur;
|
||||
break;
|
||||
case kJumbleInk:
|
||||
id = tools::WellKnownInks::Jumble;
|
||||
break;
|
||||
}
|
||||
|
||||
if (id)
|
||||
ink = App::instance()->getToolBox()->getInkById(id);
|
||||
}
|
||||
|
||||
return ink;
|
||||
}
|
||||
|
||||
void Editor::screenToEditor(int xin, int yin, int* xout, int* yout)
|
||||
@ -930,10 +1038,18 @@ bool Editor::onProcessMessage(Message* msg)
|
||||
|
||||
case kMouseDownMessage:
|
||||
if (m_sprite) {
|
||||
m_oldPos = static_cast<MouseMessage*>(msg)->position();
|
||||
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
|
||||
|
||||
m_oldPos = mouseMsg->position();
|
||||
if (!m_secondaryButton && mouseMsg->right()) {
|
||||
m_secondaryButton = mouseMsg->right();
|
||||
|
||||
editor_update_quicktool();
|
||||
editor_setcursor();
|
||||
}
|
||||
|
||||
EditorStatePtr holdState(m_state);
|
||||
return m_state->onMouseDown(this, static_cast<MouseMessage*>(msg));
|
||||
return m_state->onMouseDown(this, mouseMsg);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -947,7 +1063,16 @@ bool Editor::onProcessMessage(Message* msg)
|
||||
case kMouseUpMessage:
|
||||
if (m_sprite) {
|
||||
EditorStatePtr holdState(m_state);
|
||||
if (m_state->onMouseUp(this, static_cast<MouseMessage*>(msg)))
|
||||
bool result = m_state->onMouseUp(this, static_cast<MouseMessage*>(msg));
|
||||
|
||||
if (!hasCapture() && m_secondaryButton) {
|
||||
m_secondaryButton = false;
|
||||
|
||||
editor_update_quicktool();
|
||||
editor_setcursor();
|
||||
}
|
||||
|
||||
if (result)
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@ -1169,8 +1294,7 @@ void Editor::pasteImage(const Image* image, int x, int y)
|
||||
// which will use the extra cel for transformation preview, and is
|
||||
// not compatible with the drawing cursor preview which overwrite
|
||||
// the extra cel.
|
||||
tools::Tool* currentTool = getCurrentEditorTool();
|
||||
if (!currentTool->getInk(0)->isSelection()) {
|
||||
if (!getCurrentEditorInk()->isSelection()) {
|
||||
tools::Tool* defaultSelectionTool =
|
||||
App::instance()->getToolBox()->getToolById(tools::WellKnownTools::RectangularMarquee);
|
||||
|
||||
|
@ -58,6 +58,7 @@ namespace app {
|
||||
class PixelsMovement;
|
||||
|
||||
namespace tools {
|
||||
class Ink;
|
||||
class Tool;
|
||||
}
|
||||
|
||||
@ -169,6 +170,9 @@ namespace app {
|
||||
gfx::Point controlInfiniteScroll(ui::MouseMessage* msg);
|
||||
|
||||
tools::Tool* getCurrentEditorTool();
|
||||
tools::Ink* getCurrentEditorInk();
|
||||
|
||||
bool isSecondaryButton() const { return m_secondaryButton; }
|
||||
|
||||
// Returns true if we are able to draw in the current doc/sprite/layer/cel.
|
||||
bool canDraw();
|
||||
@ -213,6 +217,7 @@ namespace app {
|
||||
void moveBrushPreview(int x, int y, bool refresh = true);
|
||||
void clearBrushPreview(bool refresh = true);
|
||||
bool doesBrushPreviewNeedSubpixel();
|
||||
bool isCurrentToolAffectedByRightClickMode();
|
||||
|
||||
void drawMaskSafe();
|
||||
void drawMask(ui::Graphics* g);
|
||||
@ -286,6 +291,8 @@ namespace app {
|
||||
gfx::Point m_oldPos;
|
||||
|
||||
EditorFlags m_flags;
|
||||
|
||||
bool m_secondaryButton;
|
||||
};
|
||||
|
||||
ui::WidgetType editor_type();
|
||||
|
@ -63,7 +63,7 @@ MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMo
|
||||
// MovingPixelsState needs a selection tool to avoid problems
|
||||
// sharing the extra cel between the drawing cursor preview and the
|
||||
// pixels movement/transformation preview.
|
||||
//ASSERT(!editor->getCurrentEditorTool()->getInk(0)->isSelection());
|
||||
//ASSERT(!editor->getCurrentEditorInk()->isSelection());
|
||||
|
||||
UIContext* context = UIContext::instance();
|
||||
|
||||
|
@ -124,8 +124,7 @@ void StandbyState::onCurrentToolChange(Editor* editor)
|
||||
|
||||
bool StandbyState::checkForScroll(Editor* editor, MouseMessage* msg)
|
||||
{
|
||||
tools::Tool* currentTool = editor->getCurrentEditorTool();
|
||||
tools::Ink* clickedInk = currentTool->getInk(msg->right() ? 1: 0);
|
||||
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
||||
|
||||
// Start scroll loop
|
||||
if (msg->middle() || clickedInk->isScrollMovement()) { // TODO msg->middle() should be customizable
|
||||
@ -141,8 +140,7 @@ bool StandbyState::checkForScroll(Editor* editor, MouseMessage* msg)
|
||||
|
||||
bool StandbyState::checkForZoom(Editor* editor, MouseMessage* msg)
|
||||
{
|
||||
tools::Tool* currentTool = editor->getCurrentEditorTool();
|
||||
tools::Ink* clickedInk = currentTool->getInk(msg->right() ? 1: 0);
|
||||
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
||||
|
||||
// Start scroll loop
|
||||
if (clickedInk->isZoom()) {
|
||||
@ -162,8 +160,8 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
|
||||
return true;
|
||||
|
||||
UIContext* context = UIContext::instance();
|
||||
tools::Tool* current_tool = editor->getCurrentEditorTool();
|
||||
tools::Ink* clickedInk = current_tool->getInk(msg->right() ? 1: 0);
|
||||
tools::Tool* currentTool = editor->getCurrentEditorTool();
|
||||
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
||||
DocumentLocation location;
|
||||
editor->getDocumentLocation(&location);
|
||||
Document* document = location.document();
|
||||
@ -225,7 +223,7 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
|
||||
|
||||
// Move selected pixels
|
||||
if (editor->isInsideSelection() &&
|
||||
current_tool->getInk(0)->isSelection() &&
|
||||
currentTool->getInk(0)->isSelection() &&
|
||||
msg->left()) {
|
||||
int x, y, opacity;
|
||||
Image* image = location.image(&x, &y, &opacity);
|
||||
@ -243,20 +241,13 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
|
||||
|
||||
// Call the eyedropper command
|
||||
if (clickedInk->isEyedropper()) {
|
||||
Command* eyedropper_cmd =
|
||||
CommandsModule::instance()->getCommandByName(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, ¶ms);
|
||||
onMouseMove(editor, msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Start the Tool-Loop
|
||||
if (layer) {
|
||||
tools::ToolLoop* toolLoop = create_tool_loop(editor, context, msg);
|
||||
tools::ToolLoop* toolLoop = create_tool_loop(editor, context);
|
||||
if (toolLoop)
|
||||
editor->setState(EditorStatePtr(new DrawingState(toolLoop, editor, msg)));
|
||||
return true;
|
||||
@ -273,6 +264,21 @@ bool StandbyState::onMouseUp(Editor* editor, MouseMessage* msg)
|
||||
|
||||
bool StandbyState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
{
|
||||
// We control eyedropper tool from here. TODO move this to another place
|
||||
if (msg->left() || msg->right()) {
|
||||
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
||||
if (clickedInk->isEyedropper()) {
|
||||
Command* eyedropper_cmd =
|
||||
CommandsModule::instance()->getCommandByName(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, ¶ms);
|
||||
}
|
||||
}
|
||||
|
||||
editor->moveDrawingCursor();
|
||||
editor->updateStatusBar();
|
||||
return true;
|
||||
@ -397,13 +403,10 @@ bool StandbyState::onMouseWheel(Editor* editor, MouseMessage* msg)
|
||||
|
||||
bool StandbyState::onSetCursor(Editor* editor)
|
||||
{
|
||||
tools::Tool* current_tool = editor->getCurrentEditorTool();
|
||||
|
||||
if (current_tool) {
|
||||
tools::Ink* current_ink = current_tool->getInk(0);
|
||||
|
||||
tools::Ink* ink = editor->getCurrentEditorInk();
|
||||
if (ink) {
|
||||
// If the current tool change selection (e.g. rectangular marquee, etc.)
|
||||
if (current_ink->isSelection()) {
|
||||
if (ink->isSelection()) {
|
||||
// See if the cursor is in some selection handle.
|
||||
if (m_decorator->onSetCursor(editor))
|
||||
return true;
|
||||
@ -422,27 +425,27 @@ bool StandbyState::onSetCursor(Editor* editor)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (current_ink->isEyedropper()) {
|
||||
else if (ink->isEyedropper()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(kEyedropperCursor);
|
||||
return true;
|
||||
}
|
||||
else if (current_ink->isZoom()) {
|
||||
else if (ink->isZoom()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(kMagnifierCursor);
|
||||
return true;
|
||||
}
|
||||
else if (current_ink->isScrollMovement()) {
|
||||
else if (ink->isScrollMovement()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(kScrollCursor);
|
||||
return true;
|
||||
}
|
||||
else if (current_ink->isCelMovement()) {
|
||||
else if (ink->isCelMovement()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(kMoveCursor);
|
||||
return true;
|
||||
}
|
||||
else if (current_ink->isSlice()) {
|
||||
else if (ink->isSlice()) {
|
||||
jmouse_set_cursor(kNoCursor);
|
||||
editor->showDrawingCursor();
|
||||
return true;
|
||||
@ -475,7 +478,7 @@ bool StandbyState::onKeyUp(Editor* editor, KeyMessage* msg)
|
||||
|
||||
bool StandbyState::onUpdateStatusBar(Editor* editor)
|
||||
{
|
||||
tools::Tool* current_tool = editor->getCurrentEditorTool();
|
||||
tools::Ink* ink = editor->getCurrentEditorInk();
|
||||
const Sprite* sprite = editor->sprite();
|
||||
int x, y;
|
||||
|
||||
@ -485,7 +488,7 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
|
||||
StatusBar::instance()->clearText();
|
||||
}
|
||||
// For eye-dropper
|
||||
else if (current_tool->getInk(0)->isEyedropper()) {
|
||||
else if (ink->isEyedropper()) {
|
||||
bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha();
|
||||
ColorPicker picker;
|
||||
picker.pickColor(editor->getDocumentLocation(), x, y,
|
||||
@ -663,9 +666,9 @@ void StandbyState::Decorator::postRenderDecorator(EditorPostRender* render)
|
||||
editor->document()->isMaskVisible() &&
|
||||
!editor->document()->mask()->isFrozen()) {
|
||||
// And draw only when the user has a selection tool as active tool.
|
||||
tools::Tool* currentTool = editor->getCurrentEditorTool();
|
||||
tools::Ink* ink = editor->getCurrentEditorInk();
|
||||
|
||||
if (currentTool->getInk(0)->isSelection())
|
||||
if (ink->isSelection())
|
||||
getTransformHandles(editor)->drawHandles(editor,
|
||||
m_standbyState->getTransformation(editor));
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
ToolLoopImpl(Editor* editor,
|
||||
Context* context,
|
||||
tools::Tool* tool,
|
||||
tools::Ink* ink,
|
||||
Document* document,
|
||||
tools::ToolLoop::Button button,
|
||||
const app::Color& primary_color,
|
||||
@ -108,7 +109,7 @@ public:
|
||||
, m_toolSettings(m_settings->getToolSettings(m_tool))
|
||||
, m_canceled(false)
|
||||
, m_button(button)
|
||||
, m_ink(getInkFromType())
|
||||
, m_ink(ink)
|
||||
, m_primary_color(color_utils::color_for_layer(primary_color, m_layer))
|
||||
, m_secondary_color(color_utils::color_for_layer(secondary_color, m_layer))
|
||||
, m_selectionMode(m_settings->selection()->getSelectionMode())
|
||||
@ -282,61 +283,13 @@ public:
|
||||
return m_shadeTable;
|
||||
}
|
||||
|
||||
private:
|
||||
tools::Ink* getInkFromType()
|
||||
{
|
||||
using namespace tools;
|
||||
|
||||
InkType inkType = m_toolSettings->getInkType();
|
||||
if (inkType == kDefaultInk)
|
||||
return m_tool->getInk(m_button);
|
||||
|
||||
const char* id = WellKnownInks::Paint;
|
||||
switch (inkType) {
|
||||
case kOpaqueInk:
|
||||
id = WellKnownInks::PaintOpaque;
|
||||
break;
|
||||
case kSetAlphaInk:
|
||||
id = WellKnownInks::PaintSetAlpha;
|
||||
break;
|
||||
case kLockAlphaInk:
|
||||
id = WellKnownInks::PaintLockAlpha;
|
||||
break;
|
||||
case kMergeInk:
|
||||
id = WellKnownInks::Paint;
|
||||
break;
|
||||
case kShadingInk:
|
||||
id = WellKnownInks::Shading;
|
||||
break;
|
||||
case kReplaceInk:
|
||||
if (m_button == ToolLoop::Left)
|
||||
id = WellKnownInks::ReplaceBgWithFg;
|
||||
else
|
||||
id = WellKnownInks::ReplaceFgWithBg;
|
||||
break;
|
||||
case kEraseInk:
|
||||
id = WellKnownInks::Eraser;
|
||||
break;
|
||||
case kSelectionInk:
|
||||
id = WellKnownInks::Selection;
|
||||
break;
|
||||
case kBlurInk:
|
||||
id = WellKnownInks::Blur;
|
||||
break;
|
||||
case kJumbleInk:
|
||||
id = WellKnownInks::Jumble;
|
||||
break;
|
||||
}
|
||||
|
||||
return App::instance()->getToolBox()->getInkById(id);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
tools::ToolLoop* create_tool_loop(Editor* editor, Context* context, MouseMessage* msg)
|
||||
tools::ToolLoop* create_tool_loop(Editor* editor, Context* context)
|
||||
{
|
||||
tools::Tool* current_tool = context->settings()->getCurrentTool();
|
||||
if (!current_tool)
|
||||
tools::Tool* current_tool = editor->getCurrentEditorTool();
|
||||
tools::Ink* current_ink = editor->getCurrentEditorInk();
|
||||
if (!current_tool || !current_ink)
|
||||
return NULL;
|
||||
|
||||
Layer* layer = editor->layer();
|
||||
@ -376,19 +329,16 @@ tools::ToolLoop* create_tool_loop(Editor* editor, Context* context, MouseMessage
|
||||
}
|
||||
|
||||
// Create the new tool loop
|
||||
try
|
||||
{
|
||||
return new ToolLoopImpl(editor,
|
||||
context,
|
||||
current_tool,
|
||||
editor->document(),
|
||||
msg->left() ? tools::ToolLoop::Left:
|
||||
tools::ToolLoop::Right,
|
||||
msg->left() ? fg: bg,
|
||||
msg->left() ? bg: fg);
|
||||
try {
|
||||
return new ToolLoopImpl(editor, context,
|
||||
current_tool,
|
||||
current_ink,
|
||||
editor->document(),
|
||||
!editor->isSecondaryButton() ? tools::ToolLoop::Left: tools::ToolLoop::Right,
|
||||
!editor->isSecondaryButton() ? fg: bg,
|
||||
!editor->isSecondaryButton() ? bg: fg);
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
catch (const std::exception& ex) {
|
||||
Alert::show(PACKAGE
|
||||
"<<Error drawing ink:"
|
||||
"<<%s"
|
||||
|
@ -20,10 +20,6 @@
|
||||
#define APP_UI_EDITOR_TOOL_LOOP_IMPL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
namespace ui {
|
||||
class MouseMessage;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
class Context;
|
||||
class Editor;
|
||||
@ -32,7 +28,7 @@ namespace app {
|
||||
class ToolLoop;
|
||||
}
|
||||
|
||||
tools::ToolLoop* create_tool_loop(Editor* editor, Context* context, ui::MouseMessage* msg);
|
||||
tools::ToolLoop* create_tool_loop(Editor* editor, Context* context);
|
||||
|
||||
} // namespace app
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user