Add red 'X' to mouse cursor if blocks are over toolbox.

This commit is contained in:
Neil Fraser 2014-12-02 15:00:10 -08:00
parent 3bc81bd543
commit c9169285d9
6 changed files with 48 additions and 12 deletions
core

View file

@ -74,7 +74,7 @@ Blockly.Css.inject = function() {
goog.cssom.addCssText(text);
var sheets = goog.cssom.getAllCssStyleSheets();
Blockly.Css.styleSheet_ = sheets[sheets.length - 1];
Blockly.Css.setCursor('handopen');
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
};
/**
@ -98,11 +98,22 @@ Blockly.Css.setCursor = function(cursor) {
}
var url = 'url(' + Blockly.Css.mediaPath_ + '/' + cursor +
'.cur) ' + xy + ', auto';
// There are potentially hundreds of draggable objects. Changing their style
// properties individually is too slow, so change the CSS rule instead.
var rule = '.blocklyDraggable {\n cursor: ' + url + ';\n}\n';
goog.cssom.replaceCssRule('', rule, Blockly.Css.styleSheet_, 0);
// There is probably only one toolbox, so just change its style property.
var toolboxen = document.getElementsByClassName('blocklyToolboxDiv');
for (var i = 0, toolbox; toolbox = toolboxen[i]; i++) {
if (cursor == Blockly.Css.Cursor.OPEN) {
toolbox.style.cursor = '';
} else {
toolbox.style.cursor = url;
}
}
// Set cursor on the SVG surface as well, so that rapid movements
// don't result in cursor changing to an arrow momentarily.
if (Blockly.svg) {
// Set cursor on the SVG surface as well, so that rapid movements
// don't result in cursor changing to an arrow momentarily.
if (cursor == Blockly.Css.Cursor.OPEN) {
Blockly.svg.style.cursor = '';
} else {