Skip to content

Commit

Permalink
Allow cursor to be updated without moving in and out of the current h…
Browse files Browse the repository at this point in the history
…it target
  • Loading branch information
sebmarkbage committed Mar 1, 2013
1 parent cdde4ad commit ad1af16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions demos/opacity/opacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ blue.subscribe({

group2.subscribe('click', function(){
this.blend(1);
blue.indicate('wait');
});

art.inject(document.body);
38 changes: 23 additions & 15 deletions src/modes/canvas/surface.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var fps = 1000 / 60, invalids = [], renderTimer, renderInvalids = function(){
}
};

var previousHit = null;
var previousHit = null, previousHitSurface = null;

var CanvasSurface = Class(Element, Container, {

Expand Down Expand Up @@ -59,25 +59,32 @@ var CanvasSurface = Class(Element, Container, {
});
}
previousHit = hit;
var hitCursor = '', hitTooltip = '';
while (hit){
if (!hitCursor && hit._cursor){
hitCursor = hit._cursor;
if (hitTooltip) break;
}
if (!hitTooltip && hit._tooltip){
hitTooltip = hit._tooltip;
if (hitCursor) break;
}
hit = hit.container;
}
this.element.style.cursor = hitCursor;
this.element.title = hitTooltip;
previousHitSurface = this;
this.refreshCursor();
}

if (hit) hit.dispatch(event);
},

refreshCursor: function(){
if (previousHitSurface !== this) return;
var hit = previousHit, hitCursor = '', hitTooltip = '';
while (hit){
if (!hitCursor && hit._cursor){
hitCursor = hit._cursor;
if (hitTooltip) break;
}
if (!hitTooltip && hit._tooltip){
hitTooltip = hit._tooltip;
if (hitCursor) break;
}
hit = hit.container;
}
// TODO: No way to set cursor/title on the surface
this.element.style.cursor = hitCursor;
this.element.title = hitTooltip;
},

resize: function(width, height){
var element = this.element;
element.setAttribute('width', width);
Expand Down Expand Up @@ -123,6 +130,7 @@ var CanvasSurface = Class(Element, Container, {
for (var i = 0, l = children.length; i < l; i++){
children[i].renderTo(context, 1, 0, 0, 1, 0, 0);
}
this.refreshCursor();
}

});
Expand Down

0 comments on commit ad1af16

Please sign in to comment.