Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improvements to resolving mouse position on stage. Should now support…

… CSS scaled canvases & canvases with border/padding.

Signed-off-by: Grant Skinner <info@gskinner.com>
  • Loading branch information...
commit 20d5dc70a0b2c21f6e2b95c7654bd26785c01628 1 parent 62ed9dc
@gskinner gskinner authored
View
3  VERSIONS.txt
@@ -1,7 +1,6 @@
Version NEXT [release TBD]
****************************************************************************************************
- moved all classes into a configurable createjs namespace
-- added AlphaMapFilter & AlphaMaskFilter
- added support for multitouch
- complete rewrite of drawing model to use a hybrid approach (save/restore & matrix)
- added DisplayObject.mask
@@ -30,6 +29,8 @@ Version NEXT [release TBD]
- text.color now defaults to "#000" instead of null
- parameters passed to Stage.update are now passed on to onTick handlers
- for example, Ticker elapsedTime and paused params
+- correctly resolves mouse positions for CSS scaled canvases & canvases with borders/padding
+- added AlphaMapFilter & AlphaMaskFilter
Version 0.4.2 [Apr 18, 2012]
View
BIN  docs/EaselJS_docs-NEXT.zip
Binary file not shown
View
26 lib/easeljs-NEXT.min.js
@@ -14,20 +14,20 @@
c.getMeasuredFPS=function(a){if(c._times.length<2)return-1;a==null&&(a=c.getFPS()|0);a=Math.min(c._times.length-1,a);return 1E3/((c._times[0]-c._times[a])/a)};c.setPaused=function(a){c._paused=a};c.getPaused=function(){return c._paused};c.getTime=function(a){return c._getTime()-c._startTime-(a?c._pausedTime:0)};c.getTicks=function(a){return c._ticks-(a?c._pausedTicks:0)};c._handleAF=function(){c._rafActive=false;c._setupTick();c._getTime()-c._lastTime>=(c._interval-1)*0.97&&c._tick()};c._handleTimeout=
function(){c.timeoutID=null;c._setupTick();c._tick()};c._setupTick=function(){if(!(c._rafActive||c.timeoutID!=null)){if(c.useRAF){var a=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;if(a){a(c._handleAF);c._rafActive=true;return}}c.timeoutID=setTimeout(c._handleTimeout,c._interval)}};c._tick=function(){var a=c._getTime();c._ticks++;var k=a-c._lastTime,b=c._paused;b&&(c._pausedTicks++,
c._pausedTime+=k);c._lastTime=a;for(var d=c._pauseable,e=c._listeners.slice(),f=e?e.length:0,h=0;h<f;h++){var i=e[h];i==null||b&&d[h]||(i.tick?i.tick(k,b):i instanceof Function&&i(k,b))}for(c._tickTimes.unshift(c._getTime()-a);c._tickTimes.length>100;)c._tickTimes.pop();for(c._times.unshift(a);c._times.length>100;)c._times.pop()};var b=window.performance&&(performance.now||performance.mozNow||performance.msNow||performance.oNow||performance.webkitNow);c._getTime=function(){return b&&b.call(performance)||
-(new Date).getTime()};g.Ticker=c})(createjs||(createjs={}));(function(g){var c=function(a,k,b,d,c,f,h,i,j){this.initialize(a,k,b,d,c,f,h,i,j)},b=c.prototype;b.stageX=0;b.stageY=0;b.rawX=0;b.rawY=0;b.type=null;b.nativeEvent=null;b.onMouseMove=null;b.onMouseUp=null;b.target=null;b.pointerID=0;b.primary=false;b.initialize=function(a,k,b,d,c,f,h,i,j){this.type=a;this.stageX=k;this.stageY=b;this.target=d;this.nativeEvent=c;this.pointerID=f;this.primary=h;this.rawX=i==null?k:i;this.rawY=j==null?b:j};b.clone=function(){return new c(this.type,this.stageX,this.stageY,
-this.target,this.nativeEvent,this.pointerID,this.primary,this.rawX,this.rawY)};b.toString=function(){return"[MouseEvent (type="+this.type+" stageX="+this.stageX+" stageY="+this.stageY+")]"};g.MouseEvent=c})(createjs||(createjs={}));(function(g){var c=function(a,k,b,d,c,f){this.initialize(a,k,b,d,c,f)},b=c.prototype;c.identity=null;c.DEG_TO_RAD=Math.PI/180;b.a=1;b.b=0;b.c=0;b.d=1;b.tx=0;b.ty=0;b.alpha=1;b.shadow=null;b.compositeOperation=null;b.initialize=function(a,k,b,d,c,f){if(a!=null)this.a=a;this.b=k||0;this.c=b||0;if(d!=null)this.d=d;this.tx=c||0;this.ty=f||0;return this};b.prepend=function(a,k,b,d,c,f){var h=this.tx;if(a!=1||k!=0||b!=0||d!=1){var i=this.a,j=this.c;this.a=i*a+this.b*b;this.b=i*k+this.b*d;this.c=j*a+this.d*
-b;this.d=j*k+this.d*d}this.tx=h*a+this.ty*b+c;this.ty=h*k+this.ty*d+f;return this};b.append=function(a,k,b,d,c,f){var h=this.a,i=this.b,j=this.c,l=this.d;this.a=a*h+k*j;this.b=a*i+k*l;this.c=b*h+d*j;this.d=b*i+d*l;this.tx=c*h+f*j+this.tx;this.ty=c*i+f*l+this.ty;return this};b.prependMatrix=function(a){this.prepend(a.a,a.b,a.c,a.d,a.tx,a.ty);this.prependProperties(a.alpha,a.shadow,a.compositeOperation);return this};b.appendMatrix=function(a){this.append(a.a,a.b,a.c,a.d,a.tx,a.ty);this.appendProperties(a.alpha,
+(new Date).getTime()};g.Ticker=c})(createjs||(createjs={}));(function(g){var c=function(a,k,b,d,e,c,h,i,j){this.initialize(a,k,b,d,e,c,h,i,j)},b=c.prototype;b.stageX=0;b.stageY=0;b.rawX=0;b.rawY=0;b.type=null;b.nativeEvent=null;b.onMouseMove=null;b.onMouseUp=null;b.target=null;b.pointerID=0;b.primary=false;b.initialize=function(a,k,b,d,e,c,h,i,j){this.type=a;this.stageX=k;this.stageY=b;this.target=d;this.nativeEvent=e;this.pointerID=c;this.primary=h;this.rawX=i==null?k:i;this.rawY=j==null?b:j};b.clone=function(){return new c(this.type,this.stageX,this.stageY,
+this.target,this.nativeEvent,this.pointerID,this.primary,this.rawX,this.rawY)};b.toString=function(){return"[MouseEvent (type="+this.type+" stageX="+this.stageX+" stageY="+this.stageY+")]"};g.MouseEvent=c})(createjs||(createjs={}));(function(g){var c=function(a,k,b,d,e,c){this.initialize(a,k,b,d,e,c)},b=c.prototype;c.identity=null;c.DEG_TO_RAD=Math.PI/180;b.a=1;b.b=0;b.c=0;b.d=1;b.tx=0;b.ty=0;b.alpha=1;b.shadow=null;b.compositeOperation=null;b.initialize=function(a,k,b,d,e,c){if(a!=null)this.a=a;this.b=k||0;this.c=b||0;if(d!=null)this.d=d;this.tx=e||0;this.ty=c||0;return this};b.prepend=function(a,k,b,d,e,c){var h=this.tx;if(a!=1||k!=0||b!=0||d!=1){var i=this.a,j=this.c;this.a=i*a+this.b*b;this.b=i*k+this.b*d;this.c=j*a+this.d*
+b;this.d=j*k+this.d*d}this.tx=h*a+this.ty*b+e;this.ty=h*k+this.ty*d+c;return this};b.append=function(a,k,b,d,e,c){var h=this.a,i=this.b,j=this.c,l=this.d;this.a=a*h+k*j;this.b=a*i+k*l;this.c=b*h+d*j;this.d=b*i+d*l;this.tx=e*h+c*j+this.tx;this.ty=e*i+c*l+this.ty;return this};b.prependMatrix=function(a){this.prepend(a.a,a.b,a.c,a.d,a.tx,a.ty);this.prependProperties(a.alpha,a.shadow,a.compositeOperation);return this};b.appendMatrix=function(a){this.append(a.a,a.b,a.c,a.d,a.tx,a.ty);this.appendProperties(a.alpha,
a.shadow,a.compositeOperation);return this};b.prependTransform=function(a,k,b,d,e,f,h,i,j){if(e%360)var l=e*c.DEG_TO_RAD,e=Math.cos(l),l=Math.sin(l);else e=1,l=0;if(i||j)this.tx-=i,this.ty-=j;f||h?(f*=c.DEG_TO_RAD,h*=c.DEG_TO_RAD,this.prepend(e*b,l*b,-l*d,e*d,0,0),this.prepend(Math.cos(h),Math.sin(h),-Math.sin(f),Math.cos(f),a,k)):this.prepend(e*b,l*b,-l*d,e*d,a,k);return this};b.appendTransform=function(a,k,b,d,e,f,h,i,j){if(e%360)var l=e*c.DEG_TO_RAD,e=Math.cos(l),l=Math.sin(l);else e=1,l=0;f||
h?(f*=c.DEG_TO_RAD,h*=c.DEG_TO_RAD,this.append(Math.cos(h),Math.sin(h),-Math.sin(f),Math.cos(f),a,k),this.append(e*b,l*b,-l*d,e*d,0,0)):this.append(e*b,l*b,-l*d,e*d,a,k);if(i||j)this.tx-=i*this.a+j*this.c,this.ty-=i*this.b+j*this.d;return this};b.rotate=function(a){var k=Math.cos(a),a=Math.sin(a),b=this.a,d=this.c,c=this.tx;this.a=b*k-this.b*a;this.b=b*a+this.b*k;this.c=d*k-this.d*a;this.d=d*a+this.d*k;this.tx=c*k-this.ty*a;this.ty=c*a+this.ty*k;return this};b.skew=function(a,k){a*=c.DEG_TO_RAD;k*=
c.DEG_TO_RAD;this.append(Math.cos(k),Math.sin(k),-Math.sin(a),Math.cos(a),0,0);return this};b.scale=function(a,k){this.a*=a;this.d*=k;this.tx*=a;this.ty*=k;return this};b.translate=function(a,k){this.tx+=a;this.ty+=k;return this};b.identity=function(){this.alpha=this.a=this.d=1;this.b=this.c=this.tx=this.ty=0;this.shadow=this.compositeOperation=null;return this};b.invert=function(){var a=this.a,k=this.b,b=this.c,d=this.d,c=this.tx,f=a*d-k*b;this.a=d/f;this.b=-k/f;this.c=-b/f;this.d=a/f;this.tx=(b*
this.ty-d*c)/f;this.ty=-(a*this.ty-k*c)/f;return this};b.isIdentity=function(){return this.tx==0&&this.ty==0&&this.a==1&&this.b==0&&this.c==0&&this.d==1};b.decompose=function(a){a==null&&(a={});a.x=this.tx;a.y=this.ty;a.scaleX=Math.sqrt(this.a*this.a+this.b*this.b);a.scaleY=Math.sqrt(this.c*this.c+this.d*this.d);var k=Math.atan2(-this.c,this.d),b=Math.atan2(this.b,this.a);k==b?(a.rotation=b/c.DEG_TO_RAD,this.a<0&&this.d>=0&&(a.rotation+=a.rotation<=0?180:-180),a.skewX=a.skewY=0):(a.skewX=k/c.DEG_TO_RAD,
a.skewY=b/c.DEG_TO_RAD);return a};b.reinitialize=function(a,k,b,d,c,f,h,i,j){this.initialize(a,k,b,d,c,f);this.alpha=h||1;this.shadow=i;this.compositeOperation=j;return this};b.appendProperties=function(a,k,b){this.alpha*=a;this.shadow=k||this.shadow;this.compositeOperation=b||this.compositeOperation;return this};b.prependProperties=function(a,k,b){this.alpha*=a;this.shadow=this.shadow||k;this.compositeOperation=this.compositeOperation||b;return this};b.clone=function(){var a=new c(this.a,this.b,
-this.c,this.d,this.tx,this.ty);a.shadow=this.shadow;a.alpha=this.alpha;a.compositeOperation=this.compositeOperation;return a};b.toString=function(){return"[Matrix2D (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")]"};c.identity=new c(1,0,0,1,0,0);g.Matrix2D=c})(createjs||(createjs={}));(function(g){var c=function(a,k){this.initialize(a,k)},b=c.prototype;b.x=0;b.y=0;b.initialize=function(a,k){this.x=a==null?0:a;this.y=k==null?0:k};b.clone=function(){return new c(this.x,this.y)};b.toString=function(){return"[Point (x="+this.x+" y="+this.y+")]"};g.Point=c})(createjs||(createjs={}));(function(g){var c=function(a,k,b,d){this.initialize(a,k,b,d)},b=c.prototype;b.x=0;b.y=0;b.width=0;b.height=0;b.initialize=function(a,k,b,d){this.x=a==null?0:a;this.y=k==null?0:k;this.width=b==null?0:b;this.height=d==null?0:d};b.clone=function(){return new c(this.x,this.y,this.width,this.height)};b.toString=function(){return"[Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+")]"};g.Rectangle=c})(createjs||(createjs={}));(function(g){var c=function(a,b,m,d){this.initialize(a,b,m,d)},b=c.prototype;c.identity=null;b.color=null;b.offsetX=0;b.offsetY=0;b.blur=0;b.initialize=function(a,b,m,d){this.color=a;this.offsetX=b;this.offsetY=m;this.blur=d};b.toString=function(){return"[Shadow]"};b.clone=function(){return new c(this.color,this.offsetX,this.offsetY,this.blur)};c.identity=new c("transparent",0,0,0);g.Shadow=c})(createjs||(createjs={}));(function(g){var c=function(a){this.initialize(a)},b=c.prototype;b.complete=true;b.onComplete=null;b._animations=null;b._frames=null;b._images=null;b._data=null;b._loadCount=0;b._frameHeight=0;b._frameWidth=0;b._numFrames=0;b._regX=0;b._regY=0;b.initialize=function(a){var b,m,d;if(a!=null){if(a.images&&(m=a.images.length)>0){d=this._images=[];for(b=0;b<m;b++){var c=a.images[b];if(typeof c=="string"){var f=c,c=new Image;c.src=f}d.push(c);if(!c.getContext&&!c.complete)this._loadCount++,this.complete=
+this.c,this.d,this.tx,this.ty);a.shadow=this.shadow;a.alpha=this.alpha;a.compositeOperation=this.compositeOperation;return a};b.toString=function(){return"[Matrix2D (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")]"};c.identity=new c(1,0,0,1,0,0);g.Matrix2D=c})(createjs||(createjs={}));(function(g){var c=function(a,k){this.initialize(a,k)},b=c.prototype;b.x=0;b.y=0;b.initialize=function(a,k){this.x=a==null?0:a;this.y=k==null?0:k};b.clone=function(){return new c(this.x,this.y)};b.toString=function(){return"[Point (x="+this.x+" y="+this.y+")]"};g.Point=c})(createjs||(createjs={}));(function(g){var c=function(a,k,b,d){this.initialize(a,k,b,d)},b=c.prototype;b.x=0;b.y=0;b.width=0;b.height=0;b.initialize=function(a,k,b,d){this.x=a==null?0:a;this.y=k==null?0:k;this.width=b==null?0:b;this.height=d==null?0:d};b.clone=function(){return new c(this.x,this.y,this.width,this.height)};b.toString=function(){return"[Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+")]"};g.Rectangle=c})(createjs||(createjs={}));(function(g){var c=function(a,k,b,d){this.initialize(a,k,b,d)},b=c.prototype;c.identity=null;b.color=null;b.offsetX=0;b.offsetY=0;b.blur=0;b.initialize=function(a,k,b,d){this.color=a;this.offsetX=k;this.offsetY=b;this.blur=d};b.toString=function(){return"[Shadow]"};b.clone=function(){return new c(this.color,this.offsetX,this.offsetY,this.blur)};c.identity=new c("transparent",0,0,0);g.Shadow=c})(createjs||(createjs={}));(function(g){var c=function(a){this.initialize(a)},b=c.prototype;b.complete=true;b.onComplete=null;b._animations=null;b._frames=null;b._images=null;b._data=null;b._loadCount=0;b._frameHeight=0;b._frameWidth=0;b._numFrames=0;b._regX=0;b._regY=0;b.initialize=function(a){var b,m,d;if(a!=null){if(a.images&&(m=a.images.length)>0){d=this._images=[];for(b=0;b<m;b++){var c=a.images[b];if(typeof c=="string"){var f=c,c=new Image;c.src=f}d.push(c);if(!c.getContext&&!c.complete)this._loadCount++,this.complete=
false,function(a){c.onload=function(){a._handleImageLoad()}}(this)}}if(a.frames!=null)if(a.frames instanceof Array){this._frames=[];d=a.frames;for(b=0,m=d.length;b<m;b++)f=d[b],this._frames.push({image:this._images[f[4]?f[4]:0],rect:new g.Rectangle(f[0],f[1],f[2],f[3]),regX:f[5]||0,regY:f[6]||0})}else m=a.frames,this._frameWidth=m.width,this._frameHeight=m.height,this._regX=m.regX||0,this._regY=m.regY||0,this._numFrames=m.count,this._loadCount==0&&this._calculateFrames();if((m=a.animations)!=null){this._animations=
[];this._data={};for(var h in m){a={name:h};f=m[h];if(isNaN(f))if(f instanceof Array){a.frequency=f[3];a.next=f[2];d=a.frames=[];for(b=f[0];b<=f[1];b++)d.push(b)}else a.frequency=f.frequency,a.next=f.next,b=f.frames,d=a.frames=!isNaN(b)?[b]:b.slice(0);else d=a.frames=[f];a.next=d.length<2||a.next==false?null:a.next==null||a.next==true?h:a.next;if(!a.frequency)a.frequency=1;this._animations.push(h);this._data[h]=a}}}};b.getNumFrames=function(a){return a==null?this._frames?this._frames.length:this._numFrames:
(a=this._data[a],a==null?0:a.frames.length)};b.getAnimations=function(){return this._animations.slice(0)};b.getAnimation=function(a){return this._data[a]};b.getFrame=function(a){return this.complete&&this._frames&&(frame=this._frames[a])?frame:null};b.toString=function(){return"[SpriteSheet]"};b.clone=function(){var a=new c;a.complete=this.complete;a._animations=this._animations;a._frames=this._frames;a._images=this._images;a._data=this._data;a._frameHeight=this._frameHeight;a._frameWidth=this._frameWidth;
-a._numFrames=this._numFrames;a._loadCount=this._loadCount;return a};b._handleImageLoad=function(){if(--this._loadCount==0)this._calculateFrames(),this.complete=true,this.onComplete&&this.onComplete()};b._calculateFrames=function(){if(!(this._frames||this._frameWidth==0)){this._frames=[];for(var a=0,b=this._frameWidth,m=this._frameHeight,c=0,e=this._images;c<e.length;c++){for(var f=e[c],h=(f.width+1)/b|0,i=(f.height+1)/m|0,i=this._numFrames>0?Math.min(this._numFrames-a,h*i):h*i,j=0;j<i;j++)this._frames.push({image:f,
-rect:new g.Rectangle(j%h*b,(j/h|0)*m,b,m),regX:this._regX,regY:this._regY});a+=i}this._numFrames=a}};g.SpriteSheet=c})(createjs||(createjs={}));(function(g){function c(a,b,c){this.f=a;this.params=b;this.path=c==null?true:c}c.prototype.exec=function(a){this.f.apply(a,this.params)};var b=function(){this.initialize()},a=b.prototype;b.getRGB=function(a,b,c,e){a!=null&&c==null&&(e=b,c=a&255,b=a>>8&255,a=a>>16&255);return e==null?"rgb("+a+","+b+","+c+")":"rgba("+a+","+b+","+c+","+e+")"};b.getHSL=function(a,b,c,e){return e==null?"hsl("+a%360+","+b+"%,"+c+"%)":"hsla("+a%360+","+b+"%,"+c+"%,"+e+")"};b.BASE_64={A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,
+a._numFrames=this._numFrames;a._loadCount=this._loadCount;return a};b._handleImageLoad=function(){if(--this._loadCount==0)this._calculateFrames(),this.complete=true,this.onComplete&&this.onComplete()};b._calculateFrames=function(){if(!(this._frames||this._frameWidth==0)){this._frames=[];for(var a=0,b=this._frameWidth,m=this._frameHeight,d=0,c=this._images;d<c.length;d++){for(var f=c[d],h=(f.width+1)/b|0,i=(f.height+1)/m|0,i=this._numFrames>0?Math.min(this._numFrames-a,h*i):h*i,j=0;j<i;j++)this._frames.push({image:f,
+rect:new g.Rectangle(j%h*b,(j/h|0)*m,b,m),regX:this._regX,regY:this._regY});a+=i}this._numFrames=a}};g.SpriteSheet=c})(createjs||(createjs={}));(function(g){function c(a,b,d){this.f=a;this.params=b;this.path=d==null?true:d}c.prototype.exec=function(a){this.f.apply(a,this.params)};var b=function(){this.initialize()},a=b.prototype;b.getRGB=function(a,b,d,c){a!=null&&d==null&&(c=b,d=a&255,b=a>>8&255,a=a>>16&255);return c==null?"rgb("+a+","+b+","+d+")":"rgba("+a+","+b+","+d+","+c+")"};b.getHSL=function(a,b,c,e){return e==null?"hsl("+a%360+","+b+"%,"+c+"%)":"hsla("+a%360+","+b+"%,"+c+"%,"+e+")"};b.BASE_64={A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,
J:9,K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25,a:26,b:27,c:28,d:29,e:30,f:31,g:32,h:33,i:34,j:35,k:36,l:37,m:38,n:39,o:40,p:41,q:42,r:43,s:44,t:45,u:46,v:47,w:48,x:49,y:50,z:51,0:52,1:53,2:54,3:55,4:56,5:57,6:58,7:59,8:60,9:61,"+":62,"/":63};b.STROKE_CAPS_MAP=["butt","round","square"];b.STROKE_JOINTS_MAP=["miter","round","bevel"];b._ctx=(g.createCanvas?g.createCanvas():document.createElement("canvas")).getContext("2d");b.beginCmd=new c(b._ctx.beginPath,[],false);
b.fillCmd=new c(b._ctx.fill,[],false);b.strokeCmd=new c(b._ctx.stroke,[],false);a._strokeInstructions=null;a._strokeStyleInstructions=null;a._fillInstructions=null;a._instructions=null;a._oldInstructions=null;a._activeInstructions=null;a._active=false;a._dirty=false;a.initialize=function(){this.clear();this._ctx=b._ctx};a.draw=function(a){this._dirty&&this._updateInstructions();for(var b=this._instructions,c=0,e=b.length;c<e;c++)b[c].exec(a)};a.drawAsPath=function(a){this._dirty&&this._updateInstructions();
for(var b,c=this._instructions,e=0,f=c.length;e<f;e++)((b=c[e]).path||e==0)&&b.exec(a)};a.moveTo=function(a,b){this._activeInstructions.push(new c(this._ctx.moveTo,[a,b]));return this};a.lineTo=function(a,b){this._dirty=this._active=true;this._activeInstructions.push(new c(this._ctx.lineTo,[a,b]));return this};a.arcTo=function(a,b,d,e,f){this._dirty=this._active=true;this._activeInstructions.push(new c(this._ctx.arcTo,[a,b,d,e,f]));return this};a.arc=function(a,b,d,e,f,h){this._dirty=this._active=
@@ -69,12 +69,14 @@ a instanceof HTMLCanvasElement?a:document.getElementById(a);this._pointerData={}
0,this.canvas.width,this.canvas.height)}};b.toDataURL=function(a,b){b||(b="image/png");var c=this.canvas.getContext("2d"),d=this.canvas.width,e=this.canvas.height,f;if(a){f=c.getImageData(0,0,d,e);var h=c.globalCompositeOperation;c.globalCompositeOperation="destination-over";c.fillStyle=a;c.fillRect(0,0,d,e)}var g=this.canvas.toDataURL(b);if(a)c.clearRect(0,0,d,e),c.putImageData(f,0,0),c.globalCompositeOperation=h;return g};b.enableMouseOver=function(a){if(this._mouseOverIntervalID)clearInterval(this._mouseOverIntervalID),
this._mouseOverIntervalID=null;if(a==null)a=20;else if(a<=0)return;var b=this;this._mouseOverIntervalID=setInterval(function(){b._testMouseOver()},1E3/Math.min(50,a))};b.clone=function(){var a=new c(null);this.cloneProps(a);return a};b.toString=function(){return"[Stage (name="+this.name+")]"};b._enableMouseEvents=function(){var a=this,b=window.addEventListener?window:document;b.addEventListener("mouseup",function(b){a._handleMouseUp(b)},false);b.addEventListener("mousemove",function(b){a._handleMouseMove(b)},
false);b.addEventListener("dblclick",function(b){a._handleDoubleClick(b)},false);this.canvas&&this.canvas.addEventListener("mousedown",function(b){a._handleMouseDown(b)},false)};b._getPointerData=function(a){var b=this._pointerData[a];if(!b&&(b=this._pointerData[a]={x:0,y:0},this._primaryPointerID==null))this._primaryPointerID=a;return b};b._handleMouseMove=function(a){if(!a)a=window.event;this._handlePointerMove(-1,a,a.pageX,a.pageY)};b._handlePointerMove=function(a,b,c,d){if(this.canvas){var e=
-this._getPointerData(a),f=e.inBounds;this._updatePointerPosition(a,c,d);if(f||e.inBounds||this.mouseMoveOutside){a=new g.MouseEvent("onMouseMove",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY);if(this.onMouseMove)this.onMouseMove(a);if(e.event&&e.event.onMouseMove)a=a.clone(),a.target=e.event.target,e.event.onMouseMove(a)}}};b._updatePointerPosition=function(a,b,c){var d=this.canvas;do b-=d.offsetLeft,c-=d.offsetTop;while(d=d.offsetParent);var d=this.canvas.width,e=this.canvas.height,f=
-this._getPointerData(a);if(f.inBounds=b>=0&&c>=0&&b<=d-1&&c<=e-1)f.x=b,f.y=c;else if(this.mouseMoveOutside)f.x=b<0?0:b>d-1?d-1:b,f.y=c<0?0:c>e-1?e-1:c;f.rawX=b;f.rawY=c;if(a==this._primaryPointerID)this.mouseX=f.x,this.mouseY=f.y,this.mouseInBounds=f.inBounds};b._handleMouseUp=function(a){this._handlePointerUp(-1,a,false)};b._handlePointerUp=function(a,b,c){var d=this._getPointerData(a),e=new g.MouseEvent("onMouseUp",d.x,d.y,this,b,a,a==this._primaryPointerID,d.rawX,d.rawY);if(this.onMouseUp)this.onMouseUp(e);
-if(d.event&&d.event.onMouseUp)e=e.clone(),e.target=d.event.target,d.event.onMouseUp(e);if(d.target&&d.target.onClick&&this._getObjectsUnderPoint(d.x,d.y,null,true,this._mouseOverIntervalID?3:1)==d.target)d.target.onClick(new g.MouseEvent("onClick",d.x,d.y,d.target,b,a,a==this._primaryPointerID,d.rawX,d.rawY));if(c){if(a==this._primaryPointerID)this._primaryPointerID=null;delete this._pointerData[a]}else d.event=d.target=null};b._handleMouseDown=function(a){this._handlePointerDown(-1,a,false)};b._handlePointerDown=
-function(a,b,c,d){var e=this._getPointerData(a);d!=null&&this._updatePointerPosition(a,c,d);if(this.onMouseDown)this.onMouseDown(new g.MouseEvent("onMouseDown",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY));if(c=this._getObjectsUnderPoint(e.x,e.y,null,this._mouseOverIntervalID?3:1)){if(c.onPress&&(a=new g.MouseEvent("onPress",e.x,e.y,c,b,a,a==this._primaryPointerID,e.rawX,e.rawY),c.onPress(a),a.onMouseMove||a.onMouseUp))e.event=a;e.target=c}};b._testMouseOver=function(){if(this._primaryPointerID==
--1&&!(this.mouseX==this._mouseOverX&&this.mouseY==this._mouseOverY&&this.mouseInBounds)){var a=null;if(this.mouseInBounds)a=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,3),this._mouseOverX=this.mouseX,this._mouseOverY=this.mouseY;if(this._mouseOverTarget!=a){if(this._mouseOverTarget&&this._mouseOverTarget.onMouseOut)this._mouseOverTarget.onMouseOut(new g.MouseEvent("onMouseOut",this.mouseX,this.mouseY,this._mouseOverTarget));if(a&&a.onMouseOver)a.onMouseOver(new g.MouseEvent("onMouseOver",
-this.mouseX,this.mouseY,a));this._mouseOverTarget=a}}};b._handleDoubleClick=function(a){if(this.onDoubleClick)this.onDoubleClick(new g.MouseEvent("onDoubleClick",this.mouseX,this.mouseY,this,a,-1,true));var b=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,this._mouseOverIntervalID?3:1);if(b&&b.onDoubleClick)b.onDoubleClick(new g.MouseEvent("onDoubleClick",this.mouseX,this.mouseY,b,a,-1,true))};g.Stage=c})(createjs||(createjs={}));(function(g){var c=function(a){this.initialize(a)},b=c.prototype=new g.DisplayObject;b.image=null;b.snapToPixel=true;b.sourceRect=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();typeof a=="string"?(this.image=new Image,this.image.src=a):this.image=a};b.isVisible=function(){return this.visible&&this.alpha>0&&this.scaleX!=0&&this.scaleY!=0&&this.image&&(this.image.complete||this.image.getContext||this.image.readyState>=2)};b.DisplayObject_draw=b.draw;
+this._getPointerData(a),f=e.inBounds;this._updatePointerPosition(a,c,d);if(f||e.inBounds||this.mouseMoveOutside){a=new g.MouseEvent("onMouseMove",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY);if(this.onMouseMove)this.onMouseMove(a);if(e.event&&e.event.onMouseMove)a=a.clone(),a.target=e.event.target,e.event.onMouseMove(a)}}};b._updatePointerPosition=function(a,b,c){var d=this._getElementRect(this.canvas);b-=d.left;c-=d.top;var e=this.canvas.width,f=this.canvas.height;b/=(d.right-d.left)/
+e;c/=(d.bottom-d.top)/f;d=this._getPointerData(a);if(d.inBounds=b>=0&&c>=0&&b<=e-1&&c<=f-1)d.x=b,d.y=c;else if(this.mouseMoveOutside)d.x=b<0?0:b>e-1?e-1:b,d.y=c<0?0:c>f-1?f-1:c;d.rawX=b;d.rawY=c;if(a==this._primaryPointerID)this.mouseX=d.x,this.mouseY=d.y,this.mouseInBounds=d.inBounds};b._getElementRect=function(a){var b=a.getBoundingClientRect(),c=(window.pageXOffset||document.scrollLeft||0)-(document.clientLeft||document.body.clientLeft||0),d=(window.pageYOffset||document.scrollTop||0)-(document.clientTop||
+document.body.clientTop||0),e=window.getComputedStyle?getComputedStyle(a):a.currentStyle,a=parseInt(e.paddingLeft)+parseInt(e.borderLeftWidth),f=parseInt(e.paddingTop)+parseInt(e.borderTopWidth),h=parseInt(e.paddingRight)+parseInt(e.borderRightWidth),e=parseInt(e.paddingBottom)+parseInt(e.borderBottomWidth);return{left:b.left+c+a,right:b.right+c-h,top:b.top+d+f,bottom:b.bottom+d-e}};b._handleMouseUp=function(a){this._handlePointerUp(-1,a,false)};b._handlePointerUp=function(a,b,c){var d=this._getPointerData(a),
+e=new g.MouseEvent("onMouseUp",d.x,d.y,this,b,a,a==this._primaryPointerID,d.rawX,d.rawY);if(this.onMouseUp)this.onMouseUp(e);if(d.event&&d.event.onMouseUp)e=e.clone(),e.target=d.event.target,d.event.onMouseUp(e);if(d.target&&d.target.onClick&&this._getObjectsUnderPoint(d.x,d.y,null,true,this._mouseOverIntervalID?3:1)==d.target)d.target.onClick(new g.MouseEvent("onClick",d.x,d.y,d.target,b,a,a==this._primaryPointerID,d.rawX,d.rawY));if(c){if(a==this._primaryPointerID)this._primaryPointerID=null;delete this._pointerData[a]}else d.event=
+d.target=null};b._handleMouseDown=function(a){this._handlePointerDown(-1,a,false)};b._handlePointerDown=function(a,b,c,d){var e=this._getPointerData(a);d!=null&&this._updatePointerPosition(a,c,d);if(this.onMouseDown)this.onMouseDown(new g.MouseEvent("onMouseDown",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY));if(c=this._getObjectsUnderPoint(e.x,e.y,null,this._mouseOverIntervalID?3:1)){if(c.onPress&&(a=new g.MouseEvent("onPress",e.x,e.y,c,b,a,a==this._primaryPointerID,e.rawX,e.rawY),c.onPress(a),
+a.onMouseMove||a.onMouseUp))e.event=a;e.target=c}};b._testMouseOver=function(){if(this._primaryPointerID==-1&&!(this.mouseX==this._mouseOverX&&this.mouseY==this._mouseOverY&&this.mouseInBounds)){var a=null;if(this.mouseInBounds)a=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,3),this._mouseOverX=this.mouseX,this._mouseOverY=this.mouseY;if(this._mouseOverTarget!=a){if(this._mouseOverTarget&&this._mouseOverTarget.onMouseOut)this._mouseOverTarget.onMouseOut(new g.MouseEvent("onMouseOut",this.mouseX,
+this.mouseY,this._mouseOverTarget));if(a&&a.onMouseOver)a.onMouseOver(new g.MouseEvent("onMouseOver",this.mouseX,this.mouseY,a));this._mouseOverTarget=a}}};b._handleDoubleClick=function(a){if(this.onDoubleClick)this.onDoubleClick(new g.MouseEvent("onDoubleClick",this.mouseX,this.mouseY,this,a,-1,true));var b=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,this._mouseOverIntervalID?3:1);if(b&&b.onDoubleClick)b.onDoubleClick(new g.MouseEvent("onDoubleClick",this.mouseX,this.mouseY,b,a,-1,true))};
+g.Stage=c})(createjs||(createjs={}));(function(g){var c=function(a){this.initialize(a)},b=c.prototype=new g.DisplayObject;b.image=null;b.snapToPixel=true;b.sourceRect=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();typeof a=="string"?(this.image=new Image,this.image.src=a):this.image=a};b.isVisible=function(){return this.visible&&this.alpha>0&&this.scaleX!=0&&this.scaleY!=0&&this.image&&(this.image.complete||this.image.getContext||this.image.readyState>=2)};b.DisplayObject_draw=b.draw;
b.draw=function(a,b){if(this.DisplayObject_draw(a,b))return true;var c=this.sourceRect;c?a.drawImage(this.image,c.x,c.y,c.width,c.height,0,0,c.width,c.height):a.drawImage(this.image,0,0);return true};b.clone=function(){var a=new c(this.image);this.cloneProps(a);return a};b.toString=function(){return"[Bitmap (name="+this.name+")]"};g.Bitmap=c})(createjs||(createjs={}));(function(g){var c=function(a){this.initialize(a)},b=c.prototype=new g.DisplayObject;b.onAnimationEnd=null;b.currentFrame=-1;b.currentAnimation=null;b.paused=true;b.spriteSheet=null;b.snapToPixel=true;b.offset=0;b.currentAnimationFrame=0;b._advanceCount=0;b._animation=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();this.spriteSheet=a};b.isVisible=function(){return this.visible&&this.alpha>0&&this.scaleX!=0&&this.scaleY!=0&&this.spriteSheet.complete&&
this.currentFrame>=0};b.DisplayObject_draw=b.draw;b.draw=function(a,b){if(this.DisplayObject_draw(a,b))return true;this._normalizeFrame();var c=this.spriteSheet.getFrame(this.currentFrame);if(c!=null){var d=c.rect;a.drawImage(c.image,d.x,d.y,d.width,d.height,-c.regX,-c.regY,d.width,d.height);return true}};b.play=function(){this.paused=false};b.stop=function(){this.paused=true};b.gotoAndPlay=function(a){this.paused=false;this._goto(a)};b.gotoAndStop=function(a){this.paused=true;this._goto(a)};b.advance=
function(){this._animation?this.currentAnimationFrame++:this.currentFrame++;this._normalizeFrame()};b.clone=function(){var a=new c(this.spriteSheet);this.cloneProps(a);return a};b.toString=function(){return"[BitmapAnimation (name="+this.name+")]"};b.DisplayObject__tick=b._tick;b._tick=function(a){var b=this._animation?this._animation.frequency:1;!this.paused&&(++this._advanceCount+this.offset)%b==0&&this.advance();this.DisplayObject__tick(a)};b._normalizeFrame=function(){var a=this._animation;if(a)if(this.currentAnimationFrame>=
View
36 src/easeljs/display/Stage.js
@@ -410,14 +410,14 @@ var p = Stage.prototype = new ns.Container();
* @param {Number} pageY
**/
p._updatePointerPosition = function(id, pageX, pageY) {
- var element = this.canvas;
- do {
- pageX -= element.offsetLeft;
- pageY -= element.offsetTop;
- } while (element = element.offsetParent);
+ var rect = this._getElementRect(this.canvas);
+ pageX -= rect.left;
+ pageY -= rect.top;
var w = this.canvas.width;
var h = this.canvas.height;
+ pageX /= (rect.right-rect.left)/w;
+ pageY /= (rect.bottom-rect.top)/h;
var o = this._getPointerData(id);
if (o.inBounds = (pageX >= 0 && pageY >= 0 && pageX <= w-1 && pageY <= h-1)) {
o.x = pageX;
@@ -436,6 +436,32 @@ var p = Stage.prototype = new ns.Container();
this.mouseInBounds = o.inBounds;
}
}
+
+ /**
+ * @method _getElementRect
+ * @protected
+ * @param {HTMLElement} e
+ **/
+ p._getElementRect = function(e) {
+ // TODO: should we add support for padding and borders here?
+ var bounds = e.getBoundingClientRect();
+ var offX = (window.pageXOffset || document.scrollLeft || 0) - (document.clientLeft || document.body.clientLeft || 0);
+ var offY = (window.pageYOffset || document.scrollTop || 0) - (document.clientTop || document.body.clientTop || 0);
+
+ var styles = window.getComputedStyle ? getComputedStyle(e) : e.currentStyle; // IE <9 compatibility.
+ var padL = parseInt(styles.paddingLeft)+parseInt(styles.borderLeftWidth);
+ var padT = parseInt(styles.paddingTop)+parseInt(styles.borderTopWidth);
+ var padR = parseInt(styles.paddingRight)+parseInt(styles.borderRightWidth);
+ var padB = parseInt(styles.paddingBottom)+parseInt(styles.borderBottomWidth);
+
+ // note: in some browsers bounds properties are read only.
+ return {
+ left: bounds.left+offX+padL,
+ right: bounds.right+offX-padR,
+ top: bounds.top+offY+padT,
+ bottom: bounds.bottom+offY-padB
+ }
+ }
/**
* @method _handleMouseUp
Please sign in to comment.
Something went wrong with that request. Please try again.