Merge pull request from yueyuzhao/issue/473-drag-with-mouse-with-grid-on

Drag sprite with a mouse/trackpad with grid turned on
This commit is contained in:
Deep Malhan 2022-04-08 08:49:11 -04:00 committed by GitHub
commit 918c42a56f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 24 deletions
src
editor/ui
utils

View file

@ -5,7 +5,7 @@
import ScratchJr from '../ScratchJr';
import Events from '../../utils/Events';
import Localization from '../../utils/Localization';
import {gn, scaleMultiplier, isTablet, newDiv, setProps, newP, newCanvas} from '../../utils/lib';
import {gn, scaleMultiplier, newDiv, setProps, newP, newCanvas} from '../../utils/lib';
let width = 482;
let height = 362;
@ -69,15 +69,12 @@ export default class Grid {
ctx.stroke();
dy += size;
}
if (isTablet) {
cnv.ontouchstart = function (evt) {
ScratchJr.stage.mouseDown(evt);
};
} else {
cnv.onmousedown = function (evt) {
ScratchJr.stage.mouseDown(evt);
};
}
cnv.ontouchstart = function (evt) {
ScratchJr.stage.mouseDown(evt);
};
cnv.onmousedown = function (evt) {
ScratchJr.stage.mouseDown(evt);
};
}
static createNumbering (w, h) {
@ -153,15 +150,12 @@ export default class Grid {
var cnv = newCanvas(gc, 0, 0, size + 2, size + 2, {
position: 'absolute'
});
if (isTablet) {
cnv.ontouchstart = function (evt) {
Grid.mouseDownOnCursor(evt);
};
} else {
cnv.onmousedown = function (evt) {
Grid.mouseDownOnCursor(evt);
};
}
cnv.ontouchstart = function (evt) {
Grid.mouseDownOnCursor(evt);
};
cnv.onmousedown = function (evt) {
Grid.mouseDownOnCursor(evt);
};
var ctx = cnv.getContext('2d');
ctx.globalAlpha = 0.5;
ctx.fillStyle = '#28A5DA';
@ -169,11 +163,8 @@ export default class Grid {
ctx.lineWidth = 3;
ctx.strokeRect(3, 3, size - 6, size - 6);
ctx.fillRect(3, 3, size - 6, size - 6);
if (isTablet) {
gc.ontouchstart = Grid.mouseDownOnCursor;
} else {
gc.onmousedown = Grid.mouseDownOnCursor;
}
gc.ontouchstart = Grid.mouseDownOnCursor;
gc.onmousedown = Grid.mouseDownOnCursor;
}
static mouseDownOnCursor (e) {

View file

@ -144,6 +144,9 @@ export default class Events {
}
static holdit (c, fcn) {
if (timeoutEvent) {
return;
}
var repeat = function () {
Events.clearEvents();
fcn(dragthumbnail);