Pencil.js 2.0 KB

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