| 1 |
define(["dojo", "../util/oo", "dojox/gfx"], |
| 2 |
function(dojo, oo, gfx){ |
| 3 |
|
| 4 |
|
| 5 |
return oo.declare( |
| 6 |
function(options){ |
| 7 |
dojo.mixin(this, options); |
| 8 |
|
| 9 |
var dim = dojo.contentBox(this.srcRefNode); |
| 10 |
this.height = this.parentHeight = options.height || dim.h; |
| 11 |
this.width = this.parentWidth = options.width || dim.w; |
| 12 |
this.domNode = dojo.create("div", {id:"canvasNode"}, this.srcRefNode); |
| 13 |
dojo.style(this.domNode, { |
| 14 |
width:this.width, |
| 15 |
height:"auto" |
| 16 |
}); |
| 17 |
|
| 18 |
dojo.setSelectable(this.domNode, false); |
| 19 |
|
| 20 |
this.id = this.id || this.util.uid("surface"); |
| 21 |
|
| 22 |
console.info("create canvas"); |
| 23 |
this.gfxSurface = gfx.createSurface(this.domNode, this.width, this.height); |
| 24 |
this.gfxSurface.whenLoaded(this, function(){ |
| 25 |
setTimeout(dojo.hitch(this, function(){ |
| 26 |
this.surfaceReady = true; |
| 27 |
if(dojo.isIE){ |
| 28 |
|
| 29 |
}else if(gfx.renderer == "silverlight"){ |
| 30 |
this.id = this.domNode.firstChild.id |
| 31 |
}else{ |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
this.underlay = this.gfxSurface.createGroup(); |
| 36 |
this.surface = this.gfxSurface.createGroup(); |
| 37 |
this.overlay = this.gfxSurface.createGroup(); |
| 38 |
this.surface.setTransform({dx:0, dy:0,xx:1,yy:1}); |
| 39 |
|
| 40 |
this.gfxSurface.getDimensions = dojo.hitch(this.gfxSurface, "getDimensions"); |
| 41 |
if(options.callback){ |
| 42 |
options.callback(this.domNode); |
| 43 |
} |
| 44 |
}),500); |
| 45 |
}); |
| 46 |
this._mouseHandle = this.mouse.register(this); |
| 47 |
}, |
| 48 |
{ |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
zoom:1, |
| 62 |
|
| 63 |
useScrollbars: true, |
| 64 |
baseClass:"drawingCanvas", |
| 65 |
|
| 66 |
resize: function(width, height){ |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
this.parentWidth = width; |
| 73 |
this.parentHeight = height; |
| 74 |
this.setDimensions(width, height); |
| 75 |
}, |
| 76 |
|
| 77 |
setDimensions: function(width, height, scrollx, scrolly){ |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
var sw = this.getScrollWidth(); |
| 85 |
this.width = Math.max(width, this.parentWidth); |
| 86 |
this.height = Math.max(height, this.parentHeight); |
| 87 |
|
| 88 |
if(this.height>this.parentHeight){ |
| 89 |
this.width -= sw; |
| 90 |
} |
| 91 |
if(this.width>this.parentWidth){ |
| 92 |
this.height -= sw; |
| 93 |
} |
| 94 |
|
| 95 |
this.mouse.resize(this.width,this.height); |
| 96 |
this.gfxSurface.setDimensions(this.width, this.height); |
| 97 |
|
| 98 |
|
| 99 |
this.domNode.parentNode.scrollTop = scrolly || 0; |
| 100 |
this.domNode.parentNode.scrollLeft = scrollx || 0; |
| 101 |
|
| 102 |
|
| 103 |
if(this.useScrollbars){ |
| 104 |
|
| 105 |
dojo.style(this.domNode.parentNode, { |
| 106 |
overflowY: this.height > this.parentHeight ? "scroll" : "hidden", |
| 107 |
overflowX: this.width > this.parentWidth ? "scroll" : "hidden" |
| 108 |
}); |
| 109 |
}else{ |
| 110 |
dojo.style(this.domNode.parentNode, { |
| 111 |
overflowY: "hidden", |
| 112 |
overflowX: "hidden" |
| 113 |
}); |
| 114 |
} |
| 115 |
}, |
| 116 |
|
| 117 |
|
| 118 |
setZoom: function(zoom){ |
| 119 |
|
| 120 |
|
| 121 |
this.zoom = zoom; |
| 122 |
this.surface.setTransform({xx:zoom, yy:zoom}); |
| 123 |
this.setDimensions(this.width*zoom, this.height*zoom) |
| 124 |
}, |
| 125 |
|
| 126 |
onScroll: function(){ |
| 127 |
|
| 128 |
|
| 129 |
}, |
| 130 |
|
| 131 |
getScrollOffset: function(){ |
| 132 |
|
| 133 |
|
| 134 |
return { |
| 135 |
top:this.domNode.parentNode.scrollTop, |
| 136 |
left:this.domNode.parentNode.scrollLeft |
| 137 |
}; |
| 138 |
}, |
| 139 |
|
| 140 |
getScrollWidth: function(){ |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
var p = dojo.create('div'); |
| 146 |
p.innerHTML = '<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:0;left:-1000px;"><div style="height:100px;"></div>'; |
| 147 |
var div = p.firstChild; |
| 148 |
dojo.body().appendChild(div); |
| 149 |
var noscroll = dojo.contentBox(div).h; |
| 150 |
dojo.style(div, "overflow", "scroll"); |
| 151 |
var scrollWidth = noscroll - dojo.contentBox(div).h; |
| 152 |
dojo.destroy(div); |
| 153 |
this.getScrollWidth = function(){ |
| 154 |
return scrollWidth; |
| 155 |
}; |
| 156 |
return scrollWidth; |
| 157 |
} |
| 158 |
} |
| 159 |
); |
| 160 |
|
| 161 |
}); |