Pencil.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.tools.Pencil"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.drawing.tools.Pencil"] = true;
  8. dojo.provide("dojox.drawing.tools.Pencil");
  9. dojox.drawing.tools.Pencil = dojox.drawing.util.oo.declare(
  10. // summary:
  11. // Class for a drawable, continous Path
  12. //
  13. dojox.drawing.stencil.Path,
  14. function(){
  15. // summary: constructor
  16. this._started = false;
  17. },
  18. {
  19. draws:true,
  20. // minDist: Number
  21. // The distance the mouse must travel before rendering
  22. // a path segment. Lower number is a higher definition
  23. // path but more points.
  24. minDist: 15, // how to make this more dynamic? Settable?
  25. onDown: function(obj){
  26. this._started = true;
  27. var p = {
  28. x:obj.x,
  29. y:obj.y
  30. };
  31. this.points = [p];
  32. this.lastPoint = p;
  33. this.revertRenderHit = this.renderHit;
  34. this.renderHit = false;
  35. this.closePath = false;
  36. },
  37. onDrag: function(obj){
  38. if(
  39. !this._started
  40. || this.minDist > this.util.distance(obj.x, obj.y, this.lastPoint.x, this.lastPoint.y)
  41. ){ return; }
  42. var p = {
  43. x:obj.x,
  44. y:obj.y
  45. };
  46. this.points.push(p);
  47. this.render();
  48. this.checkClosePoint(this.points[0], obj);
  49. this.lastPoint = p;
  50. },
  51. onUp: function(obj){
  52. if(!this._started){ return; }
  53. if(!this.points || this.points.length<2){
  54. this._started = false;
  55. this.points = [];
  56. return;
  57. }
  58. var box = this.getBounds();
  59. if(box.w<this.minimumSize && box.h<this.minimumSize){
  60. this.remove(this.hit, this.shape, this.closeGuide);
  61. this._started = false;
  62. this.setPoints([]);
  63. return;
  64. }
  65. if(this.checkClosePoint(this.points[0], obj, true)){
  66. this.closePath = true;
  67. }
  68. this.renderHit = this.revertRenderHit;
  69. this.renderedOnce = true;
  70. this.render();
  71. this.onRender(this);
  72. }
  73. }
  74. );
  75. dojox.drawing.tools.Pencil.setup = {
  76. // summary: See Base ToolsSetup
  77. //
  78. name:"dojox.drawing.tools.Pencil",
  79. tooltip:"Pencil Tool",
  80. iconClass:"iconLine"
  81. };
  82. dojox.drawing.register(dojox.drawing.tools.Pencil.setup, "tool");
  83. }