mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2025-06-30 07:00:51 -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) {
|
static getHitIndex (ctx, commands, pt) {
|
||||||
ctx.save();
|
var drawWithLineMask = function (lineWidth) {
|
||||||
ctx.beginPath();
|
ctx.save();
|
||||||
for (var i = 0; i < commands.length; i++) {
|
ctx.lineWidth = lineWidth;
|
||||||
SVG2Canvas.drawCommand(ctx, commands[i]);
|
ctx.beginPath();
|
||||||
ctx.stroke();
|
for (var i = 0; i < commands.length; i++) {
|
||||||
pt = Vector.floor(pt);
|
SVG2Canvas.drawCommand(ctx, commands[i]);
|
||||||
var pixel = ctx.getImageData(pt.x, pt.y, 1, 1).data;
|
ctx.stroke();
|
||||||
if (pixel[3] != 0) {
|
pt = Vector.floor(pt);
|
||||||
return i;
|
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();
|
return drawWithLineMask(Ghost.linemask);
|
||||||
ctx.restore();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static getHitPointIndex (list, pt) {
|
static getHitPointIndex (list, pt) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue