| 1 |
define(["dojo/_base/lang", "../../util/oo", "../_Plugin", "../../manager/_registry"], |
| 2 |
function(lang, oo, Plugin, registry){ |
| 3 |
|
| 4 |
var Pan = oo.declare( |
| 5 |
Plugin, |
| 6 |
function(options){ |
| 7 |
this.domNode = options.node; |
| 8 |
var _scrollTimeout; |
| 9 |
this.toolbar = options.scope; |
| 10 |
this.connect(this.toolbar, "onToolClick", this, function(){ |
| 11 |
this.onSetPan(false) |
| 12 |
}); |
| 13 |
this.connect(this.keys, "onKeyUp", this, "onKeyUp"); |
| 14 |
this.connect(this.keys, "onKeyDown", this, "onKeyDown"); |
| 15 |
this.connect(this.keys, "onArrow", this, "onArrow"); |
| 16 |
this.connect(this.anchors, "onAnchorUp", this, "checkBounds"); |
| 17 |
this.connect(this.stencils, "register", this, "checkBounds"); |
| 18 |
this.connect(this.canvas, "resize", this, "checkBounds"); |
| 19 |
this.connect(this.canvas, "setZoom", this, "checkBounds"); |
| 20 |
this.connect(this.canvas, "onScroll", this, function(){ |
| 21 |
if(this._blockScroll){ |
| 22 |
this._blockScroll = false; |
| 23 |
return; |
| 24 |
} |
| 25 |
_scrollTimeout && clearTimeout(_scrollTimeout); |
| 26 |
_scrollTimeout = setTimeout(lang.hitch(this, "checkBounds"), 200); |
| 27 |
}); |
| 28 |
this._mouseHandle = this.mouse.register(this); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
},{ |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
selected:false, |
| 46 |
keyScroll:false, |
| 47 |
type:"dojox.drawing.plugins.tools.Pan", |
| 48 |
|
| 49 |
onPanUp: function(obj){ |
| 50 |
if(obj.id == this.button.id){ |
| 51 |
this.onSetPan(false); |
| 52 |
} |
| 53 |
}, |
| 54 |
|
| 55 |
onKeyUp: function(evt){ |
| 56 |
switch(evt.keyCode){ |
| 57 |
case 32: |
| 58 |
this.onSetPan(false); |
| 59 |
break; |
| 60 |
case 39: case 37: case 38: case 40: |
| 61 |
clearInterval(this._timer); |
| 62 |
break; |
| 63 |
} |
| 64 |
}, |
| 65 |
|
| 66 |
onKeyDown: function(evt){ |
| 67 |
if(evt.keyCode == 32){ |
| 68 |
this.onSetPan(true); |
| 69 |
} |
| 70 |
}, |
| 71 |
|
| 72 |
interval: 20, |
| 73 |
|
| 74 |
onArrow: function(evt){ |
| 75 |
if(this._timer){ clearInterval(this._timer); } |
| 76 |
this._timer = setInterval(lang.hitch(this,function(evt){ |
| 77 |
this.canvas.domNode.parentNode.scrollLeft += evt.x*10; |
| 78 |
this.canvas.domNode.parentNode.scrollTop += evt.y*10; |
| 79 |
},evt), this.interval); |
| 80 |
}, |
| 81 |
|
| 82 |
onSetPan: function( bool){ |
| 83 |
if(bool === true || bool === false){ |
| 84 |
this.selected = !bool; |
| 85 |
} |
| 86 |
console.log('ON SET PAN:', this.selected) |
| 87 |
if(this.selected){ |
| 88 |
this.selected = false; |
| 89 |
this.button.deselect(); |
| 90 |
}else{ |
| 91 |
this.selected = true; |
| 92 |
this.button.select(); |
| 93 |
} |
| 94 |
this.mouse.setEventMode(this.selected ? "pan" : ""); |
| 95 |
}, |
| 96 |
|
| 97 |
onPanDrag: function(obj){ |
| 98 |
var x = obj.x - obj.last.x; |
| 99 |
var y = obj.y - obj.last.y; |
| 100 |
this.canvas.domNode.parentNode.scrollTop -= obj.move.y; |
| 101 |
this.canvas.domNode.parentNode.scrollLeft -= obj.move.x; |
| 102 |
this.canvas.onScroll(); |
| 103 |
}, |
| 104 |
|
| 105 |
onUp: function(obj){ |
| 106 |
if(obj.withinCanvas){ |
| 107 |
this.keyScroll = true; |
| 108 |
}else{ |
| 109 |
this.keyScroll = false; |
| 110 |
} |
| 111 |
}, |
| 112 |
|
| 113 |
onStencilUp: function(obj){ |
| 114 |
|
| 115 |
|
| 116 |
this.checkBounds(); |
| 117 |
}, |
| 118 |
onStencilDrag: function(obj){ |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
}, |
| 123 |
|
| 124 |
checkBounds: function(){ |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
var log = function(){ |
| 139 |
|
| 140 |
} |
| 141 |
var warn = function(){ |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
var t=Infinity, r=-Infinity, b=-10000, l=10000, |
| 149 |
sx=0, sy=0, dy=0, dx=0, |
| 150 |
mx = this.stencils.group ? this.stencils.group.getTransform() : {dx:0, dy:0}, |
| 151 |
sc = this.mouse.scrollOffset(), |
| 152 |
|
| 153 |
scY = sc.left ? 10 : 0, |
| 154 |
scX = sc.top ? 10 : 0, |
| 155 |
|
| 156 |
ch = this.canvas.height, |
| 157 |
cw = this.canvas.width, |
| 158 |
z = this.canvas.zoom, |
| 159 |
|
| 160 |
|
| 161 |
pch = this.canvas.parentHeight, |
| 162 |
pcw = this.canvas.parentWidth; |
| 163 |
|
| 164 |
|
| 165 |
this.stencils.withSelected(function(m){ |
| 166 |
var o = m.getBounds(); |
| 167 |
warn("SEL BOUNDS:", o); |
| 168 |
t = Math.min(o.y1 + mx.dy, t); |
| 169 |
r = Math.max(o.x2 + mx.dx, r); |
| 170 |
b = Math.max(o.y2 + mx.dy, b); |
| 171 |
l = Math.min(o.x1 + mx.dx, l); |
| 172 |
}); |
| 173 |
|
| 174 |
this.stencils.withUnselected(function(m){ |
| 175 |
var o = m.getBounds(); |
| 176 |
warn("UN BOUNDS:", o); |
| 177 |
t = Math.min(o.y1, t); |
| 178 |
r = Math.max(o.x2, r); |
| 179 |
b = Math.max(o.y2, b); |
| 180 |
l = Math.min(o.x1, l); |
| 181 |
log("----------- B:", b, o.y2) |
| 182 |
}); |
| 183 |
|
| 184 |
b *= z; |
| 185 |
var xscroll = 0, yscroll = 0; |
| 186 |
log("Bottom test", "b:", b, "z:", z, "ch:", ch, "pch:", pch, "top:", sc.top, "sy:", sy, "mx.dy:", mx.dy); |
| 187 |
if(b > pch || sc.top ){ |
| 188 |
log("*bottom scroll*"); |
| 189 |
|
| 190 |
ch = Math.max(b, pch + sc.top); |
| 191 |
sy = sc.top; |
| 192 |
xscroll += this.canvas.getScrollWidth(); |
| 193 |
}else if(!sy && ch>pch){ |
| 194 |
log("*bottom remove*"); |
| 195 |
|
| 196 |
ch = pch; |
| 197 |
} |
| 198 |
|
| 199 |
r *= z; |
| 200 |
if(r > pcw || sc.left){ |
| 201 |
|
| 202 |
|
| 203 |
cw = Math.max(r, pcw + sc.left); |
| 204 |
sx = sc.left; |
| 205 |
yscroll += this.canvas.getScrollWidth(); |
| 206 |
}else if(!sx && cw>pcw){ |
| 207 |
|
| 208 |
|
| 209 |
cw = pcw; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
cw += xscroll*2; |
| 215 |
ch += yscroll*2; |
| 216 |
|
| 217 |
this._blockScroll = true; |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
this.stencils.group && this.stencils.group.applyTransform({dx:dx, dy:dy}); |
| 222 |
|
| 223 |
|
| 224 |
this.stencils.withUnselected(function(m){ |
| 225 |
m.transformPoints({dx:dx, dy:dy}); |
| 226 |
}); |
| 227 |
|
| 228 |
this.canvas.setDimensions(cw, ch, sx, sy); |
| 229 |
|
| 230 |
|
| 231 |
} |
| 232 |
} |
| 233 |
); |
| 234 |
|
| 235 |
Pan.setup = { |
| 236 |
name:"dojox.drawing.plugins.tools.Pan", |
| 237 |
tooltip:"Pan Tool", |
| 238 |
iconClass:"iconPan", |
| 239 |
button:false |
| 240 |
}; |
| 241 |
|
| 242 |
lang.setObject("dojox.drawing.plugins.tools.Pan", Pan); |
| 243 |
registry.register(Pan.setup, "plugin"); |
| 244 |
return Pan; |
| 245 |
|
| 246 |
}); |