Skip to content

Commit

Permalink
Allow hoverCursor to appear on non selectable objects. (#2924)
Browse files Browse the repository at this point in the history
Fixed regression from #2907, added object.moveCursor
  • Loading branch information
asturur committed May 1, 2016
1 parent bc0591b commit 2006320
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
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

0 comments on commit 2006320

Please sign in to comment.