| 1 |
define(["dojo/_base/lang", "../util/oo", "../manager/_registry", "../stencil/Line"], |
| 2 |
function(lang, oo, registry, StencilLine){ |
| 3 |
|
| 4 |
|
| 5 |
var Line = oo.declare( |
| 6 |
StencilLine, |
| 7 |
function(){ |
| 8 |
|
| 9 |
|
| 10 |
}, |
| 11 |
{ |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
draws:true, |
| 16 |
showAngle:true, |
| 17 |
onTransformEnd: function(anchor){ |
| 18 |
this._toggleSelected(); |
| 19 |
if(this.getRadius()<this.minimumSize){ |
| 20 |
var p = this.points; |
| 21 |
this.setPoints([ |
| 22 |
{x:p[0].x, y:p[0].y}, |
| 23 |
{x:p[0].x, y:p[0].y} |
| 24 |
]); |
| 25 |
}else{ |
| 26 |
var d = this.data; |
| 27 |
var obj = {start:{x:d.x1,y:d.y1},x:d.x2,y:d.y2}; |
| 28 |
var pt = this.util.snapAngle(obj, this.angleSnap/180); |
| 29 |
this.setPoints([ |
| 30 |
{x:d.x1, y:d.y1}, |
| 31 |
{x:pt.x, y:pt.y} |
| 32 |
]); |
| 33 |
|
| 34 |
this._isBeingModified = false; |
| 35 |
this.onModify(this); |
| 36 |
} |
| 37 |
}, |
| 38 |
|
| 39 |
onDrag: function(obj){ |
| 40 |
if(this.created){ return; } |
| 41 |
var x1 = obj.start.x, |
| 42 |
y1 = obj.start.y, |
| 43 |
x2 = obj.x, |
| 44 |
y2 = obj.y; |
| 45 |
|
| 46 |
if(this.keys.shift){ |
| 47 |
var pt = this.util.snapAngle(obj, 45/180); |
| 48 |
x2 = pt.x; |
| 49 |
y2 = pt.y; |
| 50 |
} |
| 51 |
|
| 52 |
if(this.keys.alt){ |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
var dx = x2>x1 ? ((x2-x1)/2) : ((x1-x2)/-2); |
| 59 |
var dy = y2>y1 ? ((y2-y1)/2) : ((y1-y2)/-2); |
| 60 |
x1 -= dx; |
| 61 |
x2 -= dx; |
| 62 |
y1 -= dy; |
| 63 |
y2 -= dy; |
| 64 |
} |
| 65 |
|
| 66 |
this.setPoints([ |
| 67 |
{x:x1, y:y1}, |
| 68 |
{x:x2, y:y2} |
| 69 |
]); |
| 70 |
this.render(); |
| 71 |
}, |
| 72 |
|
| 73 |
onUp: function(obj){ |
| 74 |
if(this.created || !this._downOnCanvas){ return; } |
| 75 |
this._downOnCanvas = false; |
| 76 |
|
| 77 |
if(!this.shape){ |
| 78 |
var s = obj.start, e = this.minimumSize*4; |
| 79 |
this.setPoints([ |
| 80 |
{x:s.x, y:s.y+e}, |
| 81 |
{x:s.x, y:s.y} |
| 82 |
]); |
| 83 |
this.render(); |
| 84 |
|
| 85 |
}else{ |
| 86 |
|
| 87 |
|
| 88 |
if(this.getRadius()<this.minimumSize){ |
| 89 |
this.remove(this.shape, this.hit); |
| 90 |
return; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
var pt = this.util.snapAngle(obj, this.angleSnap/180); |
| 95 |
var p = this.points; |
| 96 |
this.setPoints([ |
| 97 |
{x:p[0].x, y:p[0].y}, |
| 98 |
{x:pt.x, y:pt.y} |
| 99 |
]); |
| 100 |
|
| 101 |
this.renderedOnce = true; |
| 102 |
this.onRender(this); |
| 103 |
} |
| 104 |
} |
| 105 |
); |
| 106 |
|
| 107 |
lang.setObject("dojox.drawing.tools.Line", Line); |
| 108 |
Line.setup = { |
| 109 |
name:"dojox.drawing.tools.Line", |
| 110 |
tooltip:"Line Tool", |
| 111 |
iconClass:"iconLine" |
| 112 |
}; |
| 113 |
|
| 114 |
registry.register(Line.setup, "tool"); |
| 115 |
|
| 116 |
return Line; |
| 117 |
}); |