123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- if(!dojo._hasResource["dojox.drawing.stencil.Image"]){
- dojo._hasResource["dojox.drawing.stencil.Image"] = true;
- dojo.provide("dojox.drawing.stencil.Image");
- dojox.drawing.stencil.Image = dojox.drawing.util.oo.declare(
-
-
-
-
- dojox.drawing.stencil._Base,
- function(options){
-
-
- },
- {
- type:"dojox.drawing.stencil.Image",
- anchorType: "group",
- baseRender:true,
-
-
- dataToPoints: function(/*Object*/o){
-
-
- o = o || this.data;
- this.points = [
- {x:o.x, y:o.y},
- {x:o.x + o.width, y:o.y},
- {x:o.x + o.width, y:o.y + o.height},
- {x:o.x, y:o.y + o.height}
- ];
- return this.points;
- },
-
- pointsToData: function(/*Array*/p){
-
-
- p = p || this.points;
- var s = p[0];
- var e = p[2];
- this.data = {
- x: s.x,
- y: s.y,
- width: e.x-s.x,
- height: e.y-s.y,
- src: this.src || this.data.src
- };
- return this.data;
-
- },
-
- _createHilite: function(){
-
-
-
- this.remove(this.hit);
- this.hit = this.container.createRect(this.data)
- .setStroke(this.style.current)
- .setFill(this.style.current.fill);
- this._setNodeAtts(this.hit);
- },
- _create: function(/*String*/shp, /*StencilData*/d, /*Object*/sty){
-
-
-
-
-
- this.remove(this[shp]);
- var s = this.container.getParent();
- this[shp] = s.createImage(d)
- this.container.add(this[shp]);
- this._setNodeAtts(this[shp]);
- },
-
- render: function(dbg){
-
-
-
-
-
-
-
- if(this.data.width == "auto" || isNaN(this.data.width)){
- this.getImageSize(true);
- console.warn("Image size not provided. Acquiring...")
- return;
- }
- this.onBeforeRender(this);
- this.renderHit && this._createHilite();
- this._create("shape", this.data, this.style.current);
- },
- getImageSize: function(render){
-
-
-
-
-
- if(this._gettingSize){ return; }
- this._gettingSize = true;
- var img = dojo.create("img", {src:this.data.src}, dojo.body());
- var err = dojo.connect(img, "error", this, function(){
- dojo.disconnect(c);
- dojo.disconnect(err);
- console.error("Error loading image:", this.data.src)
- console.warn("Error image:", this.data)
-
- });
- var c = dojo.connect(img, "load", this, function(){
- var dim = dojo.marginBox(img);
- this.setData({
- x:this.data.x,
- y:this.data.y,
- src:this.data.src,
- width:dim.w,
- height:dim.h
- });
- dojo.disconnect(c);
- dojo.destroy(img);
- render && this.render(true);
- });
- }
- }
- );
- dojox.drawing.register({
- name:"dojox.drawing.stencil.Image"
- }, "stencil");
- }
|