Fix gradients from center and/or outside sprite canvas

This commit is contained in:
David Capello 2019-03-19 20:40:23 -03:00
parent da695c0a98
commit 250d40c0f3
5 changed files with 29 additions and 7 deletions

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -644,7 +645,8 @@ private:
pt = wrap_point(m_tiledMode,
gfx::Size(m_srcImageWidth,
m_srcImageHeight), pt);
m_srcImageHeight),
pt, false);
pt.x = MID(0, pt.x, m_srcImageWidth-1);
pt.y = MID(0, pt.y, m_srcImageHeight-1);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -30,8 +30,19 @@ public:
bool snapByAngle() override { return true; }
void joinStroke(ToolLoop* loop, const Stroke& stroke) override {
if (!stroke.empty())
doPointshapePoint(stroke[0].x, stroke[0].y, loop);
if (!stroke.empty()) {
gfx::Point mid(0, 0);
int n = 0;
for (auto& pt : stroke) {
mid.x += pt.x;
mid.y += pt.y;
++n;
}
mid.x /= n;
mid.y /= n;
doPointshapePoint(mid.x, mid.y, loop);
}
}
void fillStroke(ToolLoop* loop, const Stroke& stroke) override {

View File

@ -93,7 +93,7 @@ public:
gfx::Point pt = wrap_point(loop->getTiledMode(),
gfx::Size(srcImage->width(),
srcImage->height()),
gfx::Point(x, y));
gfx::Point(x, y), true);
doc::algorithm::floodfill(
srcImage,

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2017 David Capello
//
// This program is distributed under the terms of
@ -11,22 +12,28 @@
#include "app/util/wrap_point.h"
#include "app/util/wrap_value.h"
#include "base/clamp.h"
namespace app {
gfx::Point wrap_point(const filters::TiledMode tiledMode,
const gfx::Size& spriteSize,
const gfx::Point& pt)
const gfx::Point& pt,
const bool clamp)
{
gfx::Point out;
if (int(tiledMode) & int(filters::TiledMode::X_AXIS))
out.x = wrap_value(pt.x, spriteSize.w);
else if (clamp)
out.x = base::clamp(pt.x, 0, spriteSize.w-1);
else
out.x = pt.x;
if (int(tiledMode) & int(filters::TiledMode::Y_AXIS))
out.y = wrap_value(pt.y, spriteSize.h);
else if (clamp)
out.y = base::clamp(pt.y, 0, spriteSize.h-1);
else
out.y = pt.y;

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2017 David Capello
//
// This program is distributed under the terms of
@ -16,7 +17,8 @@ namespace app {
gfx::Point wrap_point(const filters::TiledMode tiledMode,
const gfx::Size& spriteSize,
const gfx::Point& pt);
const gfx::Point& pt,
const bool clamp);
gfx::PointF wrap_pointF(const filters::TiledMode tiledMode,
const gfx::Size& spriteSize,