summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/drawing/tools/Pencil.js
blob: a0b82a12c717d7e713fba82190383f1cb6a5d239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//>>built
// wrapped by build app
define("dojox/drawing/tools/Pencil", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){
dojo.provide("dojox.drawing.tools.Pencil");

dojox.drawing.tools.Pencil = dojox.drawing.util.oo.declare(
	// summary:
	//		Class for a drawable, continous Path
	//
	dojox.drawing.stencil.Path,
	function(){
		// summary: constructor
		this._started = false;
	},
	{
		draws:true,
		// minDist: Number
		//		The distance the mouse must travel before rendering
		//		a path segment. Lower number is a higher definition
		//		path but more points.
		minDist: 15, // how to make this more dynamic? Settable?
		
		onDown: function(obj){
			this._started = true;
			var p = {
				x:obj.x,
				y:obj.y
			};
			this.points = [p];
			this.lastPoint = p;
			this.revertRenderHit = this.renderHit;
			this.renderHit = false;
			this.closePath = false;
		},
		
		onDrag: function(obj){
			if(
			   !this._started
			   || this.minDist > this.util.distance(obj.x, obj.y, this.lastPoint.x, this.lastPoint.y)
			){ return; }
			
			var p = {
				x:obj.x,
				y:obj.y
			};
			this.points.push(p);
			this.render();
			this.checkClosePoint(this.points[0], obj);
			this.lastPoint = p;
		},
		
		onUp: function(obj){
			if(!this._started){ return; }
			if(!this.points || this.points.length<2){
				this._started = false;
				this.points = [];
				return;
			}
			var box = this.getBounds();
			if(box.w<this.minimumSize && box.h<this.minimumSize){
				this.remove(this.hit, this.shape, this.closeGuide);
				this._started = false;
				this.setPoints([]);
				return;
			}
			if(this.checkClosePoint(this.points[0], obj, true)){
				this.closePath = true;
			}
			this.renderHit = this.revertRenderHit;
			this.renderedOnce = true;
			this.render();
			this.onRender(this);
			
		}
	}
);

dojox.drawing.tools.Pencil.setup = {
	// summary: See Base ToolsSetup
	//
	name:"dojox.drawing.tools.Pencil",
	tooltip:"Pencil Tool",
	iconClass:"iconLine"
};

dojox.drawing.register(dojox.drawing.tools.Pencil.setup, "tool");
});