Fix paintbucket in transformed shapes

This commit is contained in:
Skyler Lehmkuhl 2025-01-06 15:26:56 -05:00
parent 95c78a994e
commit 49dd8f83d1
2 changed files with 39 additions and 8 deletions

View File

@ -1647,7 +1647,6 @@ let actions = {
let selection = []; let selection = [];
let shapeselection = []; let shapeselection = [];
for (let item of context.selection) { for (let item of context.selection) {
let idx = child.idx;
selection.push(item.idx); selection.push(item.idx);
} }
for (let shape of context.shapeselection) { for (let shape of context.shapeselection) {
@ -2917,11 +2916,15 @@ class Shape extends BaseShape {
return pointsSorted; return pointsSorted;
} }
translate(x, y) { translate(x, y) {
this.quadtree.clear()
let j=0;
for (let curve of this.curves) { for (let curve of this.curves) {
for (let i in curve.points) { for (let i in curve.points) {
const point = curve.points[i]; const point = curve.points[i];
curve.points[i] = { x: point.x + x, y: point.y + y }; curve.points[i] = { x: point.x + x, y: point.y + y };
} }
this.quadtree.insert(curve, j)
j++;
} }
this.update(); this.update();
} }
@ -3204,12 +3207,16 @@ class GraphicsObject {
bbox.y.max += this.y; bbox.y.max += this.y;
return bbox; return bbox;
} }
draw(context) { draw(context, calculateTransform=false) {
let ctx = context.ctx; let ctx = context.ctx;
ctx.save(); ctx.save();
if (calculateTransform) {
this.transformCanvas(ctx)
} else {
ctx.translate(this.x, this.y); ctx.translate(this.x, this.y);
ctx.rotate(this.rotation); ctx.rotate(this.rotation);
ctx.scale(this.scale_x, this.scale_y); ctx.scale(this.scale_x, this.scale_y);
}
// if (this.currentFrameNum>=this.maxFrame) { // if (this.currentFrameNum>=this.maxFrame) {
// this.currentFrameNum = 0; // this.currentFrameNum = 0;
// } // }
@ -3378,6 +3385,14 @@ class GraphicsObject {
} }
ctx.restore(); ctx.restore();
} }
transformCanvas(ctx) {
if (this.parent) {
this.parent.transformCanvas(ctx)
}
ctx.translate(this.x, this.y);
ctx.rotate(this.rotation);
ctx.scale(this.scale_x, this.scale_y);
}
transformMouse(mouse) { transformMouse(mouse) {
if (this.parent) { if (this.parent) {
mouse = this.parent.transformMouse(mouse); mouse = this.parent.transformMouse(mouse);
@ -4641,10 +4656,12 @@ function stage() {
} }
// We didn't find an existing region to paintbucket, see if we can make one // We didn't find an existing region to paintbucket, see if we can make one
const offset = context.activeObject.transformMouse({x:0, y:0})
try { try {
regionPoints = floodFillRegion( regionPoints = floodFillRegion(
mouse, mouse,
epsilon, epsilon,
offset,
config.fileWidth, config.fileWidth,
config.fileHeight, config.fileHeight,
context, context,
@ -4660,6 +4677,7 @@ function stage() {
regionPoints = floodFillRegion( regionPoints = floodFillRegion(
mouse, mouse,
1, 1,
offset,
config.fileWidth, config.fileWidth,
config.fileHeight, config.fileHeight,
context, context,
@ -6019,12 +6037,14 @@ function renderUI() {
if (context.activeObject != root) { if (context.activeObject != root) {
ctx.fillStyle = "rgba(255,255,255,0.5)"; ctx.fillStyle = "rgba(255,255,255,0.5)";
ctx.fillRect(0, 0, config.fileWidth, config.fileHeight); ctx.fillRect(0, 0, config.fileWidth, config.fileHeight);
context.activeObject.draw(context); context.activeObject.draw(context, true);
} }
if (context.activeShape) { if (context.activeShape) {
context.activeShape.draw(context); context.activeShape.draw(context);
} }
ctx.save()
context.activeObject.transformCanvas(ctx)
// Debug rendering // Debug rendering
if (debugQuadtree) { if (debugQuadtree) {
ctx.fillStyle = "rgba(255,255,255,0.5)"; ctx.fillStyle = "rgba(255,255,255,0.5)";
@ -6040,6 +6060,7 @@ function renderUI() {
debugCurves.push(shape.curves[i]); debugCurves.push(shape.curves[i]);
} }
} }
} }
// let i=4; // let i=4;
for (let curve of debugCurves) { for (let curve of debugCurves) {
@ -6077,6 +6098,7 @@ function renderUI() {
ctx.arc(point.x, point.y, 3, 0, 2 * Math.PI); ctx.arc(point.x, point.y, 3, 0, 2 * Math.PI);
ctx.fill(); ctx.fill();
} }
ctx.restore()
if (context.activeAction) { if (context.activeAction) {
actions[context.activeAction.type].render(context.activeAction, ctx); actions[context.activeAction.type].render(context.activeAction, ctx);
} }

View File

@ -195,10 +195,19 @@ function generateWaveform(img, buffer, imgHeight, frameWidth, framesPerSecond) {
img.src = dataUrl; img.src = dataUrl;
} }
function floodFillRegion(startPoint, epsilon, fileWidth, fileHeight, context, debugPoints, debugPaintbucket) { function floodFillRegion(
startPoint,
epsilon,
offset, // TODO: this needs to be a generalized transform
fileWidth,
fileHeight,
context,
debugPoints,
debugPaintbucket) {
// Helper function to check if the point is at the boundary of the region // Helper function to check if the point is at the boundary of the region
function isBoundaryPoint(point) { function isBoundaryPoint(point) {
return point.x <= 0 || point.x >= fileWidth || point.y <= 0 || point.y >= fileHeight; return point.x <= offset.x || point.x >= offset.x + fileWidth ||
point.y <= offset.y || point.y >= offset.y + fileHeight;
} }
let halfEpsilon = epsilon/2 let halfEpsilon = epsilon/2