Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cursor style for morphs #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions morphic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3236,6 +3236,8 @@ Morph.prototype.init = function () {
this.customContextMenu = null;
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]'
Expand Down Expand Up @@ -11264,6 +11266,7 @@ HandMorph.prototype.init = function (aWorld) {
// properties for caching dragged objects:
this.cachedFullImage = null;
this.cachedFullBounds = null;
this.cursorStyle = 'auto';
};

// HandMorph dragging optimizations:
Expand Down Expand Up @@ -11605,6 +11608,8 @@ HandMorph.prototype.processMouseMove = function (event) {
mouseOverBoundsNew,
morph,
topMorph;

this.cursorStyle = null;

pos = new Point(
event.pageX - posInDocument.x,
Expand Down Expand Up @@ -11709,6 +11714,20 @@ HandMorph.prototype.processMouseMove = function (event) {
});
this.mouseOverList = mouseOverNew;
this.mouseOverBounds = mouseOverBoundsNew;

if (this.mouseButton === 'left' && this.morphToGrab) {
this.cursorStyle = this.morphToGrab.cursorGrabStyle || this.morphToGrab.cursorStyle;
}
if (this.cursorStyle == null) {

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) {
Expand Down