public AsTouchProcessor(AsStage stage)
 {
     mStage = stage;
     mElapsedTime = 0.0f;
     mCurrentTouches = new AsVector<AsTouch>();
     mQueue = new AsVector<AsArray>();
     mLastTaps = new AsVector<AsTouch>();
     mStage.addEventListener(AsKeyboardEvent.KEY_DOWN, onKey);
     mStage.addEventListener(AsKeyboardEvent.KEY_UP, onKey);
     monitorInterruptions(true);
 }
        public AsStarling(AsClass rootClass, bc.flash.display.AsStage stage, AsRectangle viewPort, AsStage3D stage3D, String renderMode, String profile)
        {
            if (stage == null)
            {
                throw new AsArgumentError("Stage must not be null");
            }
            if (rootClass == null)
            {
                throw new AsArgumentError("Root class must not be null");
            }
            if (viewPort == null)
            {
                viewPort = new AsRectangle(0, 0, stage.getStageWidth(), stage.getStageHeight());
            }
            if (stage3D == null)
            {
                stage3D = stage.getStage3Ds()[0];
            }
            makeCurrent();
            mRootClass     = rootClass;
            mViewPort      = viewPort;
            mStage3D       = stage3D;
            mStage         = new AsStage(viewPort.width, viewPort.height, stage.getColor());
            mNativeOverlay = new AsSprite();
            mNativeStage   = stage;
            mNativeStage.addChild(mNativeOverlay);
            mTouchProcessor      = new AsTouchProcessor(mStage);
            mJuggler             = new AsJuggler();
            mAntiAliasing        = 0;
            mSimulateMultitouch  = false;
            mEnableErrorChecking = false;
            mLastFrameTimestamp  = AsGlobal.getTimer() / 1000.0f;
            mPrograms            = new AsDictionary();
            mCustomData          = new AsDictionary();
            mSupport             = new AsRenderSupport();
            AsArray __touchEventTypes_ = getTouchEventTypes();

            if (__touchEventTypes_ != null)
            {
                foreach (String touchEventType in __touchEventTypes_)
                {
                    stage.addEventListener(touchEventType, onTouch, false, 0, true);
                }
            }
            stage.addEventListener(AsEvent.ENTER_FRAME, onEnterFrame, false, 0, true);
            stage.addEventListener(AsKeyboardEvent.KEY_DOWN, onKey, false, 0, true);
            stage.addEventListener(AsKeyboardEvent.KEY_UP, onKey, false, 0, true);
            stage.addEventListener(AsEvent.RESIZE, onResize, false, 0, true);
            if (mStage3D.getContext3D() != null && mStage3D.getContext3D().getDriverInfo() != "Disposed")
            {
                mShareContext = true;
                AsGlobal.setTimeout(initialize, 1);
            }
            else
            {
                mShareContext = false;
                mStage3D.addEventListener(AsEvent.CONTEXT3D_CREATE, onContextCreated, false, 1, true);
                mStage3D.addEventListener(AsErrorEvent.ERROR, onStage3DError, false, 1, true);
                try
                {
                    mStage3D.requestContext3D(renderMode);
                }
                catch (AsError e)
                {
                    showFatalError("Context3D error: " + e.message);
                }
            }
        }
 private void calculateBounds(AsDisplayObject _object, AsStage stage, AsRectangle resultRect)
 {
     if(_object == stage || _object == AsStarling.getCurrent().getRoot())
     {
         resultRect.setTo(0, 0, stage.getStageWidth(), stage.getStageHeight());
     }
     else
     {
         _object.getBounds(stage, resultRect);
     }
     float deltaMargin = mResolution == 1.0f ? 0.0f : 1.0f / mResolution;
     resultRect.x = resultRect.x - mMarginX + deltaMargin;
     resultRect.y = resultRect.y - mMarginY + deltaMargin;
     resultRect.width = resultRect.width + 2 * (mMarginX + deltaMargin);
     resultRect.height = resultRect.height + 2 * (mMarginY + deltaMargin);
     resultRect.width = AsGlobal.getNextPowerOfTwo((int)(resultRect.width * mResolution)) / mResolution;
     resultRect.height = AsGlobal.getNextPowerOfTwo((int)(resultRect.height * mResolution)) / mResolution;
 }
 public AsStarling(AsClass rootClass, bc.flash.display.AsStage stage, AsRectangle viewPort, AsStage3D stage3D, String renderMode, String profile)
 {
     if(stage == null)
     {
         throw new AsArgumentError("Stage must not be null");
     }
     if(rootClass == null)
     {
         throw new AsArgumentError("Root class must not be null");
     }
     if(viewPort == null)
     {
         viewPort = new AsRectangle(0, 0, stage.getStageWidth(), stage.getStageHeight());
     }
     if(stage3D == null)
     {
         stage3D = stage.getStage3Ds()[0];
     }
     makeCurrent();
     mRootClass = rootClass;
     mViewPort = viewPort;
     mStage3D = stage3D;
     mStage = new AsStage(viewPort.width, viewPort.height, stage.getColor());
     mNativeOverlay = new AsSprite();
     mNativeStage = stage;
     mNativeStage.addChild(mNativeOverlay);
     mTouchProcessor = new AsTouchProcessor(mStage);
     mJuggler = new AsJuggler();
     mAntiAliasing = 0;
     mSimulateMultitouch = false;
     mEnableErrorChecking = false;
     mLastFrameTimestamp = AsGlobal.getTimer() / 1000.0f;
     mPrograms = new AsDictionary();
     mCustomData = new AsDictionary();
     mSupport = new AsRenderSupport();
     AsArray __touchEventTypes_ = getTouchEventTypes();
     if (__touchEventTypes_ != null)
     {
         foreach (String touchEventType in __touchEventTypes_)
         {
             stage.addEventListener(touchEventType, onTouch, false, 0, true);
         }
     }
     stage.addEventListener(AsEvent.ENTER_FRAME, onEnterFrame, false, 0, true);
     stage.addEventListener(AsKeyboardEvent.KEY_DOWN, onKey, false, 0, true);
     stage.addEventListener(AsKeyboardEvent.KEY_UP, onKey, false, 0, true);
     stage.addEventListener(AsEvent.RESIZE, onResize, false, 0, true);
     if(mStage3D.getContext3D() != null && mStage3D.getContext3D().getDriverInfo() != "Disposed")
     {
         mShareContext = true;
         AsGlobal.setTimeout(initialize, 1);
     }
     else
     {
         mShareContext = false;
         mStage3D.addEventListener(AsEvent.CONTEXT3D_CREATE, onContextCreated, false, 1, true);
         mStage3D.addEventListener(AsErrorEvent.ERROR, onStage3DError, false, 1, true);
         try
         {
             mStage3D.requestContext3D(renderMode);
         }
         catch (AsError e)
         {
             showFatalError("Context3D error: " + e.message);
         }
     }
 }