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

Allow hoverCursor to appear on non selectable objects. #2924

Merged
merged 6 commits into from
May 1, 2016
Merged
Show file tree
Hide file tree
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
31 changes: 17 additions & 14 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@

if (target !== this.getActiveGroup() && target !== this.getActiveObject()) {
this.deactivateAll();
this.setActiveObject(target, e);
target.selectable && this.setActiveObject(target, e);
}
}
// we must renderAll so that active image is placed on the top canvas
Expand Down Expand Up @@ -572,18 +572,10 @@
this.renderTop();
}
else if (!this._currentTransform) {

target = this.findTarget(e);

if (!target || target && !target.selectable) {
this.setCursor(this.defaultCursor);
}
else {
this._setCursorFromEvent(e, target);
}
this._setCursorFromEvent(e, target);
}
else {

this._transformObject(e);
}

Expand Down Expand Up @@ -637,8 +629,11 @@
(actionPerformed = this._skewObject(x, y, 'y')) && this._fire('skewing', target, e);
}
else {
(actionPerformed = this._translateObject(x, y)) && this._fire('moving', target, e);
this.setCursor(this.moveCursor);
actionPerformed = this._translateObject(x, y);
if (actionPerformed) {
this._fire('moving', target, e);
this.setCursor(target.moveCursor || this.moveCursor);
}
}
transform.actionPerformed = actionPerformed;
},
Expand Down Expand Up @@ -698,10 +693,16 @@
* @param {Object} target Object that the mouse is hovering, if so.
*/
_setCursorFromEvent: function (e, target) {
if (!target || !target.selectable) {
if (!target) {
this.setCursor(this.defaultCursor);
return false;
}

var hoverCursor = target.hoverCursor || this.hoverCursor;
if (!target.selectable) {
//let's skip _findTargetCorner if object is not selectable
this.setCursor(hoverCursor);
}
else {
var activeGroup = this.getActiveGroup(),
// only show proper corner when group selection is not active
Expand All @@ -710,12 +711,14 @@
&& target._findTargetCorner(this.getPointer(e, true));

if (!corner) {
this.setCursor(target.hoverCursor || this.hoverCursor);
this.setCursor(hoverCursor);
}
else {
this._setCornerCursor(corner, target, e);
}
}
//actually unclear why it should return something
//is never evaluated
return true;
},

Expand Down
7 changes: 7 additions & 0 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@
*/
hoverCursor: null,

/**
* Default cursor value used when moving this object on canvas
* @type String
* @default
*/
moveCursor: null,

/**
* Padding between object and its controlling borders (in pixels)
* @type Number
Expand Down