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 filters;
void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop,
bool adjustCoordinates)
void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop)
{
Ink* ink = loop->getInk();
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
// translate the x1/y/x2 coordinate.
if (adjustCoordinates &&
ink->needsCelCoordinates()) {
if (loop->needsCelCoordinates()) {
gfx::Point origin = loop->getCelOrigin();
x1 -= origin.x;
x2 -= origin.x;

View File

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

View File

@ -48,11 +48,7 @@ public:
gfx::Point newPos = grid.canvasToTile(pt.toPoint());
loop->getInk()->prepareForPointShape(loop, true, newPos.x, newPos.y);
doInkHline(
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);
doInkHline(newPos.x, newPos.y, newPos.x, loop);
}
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
virtual gfx::Point getCelOrigin() = 0;
virtual bool needsCelCoordinates() = 0;
// Velocity vector of the mouse
virtual void setSpeed(const gfx::Point& speed) = 0;

View File

@ -115,6 +115,7 @@ protected:
std::unique_ptr<tools::Symmetry> m_symmetry;
Shade m_shade;
std::unique_ptr<doc::Remap> m_shadingRemap;
bool m_tilesMode;
app::ColorTarget m_colorTarget;
doc::color_t m_fgColor;
doc::color_t m_bgColor;
@ -152,7 +153,8 @@ public:
, m_intertwine(m_tool->getIntertwine(m_button))
, m_tracePolicy(m_tool->getTracePolicy(m_button))
, m_symmetry(nullptr)
, m_colorTarget(site.tilemapMode() == TilemapMode::Tiles ? ColorTarget(ColorTarget::BackgroundLayer,
, m_tilesMode(site.tilemapMode() == TilemapMode::Tiles)
, m_colorTarget(m_tilesMode ? ColorTarget(ColorTarget::BackgroundLayer,
IMAGE_TILEMAP, 0):
m_layer ? ColorTarget(m_layer):
ColorTarget(ColorTarget::BackgroundLayer,
@ -167,7 +169,7 @@ public:
ASSERT(m_ink);
ASSERT(m_controller);
if (site.tilemapMode() == TilemapMode::Tiles) {
if (m_tilesMode) {
m_pointShape = App::instance()->toolBox()->getPointShapeById(
tools::WellKnownPointShapes::Tile);
@ -332,6 +334,7 @@ public:
const doc::Grid& getGrid() const override { return m_grid; }
gfx::Rect getGridBounds() override { return m_gridBounds; }
gfx::Point getCelOrigin() override { return m_celOrigin; }
bool needsCelCoordinates() override { return m_ink->needsCelCoordinates(); }
void setSpeed(const gfx::Point& speed) override { m_speed = speed; }
gfx::Point getSpeed() override { return m_speed; }
tools::Ink* getInk() override { return m_ink.get(); }
@ -544,15 +547,19 @@ public:
m_tx(new cmd::SetMask(m_document, &emptyMask));
}
// 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_maskOrigin = (!m_mask->isEmpty() ? gfx::Point(m_mask->bounds().x-m_celOrigin.x,
m_mask->bounds().y-m_celOrigin.y):
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() {
@ -562,6 +569,17 @@ public:
}
// 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 {
bool redraw = false;