mutator_plus.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. goog.provide('Blockly.MutatorPlus');
  3. goog.require('Blockly.Mutator');
  4. goog.require('Blockly.Bubble');
  5. goog.require('Blockly.Icon');
  6. goog.require('goog.Timer');
  7. goog.require('goog.dom');
  8. Blockly.MutatorPlus = function(quarkNames) {
  9. Blockly.MutatorPlus.superClass_.constructor.call(this, this, null);
  10. };
  11. goog.inherits(Blockly.MutatorPlus, Blockly.Mutator, Blockly.Icon);
  12. Blockly.MutatorPlus.prototype.clicked_ = false;
  13. /**
  14. * Icon in base64 format.
  15. * @private
  16. */
  17. //Blockly.Mutator.prototype.png_ = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAARCAYAAAA7bUf6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAANyAAADcgBffIlqAAAAAd0SU1FB98DGhULOIajyb8AAAHMSURBVDjLnZS9SiRBFIXP/CQ9iIHgPoGBTo8vIAaivoKaKJr6DLuxYqKYKIqRgSCMrblmIxqsICgOmAriziIiRXWjYPdnUDvT2+PMsOyBoop7qk71vedWS5KAkrWsGUMjSYjpgSQhNoZGFLEKeGoKGMNttUpULkOhAFL3USiA70MQEBnDDeDJWtaqVaJeB7uNICAKQ1ZkDI1yufOm+XnY2YHl5c6874MxPClJiDulkMvBxYWrw/095POdU0sS4hxALqcWtreloSGpVJLGxtL49bX0+Ci9vUkzM2kcXGFbypUKxHHLBXZ3YW4ONjfh4yN1aGIiPQOQEenrg6MjR+zvZz99Y8PFT09hYCArktdfsFY6PHTr83NlUKu5+eREennJchmR/n5pYcGtJyezG6em3Dw7Kw0OZrlMOr6f1gTg4ACWlmBvz9WoifHxbDpf3Flfd+54njQ9ncYvL6WHB+n9XVpcbHOnW59IUKu5m+p11zftfLHo+qRorZ6Hh/Xt7k5fsLUl1evS1dWfG9swMiJZq9+KIlaD4P/eztkZNgz5LsAzhpvjY6JK5d9e8eioE3h95SdQbDrkhSErxvArjkl6/U/imMQYnsKQH02BT7vbZZfVOiWhAAAAAElFTkSuQmCC';
  18. /**
  19. * Create the icon on the block.
  20. */
  21. Blockly.MutatorPlus.prototype.createIcon = function() {
  22. if (this.iconMark_) {
  23. // Icon already exists.
  24. return;
  25. }
  26. Blockly.Icon.prototype.createIconOld.call(this);
  27. Blockly.Icon.radius = 8;
  28. /* Here's the markup that will be generated:
  29. <rect class="blocklyIconShield" width="16" height="16" rx="4" ry="4"/>
  30. <text class="blocklyIconMark" x="8" y="12">+</text>
  31. */
  32. var quantum = Blockly.Icon.radius / 2;
  33. var iconShield = Blockly.createSvgElement('rect',
  34. {'class': 'blocklyIconShield',
  35. 'width': 4 * quantum,
  36. 'height': 4 * quantum,
  37. 'rx': quantum,
  38. 'ry': quantum}, this.iconGroup_);
  39. this.iconMark_ = Blockly.createSvgElement('text',
  40. {'class': 'blocklyIconMark',
  41. 'x': Blockly.Icon.radius,
  42. 'y': 2 * Blockly.Icon.radius - 4}, this.iconGroup_);
  43. this.iconMark_.appendChild(document.createTextNode('\u002b'));
  44. };
  45. Blockly.MutatorPlus.prototype.iconClick_ = function(e) {
  46. if (Blockly.dragMode_ == 2) {
  47. // Drag operation is concluding. Don't activate the mutator.
  48. return;
  49. }
  50. if (this.block_.isEditable()) {
  51. this.block_.updateShape_(1);
  52. }
  53. goog.Timer.callOnce(
  54. this.block_.bumpNeighbours_, Blockly.BUMP_DELAY, this.block_);
  55. };