Advertisement
henke37

DisplayObjectProxy

Aug 8th, 2013
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package HTools.Starling {
  2.     import flash.geom.*;
  3.  
  4.     import starling.core.RenderSupport;
  5.     //import starling.core.starling_internal;
  6.     import starling.filters.FragmentFilter;
  7.     import starling.utils.MatrixUtil;
  8.  
  9.     //use namespace starling_internal;
  10.  
  11.     public class DisplayObjectProxy extends DisplayObject {
  12.         public var real:DisplayObject;
  13.  
  14.         /** Helper objects. */
  15.         private static var scratchMatrix:Matrix = new Matrix();
  16.         private static var scratchPoint:Point = new Point();
  17.  
  18.         public function DisplayObjectProxy() {
  19.  
  20.         }
  21.  
  22.         /** @inheritDoc */
  23.         public override function getBounds(targetSpace:DisplayObject, resultRect:Rectangle = null):Rectangle {
  24.             resultRect ||= new Rectangle();
  25.  
  26.             resultRect = real.getBounds(targetSpace, resultRect);
  27.  
  28.             return resultRect;
  29.         }
  30.  
  31.         /** @inheritDoc */
  32.         public override function hitTest(localPoint:Point, forTouch:Boolean = false):DisplayObject {
  33.             if(forTouch && (!visible || !touchable)) {
  34.                 return null;
  35.             }
  36.  
  37.             var localX:Number = localPoint.x;
  38.             var localY:Number = localPoint.y;
  39.  
  40.             var child: DisplayObject = real;
  41.             getTransformationMatrix(child, scratchMatrix);
  42.  
  43.             MatrixUtil.transformCoords(scratchMatrix, localX, localY, scratchPoint);
  44.             var target: DisplayObject = real.hitTest(scratchPoint, forTouch);
  45.  
  46.             return target;
  47.         }
  48.  
  49.         /** @inheritDoc */
  50.         public override function render(support:RenderSupport, parentAlpha:Number):void {
  51.             if(!real.hasVisibleArea) return;
  52.            
  53.             var alpha:Number = parentAlpha * this.alpha;
  54.             var oldBlendMode:String = support.blendMode;
  55.            
  56.             support.pushMatrix();
  57.             support.transformMatrix(real);
  58.             support.blendMode = real.blendMode;
  59.            
  60.             var filter:FragmentFilter = real.filter;
  61.  
  62.             if(filter) {
  63.                 filter.render(real, support, alpha);
  64.             } else {
  65.                 real.render(support, alpha);
  66.             }
  67.  
  68.             support.blendMode = oldBlendMode;
  69.             support.popMatrix();
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement