mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2025-06-13 05:31:18 -04:00
Merge pull request #522 from yueyuzhao/issue/504-dots-to-sharp-corner
add precise guess first when adding points to paths
This commit is contained in:
commit
ff15b0f5f0
1 changed files with 22 additions and 12 deletions
|
@ -851,20 +851,30 @@ export default class Path {
|
|||
}
|
||||
|
||||
static getHitIndex (ctx, commands, pt) {
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
for (var i = 0; i < commands.length; i++) {
|
||||
SVG2Canvas.drawCommand(ctx, commands[i]);
|
||||
ctx.stroke();
|
||||
pt = Vector.floor(pt);
|
||||
var pixel = ctx.getImageData(pt.x, pt.y, 1, 1).data;
|
||||
if (pixel[3] != 0) {
|
||||
return i;
|
||||
var drawWithLineMask = function (lineWidth) {
|
||||
ctx.save();
|
||||
ctx.lineWidth = lineWidth;
|
||||
ctx.beginPath();
|
||||
for (var i = 0; i < commands.length; i++) {
|
||||
SVG2Canvas.drawCommand(ctx, commands[i]);
|
||||
ctx.stroke();
|
||||
pt = Vector.floor(pt);
|
||||
var pixel = ctx.getImageData(pt.x, pt.y, 1, 1).data;
|
||||
if (pixel[3] != 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
};
|
||||
// When using a mouse to add dragging points to paths,
|
||||
// we need to try a precise guess first.
|
||||
// For more detail see #504
|
||||
var index = drawWithLineMask(2);
|
||||
if (index > -1) {
|
||||
return index;
|
||||
}
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
return -1;
|
||||
return drawWithLineMask(Ghost.linemask);
|
||||
}
|
||||
|
||||
static getHitPointIndex (list, pt) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue