source: Dev/branches/rest-dojo-ui/client/dojox/drawing/tools/Pencil.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.9 KB
Line 
1dojo.provide("dojox.drawing.tools.Pencil");
2
3dojox.drawing.tools.Pencil = dojox.drawing.util.oo.declare(
4        // summary:
5        //              Class for a drawable, continous Path
6        //
7        dojox.drawing.stencil.Path,
8        function(){
9                // summary: constructor
10                this._started = false;
11        },
12        {
13                draws:true,
14                // minDist: Number
15                //              The distance the mouse must travel before rendering
16                //              a path segment. Lower number is a higher definition
17                //              path but more points.
18                minDist: 15, // how to make this more dynamic? Settable?
19               
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               
33                onDrag: function(obj){
34                        if(
35                           !this._started
36                           || this.minDist > this.util.distance(obj.x, obj.y, this.lastPoint.x, this.lastPoint.y)
37                        ){ return; }
38                       
39                        var p = {
40                                x:obj.x,
41                                y:obj.y
42                        };
43                        this.points.push(p);
44                        this.render();
45                        this.checkClosePoint(this.points[0], obj);
46                        this.lastPoint = p;
47                },
48               
49                onUp: function(obj){
50                        if(!this._started){ return; }
51                        if(!this.points || this.points.length<2){
52                                this._started = false;
53                                this.points = [];
54                                return;
55                        }
56                        var box = this.getBounds();
57                        if(box.w<this.minimumSize && box.h<this.minimumSize){
58                                this.remove(this.hit, this.shape, this.closeGuide);
59                                this._started = false;
60                                this.setPoints([]);
61                                return;
62                        }
63                        if(this.checkClosePoint(this.points[0], obj, true)){
64                                this.closePath = true;
65                        }
66                        this.renderHit = this.revertRenderHit;
67                        this.renderedOnce = true;
68                        this.render();
69                        this.onRender(this);
70                       
71                }
72        }
73);
74
75dojox.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
83dojox.drawing.register(dojox.drawing.tools.Pencil.setup, "tool");
Note: See TracBrowser for help on using the repository browser.