| 1 |
define(["dojo", "../util/oo", "./_Base", "../manager/_registry"], |
| 2 |
function(dojo, oo, Base, registry){ |
| 3 |
|
| 4 |
var Image = oo.declare( |
| 5 |
Base, |
| 6 |
function(options){ |
| 7 |
|
| 8 |
|
| 9 |
}, |
| 10 |
{ |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
type:"dojox.drawing.stencil.Image", |
| 16 |
anchorType: "group", |
| 17 |
baseRender:true, |
| 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 |
dataToPoints: function(o){ |
| 43 |
|
| 44 |
|
| 45 |
o = o || this.data; |
| 46 |
this.points = [ |
| 47 |
{x:o.x, y:o.y}, |
| 48 |
{x:o.x + o.width, y:o.y}, |
| 49 |
{x:o.x + o.width, y:o.y + o.height}, |
| 50 |
{x:o.x, y:o.y + o.height} |
| 51 |
]; |
| 52 |
return this.points; |
| 53 |
}, |
| 54 |
|
| 55 |
pointsToData: function(p){ |
| 56 |
|
| 57 |
|
| 58 |
p = p || this.points; |
| 59 |
var s = p[0]; |
| 60 |
var e = p[2]; |
| 61 |
this.data = { |
| 62 |
x: s.x, |
| 63 |
y: s.y, |
| 64 |
width: e.x-s.x, |
| 65 |
height: e.y-s.y, |
| 66 |
src: this.src || this.data.src |
| 67 |
}; |
| 68 |
return this.data; |
| 69 |
|
| 70 |
}, |
| 71 |
|
| 72 |
_createHilite: function(){ |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
this.remove(this.hit); |
| 77 |
this.hit = this.container.createRect(this.data) |
| 78 |
.setStroke(this.style.current) |
| 79 |
.setFill(this.style.current.fill); |
| 80 |
this._setNodeAtts(this.hit); |
| 81 |
}, |
| 82 |
_create: function(shp, d, sty){ |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
this.remove(this[shp]); |
| 89 |
var s = this.container.getParent(); |
| 90 |
this[shp] = s.createImage(d) |
| 91 |
this.container.add(this[shp]); |
| 92 |
this._setNodeAtts(this[shp]); |
| 93 |
}, |
| 94 |
|
| 95 |
render: function(dbg){ |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
if(this.data.width == "auto" || isNaN(this.data.width)){ |
| 104 |
this.getImageSize(true); |
| 105 |
console.warn("Image size not provided. Acquiring...") |
| 106 |
return; |
| 107 |
} |
| 108 |
this.onBeforeRender(this); |
| 109 |
this.renderHit && this._createHilite(); |
| 110 |
this._create("shape", this.data, this.style.current); |
| 111 |
}, |
| 112 |
getImageSize: function(render){ |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
if(this._gettingSize){ return; } |
| 119 |
this._gettingSize = true; |
| 120 |
var img = dojo.create("img", {src:this.data.src}, dojo.body()); |
| 121 |
var err = dojo.connect(img, "error", this, function(){ |
| 122 |
dojo.disconnect(c); |
| 123 |
dojo.disconnect(err); |
| 124 |
console.error("Error loading image:", this.data.src) |
| 125 |
console.warn("Error image:", this.data) |
| 126 |
|
| 127 |
}); |
| 128 |
var c = dojo.connect(img, "load", this, function(){ |
| 129 |
var dim = dojo.marginBox(img); |
| 130 |
this.setData({ |
| 131 |
x:this.data.x, |
| 132 |
y:this.data.y, |
| 133 |
src:this.data.src, |
| 134 |
width:dim.w, |
| 135 |
height:dim.h |
| 136 |
}); |
| 137 |
dojo.disconnect(c); |
| 138 |
dojo.destroy(img); |
| 139 |
render && this.render(true); |
| 140 |
}); |
| 141 |
} |
| 142 |
} |
| 143 |
); |
| 144 |
|
| 145 |
dojo.setObject("dojox.drawing.stencil.Image", Image); |
| 146 |
registry.register({ |
| 147 |
name:"dojox.drawing.stencil.Image" |
| 148 |
}, "stencil"); |
| 149 |
|
| 150 |
return Image; |
| 151 |
}); |