From 722acf10623d0bd73c049029d05de0e9485aa6df Mon Sep 17 00:00:00 2001 From: ego-lay-atman-bay <70973578+ego-lay-atman-bay@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:07:41 -0600 Subject: [PATCH 1/3] add cursor changing for morphs (for hover effects) --- morphic.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/morphic.js b/morphic.js index 70b4f1e..90eb609 100644 --- a/morphic.js +++ b/morphic.js @@ -3236,6 +3236,7 @@ Morph.prototype.init = function () { this.customContextMenu = null; this.lastTime = Date.now(); this.onNextStep = null; // optional function to be run once + this.cursorStyle = null; }; // Morph string representation: e.g. 'a Morph 2 [20@45 | 130@250]' @@ -11264,6 +11265,7 @@ HandMorph.prototype.init = function (aWorld) { // properties for caching dragged objects: this.cachedFullImage = null; this.cachedFullBounds = null; + this.cursorStyle = 'auto'; }; // HandMorph dragging optimizations: @@ -11605,6 +11607,8 @@ HandMorph.prototype.processMouseMove = function (event) { mouseOverBoundsNew, morph, topMorph; + + this.cursorStyle = null; pos = new Point( event.pageX - posInDocument.x, @@ -11654,6 +11658,7 @@ HandMorph.prototype.processMouseMove = function (event) { } this.setPosition(pos); } + this.cursorStyle = morph.cursorStyle; } this.mouseOverBounds.forEach(old => { @@ -11709,6 +11714,18 @@ HandMorph.prototype.processMouseMove = function (event) { }); this.mouseOverList = mouseOverNew; this.mouseOverBounds = mouseOverBoundsNew; + + if (this.cursorStyle == null) { + this.cursorStyle = 'auto'; + + for (const morph of this.mouseOverList) { + if (morph.cursorStyle != null) { + this.cursorStyle = morph.cursorStyle; + break; + } + } + } + this.world.worldCanvas.style.cursor = this.cursorStyle; }; HandMorph.prototype.processMouseScroll = function (event) { From 5b6bc4644849d9d0c555eed88eab1cc97fef53cd Mon Sep 17 00:00:00 2001 From: ego-lay-atman-bay <70973578+ego-lay-atman-bay@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:45:58 -0600 Subject: [PATCH 2/3] fix up cursorStyle on dragging --- morphic.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/morphic.js b/morphic.js index 90eb609..48f262b 100644 --- a/morphic.js +++ b/morphic.js @@ -11658,7 +11658,6 @@ HandMorph.prototype.processMouseMove = function (event) { } this.setPosition(pos); } - this.cursorStyle = morph.cursorStyle; } this.mouseOverBounds.forEach(old => { @@ -11715,8 +11714,10 @@ HandMorph.prototype.processMouseMove = function (event) { this.mouseOverList = mouseOverNew; this.mouseOverBounds = mouseOverBoundsNew; + if (this.mouseButton === 'left' && this.morphToGrab) { + this.cursorStyle = this.morphToGrab.cursorStyle; + } if (this.cursorStyle == null) { - this.cursorStyle = 'auto'; for (const morph of this.mouseOverList) { if (morph.cursorStyle != null) { From 5b81031df80f7b54e7d35d611de04a26ee7ce03a Mon Sep 17 00:00:00 2001 From: ego-lay-atman-bay <70973578+ego-lay-atman-bay@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:14:06 -0600 Subject: [PATCH 3/3] add `cursorGrabStyle` --- morphic.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/morphic.js b/morphic.js index 48f262b..3b627d6 100644 --- a/morphic.js +++ b/morphic.js @@ -3237,6 +3237,7 @@ Morph.prototype.init = function () { this.lastTime = Date.now(); this.onNextStep = null; // optional function to be run once this.cursorStyle = null; + this.cursorGrabStyle = null; }; // Morph string representation: e.g. 'a Morph 2 [20@45 | 130@250]' @@ -11715,7 +11716,7 @@ HandMorph.prototype.processMouseMove = function (event) { this.mouseOverBounds = mouseOverBoundsNew; if (this.mouseButton === 'left' && this.morphToGrab) { - this.cursorStyle = this.morphToGrab.cursorStyle; + this.cursorStyle = this.morphToGrab.cursorGrabStyle || this.morphToGrab.cursorStyle; } if (this.cursorStyle == null) {