From 29d26ba3433fb96d5fed510294f7f23ecc9d5456 Mon Sep 17 00:00:00 2001 From: Yueyu Date: Fri, 21 May 2021 18:41:41 +0800 Subject: [PATCH] 1. painter add mouse event support 2. Palette and ScriptPane add mouse event support --- src/editor/ui/Thumbs.js | 14 ++++---------- src/painteditor/Paint.js | 12 ++++++------ src/utils/Events.js | 24 ++++++++++++------------ 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/editor/ui/Thumbs.js b/src/editor/ui/Thumbs.js index 1e6d1d2..790f13e 100644 --- a/src/editor/ui/Thumbs.js +++ b/src/editor/ui/Thumbs.js @@ -67,7 +67,7 @@ export default class Thumbs { } static pageMouseDown (e) { - if (isTablet && e.touches && (e.touches.length > 1)) { + if (e.touches && (e.touches.length > 1)) { return; } if (ScratchJr.onHold) { @@ -353,15 +353,9 @@ export default class Thumbs { } img.setAttribute('class', 'unselectable'); tb.setAttribute('id', 'emptypage'); - if (isTablet) { - tb.ontouchstart = function (evt) { - Thumbs.clickOnEmptyPage(evt); - }; - } else { - tb.onmousedown = function (evt) { - Thumbs.clickOnEmptyPage(evt); - }; - } + tb.onclick = function (evt) { + Thumbs.clickOnEmptyPage(evt); + }; return tb; } diff --git a/src/painteditor/Paint.js b/src/painteditor/Paint.js index 8c68c65..0ea01da 100644 --- a/src/painteditor/Paint.js +++ b/src/painteditor/Paint.js @@ -225,16 +225,16 @@ export default class Paint { } static detectGesture (e) { - if (!e.touches) { - return; - } if (Camera.active) { return; } Paint.clearEvents(e); initialPoint = PaintAction.getScreenPt(e); deltaPoint = PaintAction.getScreenPt(e); - var n = Math.min(3, e.touches.length); + var n = 1; + if (e.touches) { + n = Math.min(3, e.touches.length); + } var cmdForGesture = [Paint.ignore, Paint.mouseDown, Paint.pinchStart, Paint.Scroll]; cmdForGesture[n](e); } @@ -734,8 +734,6 @@ export default class Paint { for (var i = 0; i < pensizes.length; i++) { var ps = newHTML('div', 'pensizeholder', section); ps.key = i; - ps.ontouchstart = setSize; - ps.onmousedown = setSize; var setSize = function (e) { e.preventDefault(); e.stopPropagation(); @@ -743,6 +741,8 @@ export default class Paint { strokewidth = pensizes[Number(this.key)]; Paint.selectPenSize(n); }; + ps.ontouchstart = setSize; + ps.onmousedown = setSize; var c = newHTML('div', 'line t' + i, ps); Paint.drawPenSizeInColor(c); } diff --git a/src/utils/Events.js b/src/utils/Events.js index 72a96b0..c098438 100644 --- a/src/utils/Events.js +++ b/src/utils/Events.js @@ -120,12 +120,6 @@ export default class Events { updatefcn = atdrag; if (isTablet) { // startDrag event setting delta = 10 * scaleMultiplier; - window.ontouchmove = function (evt) { - Events.mouseMove(evt); - }; - window.ontouchend = function (evt) { - Events.mouseUp(evt); - }; window.ontouchleave = function (evt) { Events.mouseUp(evt); }; @@ -134,13 +128,19 @@ export default class Events { }; } else { delta = 7; - window.onmousemove = function (evt) { - Events.mouseMove(evt); - }; - window.onmouseup = function (evt) { - Events.mouseUp(evt); - }; } + window.ontouchmove = function (evt) { + Events.mouseMove(evt); + }; + window.ontouchend = function (evt) { + Events.mouseUp(evt); + }; + window.onmousemove = function (evt) { + Events.mouseMove(evt); + }; + window.onmouseup = function (evt) { + Events.mouseUp(evt); + }; } static holdit (c, fcn) {