StencilUI.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.drawing.manager.StencilUI"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.drawing.manager.StencilUI"] = true;
  8. dojo.provide("dojox.drawing.manager.StencilUI");
  9. (function(){
  10. var surface, surfaceNode;
  11. dojox.drawing.manager.StencilUI = dojox.drawing.util.oo.declare(
  12. // summary:
  13. // Used for handling Stencils as UI components.
  14. // description:
  15. // Replaces manager.Stencil. Handles basic UI mouse
  16. // events like onmouseover. Does not handle selections
  17. // or support delete, etc.
  18. //
  19. function(options){
  20. //
  21. // TODO: mixin props
  22. //
  23. surface = options.surface;
  24. this.canvas = options.canvas;
  25. this.defaults = dojox.drawing.defaults.copy();
  26. this.mouse = options.mouse;
  27. this.keys = options.keys;
  28. this._mouseHandle = this.mouse.register(this);
  29. this.stencils = {};
  30. },
  31. {
  32. register: function(/*Object*/stencil){
  33. this.stencils[stencil.id] = stencil;
  34. return stencil;
  35. },
  36. onUiDown: function(/*EventObject*/obj){
  37. // summary:
  38. // Event fired on mousedown on a stencil
  39. //
  40. if(!this._isStencil(obj)){ return; }
  41. this.stencils[obj.id].onDown(obj);
  42. },
  43. onUiUp: function(/*EventObject*/obj){
  44. // summary:
  45. // Event fired on mousedown on a stencil
  46. //
  47. if(!this._isStencil(obj)){ return; }
  48. this.stencils[obj.id].onUp(obj);
  49. },
  50. onOver: function(/*EventObject*/obj){
  51. // summary:
  52. // Event fired on mousedown on a stencil
  53. //
  54. if(!this._isStencil(obj)){ return; }
  55. this.stencils[obj.id].onOver(obj);
  56. },
  57. onOut: function(/*EventObject*/obj){
  58. // summary:
  59. // Event fired on mousedown on a stencil
  60. //
  61. if(!this._isStencil(obj)){ return; }
  62. this.stencils[obj.id].onOut(obj);
  63. },
  64. _isStencil: function(/*EventObject*/obj){
  65. return !!obj.id && !!this.stencils[obj.id] && this.stencils[obj.id].type == "drawing.library.UI.Button";
  66. }
  67. }
  68. );
  69. })();
  70. }