Fix brush preview and drawing in tiles mode

This commit is contained in:
David Capello 2020-08-19 20:17:50 -03:00
parent 319eb3fd62
commit e8dc717b08
5 changed files with 31 additions and 19 deletions

View File

@ -25,8 +25,7 @@ namespace tools {
using namespace doc; using namespace doc;
using namespace filters; using namespace filters;
void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop, void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop)
bool adjustCoordinates)
{ {
Ink* ink = loop->getInk(); Ink* ink = loop->getInk();
TiledMode tiledMode = loop->getTiledMode(); TiledMode tiledMode = loop->getTiledMode();
@ -36,8 +35,7 @@ void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop,
// In case the ink needs original cel coordinates, we have to // In case the ink needs original cel coordinates, we have to
// translate the x1/y/x2 coordinate. // translate the x1/y/x2 coordinate.
if (adjustCoordinates && if (loop->needsCelCoordinates()) {
ink->needsCelCoordinates()) {
gfx::Point origin = loop->getCelOrigin(); gfx::Point origin = loop->getCelOrigin();
x1 -= origin.x; x1 -= origin.x;
x2 -= origin.x; x2 -= origin.x;

View File

@ -33,8 +33,7 @@ namespace app {
protected: protected:
// Calls loop->getInk()->inkHline() function for each horizontal-scanline // Calls loop->getInk()->inkHline() function for each horizontal-scanline
// that should be drawn (applying the "tiled" mode loop->getTiledMode()) // that should be drawn (applying the "tiled" mode loop->getTiledMode())
static void doInkHline(int x1, int y, int x2, ToolLoop* loop, static void doInkHline(int x1, int y, int x2, ToolLoop* loop);
const bool adjustCoordinates = true);
}; };
} // namespace tools } // namespace tools

View File

@ -48,11 +48,7 @@ public:
gfx::Point newPos = grid.canvasToTile(pt.toPoint()); gfx::Point newPos = grid.canvasToTile(pt.toPoint());
loop->getInk()->prepareForPointShape(loop, true, newPos.x, newPos.y); loop->getInk()->prepareForPointShape(loop, true, newPos.x, newPos.y);
doInkHline( doInkHline(newPos.x, newPos.y, newPos.x, loop);
newPos.x, newPos.y, newPos.x, loop,
// Don't adjust by loop->getCelOrigin() because loop->getGrid()
// is already adjusted to the new cel position.
false);
} }
void getModifiedArea(ToolLoop* loop, int x, int y, Rect& area) override { void getModifiedArea(ToolLoop* loop, int x, int y, Rect& area) override {

View File

@ -202,6 +202,7 @@ namespace app {
// X,Y origin of the cel where we are drawing // X,Y origin of the cel where we are drawing
virtual gfx::Point getCelOrigin() = 0; virtual gfx::Point getCelOrigin() = 0;
virtual bool needsCelCoordinates() = 0;
// Velocity vector of the mouse // Velocity vector of the mouse
virtual void setSpeed(const gfx::Point& speed) = 0; virtual void setSpeed(const gfx::Point& speed) = 0;

View File

@ -115,6 +115,7 @@ protected:
std::unique_ptr<tools::Symmetry> m_symmetry; std::unique_ptr<tools::Symmetry> m_symmetry;
Shade m_shade; Shade m_shade;
std::unique_ptr<doc::Remap> m_shadingRemap; std::unique_ptr<doc::Remap> m_shadingRemap;
bool m_tilesMode;
app::ColorTarget m_colorTarget; app::ColorTarget m_colorTarget;
doc::color_t m_fgColor; doc::color_t m_fgColor;
doc::color_t m_bgColor; doc::color_t m_bgColor;
@ -152,8 +153,9 @@ public:
, m_intertwine(m_tool->getIntertwine(m_button)) , m_intertwine(m_tool->getIntertwine(m_button))
, m_tracePolicy(m_tool->getTracePolicy(m_button)) , m_tracePolicy(m_tool->getTracePolicy(m_button))
, m_symmetry(nullptr) , m_symmetry(nullptr)
, m_colorTarget(site.tilemapMode() == TilemapMode::Tiles ? ColorTarget(ColorTarget::BackgroundLayer, , m_tilesMode(site.tilemapMode() == TilemapMode::Tiles)
IMAGE_TILEMAP, 0): , m_colorTarget(m_tilesMode ? ColorTarget(ColorTarget::BackgroundLayer,
IMAGE_TILEMAP, 0):
m_layer ? ColorTarget(m_layer): m_layer ? ColorTarget(m_layer):
ColorTarget(ColorTarget::BackgroundLayer, ColorTarget(ColorTarget::BackgroundLayer,
m_sprite->pixelFormat(), m_sprite->pixelFormat(),
@ -167,7 +169,7 @@ public:
ASSERT(m_ink); ASSERT(m_ink);
ASSERT(m_controller); ASSERT(m_controller);
if (site.tilemapMode() == TilemapMode::Tiles) { if (m_tilesMode) {
m_pointShape = App::instance()->toolBox()->getPointShapeById( m_pointShape = App::instance()->toolBox()->getPointShapeById(
tools::WellKnownPointShapes::Tile); tools::WellKnownPointShapes::Tile);
@ -332,6 +334,7 @@ public:
const doc::Grid& getGrid() const override { return m_grid; } const doc::Grid& getGrid() const override { return m_grid; }
gfx::Rect getGridBounds() override { return m_gridBounds; } gfx::Rect getGridBounds() override { return m_gridBounds; }
gfx::Point getCelOrigin() override { return m_celOrigin; } gfx::Point getCelOrigin() override { return m_celOrigin; }
bool needsCelCoordinates() override { return m_ink->needsCelCoordinates(); }
void setSpeed(const gfx::Point& speed) override { m_speed = speed; } void setSpeed(const gfx::Point& speed) override { m_speed = speed; }
gfx::Point getSpeed() override { return m_speed; } gfx::Point getSpeed() override { return m_speed; }
tools::Ink* getInk() override { return m_ink.get(); } tools::Ink* getInk() override { return m_ink.get(); }
@ -544,15 +547,19 @@ public:
m_tx(new cmd::SetMask(m_document, &emptyMask)); m_tx(new cmd::SetMask(m_document, &emptyMask));
} }
m_celOrigin = m_expandCelCanvas->getCel()->position(); // Setup the new grid of ExpandCelCanvas which can be displaced to
// match the new temporal cel position (m_celOrigin).
m_grid = m_expandCelCanvas->getGrid();
if (m_tilesMode)
m_celOrigin = m_grid.origin();
else
m_celOrigin = m_expandCelCanvas->getCel()->position();
m_mask = m_document->mask(); m_mask = m_document->mask();
m_maskOrigin = (!m_mask->isEmpty() ? gfx::Point(m_mask->bounds().x-m_celOrigin.x, m_maskOrigin = (!m_mask->isEmpty() ? gfx::Point(m_mask->bounds().x-m_celOrigin.x,
m_mask->bounds().y-m_celOrigin.y): m_mask->bounds().y-m_celOrigin.y):
gfx::Point(0, 0)); gfx::Point(0, 0));
// Setup the new grid of ExpandCelCanvas which can be displaced to
// match the new temporal cel position (m_celOrigin).
m_grid = m_expandCelCanvas->getGrid();
} }
~ToolLoopImpl() { ~ToolLoopImpl() {
@ -562,6 +569,17 @@ public:
} }
// IToolLoop interface // IToolLoop interface
bool needsCelCoordinates() override {
if (m_tilesMode) {
// When we are painting with tiles, we don't need to adjust the
// coordinates by the cel position in PointShape (points will be
// in tiles position relative to the tilemap origin already).
return false;
}
else
return ToolLoopBase::needsCelCoordinates();
}
void commitOrRollback() override { void commitOrRollback() override {
bool redraw = false; bool redraw = false;