From a6a9c98d81f9cb0ed9d2e02b98b7b4a391f9e7ca Mon Sep 17 00:00:00 2001 From: Simon-Mong <30740101+Simon-Mong@users.noreply.github.com> Date: Wed, 2 Jul 2025 19:21:26 +0800 Subject: [PATCH] Update morphic.js for stage clicked event Update morphic.js for stage clicked event --- stitchcode/morphic.js | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/stitchcode/morphic.js b/stitchcode/morphic.js index 1f7dda53..51aa8f48 100644 --- a/stitchcode/morphic.js +++ b/stitchcode/morphic.js @@ -306,3 +306,60 @@ WorldMorph.prototype.updateBroken = function () { this.broken = []; }; + +HandMorph.prototype.oldInit = HandMorph.prototype.init; +HandMorph.init = function (aWorld) { + this.oldInit(aWorld); + this.lastClickPosition = null; +}; + +HandMorph.prototype.oldProcessMouseDown = HandMorph.prototype.processMouseDown; +HandMorph.prototype.processMouseDown = function (event) { + this.oldProcessMouseDown(event); + this.lastClickPosition = this.position(); +}; + +HandMorph.prototype.processMouseUp = function () { + var morph = this.morphAtPointer(), + context, + contextMenu, + expectedClick; + + this.destroyTemporaries(); + if (this.children.length !== 0) { + this.drop(); + } else { + if (this.mouseButton === 'left') { + morph = this.morphAtPointer(); + if (!(morph instanceof StageMorph)) { + expectedClick = 'mouseClickLeft'; + } else { + if (this.lastClickPosition.distanceTo(this.position()) < 5) { + expectedClick = 'mouseClickLeft'; + } else { + expectedClick = 'mouseLeave'; + } + } + } else { + expectedClick = 'mouseClickRight'; + if (this.mouseButton && this.contextMenuEnabled) { + context = morph; + contextMenu = context.contextMenu(); + while ((!contextMenu) && + context.parent) { + context = context.parent; + contextMenu = context.contextMenu(); + } + if (contextMenu) { + contextMenu.popUpAtHand(this.world); + } + } + } + while (!morph[expectedClick]) { + morph = morph.parent; + } + morph[expectedClick](this.bounds.origin); + } + this.mouseButton = null; + +};