mirror of
https://github.com/hiloteam/Hilo.git
synced 2026-01-25 16:25:48 +00:00
6 lines
4.0 KiB
JavaScript
6 lines
4.0 KiB
JavaScript
/**
|
|
* hilojs 2.0.3 for cmd
|
|
* Copyright 2016 alibaba.com
|
|
* Licensed under the MIT License
|
|
*/
|
|
define(function(t,e,i){var n=t("hilo/core/Hilo"),r=t("hilo/core/Class"),o=t("hilo/event/EventMixin"),a=t("hilo/geom/Matrix"),s=t("hilo/util/util"),h=function(){function t(t,e,i){for(var n,r,o,a,s=0,h=!1,u=0,l=i.length;u<l;u++){var y=i[u],c=i[(u+1)%l];if(y.y==c.y&&e==y.y&&(y.x>c.x?(n=c.x,r=y.x):(n=y.x,r=c.x),t>=n&&t<=r))h=!0;else if(y.y>c.y?(o=c.y,a=y.y):(o=y.y,a=c.y),!(e<o||e>a)){var x=(e-y.y)*(c.x-y.x)/(c.y-y.y)+y.x;if(x>t?s++:x==t&&(h=!0),y.x>t&&y.y==e){var d=i[(l+u-1)%l];(d.y<e&&c.y>e||d.y>e&&c.y<e)&&s++}}}return h||s%2==1}function e(t,e){var n=i(t,e,{overlap:-(1/0),normal:{x:0,y:0}});return!!n&&i(e,t,n)}function i(t,e,i){for(var n,r,o,a,s,h,u,l,y,c=t.length,x=e.length,d={x:0,y:0},f=0;f<c;f++){n=t[f],r=t[f<c-1?f+1:0],d.x=n.y-r.y,d.y=r.x-n.x,o=Math.sqrt(d.x*d.x+d.y*d.y),d.x/=o,d.y/=o,a=s=t[0].x*d.x+t[0].y*d.y;for(var v=1;v<c;v++)l=t[v].x*d.x+t[v].y*d.y,l>s?s=l:l<a&&(a=l);for(h=u=e[0].x*d.x+e[0].y*d.y,v=1;v<x;v++)l=e[v].x*d.x+e[v].y*d.y,l>u?u=l:l<h&&(h=l);if(a<h?(y=h-s,d.x=-d.x,d.y=-d.y):y=a-u,y>=0)return!1;y>i.overlap&&(i.overlap=y,i.normal.x=d.x,i.normal.y=d.y)}return i}return r.create({Mixes:o,constructor:function(t){t=t||{},this.id=this.id||t.id||n.getUid("View"),s.copy(this,t,!0)},tint:16777215,id:null,x:0,y:0,width:0,height:0,alpha:1,rotation:0,visible:!0,pivotX:0,pivotY:0,scaleX:1,scaleY:1,pointerEnabled:!0,background:null,mask:null,align:null,drawable:null,boundsArea:null,parent:null,depth:-1,transform:null,blendMode:"source-over",getStage:function(){for(var t,e=this;t=e.parent;)e=t;return e.canvas?e:null},getScaledWidth:function(){return this.width*this.scaleX},getScaledHeight:function(){return this.height*this.scaleY},addTo:function(t,e){return"number"==typeof e?t.addChildAt(this,e):t.addChild(this),this},removeFromParent:function(){var t=this.parent;return t&&t.removeChild(this),this},getBounds:function(){for(var t,e,i,n,r,o,a,s=this.width,h=this.height,u=this.getConcatenatedMatrix(),l=this.boundsArea||[{x:0,y:0},{x:s,y:0},{x:s,y:h},{x:0,y:h}],y=[],c=0,x=l.length;c<x;c++)t=u.transformPoint(l[c],!0,!0),e=t.x,i=t.y,0==c?(n=r=e,o=a=i):(n>e?n=e:r<e&&(r=e),o>i?o=i:a<i&&(a=i)),y[c]=t;return y.x=n,y.y=o,y.width=r-n,y.height=a-o,y},getConcatenatedMatrix:function(t){for(var e=new a(1,0,0,1,0,0),i=this;i!=t&&i.parent;i=i.parent){var n=1,r=0,o=i.rotation%360,s=i.pivotX,h=i.pivotY,u=i.scaleX,l=i.scaleY,y=i.transform;if(y)e.concat(y);else{if(o){var c=o*Math.PI/180;n=Math.cos(c),r=Math.sin(c)}0!=s&&(e.tx-=s),0!=h&&(e.ty-=h);var x=i.getAlignPosition();e.concat(n*u,r*u,-r*l,n*l,x.x,x.y)}}return e},getAlignPosition:function(){var t=this.parent,e=this.align,i=this.x,n=this.y;if(t&&this.align){if("function"==typeof e)return this.align();var r=this.width,o=this.height,a=t.width,s=t.height;switch(e){case"TL":i=0,n=0;break;case"T":i=a-r>>1,n=0;break;case"TR":i=a-r,n=0;break;case"L":i=0,n=s-o>>1;break;case"C":i=a-r>>1,n=s-o>>1;break;case"R":i=a-r,n=s-o>>1;break;case"BL":i=0,n=s-o;break;case"B":i=a-r>>1,n=s-o;break;case"BR":i=a-r,n=s-o}}return{x:i,y:n}},hitTestPoint:function(e,i,n){var r=this.getBounds(),o=e>=r.x&&e<=r.x+r.width&&i>=r.y&&i<=r.y+r.height;return o&&n&&(o=t(e,i,r)),o},hitTestObject:function(t,i){var n=this.getBounds(),r=t.getBounds(),o=n.x<=r.x+r.width&&r.x<=n.x+n.width&&n.y<=r.y+r.height&&r.y<=n.y+n.height;return o&&i&&(o=e(n,r)),!!o},_render:function(t,e){this.onUpdate&&this.onUpdate(e)===!1||!t.startDraw(this)||(t.transform(this),this.render(t,e),t.endDraw(this))},_fireMouseEvent:function(t){if(t.eventCurrentTarget=this,this.fire(t),"mousemove"==t.type){if(!this.__mouseOver){this.__mouseOver=!0;var e=s.copy({},t);e.type="mouseover",this.fire(e)}}else"mouseout"==t.type&&(this.__mouseOver=!1);var i=this.parent;t._stopped||t._stopPropagationed||!i||("mouseout"==t.type||"touchout"==t.type?i.hitTestPoint(t.stageX,t.stageY,!0)||i._fireMouseEvent(t):i._fireMouseEvent(t))},onUpdate:null,render:function(t,e){t.draw(this)},toString:function(){return n.viewToString(this)}})}();return h}); |