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

This commit is contained in:
Neil Fraser
2014-11-28 21:43:39 -08:00
parent 208e49c9e6
commit 674625c47e
9 changed files with 174 additions and 112 deletions

View File

@@ -32,6 +32,7 @@ goog.require('Blockly.ScrollbarPair');
goog.require('Blockly.Trashcan');
goog.require('Blockly.Xml');
goog.require('goog.math');
goog.require('goog.math.Coordinate');
/**
@@ -134,6 +135,10 @@ Blockly.Workspace.prototype.dispose = function() {
}
this.svgBlockCanvas_ = null;
this.svgBubbleCanvas_ = null;
if (this.flyout_) {
this.flyout_.dispose();
this.flyout_ = null;
}
if (this.trashcan) {
this.trashcan.dispose();
this.trashcan = null;
@@ -396,5 +401,49 @@ Blockly.Workspace.prototype.remainingCapacity = function() {
return this.maxBlocks - this.getAllBlocks().length;
};
/**
* Make a list of all the delete areas for this workspace.
*/
Blockly.Workspace.prototype.recordDeleteAreas = function() {
if (this.trashcan) {
this.deleteAreaTrash_ = this.trashcan.getRect();
} else {
this.deleteAreaTrash_ = null;
}
if (this.flyout_) {
this.deleteAreaToolbox_ = this.flyout_.getRect();
} else {
this.deleteAreaToolbox_ = null;
}
};
/**
* Is the mouse event over a delete area (toolbar or non-closing flyout)?
* Opens or closes the trashcan and sets the cursor as a side effect.
* @param {!Event} e Mouse move event.
* @return {boolean} True if event is in a delete area.
*/
Blockly.Workspace.prototype.isDeleteArea = function(e) {
var isDelete = false;
var mouseXY = Blockly.mouseToSvg(e);
var xy = new goog.math.Coordinate(mouseXY.x, mouseXY.y);
if (this.deleteAreaTrash_) {
if (this.deleteAreaTrash_.contains(xy)) {
this.trashcan.setOpen_(true);
Blockly.Css.setCursor(Blockly.Css.Cursor.DELETE);
return true;
}
this.trashcan.setOpen_(false);
}
if (this.deleteAreaToolbox_) {
if (this.deleteAreaToolbox_.contains(xy)) {
Blockly.Css.setCursor(Blockly.Css.Cursor.DELETE);
return true;
}
}
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
return false;
};
// Export symbols that would otherwise be renamed by Closure compiler.
Blockly.Workspace.prototype['clear'] = Blockly.Workspace.prototype.clear;