add flood fill mode with custom cursor
This commit is contained in:
@@ -25,6 +25,7 @@ std::vector<CanvasMode*> Canvas::modes[] = {
|
||||
{ new CanvasModeFill, new CanvasModeBasicCamera }, // fill
|
||||
{ new CanvasModeMaskFree, new CanvasModeBasicCamera }, // mask-free
|
||||
{ new CanvasModeMaskLine, new CanvasModeBasicCamera }, // mask-poly
|
||||
{ new CanvasModeFloodFill, new CanvasModeBasicCamera }, // flood-fill
|
||||
};
|
||||
glm::vec3 Canvas::m_plane_origin[6] = {
|
||||
{ 0, 0,-1}, // front
|
||||
@@ -1352,7 +1353,7 @@ void Canvas::flood_fill(int layer, int plane, std::vector<glm::ivec2> pos, std::
|
||||
bool flipcoord;
|
||||
adj_t(int plane, bool flipx, bool flipy, int flipcoord) :
|
||||
plane(plane), flipx(flipx), flipy(flipy), flipcoord(flipcoord) { }
|
||||
glm::ivec2 compute(glm::ivec2 p, glm::ivec2 sz)
|
||||
glm::ivec2 compute(glm::ivec2 p, glm::ivec2 sz) const
|
||||
{
|
||||
glm::ivec2 ret;
|
||||
ret[flipcoord] = flipx ? sz.x - p.x : p.x;
|
||||
@@ -1373,10 +1374,10 @@ void Canvas::flood_fill(int layer, int plane, std::vector<glm::ivec2> pos, std::
|
||||
|
||||
if (!source_color)
|
||||
source_color = std::make_unique<glm::vec4>(rgb[pos.back().y * sz.x + pos.back().x]);
|
||||
glm::vec3 c = *source_color;
|
||||
const glm::vec4 c = *source_color;
|
||||
|
||||
std::array<std::vector<glm::ivec2>, 4> edges;
|
||||
std::array<adj_t, 4> adj[6] = {
|
||||
static const std::array<adj_t, 4> adj[6] = {
|
||||
// front - ok
|
||||
{
|
||||
adj_t(3, 1, 0, 0),
|
||||
@@ -1444,14 +1445,18 @@ void Canvas::flood_fill(int layer, int plane, std::vector<glm::ivec2> pos, std::
|
||||
edges[1].push_back(adj[plane][1].compute({ p.x, sz.y - p.y + 1 }, sz));
|
||||
return false;
|
||||
}
|
||||
if (!mask[i] && rgb[i].a > 0 && glm::distance(c, glm::vec3(rgb[i])) < threshold)
|
||||
if (!mask[i])
|
||||
{
|
||||
if (set_color)
|
||||
if (c.a == 0 && glm::abs(rgb[i].a - c.a) < threshold ||
|
||||
c.a > 0 && rgb[i].a > 0 && glm::distance(glm::vec3(c), glm::vec3(rgb[i])) < threshold)
|
||||
{
|
||||
mask[i] = true;
|
||||
rgb[i] = dest_color * 255.f;
|
||||
if (set_color)
|
||||
{
|
||||
mask[i] = true;
|
||||
rgb[i] = dest_color * 255.f;
|
||||
}
|
||||
pos.push_back(p);
|
||||
}
|
||||
pos.push_back(p);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1464,9 +1469,13 @@ void Canvas::flood_fill(int layer, int plane, std::vector<glm::ivec2> pos, std::
|
||||
if(!test(p + glm::ivec2( 0, 0), true))
|
||||
continue;
|
||||
test(p + glm::ivec2(-1, 0), false);
|
||||
test(p + glm::ivec2( 1, 0), false);
|
||||
test(p + glm::ivec2( 0, 1), false);
|
||||
test(p + glm::ivec2( 0,-1), false);
|
||||
test(p + glm::ivec2(1, 0), false);
|
||||
test(p + glm::ivec2(0, 1), false);
|
||||
test(p + glm::ivec2(0, -1), false);
|
||||
//for (int x = -1; x <= 1; x++)
|
||||
// for (int y = -1; y <= 1; y++)
|
||||
// if (x != 0 && y != 0)
|
||||
// test(p + glm::ivec2(x, y), false);
|
||||
}
|
||||
|
||||
rtt.bindTexture();
|
||||
|
||||
Reference in New Issue
Block a user