2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2017-03-07 06:27:43 +08:00
|
|
|
// Copyright (C) 2001-2017 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/editor/tool_loop_impl.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
2017-03-07 06:27:43 +08:00
|
|
|
#include "app/cmd/add_slice.h"
|
2017-06-16 23:18:22 +08:00
|
|
|
#include "app/cmd/set_last_point.h"
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/cmd/set_mask.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "app/color.h"
|
|
|
|
#include "app/color_utils.h"
|
2015-04-10 07:05:02 +08:00
|
|
|
#include "app/console.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/context.h"
|
|
|
|
#include "app/context_access.h"
|
2014-08-25 06:22:43 +08:00
|
|
|
#include "app/document_undo.h"
|
2014-12-09 01:57:56 +08:00
|
|
|
#include "app/modules/gui.h"
|
2015-08-27 03:48:01 +08:00
|
|
|
#include "app/modules/palettes.h"
|
2015-02-15 20:48:38 +08:00
|
|
|
#include "app/pref/preferences.h"
|
2014-12-09 01:57:56 +08:00
|
|
|
#include "app/tools/controller.h"
|
2015-05-22 03:14:26 +08:00
|
|
|
#include "app/tools/freehand_algorithm.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/tools/ink.h"
|
2015-04-27 02:59:28 +08:00
|
|
|
#include "app/tools/point_shape.h"
|
2015-10-27 04:51:32 +08:00
|
|
|
#include "app/tools/symmetries.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/tools/tool.h"
|
|
|
|
#include "app/tools/tool_box.h"
|
|
|
|
#include "app/tools/tool_loop.h"
|
2015-01-19 09:05:33 +08:00
|
|
|
#include "app/transaction.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/color_bar.h"
|
2015-04-29 05:21:33 +08:00
|
|
|
#include "app/ui/context_bar.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/editor/editor.h"
|
2015-04-29 05:21:33 +08:00
|
|
|
#include "app/ui/main_window.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/status_bar.h"
|
|
|
|
#include "app/util/expand_cel_canvas.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/brush.h"
|
|
|
|
#include "doc/cel.h"
|
2015-04-27 02:59:28 +08:00
|
|
|
#include "doc/image.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/layer.h"
|
|
|
|
#include "doc/mask.h"
|
2015-08-27 03:48:01 +08:00
|
|
|
#include "doc/palette.h"
|
|
|
|
#include "doc/palette_picks.h"
|
|
|
|
#include "doc/remap.h"
|
2017-03-24 07:23:25 +08:00
|
|
|
#include "doc/slice.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/sprite.h"
|
2017-05-24 07:41:30 +08:00
|
|
|
#include "render/dithering.h"
|
2016-05-04 02:31:27 +08:00
|
|
|
#include "render/render.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
|
|
|
|
2015-04-27 02:59:28 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2015-05-22 03:00:27 +08:00
|
|
|
// Common properties between drawing/preview ToolLoop impl
|
2015-04-27 02:59:28 +08:00
|
|
|
|
2015-08-27 03:48:01 +08:00
|
|
|
class ToolLoopBase : public tools::ToolLoop {
|
2015-05-22 03:00:27 +08:00
|
|
|
|
|
|
|
protected:
|
2012-01-06 06:45:03 +08:00
|
|
|
Editor* m_editor;
|
|
|
|
tools::Tool* m_tool;
|
2015-04-29 05:21:33 +08:00
|
|
|
BrushRef m_brush;
|
2012-01-06 06:45:03 +08:00
|
|
|
Document* m_document;
|
|
|
|
Sprite* m_sprite;
|
|
|
|
Layer* m_layer;
|
2014-12-29 07:39:11 +08:00
|
|
|
frame_t m_frame;
|
2015-11-04 21:33:23 +08:00
|
|
|
RgbMap* m_rgbMap;
|
2015-02-15 20:48:38 +08:00
|
|
|
DocumentPreferences& m_docPref;
|
2015-05-19 03:53:25 +08:00
|
|
|
ToolPreferences& m_toolPref;
|
2012-01-06 06:45:03 +08:00
|
|
|
int m_opacity;
|
|
|
|
int m_tolerance;
|
2014-08-07 11:07:24 +08:00
|
|
|
bool m_contiguous;
|
2015-11-03 03:44:17 +08:00
|
|
|
gfx::Point m_celOrigin;
|
2012-01-06 06:45:03 +08:00
|
|
|
gfx::Point m_speed;
|
|
|
|
tools::ToolLoop::Button m_button;
|
2015-08-19 23:58:56 +08:00
|
|
|
base::UniquePtr<tools::Ink> m_ink;
|
2015-05-22 03:14:26 +08:00
|
|
|
tools::Controller* m_controller;
|
|
|
|
tools::PointShape* m_pointShape;
|
|
|
|
tools::Intertwine* m_intertwine;
|
|
|
|
tools::TracePolicy m_tracePolicy;
|
2015-10-27 04:51:32 +08:00
|
|
|
base::UniquePtr<tools::Symmetry> m_symmetry;
|
2015-08-27 03:48:01 +08:00
|
|
|
base::UniquePtr<doc::Remap> m_shadingRemap;
|
2016-05-03 05:42:02 +08:00
|
|
|
app::ColorTarget m_colorTarget;
|
2015-05-19 03:53:25 +08:00
|
|
|
doc::color_t m_fgColor;
|
|
|
|
doc::color_t m_bgColor;
|
|
|
|
doc::color_t m_primaryColor;
|
|
|
|
doc::color_t m_secondaryColor;
|
2013-01-21 05:40:37 +08:00
|
|
|
gfx::Region m_dirtyArea;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
public:
|
2015-05-22 03:00:27 +08:00
|
|
|
ToolLoopBase(Editor* editor,
|
2016-05-03 05:42:02 +08:00
|
|
|
Layer* layer,
|
2012-01-06 06:45:03 +08:00
|
|
|
tools::Tool* tool,
|
2014-08-19 19:17:57 +08:00
|
|
|
tools::Ink* ink,
|
2017-06-17 03:28:48 +08:00
|
|
|
tools::Controller* controller,
|
2012-01-06 06:45:03 +08:00
|
|
|
Document* document,
|
|
|
|
tools::ToolLoop::Button button,
|
2015-05-19 03:53:25 +08:00
|
|
|
const app::Color& fgColor,
|
|
|
|
const app::Color& bgColor)
|
2012-01-06 06:45:03 +08:00
|
|
|
: m_editor(editor)
|
|
|
|
, m_tool(tool)
|
2017-08-09 01:31:27 +08:00
|
|
|
, m_brush(App::instance()->contextBar()->activeBrush(m_tool, ink))
|
2012-01-06 06:45:03 +08:00
|
|
|
, m_document(document)
|
2014-07-30 12:28:15 +08:00
|
|
|
, m_sprite(editor->sprite())
|
2016-05-03 05:42:02 +08:00
|
|
|
, m_layer(layer)
|
2014-07-30 12:28:15 +08:00
|
|
|
, m_frame(editor->frame())
|
2015-11-04 21:33:23 +08:00
|
|
|
, m_rgbMap(nullptr)
|
2015-05-19 03:53:25 +08:00
|
|
|
, m_docPref(Preferences::instance().document(m_document))
|
|
|
|
, m_toolPref(Preferences::instance().tool(m_tool))
|
2015-05-22 03:14:26 +08:00
|
|
|
, m_opacity(m_toolPref.opacity())
|
|
|
|
, m_tolerance(m_toolPref.tolerance())
|
|
|
|
, m_contiguous(m_toolPref.contiguous())
|
2012-01-06 06:45:03 +08:00
|
|
|
, m_button(button)
|
2015-08-19 23:58:56 +08:00
|
|
|
, m_ink(ink->clone())
|
2017-06-17 03:28:48 +08:00
|
|
|
, m_controller(controller)
|
2015-05-22 03:14:26 +08:00
|
|
|
, m_pointShape(m_tool->getPointShape(m_button))
|
|
|
|
, m_intertwine(m_tool->getIntertwine(m_button))
|
|
|
|
, m_tracePolicy(m_tool->getTracePolicy(m_button))
|
2015-10-27 04:51:32 +08:00
|
|
|
, m_symmetry(nullptr)
|
2016-05-03 05:42:02 +08:00
|
|
|
, m_colorTarget(m_layer ? ColorTarget(m_layer):
|
|
|
|
ColorTarget(ColorTarget::BackgroundLayer,
|
|
|
|
m_sprite->pixelFormat(),
|
|
|
|
m_sprite->transparentColor()))
|
|
|
|
, m_fgColor(color_utils::color_for_target_mask(fgColor, m_colorTarget))
|
|
|
|
, m_bgColor(color_utils::color_for_target_mask(bgColor, m_colorTarget))
|
2015-05-19 03:53:25 +08:00
|
|
|
, m_primaryColor(button == tools::ToolLoop::Left ? m_fgColor: m_bgColor)
|
|
|
|
, m_secondaryColor(button == tools::ToolLoop::Left ? m_bgColor: m_fgColor)
|
2015-05-22 03:00:27 +08:00
|
|
|
{
|
2015-05-22 03:14:26 +08:00
|
|
|
if (m_tracePolicy == tools::TracePolicy::Accumulate ||
|
|
|
|
m_tracePolicy == tools::TracePolicy::AccumulateUpdateLast) {
|
2016-04-23 00:19:06 +08:00
|
|
|
tools::ToolBox* toolbox = App::instance()->toolBox();
|
2015-05-22 03:14:26 +08:00
|
|
|
|
2017-06-20 04:39:08 +08:00
|
|
|
switch (m_toolPref.freehandAlgorithm()) {
|
2015-05-22 03:14:26 +08:00
|
|
|
case tools::FreehandAlgorithm::DEFAULT:
|
|
|
|
m_intertwine = toolbox->getIntertwinerById(tools::WellKnownIntertwiners::AsLines);
|
|
|
|
m_tracePolicy = tools::TracePolicy::Accumulate;
|
|
|
|
break;
|
|
|
|
case tools::FreehandAlgorithm::PIXEL_PERFECT:
|
|
|
|
m_intertwine = toolbox->getIntertwinerById(tools::WellKnownIntertwiners::AsPixelPerfect);
|
|
|
|
m_tracePolicy = tools::TracePolicy::AccumulateUpdateLast;
|
|
|
|
break;
|
|
|
|
case tools::FreehandAlgorithm::DOTS:
|
|
|
|
m_intertwine = toolbox->getIntertwinerById(tools::WellKnownIntertwiners::None);
|
|
|
|
m_tracePolicy = tools::TracePolicy::Accumulate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-14 00:26:52 +08:00
|
|
|
|
2015-10-27 04:51:32 +08:00
|
|
|
// Symmetry mode
|
2015-10-29 07:00:18 +08:00
|
|
|
if (Preferences::instance().symmetryMode.enabled()) {
|
|
|
|
switch (m_docPref.symmetry.mode()) {
|
2015-10-27 04:51:32 +08:00
|
|
|
|
2015-10-29 07:00:18 +08:00
|
|
|
case app::gen::SymmetryMode::NONE:
|
|
|
|
ASSERT(m_symmetry == nullptr);
|
|
|
|
break;
|
2015-10-27 04:51:32 +08:00
|
|
|
|
2015-10-29 07:00:18 +08:00
|
|
|
case app::gen::SymmetryMode::HORIZONTAL:
|
|
|
|
m_symmetry.reset(new app::tools::HorizontalSymmetry(m_docPref.symmetry.xAxis()));
|
|
|
|
break;
|
2015-10-27 04:51:32 +08:00
|
|
|
|
2015-10-29 07:00:18 +08:00
|
|
|
case app::gen::SymmetryMode::VERTICAL:
|
|
|
|
m_symmetry.reset(new app::tools::VerticalSymmetry(m_docPref.symmetry.yAxis()));
|
|
|
|
break;
|
2017-03-28 02:27:37 +08:00
|
|
|
|
|
|
|
case app::gen::SymmetryMode::BOTH:
|
|
|
|
m_symmetry.reset(
|
|
|
|
new app::tools::SymmetryCombo(
|
|
|
|
new app::tools::HorizontalSymmetry(m_docPref.symmetry.xAxis()),
|
|
|
|
new app::tools::VerticalSymmetry(m_docPref.symmetry.yAxis())));
|
|
|
|
break;
|
2015-10-29 07:00:18 +08:00
|
|
|
}
|
2015-10-27 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2015-08-14 00:26:52 +08:00
|
|
|
// Ignore opacity for these inks
|
2015-08-14 02:41:37 +08:00
|
|
|
if (!tools::inkHasOpacity(m_toolPref.ink()) &&
|
2015-09-30 19:59:32 +08:00
|
|
|
m_brush->type() != kImageBrushType &&
|
|
|
|
!m_ink->isEffect()) {
|
2015-08-14 00:26:52 +08:00
|
|
|
m_opacity = 255;
|
2015-08-14 02:41:37 +08:00
|
|
|
}
|
2015-08-27 03:48:01 +08:00
|
|
|
|
|
|
|
if (m_toolPref.ink() == tools::InkType::SHADING) {
|
|
|
|
m_shadingRemap.reset(
|
2016-04-23 00:19:06 +08:00
|
|
|
App::instance()->contextBar()->createShadeRemap(
|
2015-08-27 03:48:01 +08:00
|
|
|
button == tools::ToolLoop::Left));
|
|
|
|
}
|
2015-05-22 03:00:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// IToolLoop interface
|
|
|
|
tools::Tool* getTool() override { return m_tool; }
|
|
|
|
Brush* getBrush() override { return m_brush.get(); }
|
|
|
|
Document* getDocument() override { return m_document; }
|
|
|
|
Sprite* sprite() override { return m_sprite; }
|
|
|
|
Layer* getLayer() override { return m_layer; }
|
|
|
|
frame_t getFrame() override { return m_frame; }
|
2015-11-04 21:33:23 +08:00
|
|
|
RgbMap* getRgbMap() override {
|
|
|
|
if (!m_rgbMap) {
|
|
|
|
Sprite::RgbMapFor forLayer =
|
2016-05-03 05:42:02 +08:00
|
|
|
((!m_layer ||
|
|
|
|
m_layer->isBackground() ||
|
2015-11-04 21:33:23 +08:00
|
|
|
m_sprite->pixelFormat() == IMAGE_RGB) ?
|
|
|
|
Sprite::RgbMapFor::OpaqueLayer:
|
|
|
|
Sprite::RgbMapFor::TransparentLayer);
|
|
|
|
m_rgbMap = m_sprite->rgbMap(m_frame, forLayer);
|
|
|
|
}
|
|
|
|
return m_rgbMap;
|
|
|
|
}
|
2015-05-22 03:00:27 +08:00
|
|
|
ToolLoop::Button getMouseButton() override { return m_button; }
|
|
|
|
doc::color_t getFgColor() override { return m_fgColor; }
|
|
|
|
doc::color_t getBgColor() override { return m_bgColor; }
|
|
|
|
doc::color_t getPrimaryColor() override { return m_primaryColor; }
|
|
|
|
void setPrimaryColor(doc::color_t color) override { m_primaryColor = color; }
|
|
|
|
doc::color_t getSecondaryColor() override { return m_secondaryColor; }
|
|
|
|
void setSecondaryColor(doc::color_t color) override { m_secondaryColor = color; }
|
|
|
|
int getOpacity() override { return m_opacity; }
|
|
|
|
int getTolerance() override { return m_tolerance; }
|
|
|
|
bool getContiguous() override { return m_contiguous; }
|
2016-04-05 05:46:48 +08:00
|
|
|
tools::ToolLoopModifiers getModifiers() override { return m_editor->getToolLoopModifiers(); }
|
2015-05-22 03:00:27 +08:00
|
|
|
filters::TiledMode getTiledMode() override { return m_docPref.tiled.mode(); }
|
2016-03-25 00:04:35 +08:00
|
|
|
bool getGridVisible() override { return m_docPref.show.grid(); }
|
2015-05-22 03:00:27 +08:00
|
|
|
bool getSnapToGrid() override { return m_docPref.grid.snap(); }
|
2015-06-18 00:22:46 +08:00
|
|
|
bool getStopAtGrid() override {
|
|
|
|
switch (m_toolPref.floodfill.stopAtGrid()) {
|
|
|
|
case app::gen::StopAtGrid::NEVER:
|
|
|
|
return false;
|
|
|
|
case app::gen::StopAtGrid::IF_VISIBLE:
|
2016-03-25 00:04:35 +08:00
|
|
|
return m_docPref.show.grid();
|
2015-06-18 00:22:46 +08:00
|
|
|
case app::gen::StopAtGrid::ALWAYS:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-22 03:00:27 +08:00
|
|
|
gfx::Rect getGridBounds() override { return m_docPref.grid.bounds(); }
|
2015-11-03 03:44:17 +08:00
|
|
|
gfx::Point getCelOrigin() override { return m_celOrigin; }
|
2015-05-22 03:00:27 +08:00
|
|
|
void setSpeed(const gfx::Point& speed) override { m_speed = speed; }
|
|
|
|
gfx::Point getSpeed() override { return m_speed; }
|
|
|
|
tools::Ink* getInk() override { return m_ink; }
|
2015-05-22 03:14:26 +08:00
|
|
|
tools::Controller* getController() override { return m_controller; }
|
|
|
|
tools::PointShape* getPointShape() override { return m_pointShape; }
|
|
|
|
tools::Intertwine* getIntertwine() override { return m_intertwine; }
|
2017-06-17 03:28:48 +08:00
|
|
|
tools::TracePolicy getTracePolicy() override {
|
|
|
|
if (m_controller->handleTracePolicy())
|
|
|
|
return m_controller->getTracePolicy();
|
|
|
|
else
|
|
|
|
return m_tracePolicy;
|
|
|
|
}
|
2015-10-27 04:51:32 +08:00
|
|
|
tools::Symmetry* getSymmetry() override { return m_symmetry.get(); }
|
2015-08-27 03:48:01 +08:00
|
|
|
doc::Remap* getShadingRemap() override { return m_shadingRemap; }
|
2015-05-22 03:00:27 +08:00
|
|
|
|
|
|
|
gfx::Region& getDirtyArea() override {
|
|
|
|
return m_dirtyArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateDirtyArea() override {
|
2016-09-23 21:22:30 +08:00
|
|
|
// This is necessary here so the "on sprite crosshair" is hidden,
|
|
|
|
// we update screen pixels with the new sprite, and then we show
|
|
|
|
// the crosshair saving the updated pixels. It fixes problems with
|
|
|
|
// filled shape tools when we release the button, or paint-bucket
|
|
|
|
// when we press the button.
|
2015-07-06 22:05:49 +08:00
|
|
|
HideBrushPreview hide(m_editor->brushPreview());
|
2016-09-23 21:22:30 +08:00
|
|
|
|
2016-09-23 07:16:14 +08:00
|
|
|
m_document->notifySpritePixelsModified(
|
|
|
|
m_sprite, m_dirtyArea, m_frame);
|
2015-05-22 03:00:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateStatusBar(const char* text) override {
|
|
|
|
StatusBar::instance()->setStatusText(0, text);
|
|
|
|
}
|
2015-09-16 23:19:10 +08:00
|
|
|
|
2017-05-24 07:41:30 +08:00
|
|
|
render::DitheringMatrix getDitheringMatrix() override {
|
|
|
|
return App::instance()->contextBar()->ditheringMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
render::DitheringAlgorithmBase* getDitheringAlgorithm() override {
|
|
|
|
return App::instance()->contextBar()->ditheringAlgorithm();
|
|
|
|
}
|
|
|
|
|
2015-05-22 03:00:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// For drawing
|
|
|
|
|
|
|
|
class ToolLoopImpl : public ToolLoopBase {
|
|
|
|
Context* m_context;
|
|
|
|
bool m_filled;
|
|
|
|
bool m_previewFilled;
|
|
|
|
int m_sprayWidth;
|
|
|
|
int m_spraySpeed;
|
|
|
|
bool m_useMask;
|
|
|
|
Mask* m_mask;
|
|
|
|
gfx::Point m_maskOrigin;
|
|
|
|
bool m_canceled;
|
|
|
|
Transaction m_transaction;
|
2016-05-04 11:02:56 +08:00
|
|
|
ExpandCelCanvas* m_expandCelCanvas;
|
2016-05-04 02:31:27 +08:00
|
|
|
Image* m_floodfillSrcImage;
|
2017-06-17 03:28:48 +08:00
|
|
|
bool m_saveLastPoint;
|
2015-05-22 03:00:27 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
ToolLoopImpl(Editor* editor,
|
2016-05-03 05:42:02 +08:00
|
|
|
Layer* layer,
|
2015-05-22 03:00:27 +08:00
|
|
|
Context* context,
|
|
|
|
tools::Tool* tool,
|
|
|
|
tools::Ink* ink,
|
2017-06-17 03:28:48 +08:00
|
|
|
tools::Controller* controller,
|
2015-05-22 03:00:27 +08:00
|
|
|
Document* document,
|
|
|
|
tools::ToolLoop::Button button,
|
|
|
|
const app::Color& fgColor,
|
2017-06-17 03:28:48 +08:00
|
|
|
const app::Color& bgColor,
|
|
|
|
const bool saveLastPoint)
|
|
|
|
: ToolLoopBase(editor,
|
|
|
|
layer,
|
|
|
|
tool,
|
|
|
|
ink,
|
|
|
|
controller,
|
|
|
|
document,
|
|
|
|
button,
|
|
|
|
fgColor,
|
|
|
|
bgColor)
|
2015-05-22 03:00:27 +08:00
|
|
|
, m_context(context)
|
|
|
|
, m_canceled(false)
|
2015-01-19 09:05:33 +08:00
|
|
|
, m_transaction(m_context,
|
|
|
|
m_tool->getText().c_str(),
|
|
|
|
((getInk()->isSelection() ||
|
|
|
|
getInk()->isEyedropper() ||
|
|
|
|
getInk()->isScrollMovement() ||
|
|
|
|
getInk()->isSlice() ||
|
|
|
|
getInk()->isZoom()) ? DoesntModifyDocument:
|
|
|
|
ModifyDocument))
|
2016-05-04 11:02:56 +08:00
|
|
|
, m_expandCelCanvas(nullptr)
|
|
|
|
, m_floodfillSrcImage(nullptr)
|
2017-06-17 03:28:48 +08:00
|
|
|
, m_saveLastPoint(saveLastPoint)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2015-08-19 06:29:37 +08:00
|
|
|
ASSERT(m_context->activeDocument() == m_editor->document());
|
|
|
|
|
2016-05-04 11:02:56 +08:00
|
|
|
if (m_pointShape->isFloodFill()) {
|
|
|
|
// Prepare a special image for floodfill when it's configured to
|
|
|
|
// stop using all visible layers.
|
|
|
|
if (m_toolPref.floodfill.referTo() == gen::FillReferTo::ALL_LAYERS) {
|
|
|
|
m_floodfillSrcImage = Image::create(m_sprite->pixelFormat(),
|
|
|
|
m_sprite->width(),
|
|
|
|
m_sprite->height());
|
|
|
|
|
|
|
|
m_floodfillSrcImage->clear(m_sprite->transparentColor());
|
|
|
|
|
|
|
|
render::Render().renderSprite(
|
|
|
|
m_floodfillSrcImage,
|
|
|
|
m_sprite,
|
|
|
|
m_frame,
|
2016-05-24 06:22:02 +08:00
|
|
|
gfx::Clip(m_sprite->bounds()));
|
2016-05-04 11:02:56 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Cel* cel = m_layer->cel(m_frame);
|
|
|
|
if (cel && (cel->x() != 0 || cel->y() != 0)) {
|
|
|
|
m_floodfillSrcImage = Image::create(m_sprite->pixelFormat(),
|
|
|
|
m_sprite->width(),
|
|
|
|
m_sprite->height());
|
|
|
|
m_floodfillSrcImage->clear(m_sprite->transparentColor());
|
|
|
|
copy_image(m_floodfillSrcImage, cel->image(), cel->x(), cel->y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_expandCelCanvas = new ExpandCelCanvas(
|
|
|
|
editor->getSite(),
|
|
|
|
layer,
|
|
|
|
m_docPref.tiled.mode(),
|
|
|
|
m_transaction,
|
|
|
|
ExpandCelCanvas::Flags(
|
|
|
|
ExpandCelCanvas::NeedsSource |
|
|
|
|
// If the tool is freehand-like, we can use the modified
|
|
|
|
// region directly as undo information to save the modified
|
2016-05-06 02:25:19 +08:00
|
|
|
// pixels. See ExpandCelCanvas::commit() for details about this flag.
|
2016-05-04 11:02:56 +08:00
|
|
|
(getController()->isFreehand() ?
|
|
|
|
ExpandCelCanvas::UseModifiedRegionAsUndoInfo:
|
|
|
|
ExpandCelCanvas::None)));
|
|
|
|
|
|
|
|
if (!m_floodfillSrcImage)
|
|
|
|
m_floodfillSrcImage = const_cast<Image*>(getSrcImage());
|
|
|
|
|
2012-11-18 21:21:06 +08:00
|
|
|
// Settings
|
2012-01-06 06:45:03 +08:00
|
|
|
switch (tool->getFill(m_button)) {
|
|
|
|
case tools::FillNone:
|
|
|
|
m_filled = false;
|
|
|
|
break;
|
|
|
|
case tools::FillAlways:
|
|
|
|
m_filled = true;
|
|
|
|
break;
|
|
|
|
case tools::FillOptional:
|
2015-05-19 03:53:25 +08:00
|
|
|
m_filled = m_toolPref.filled();
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-01-26 04:58:29 +08:00
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
m_previewFilled = m_toolPref.filledPreview();
|
|
|
|
m_sprayWidth = m_toolPref.spray.width();
|
|
|
|
m_spraySpeed = m_toolPref.spray.speed();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-08-27 20:43:42 +08:00
|
|
|
if (m_ink->isSelection())
|
|
|
|
m_useMask = false;
|
|
|
|
else
|
|
|
|
m_useMask = m_document->isMaskVisible();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
// Start with an empty mask if the user is selecting with "default selection mode"
|
2014-01-26 04:58:29 +08:00
|
|
|
if (getInk()->isSelection() &&
|
|
|
|
(!m_document->isMaskVisible() ||
|
2016-04-05 05:46:48 +08:00
|
|
|
(int(getModifiers()) & int(tools::ToolLoopModifiers::kReplaceSelection)))) {
|
2012-01-06 06:45:03 +08:00
|
|
|
Mask emptyMask;
|
2015-01-19 09:05:33 +08:00
|
|
|
m_transaction.execute(new cmd::SetMask(m_document, &emptyMask));
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 11:02:56 +08:00
|
|
|
m_celOrigin = m_expandCelCanvas->getCel()->position();
|
2014-07-30 12:28:15 +08:00
|
|
|
m_mask = m_document->mask();
|
2015-11-03 03:44:17 +08:00
|
|
|
m_maskOrigin = (!m_mask->isEmpty() ? gfx::Point(m_mask->bounds().x-m_celOrigin.x,
|
|
|
|
m_mask->bounds().y-m_celOrigin.y):
|
2012-01-09 09:34:36 +08:00
|
|
|
gfx::Point(0, 0));
|
2016-05-04 02:31:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~ToolLoopImpl() {
|
|
|
|
if (m_floodfillSrcImage != getSrcImage())
|
|
|
|
delete m_floodfillSrcImage;
|
2016-05-04 11:02:56 +08:00
|
|
|
delete m_expandCelCanvas;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2015-04-10 22:12:19 +08:00
|
|
|
// IToolLoop interface
|
2017-06-16 23:18:22 +08:00
|
|
|
void commitOrRollback() override {
|
2014-12-09 01:57:56 +08:00
|
|
|
bool redraw = false;
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
if (!m_canceled) {
|
2017-06-17 03:28:48 +08:00
|
|
|
// Freehand changes the last point
|
|
|
|
if (m_saveLastPoint) {
|
|
|
|
m_transaction.execute(
|
|
|
|
new cmd::SetLastPoint(
|
|
|
|
m_document,
|
|
|
|
getController()->getLastPoint()));
|
|
|
|
}
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
// Paint ink
|
|
|
|
if (getInk()->isPaint()) {
|
2015-04-10 22:10:42 +08:00
|
|
|
try {
|
|
|
|
ContextReader reader(m_context, 500);
|
|
|
|
ContextWriter writer(reader, 500);
|
2016-05-04 11:02:56 +08:00
|
|
|
m_expandCelCanvas->commit();
|
2015-04-10 22:10:42 +08:00
|
|
|
}
|
|
|
|
catch (const LockedDocumentException& ex) {
|
|
|
|
Console::showException(ex);
|
2015-04-08 04:50:57 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
// Selection ink
|
|
|
|
else if (getInk()->isSelection()) {
|
|
|
|
m_document->generateMaskBoundaries();
|
2014-12-09 01:57:56 +08:00
|
|
|
redraw = true;
|
2016-03-25 00:04:35 +08:00
|
|
|
|
|
|
|
// Show selection edges
|
|
|
|
m_docPref.show.selectionEdges(true);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2017-03-07 06:27:43 +08:00
|
|
|
// Slice ink
|
|
|
|
else if (getInk()->isSlice()) {
|
|
|
|
redraw = true;
|
|
|
|
}
|
2012-07-08 12:25:26 +08:00
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
m_transaction.commit();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2017-06-16 23:18:22 +08:00
|
|
|
else {
|
2014-12-09 01:57:56 +08:00
|
|
|
redraw = true;
|
2017-06-16 23:18:22 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-12-09 01:57:56 +08:00
|
|
|
// If the trace was canceled or it is not a 'paint' ink...
|
2012-01-06 06:45:03 +08:00
|
|
|
if (m_canceled || !getInk()->isPaint()) {
|
2015-04-10 22:10:42 +08:00
|
|
|
try {
|
|
|
|
ContextReader reader(m_context, 500);
|
|
|
|
ContextWriter writer(reader, 500);
|
2016-05-04 11:02:56 +08:00
|
|
|
m_expandCelCanvas->rollback();
|
2015-04-10 22:10:42 +08:00
|
|
|
}
|
|
|
|
catch (const LockedDocumentException& ex) {
|
|
|
|
Console::showException(ex);
|
2015-04-08 04:50:57 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2014-12-09 01:57:56 +08:00
|
|
|
if (redraw)
|
|
|
|
update_screen_for_document(m_document);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 11:02:56 +08:00
|
|
|
const Image* getSrcImage() override { return m_expandCelCanvas->getSourceCanvas(); }
|
2016-05-04 02:31:27 +08:00
|
|
|
const Image* getFloodFillSrcImage() override { return m_floodfillSrcImage; }
|
2016-05-04 11:02:56 +08:00
|
|
|
Image* getDstImage() override { return m_expandCelCanvas->getDestCanvas(); }
|
2014-12-09 01:57:56 +08:00
|
|
|
void validateSrcImage(const gfx::Region& rgn) override {
|
2016-05-04 11:02:56 +08:00
|
|
|
m_expandCelCanvas->validateSourceCanvas(rgn);
|
2014-12-09 01:57:56 +08:00
|
|
|
}
|
|
|
|
void validateDstImage(const gfx::Region& rgn) override {
|
2016-05-04 11:02:56 +08:00
|
|
|
m_expandCelCanvas->validateDestCanvas(rgn);
|
2014-12-09 01:57:56 +08:00
|
|
|
}
|
|
|
|
void invalidateDstImage() override {
|
2016-05-04 11:02:56 +08:00
|
|
|
m_expandCelCanvas->invalidateDestCanvas();
|
2014-12-09 01:57:56 +08:00
|
|
|
}
|
|
|
|
void invalidateDstImage(const gfx::Region& rgn) override {
|
2016-05-04 11:02:56 +08:00
|
|
|
m_expandCelCanvas->invalidateDestCanvas(rgn);
|
2014-12-09 01:57:56 +08:00
|
|
|
}
|
|
|
|
void copyValidDstToSrcImage(const gfx::Region& rgn) override {
|
2016-05-04 11:02:56 +08:00
|
|
|
m_expandCelCanvas->copyValidDestToSourceCanvas(rgn);
|
2014-12-09 01:57:56 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
bool useMask() override { return m_useMask; }
|
|
|
|
Mask* getMask() override { return m_mask; }
|
2015-01-19 09:05:33 +08:00
|
|
|
void setMask(Mask* newMask) override {
|
|
|
|
m_transaction.execute(new cmd::SetMask(m_document, newMask));
|
|
|
|
}
|
2017-03-07 06:27:43 +08:00
|
|
|
void addSlice(Slice* newSlice) override {
|
2017-03-25 12:01:59 +08:00
|
|
|
auto color = Preferences::instance().slices.defaultColor();
|
2017-03-24 07:23:25 +08:00
|
|
|
newSlice->userData().setColor(
|
|
|
|
doc::rgba(color.getRed(),
|
|
|
|
color.getGreen(),
|
|
|
|
color.getBlue(),
|
|
|
|
color.getAlpha()));
|
|
|
|
|
2017-03-07 06:27:43 +08:00
|
|
|
m_transaction.execute(new cmd::AddSlice(m_sprite, newSlice));
|
|
|
|
}
|
2014-08-15 10:07:47 +08:00
|
|
|
gfx::Point getMaskOrigin() override { return m_maskOrigin; }
|
|
|
|
bool getFilled() override { return m_filled; }
|
|
|
|
bool getPreviewFilled() override { return m_previewFilled; }
|
|
|
|
int getSprayWidth() override { return m_sprayWidth; }
|
|
|
|
int getSpraySpeed() override { return m_spraySpeed; }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
void cancel() override { m_canceled = true; }
|
|
|
|
bool isCanceled() override { return m_canceled; }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-06-17 03:28:48 +08:00
|
|
|
tools::ToolLoop* create_tool_loop(
|
|
|
|
Editor* editor,
|
|
|
|
Context* context,
|
|
|
|
const bool convertLineToFreehand)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2017-06-17 03:28:48 +08:00
|
|
|
tools::Tool* tool = editor->getCurrentEditorTool();
|
|
|
|
tools::Ink* ink = editor->getCurrentEditorInk();
|
|
|
|
if (!tool || !ink)
|
|
|
|
return nullptr;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2016-05-03 05:42:02 +08:00
|
|
|
Layer* layer;
|
|
|
|
|
|
|
|
// For selection tools, we can use any layer (even without layers at
|
|
|
|
// all), so we specify a nullptr here as the active layer. This is
|
|
|
|
// used as a special case by the render::Render class to show the
|
|
|
|
// preview image/selection stroke as a xor'd overlay in the render
|
|
|
|
// result.
|
|
|
|
//
|
|
|
|
// Anyway this cannot be used in 'magic wand' tool (isSelection +
|
|
|
|
// isFloodFill) because we need the original layer source
|
|
|
|
// image/pixels to stop the flood-fill algorithm.
|
2017-06-17 03:28:48 +08:00
|
|
|
if (ink->isSelection() &&
|
|
|
|
!tool->getPointShape(editor->isSecondaryButton() ? 1: 0)->isFloodFill()) {
|
2016-05-03 05:42:02 +08:00
|
|
|
layer = nullptr;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2016-05-03 05:42:02 +08:00
|
|
|
else {
|
|
|
|
layer = editor->layer();
|
|
|
|
if (!layer) {
|
|
|
|
StatusBar::instance()->showTip(
|
|
|
|
1000, "There is no active layer");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-06-16 02:27:38 +08:00
|
|
|
else if (!layer->isVisibleHierarchy()) {
|
2016-05-03 05:42:02 +08:00
|
|
|
StatusBar::instance()->showTip(
|
|
|
|
1000, "Layer '%s' is hidden", layer->name().c_str());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
// If the active layer is read-only.
|
2016-06-16 02:27:38 +08:00
|
|
|
else if (!layer->isEditableHierarchy()) {
|
2016-05-03 05:42:02 +08:00
|
|
|
StatusBar::instance()->showTip(
|
|
|
|
1000, "Layer '%s' is locked", layer->name().c_str());
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-10-18 00:48:52 +08:00
|
|
|
// If the active layer is reference.
|
|
|
|
else if (layer->isReference()) {
|
|
|
|
StatusBar::instance()->showTip(
|
|
|
|
1000, "Layer '%s' is reference, cannot be modified", layer->name().c_str());
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get fg/bg colors
|
2012-07-10 00:20:58 +08:00
|
|
|
ColorBar* colorbar = ColorBar::instance();
|
2013-01-07 01:45:43 +08:00
|
|
|
app::Color fg = colorbar->getFgColor();
|
|
|
|
app::Color bg = colorbar->getBgColor();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
if (!fg.isValid() || !bg.isValid()) {
|
|
|
|
Alert::show(PACKAGE
|
|
|
|
"<<The current selected foreground and/or background color"
|
2015-06-29 22:00:46 +08:00
|
|
|
"<<is out of range. Select a valid color in the color-bar."
|
2012-01-06 06:45:03 +08:00
|
|
|
"||&Close");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the new tool loop
|
2014-08-19 19:17:57 +08:00
|
|
|
try {
|
2017-06-17 03:28:48 +08:00
|
|
|
tools::ToolLoop::Button button =
|
|
|
|
(!editor->isSecondaryButton() ? tools::ToolLoop::Left:
|
|
|
|
tools::ToolLoop::Right);
|
|
|
|
|
|
|
|
tools::Controller* controller =
|
|
|
|
(convertLineToFreehand ?
|
|
|
|
App::instance()->toolBox()->getControllerById(
|
|
|
|
tools::WellKnownControllers::LineFreehand):
|
|
|
|
tool->getController(button));
|
|
|
|
|
|
|
|
const bool saveLastPoint =
|
|
|
|
(ink->isPaint() &&
|
|
|
|
(controller->isFreehand() ||
|
|
|
|
convertLineToFreehand));
|
|
|
|
|
2015-05-19 03:53:25 +08:00
|
|
|
return new ToolLoopImpl(
|
2016-05-03 05:42:02 +08:00
|
|
|
editor, layer, context,
|
2017-06-17 03:28:48 +08:00
|
|
|
tool,
|
|
|
|
ink,
|
|
|
|
controller,
|
2014-08-19 19:17:57 +08:00
|
|
|
editor->document(),
|
2017-06-17 03:28:48 +08:00
|
|
|
button,
|
|
|
|
fg, bg,
|
|
|
|
saveLastPoint);
|
2013-11-11 03:20:20 +08:00
|
|
|
}
|
2014-08-19 19:17:57 +08:00
|
|
|
catch (const std::exception& ex) {
|
2013-11-11 03:20:20 +08:00
|
|
|
Alert::show(PACKAGE
|
|
|
|
"<<Error drawing ink:"
|
|
|
|
"<<%s"
|
|
|
|
"||&Close",
|
|
|
|
ex.what());
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2015-04-27 02:59:28 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// For preview
|
|
|
|
|
2015-05-22 03:00:27 +08:00
|
|
|
class PreviewToolLoopImpl : public ToolLoopBase {
|
2015-04-27 02:59:28 +08:00
|
|
|
Image* m_image;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PreviewToolLoopImpl(
|
|
|
|
Editor* editor,
|
|
|
|
tools::Tool* tool,
|
|
|
|
tools::Ink* ink,
|
|
|
|
Document* document,
|
2015-05-19 03:53:25 +08:00
|
|
|
const app::Color& fgColor,
|
|
|
|
const app::Color& bgColor,
|
2015-04-27 02:59:28 +08:00
|
|
|
Image* image,
|
2015-11-03 03:44:17 +08:00
|
|
|
const gfx::Point& celOrigin)
|
2017-06-17 03:28:48 +08:00
|
|
|
: ToolLoopBase(editor,
|
|
|
|
editor->layer(),
|
|
|
|
tool,
|
|
|
|
ink,
|
|
|
|
tool->getController(tools::ToolLoop::Left),
|
|
|
|
document,
|
|
|
|
tools::ToolLoop::Left,
|
|
|
|
fgColor,
|
|
|
|
bgColor)
|
2015-04-27 02:59:28 +08:00
|
|
|
, m_image(image)
|
|
|
|
{
|
2015-11-03 03:44:17 +08:00
|
|
|
m_celOrigin = celOrigin;
|
2015-04-27 02:59:28 +08:00
|
|
|
|
|
|
|
// Avoid preview for spray and flood fill like tools
|
|
|
|
if (m_pointShape->isSpray()) {
|
2016-04-23 00:19:06 +08:00
|
|
|
m_pointShape = App::instance()->toolBox()->getPointShapeById(
|
2015-04-27 02:59:28 +08:00
|
|
|
tools::WellKnownPointShapes::Brush);
|
|
|
|
}
|
|
|
|
else if (m_pointShape->isFloodFill()) {
|
2016-04-23 00:19:06 +08:00
|
|
|
m_pointShape = App::instance()->toolBox()->getPointShapeById(
|
2015-04-27 02:59:28 +08:00
|
|
|
tools::WellKnownPointShapes::Pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IToolLoop interface
|
2017-06-16 23:18:22 +08:00
|
|
|
void commitOrRollback() override {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2015-04-27 02:59:28 +08:00
|
|
|
const Image* getSrcImage() override { return m_image; }
|
2016-05-04 02:31:27 +08:00
|
|
|
const Image* getFloodFillSrcImage() override { return m_image; }
|
2015-04-27 02:59:28 +08:00
|
|
|
Image* getDstImage() override { return m_image; }
|
|
|
|
void validateSrcImage(const gfx::Region& rgn) override { }
|
|
|
|
void validateDstImage(const gfx::Region& rgn) override { }
|
|
|
|
void invalidateDstImage() override { }
|
|
|
|
void invalidateDstImage(const gfx::Region& rgn) override { }
|
|
|
|
void copyValidDstToSrcImage(const gfx::Region& rgn) override { }
|
|
|
|
|
2015-05-22 03:00:27 +08:00
|
|
|
bool useMask() override { return false; }
|
|
|
|
Mask* getMask() override { return nullptr; }
|
2015-04-27 02:59:28 +08:00
|
|
|
void setMask(Mask* newMask) override { }
|
2017-03-07 06:27:43 +08:00
|
|
|
void addSlice(Slice* newSlice) override { }
|
2015-05-22 03:00:27 +08:00
|
|
|
gfx::Point getMaskOrigin() override { return gfx::Point(0, 0); }
|
2015-04-27 02:59:28 +08:00
|
|
|
bool getFilled() override { return false; }
|
|
|
|
bool getPreviewFilled() override { return false; }
|
|
|
|
int getSprayWidth() override { return 0; }
|
|
|
|
int getSpraySpeed() override { return 0; }
|
|
|
|
|
|
|
|
void cancel() override { }
|
|
|
|
bool isCanceled() override { return true; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
tools::ToolLoop* create_tool_loop_preview(
|
2015-08-19 23:54:57 +08:00
|
|
|
Editor* editor, Image* image,
|
2015-11-03 03:44:17 +08:00
|
|
|
const gfx::Point& celOrigin)
|
2015-04-27 02:59:28 +08:00
|
|
|
{
|
2017-06-17 03:28:48 +08:00
|
|
|
tools::Tool* tool = editor->getCurrentEditorTool();
|
|
|
|
tools::Ink* ink = editor->getCurrentEditorInk();
|
|
|
|
if (!tool || !ink)
|
2015-04-27 02:59:28 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
Layer* layer = editor->layer();
|
|
|
|
if (!layer ||
|
2016-06-16 02:27:38 +08:00
|
|
|
!layer->isVisibleHierarchy() ||
|
2016-10-18 00:48:52 +08:00
|
|
|
!layer->isEditableHierarchy() ||
|
|
|
|
layer->isReference()) {
|
2015-04-27 02:59:28 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get fg/bg colors
|
|
|
|
ColorBar* colorbar = ColorBar::instance();
|
|
|
|
app::Color fg = colorbar->getFgColor();
|
|
|
|
app::Color bg = colorbar->getBgColor();
|
|
|
|
if (!fg.isValid() || !bg.isValid())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Create the new tool loop
|
|
|
|
try {
|
|
|
|
return new PreviewToolLoopImpl(
|
2015-08-19 23:54:57 +08:00
|
|
|
editor,
|
2017-06-17 03:28:48 +08:00
|
|
|
tool,
|
|
|
|
ink,
|
2015-04-27 02:59:28 +08:00
|
|
|
editor->document(),
|
2015-11-03 03:44:17 +08:00
|
|
|
fg, bg, image, celOrigin);
|
2015-04-27 02:59:28 +08:00
|
|
|
}
|
|
|
|
catch (const std::exception&) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|