public virtual void testVectorPush()
 {
     AsVector<String> v = new AsVector<String>();
     v.push();
     v.push("a");
     v.push("a", "b", "c");
     v.push(new AsArray("a", "b", "c"));
 }
        public virtual void testVectorPush()
        {
            AsVector <String> v = new AsVector <String>();

            v.push();
            v.push("a");
            v.push("a", "b", "c");
            v.push(new AsArray("a", "b", "c"));
        }
Beispiel #3
0
        public virtual AsVector <AsTexture> getTextures(String prefix)
        {
            AsVector <AsTexture> textures = new AsVector <AsTexture>();
            AsVector <String>    names    = new AsVector <String>();
            AsDictionary         __names_ = mTextureRegions;

            if (__names_ != null)
            {
                foreach (String name in __names_)
                {
                    if (AsString.indexOf(name, prefix) == 0)
                    {
                        names.push(name);
                    }
                }
            }
            names.sort(AsArray.CASEINSENSITIVE);
            AsVector <String> __names_ = names;

            if (__names_ != null)
            {
                foreach (String name in __names_)
                {
                    textures.push(getTexture(name));
                }
            }
            return(textures);
        }
        private void processTap(AsTouch touch)
        {
            AsTouch            nearbyTap = null;
            float              minSqDist = MULTITAP_DISTANCE * MULTITAP_DISTANCE;
            AsVector <AsTouch> __taps_   = mLastTaps;

            if (__taps_ != null)
            {
                foreach (AsTouch tap in __taps_)
                {
                    float sqDist = AsMath.pow(tap.getGlobalX() - touch.getGlobalX(), 2) + AsMath.pow(tap.getGlobalY() - touch.getGlobalY(), 2);
                    if (sqDist <= minSqDist)
                    {
                        nearbyTap = tap;
                        break;
                    }
                }
            }
            if (nearbyTap != null)
            {
                touch.setTapCount(nearbyTap.getTapCount() + 1);
                mLastTaps.splice(mLastTaps.indexOf(nearbyTap), (uint)(1));
            }
            else
            {
                touch.setTapCount(1);
            }
            mLastTaps.push(touch.clone());
        }
Beispiel #5
0
 public virtual void removeEventListener(String type, AsEventListenerCallback listener, bool useCapture)
 {
     if (mEventListeners != null)
     {
         AsVector <AsEventListenerCallback> listeners = (AsVector <AsEventListenerCallback>)(mEventListeners[type]);
         if (listeners != null)
         {
             AsVector <AsEventListenerCallback> remainListeners   = new AsVector <AsEventListenerCallback>();
             AsVector <AsEventListenerCallback> __eventListeners_ = listeners;
             if (__eventListeners_ != null)
             {
                 foreach (AsEventListenerCallback eventListener in __eventListeners_)
                 {
                     if (eventListener != listener)
                     {
                         remainListeners.push(eventListener);
                     }
                 }
             }
             if (remainListeners.getLength() > 0)
             {
                 mEventListeners[type] = remainListeners;
             }
             else
             {
                 mEventListeners.remove(type);
             }
         }
     }
 }
 public virtual void pushMatrix()
 {
     if (mMatrixStack.getLength() < mMatrixStackSize + 1)
     {
         mMatrixStack.push(new AsMatrix());
     }
     mMatrixStack[mMatrixStackSize++].copyFrom(mModelViewMatrix);
 }
        public void testSort()
        {
            AsVector<int> vector = new AsVector<int>();
            vector.push(3);
            vector.push(1);
            vector.push(4);
            vector.push(0);

            vector.sort(sorter);
            List<int> list = vector.internalList;
            foreach (int i in list)
            {
                Console.WriteLine(i);
            }

            Assert.AreEqual(vector[0] == 0 && vector[1] == 1 && vector[2] == 3 && vector[3] == 4, true);
        }
 public virtual void pushMatrix()
 {
     if ((mMatrixStack.getLength() < (mMatrixStackSize + 1)))
     {
         mMatrixStack.push(new AsMatrix());
     }
     mMatrixStack[mMatrixStackSize++].copyFrom(mCurrentMatrix);
 }
 public virtual void testGeneric()
 {
     AsVector<bc.test.basic.packages.foo.AsPackageClass> v1 = new AsVector<bc.test.basic.packages.foo.AsPackageClass>();
     AsVector<bc.test.basic.packages.bar.AsPackageClass> v2 = new AsVector<bc.test.basic.packages.bar.AsPackageClass>();
     v1.push(foo1);
     v2.push(foo2);
     foo1 = v1[0];
     foo2 = v2[0];
 }
Beispiel #10
0
 public static void toPool(AsTween tween)
 {
     tween.mOnStart        = tween.mOnUpdate = tween.mOnRepeat = tween.mOnComplete = null;
     tween.mOnStartArgs    = tween.mOnUpdateArgs = tween.mOnRepeatArgs = tween.mOnCompleteArgs = null;
     tween.mTarget         = null;
     tween.mTransitionFunc = null;
     tween.removeEventListeners();
     sTweenPool.push(tween);
 }
Beispiel #11
0
        public virtual void testGeneric()
        {
            AsVector <bc.test.basic.packages.foo.AsPackageClass> v1 = new AsVector <bc.test.basic.packages.foo.AsPackageClass>();
            AsVector <bc.test.basic.packages.bar.AsPackageClass> v2 = new AsVector <bc.test.basic.packages.bar.AsPackageClass>();

            v1.push(foo1);
            v2.push(foo2);
            foo1 = v1[0];
            foo2 = v2[0];
        }
Beispiel #12
0
 public virtual void animate(String property, float targetValue)
 {
     if (mTarget == null)
     {
         return;
     }
     mProperties.push(property);
     mStartValues.push(AsNumber.NaN);
     mEndValues.push(targetValue);
 }
Beispiel #13
0
 public virtual void _add(AsIAnimatable _object)
 {
     if (_object != null && mObjects.indexOf(_object) == -1)
     {
         mObjects.push(_object);
         AsEventDispatcher dispatcher = _object as AsEventDispatcher;
         if (dispatcher != null)
         {
             dispatcher.addEventListener(AsEvent.REMOVE_FROM_JUGGLER, onRemove);
         }
     }
 }
        private void addCurrentTouch(AsTouch touch)
        {
            int i = (int)(mCurrentTouches.getLength() - 1);

            for (; i >= 0; --i)
            {
                if (mCurrentTouches[i].getId() == touch.getId())
                {
                    mCurrentTouches.splice(i, (uint)(1));
                }
            }
            mCurrentTouches.push(touch);
        }
        public virtual void finishQuadBatch()
        {
            AsQuadBatch currentBatch = mQuadBatches[mCurrentQuadBatchID];

            if (currentBatch.getNumQuads() != 0)
            {
                currentBatch.renderCustom(mProjectionMatrix);
                currentBatch.reset();
                ++mCurrentQuadBatchID;
                ++mDrawCount;
                if (mQuadBatches.getLength() <= mCurrentQuadBatchID)
                {
                    mQuadBatches.push(new AsQuadBatch());
                }
            }
        }
        public virtual void setNumVertices(int _value)
        {
            mRawData.setOwnProperty("_fixed", false);
            int i     = 0;
            int delta = _value - mNumVertices;

            for (i = 0; i < delta; ++i)
            {
                mRawData.push(0, 0, 0, 0, 0, 1, 0, 0);
            }
            for (i = 0; i < -(delta * ELEMENTS_PER_VERTEX); ++i)
            {
                mRawData.pop();
            }
            mNumVertices = _value;
            mRawData.setOwnProperty("_fixed", true);
        }
        public virtual AsVector <AsTouch> getTouches(AsDisplayObject target, String phase)
        {
            AsVector <AsTouch> touchesFound = new AsVector <AsTouch>();
            int numTouches = (int)(mTouches.getLength());
            int i          = 0;

            for (; i < numTouches; ++i)
            {
                AsTouch touch         = mTouches[i];
                bool    correctTarget = (touch.getTarget() == target) || ((target is AsDisplayObjectContainer) && target as AsDisplayObjectContainer.contains(touch.getTarget()));
                bool    correctPhase  = phase == null || phase == touch.getPhase();
                if (correctTarget && correctPhase)
                {
                    touchesFound.push(touch);
                }
            }
            return(touchesFound);
        }
        private void getChildEventListeners(AsDisplayObject _object, String eventType, AsVector <AsDisplayObject> listeners)
        {
            AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;

            if (_object.hasEventListener(eventType))
            {
                listeners.push(_object);
            }
            if (container != null && container.getNumChildren() > 0)
            {
                AsVector <AsDisplayObject> children = container.mChildren;
                int numChildren = (int)(children.getLength());
                int i           = 0;
                for (; i < numChildren; ++i)
                {
                    getChildEventListeners(children[i], eventType, listeners);
                }
            }
        }
        public virtual void addEventListener(String type, AsEventListenerCallback listener)
        {
            if (mEventListeners == null)
            {
                mEventListeners = new AsDictionary();
            }
            AsVector <AsEventListenerCallback> listeners = mEventListeners[type] as AsVector <AsEventListenerCallback>;

            if (listeners == null)
            {
                mEventListeners[type] = new AsVector <AsEventListenerCallback>();
            }
            else
            {
                if (listeners.indexOf(listener) == -1)
                {
                    listeners.push(listener);
                }
            }
        }
 public virtual void removeEventListener(String type, AsEventListenerCallback listener)
 {
     if (mEventListeners != null)
     {
         AsVector <AsEventListenerCallback> listeners = mEventListeners[type] as AsVector <AsEventListenerCallback>;
         if (listeners != null)
         {
             int numListeners = (int)(listeners.getLength());
             AsVector <AsEventListenerCallback> remainingListeners = new AsVector <AsEventListenerCallback>();
             int i = 0;
             for (; i < numListeners; ++i)
             {
                 if (listeners[i] != listener)
                 {
                     remainingListeners.push(listeners[i]);
                 }
             }
             mEventListeners[type] = remainingListeners;
         }
     }
 }
        public virtual AsDisplayObject addChildAt(AsDisplayObject child, int index)
        {
            int numChildren = (int)(mChildren.getLength());

            if (index >= 0 && index <= numChildren)
            {
                child.removeFromParent();
                if (index == numChildren)
                {
                    mChildren.push(child);
                }
                else
                {
                    mChildren.splice(index, (uint)(0), child);
                }
                child.setParent(this);
                child.dispatchEventWith(AsEvent.ADDED, true);
                if (getStage() != null)
                {
                    AsDisplayObjectContainer container = child as AsDisplayObjectContainer;
                    if (container != null)
                    {
                        container.broadcastEventWith(AsEvent.ADDED_TO_STAGE);
                    }
                    else
                    {
                        child.dispatchEventWith(AsEvent.ADDED_TO_STAGE);
                    }
                }
                return(child);
            }
            else
            {
                throw new AsRangeError("Invalid child index");
            }
        }
 public virtual void dispatch(AsVector <AsEventDispatcher> chain)
 {
     if (chain != null && chain.getLength() != 0)
     {
         int chainLength = (int)(getBubbles() ? chain.getLength() : 1);
         AsEventDispatcher previousTarget = getTarget();
         setTarget(chain[0] as AsEventDispatcher);
         int i = 0;
         for (; i < chainLength; ++i)
         {
             AsEventDispatcher chainElement = chain[i] as AsEventDispatcher;
             if (mVisitedObjects.indexOf(chainElement) == -1)
             {
                 bool stopPropagation = chainElement.invokeEvent(this);
                 mVisitedObjects.push(chainElement);
                 if (stopPropagation)
                 {
                     break;
                 }
             }
         }
         setTarget(previousTarget);
     }
 }
        public virtual AsMatrix getTransformationMatrix(AsDisplayObject targetSpace, AsMatrix resultMatrix)
        {
            if (resultMatrix != null)
            {
                resultMatrix.identity();
            }
            else
            {
                resultMatrix = new AsMatrix();
            }
            AsDisplayObject currentObject = this;

            if (targetSpace == this)
            {
                return(resultMatrix);
            }
            else
            {
                if (targetSpace == mParent || (targetSpace == null && mParent == null))
                {
                    if (mPivotX != 0.0f || mPivotY != 0.0f)
                    {
                        resultMatrix.translate(-mPivotX, -mPivotY);
                    }
                    if (mScaleX != 1.0f || mScaleY != 1.0f)
                    {
                        resultMatrix.scale(mScaleX, mScaleY);
                    }
                    if (mRotation != 0.0f)
                    {
                        resultMatrix.rotate(AsMathHelper.toRadians(mRotation));
                    }
                    if (mX != 0.0f || mY != 0.0f)
                    {
                        resultMatrix.translate(mX, mY);
                    }
                    return(resultMatrix);
                }
                else
                {
                    if (targetSpace == null)
                    {
                        currentObject = this;
                        while (currentObject != null)
                        {
                            currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
                            resultMatrix.concat(sHelperMatrix);
                            currentObject = currentObject.getParent();
                        }
                        return(resultMatrix);
                    }
                    else
                    {
                        if (targetSpace.mParent == this)
                        {
                            targetSpace.getTransformationMatrix(this, resultMatrix);
                            resultMatrix.invert();
                            return(resultMatrix);
                        }
                    }
                }
            }
            sAncestors.setLength(0);
            AsDisplayObject commonParent = null;

            while (currentObject != null)
            {
                sAncestors.push(currentObject);
                currentObject = currentObject.getParent();
            }
            currentObject = targetSpace;
            while (currentObject != null && sAncestors.indexOf(currentObject) == -1)
            {
                currentObject = currentObject.getParent();
            }
            if (currentObject == null)
            {
                throw new AsArgumentError("Object not connected to target");
            }
            else
            {
                commonParent = currentObject;
            }
            currentObject = this;
            while (currentObject != commonParent)
            {
                currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
                resultMatrix.concat(sHelperMatrix);
                currentObject = currentObject.getParent();
            }
            sTargetMatrix.identity();
            currentObject = targetSpace;
            while (currentObject != commonParent)
            {
                currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix);
                sTargetMatrix.concat(sHelperMatrix);
                currentObject = currentObject.getParent();
            }
            sTargetMatrix.invert();
            resultMatrix.concat(sTargetMatrix);
            return(resultMatrix);
        }
Beispiel #24
0
 public static void toPool(AsEvent _event)
 {
     _event.mData = _event.mTarget = _event.mCurrentTarget = null;
     sEventPool.push(_event);
 }
 private static int compileObject(AsDisplayObject _object, AsVector<AsQuadBatch> quadBatches, int quadBatchID, AsMatrix transformationMatrix, float alpha, String blendMode, bool ignoreCurrentFilter)
 {
     int i = 0;
     AsQuadBatch quadBatch = null;
     bool isRootObject = false;
     float objectAlpha = _object.getAlpha();
     AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;
     AsQuad quad = _object as AsQuad;
     AsQuadBatch batch = _object as AsQuadBatch;
     AsFragmentFilter filter = _object.getFilter();
     if(quadBatchID == -1)
     {
         isRootObject = true;
         quadBatchID = 0;
         objectAlpha = 1.0f;
         blendMode = _object.getBlendMode();
         if(quadBatches.getLength() == 0)
         {
             quadBatches.push(new AsQuadBatch());
         }
         else
         {
             quadBatches[0].reset();
         }
     }
     if(filter != null && !ignoreCurrentFilter)
     {
         if(filter.getMode() == AsFragmentFilterMode.ABOVE)
         {
             quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
         }
         quadBatchID = compileObject(filter.compile(_object), quadBatches, quadBatchID, transformationMatrix, alpha, blendMode);
         if(filter.getMode() == AsFragmentFilterMode.BELOW)
         {
             quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
         }
     }
     else
     {
         if(container != null)
         {
             int numChildren = container.getNumChildren();
             AsMatrix childMatrix = new AsMatrix();
             for (i = 0; i < numChildren; ++i)
             {
                 AsDisplayObject child = container.getChildAt(i);
                 bool childVisible = child.getAlpha() != 0.0f && child.getVisible() && child.getScaleX() != 0.0f && child.getScaleY() != 0.0f;
                 if(childVisible)
                 {
                     String childBlendMode = child.getBlendMode() == AsBlendMode.AUTO ? blendMode : child.getBlendMode();
                     childMatrix.copyFrom(transformationMatrix);
                     AsRenderSupport.transformMatrixForObject(childMatrix, child);
                     quadBatchID = compileObject(child, quadBatches, quadBatchID, childMatrix, alpha * objectAlpha, childBlendMode);
                 }
             }
         }
         else
         {
             if(quad != null || batch != null)
             {
                 AsTexture texture = null;
                 String smoothing = null;
                 bool tinted = false;
                 int numQuads = 0;
                 if(quad != null)
                 {
                     AsImage image = quad as AsImage;
                     texture = image != null ? image.getTexture() : null;
                     smoothing = image != null ? image.getSmoothing() : null;
                     tinted = quad.getTinted();
                     numQuads = 1;
                 }
                 else
                 {
                     texture = batch.mTexture;
                     smoothing = batch.mSmoothing;
                     tinted = batch.mTinted;
                     numQuads = batch.mNumQuads;
                 }
                 quadBatch = quadBatches[quadBatchID];
                 if(quadBatch.isStateChange(tinted, alpha * objectAlpha, texture, smoothing, blendMode, numQuads))
                 {
                     quadBatchID++;
                     if(quadBatches.getLength() <= quadBatchID)
                     {
                         quadBatches.push(new AsQuadBatch());
                     }
                     quadBatch = quadBatches[quadBatchID];
                     quadBatch.reset();
                 }
                 if(quad != null)
                 {
                     quadBatch.addQuad(quad, alpha, texture, smoothing, transformationMatrix, blendMode);
                 }
                 else
                 {
                     quadBatch.addQuadBatch(batch, alpha, transformationMatrix, blendMode);
                 }
             }
             else
             {
                 throw new AsError("Unsupported display object: " + AsGlobal.getQualifiedClassName(_object));
             }
         }
     }
     if(isRootObject)
     {
         for (i = (int)(quadBatches.getLength() - 1); i > quadBatchID; --i)
         {
             quadBatches.pop().dispose();
         }
     }
     return quadBatchID;
 }
 private void updateShaderMatrix()
 {
     mShaderMatrix.setLength(0);
     mShaderMatrix.push(mUserMatrix[0], mUserMatrix[1], mUserMatrix[2], mUserMatrix[3], mUserMatrix[5], mUserMatrix[6], mUserMatrix[7], mUserMatrix[8], mUserMatrix[10], mUserMatrix[11], mUserMatrix[12], mUserMatrix[13], mUserMatrix[15], mUserMatrix[16], mUserMatrix[17], mUserMatrix[18], mUserMatrix[4] / 255.0f, mUserMatrix[9] / 255.0f, mUserMatrix[14] / 255.0f, mUserMatrix[19] / 255.0f);
 }
 private void getChildEventListeners(AsDisplayObject _object, String eventType, AsVector<AsDisplayObject> listeners)
 {
     AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;
     if(_object.hasEventListener(eventType))
     {
         listeners.push(_object);
     }
     if(container != null)
     {
         AsVector<AsDisplayObject> children = container.mChildren;
         int numChildren = (int)(children.getLength());
         int i = 0;
         for (; i < numChildren; ++i)
         {
             getChildEventListeners(children[i], eventType, listeners);
         }
     }
 }
        public virtual void advanceTime(float passedTime)
        {
            int     i       = 0;
            int     touchID = 0;
            AsTouch touch   = null;

            mElapsedTime = mElapsedTime + passedTime;
            if (mLastTaps.getLength() > 0)
            {
                for (i = (int)(mLastTaps.getLength() - 1); i >= 0; --i)
                {
                    if (mElapsedTime - mLastTaps[i].getTimestamp() > MULTITAP_TIME)
                    {
                        mLastTaps.splice(i, (uint)(1));
                    }
                }
            }
            while (mQueue.getLength() > 0)
            {
                sProcessedTouchIDs.setLength(sHoveringTouchData.setLength(0));
                AsVector <AsTouch> __touchs_ = mCurrentTouches;
                if (__touchs_ != null)
                {
                    foreach (AsTouch touch in __touchs_)
                    {
                        if (touch.getPhase() == AsTouchPhase.BEGAN || touch.getPhase() == AsTouchPhase.MOVED)
                        {
                            touch.setPhase(AsTouchPhase.STATIONARY);
                        }
                    }
                }
                while (mQueue.getLength() > 0 && sProcessedTouchIDs.indexOf(mQueue[mQueue.getLength() - 1][0]) == -1)
                {
                    AsArray touchArgs = mQueue.pop();
                    touch = getCurrentTouch(touchID);
                    if (touch != null && touch.getPhase() == AsTouchPhase.HOVER && touch.getTarget() != null)
                    {
                        sHoveringTouchData.push((As_AS_REST)(AsObject.createLiteralObject("touch", touch, "target", touch.getTarget())));
                    }
                    this.(int)(touchArgs[0]), (String)(touchArgs[1]), (float)(touchArgs[2]), (float)(touchArgs[3]), (float)(touchArgs[4]), (float)(touchArgs[5]), (float)(touchArgs[6]);
                    sProcessedTouchIDs.push(touchID);
                }
                AsTouchEvent      touchEvent    = new AsTouchEvent(AsTouchEvent.TOUCH, mCurrentTouches, mShiftDown, mCtrlDown);
                AsVector <Object> __touchDatas_ = sHoveringTouchData;
                if (__touchDatas_ != null)
                {
                    foreach (Object touchData in __touchDatas_)
                    {
                        if (((AsObject)(((AsObject)(touchData)).getOwnProperty("touch"))).getOwnProperty("target") != ((AsObject)(touchData)).getOwnProperty("target"))
                        {
                            touchEvent.dispatch(getBubbleChain((AsDisplayObject)(((AsObject)(touchData)).getOwnProperty("target")), sBubbleChain));
                        }
                    }
                }
                AsVector <int> __touchIDs_ = sProcessedTouchIDs;
                if (__touchIDs_ != null)
                {
                    foreach (int touchID in __touchIDs_)
                    {
                        getCurrentTouch(touchID).dispatchEvent(touchEvent);
                    }
                }
                for (i = (int)(mCurrentTouches.getLength() - 1); i >= 0; --i)
                {
                    if (mCurrentTouches[i].getPhase() == AsTouchPhase.ENDED)
                    {
                        mCurrentTouches.splice(i, (uint)(1));
                    }
                }
            }
            sBubbleChain.setLength(0);
        }
        private static int compileObject(AsDisplayObject _object, AsVector <AsQuadBatch> quadBatches, int quadBatchID, AsMatrix transformationMatrix, float alpha, String blendMode, bool ignoreCurrentFilter)
        {
            int         i                      = 0;
            AsQuadBatch quadBatch              = null;
            bool        isRootObject           = false;
            float       objectAlpha            = _object.getAlpha();
            AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;
            AsQuad           quad              = _object as AsQuad;
            AsQuadBatch      batch             = _object as AsQuadBatch;
            AsFragmentFilter filter            = _object.getFilter();

            if (quadBatchID == -1)
            {
                isRootObject = true;
                quadBatchID  = 0;
                objectAlpha  = 1.0f;
                blendMode    = _object.getBlendMode();
                if (quadBatches.getLength() == 0)
                {
                    quadBatches.push(new AsQuadBatch());
                }
                else
                {
                    quadBatches[0].reset();
                }
            }
            if (filter != null && !ignoreCurrentFilter)
            {
                if (filter.getMode() == AsFragmentFilterMode.ABOVE)
                {
                    quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
                }
                quadBatchID = compileObject(filter.compile(_object), quadBatches, quadBatchID, transformationMatrix, alpha, blendMode);
                if (filter.getMode() == AsFragmentFilterMode.BELOW)
                {
                    quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
                }
            }
            else
            {
                if (container != null)
                {
                    int      numChildren = container.getNumChildren();
                    AsMatrix childMatrix = new AsMatrix();
                    for (i = 0; i < numChildren; ++i)
                    {
                        AsDisplayObject child        = container.getChildAt(i);
                        bool            childVisible = child.getAlpha() != 0.0f && child.getVisible() && child.getScaleX() != 0.0f && child.getScaleY() != 0.0f;
                        if (childVisible)
                        {
                            String childBlendMode = child.getBlendMode() == AsBlendMode.AUTO ? blendMode : child.getBlendMode();
                            childMatrix.copyFrom(transformationMatrix);
                            AsRenderSupport.transformMatrixForObject(childMatrix, child);
                            quadBatchID = compileObject(child, quadBatches, quadBatchID, childMatrix, alpha * objectAlpha, childBlendMode);
                        }
                    }
                }
                else
                {
                    if (quad != null || batch != null)
                    {
                        AsTexture texture   = null;
                        String    smoothing = null;
                        bool      tinted    = false;
                        int       numQuads  = 0;
                        if (quad != null)
                        {
                            AsImage image = quad as AsImage;
                            texture = image != null?image.getTexture() : null;

                            smoothing = image != null?image.getSmoothing() : null;

                            tinted   = quad.getTinted();
                            numQuads = 1;
                        }
                        else
                        {
                            texture   = batch.mTexture;
                            smoothing = batch.mSmoothing;
                            tinted    = batch.mTinted;
                            numQuads  = batch.mNumQuads;
                        }
                        quadBatch = quadBatches[quadBatchID];
                        if (quadBatch.isStateChange(tinted, alpha * objectAlpha, texture, smoothing, blendMode, numQuads))
                        {
                            quadBatchID++;
                            if (quadBatches.getLength() <= quadBatchID)
                            {
                                quadBatches.push(new AsQuadBatch());
                            }
                            quadBatch = quadBatches[quadBatchID];
                            quadBatch.reset();
                        }
                        if (quad != null)
                        {
                            quadBatch.addQuad(quad, alpha, texture, smoothing, transformationMatrix, blendMode);
                        }
                        else
                        {
                            quadBatch.addQuadBatch(batch, alpha, transformationMatrix, blendMode);
                        }
                    }
                    else
                    {
                        throw new AsError("Unsupported display object: " + AsGlobal.getQualifiedClassName(_object));
                    }
                }
            }
            if (isRootObject)
            {
                for (i = (int)(quadBatches.getLength() - 1); i > quadBatchID; --i)
                {
                    quadBatches.pop().dispose();
                }
            }
            return(quadBatchID);
        }
Beispiel #30
0
        private AsVector <AsCharLocation> arrangeChars(float width, float height, String text, float fontSize, String hAlign, String vAlign, bool autoScale, bool kerning)
        {
            if (text == null || text.Length == 0)
            {
                return(new AsVector <AsCharLocation>());
            }
            if (fontSize < 0)
            {
                fontSize = fontSize * -mSize;
            }
            AsVector <AsVector <AsCharLocation> > lines = null;
            bool           finished        = false;
            AsCharLocation charLocation    = null;
            int            numChars        = 0;
            float          containerWidth  = 0;
            float          containerHeight = 0;
            float          scale           = 0;

            while (!finished)
            {
                scale           = fontSize / mSize;
                containerWidth  = width / scale;
                containerHeight = height / scale;
                lines           = new AsVector <AsVector <AsCharLocation> >();
                if (mLineHeight <= containerHeight)
                {
                    int   lastWhiteSpace = -1;
                    int   lastCharID     = -1;
                    float currentX       = 0;
                    float currentY       = 0;
                    AsVector <AsCharLocation> currentLine = new AsVector <AsCharLocation>();
                    numChars = text.Length;
                    int i = 0;
                    for (; i < numChars; ++i)
                    {
                        bool         lineFull = false;
                        int          charID   = (int)(AsString.charCodeAt(text, i));
                        AsBitmapChar _char    = getChar(charID);
                        if (charID == CHAR_NEWLINE || charID == CHAR_CARRIAGE_RETURN)
                        {
                            lineFull = true;
                        }
                        else
                        {
                            if (_char == null)
                            {
                                AsGlobal.trace("[Starling] Missing character: " + charID);
                            }
                            else
                            {
                                if (charID == CHAR_SPACE || charID == CHAR_TAB)
                                {
                                    lastWhiteSpace = i;
                                }
                                if (kerning)
                                {
                                    currentX = currentX + _char.getKerning(lastCharID);
                                }
                                charLocation       = mCharLocationPool.getLength() != 0 ? mCharLocationPool.pop() : new AsCharLocation(_char);
                                charLocation._char = _char;
                                charLocation.x     = currentX + _char.getXOffset();
                                charLocation.y     = currentY + _char.getYOffset();
                                currentLine.push(charLocation);
                                currentX   = currentX + _char.getXAdvance();
                                lastCharID = charID;
                                if (currentLine.getLength() == 1)
                                {
                                    currentX       = currentX - _char.getXOffset();
                                    charLocation.x = charLocation.x - _char.getXOffset();
                                }
                                if (charLocation.x + _char.getWidth() > containerWidth)
                                {
                                    int numCharsToRemove = lastWhiteSpace == -1 ? 1 : i - lastWhiteSpace;
                                    int removeIndex      = (int)(currentLine.getLength() - numCharsToRemove);
                                    currentLine.splice(removeIndex, (uint)(numCharsToRemove));
                                    if (currentLine.getLength() == 0)
                                    {
                                        break;
                                    }
                                    i        = i - numCharsToRemove;
                                    lineFull = true;
                                }
                            }
                        }
                        if (i == numChars - 1)
                        {
                            lines.push(currentLine);
                            finished = true;
                        }
                        else
                        {
                            if (lineFull)
                            {
                                lines.push(currentLine);
                                if (lastWhiteSpace == i)
                                {
                                    currentLine.pop();
                                }
                                if (currentY + 2 * mLineHeight <= containerHeight)
                                {
                                    currentLine    = new AsVector <AsCharLocation>();
                                    currentX       = 0;
                                    currentY       = currentY + mLineHeight;
                                    lastWhiteSpace = -1;
                                    lastCharID     = -1;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                if (autoScale && !finished)
                {
                    fontSize = fontSize - 1;
                    lines.setLength(0);
                }
                else
                {
                    finished = true;
                }
            }
            AsVector <AsCharLocation> finalLocations = new AsVector <AsCharLocation>();
            int   numLines = (int)(lines.getLength());
            float bottom   = currentY + mLineHeight;
            int   yOffset  = 0;

            if (vAlign == AsVAlign.BOTTOM)
            {
                yOffset = (int)(containerHeight - bottom);
            }
            else
            {
                if (vAlign == AsVAlign.CENTER)
                {
                    yOffset = (int)((containerHeight - bottom) / 2);
                }
            }
            int lineID = 0;

            for (; lineID < numLines; ++lineID)
            {
                AsVector <AsCharLocation> line = lines[lineID];
                numChars = (int)(line.getLength());
                if (numChars == 0)
                {
                    continue;
                }
                AsCharLocation lastLocation = line[line.getLength() - 1];
                float          right        = lastLocation.x + lastLocation._char.getWidth();
                int            xOffset      = 0;
                if (hAlign == AsHAlign.RIGHT)
                {
                    xOffset = (int)(containerWidth - right);
                }
                else
                {
                    if (hAlign == AsHAlign.CENTER)
                    {
                        xOffset = (int)((containerWidth - right) / 2);
                    }
                }
                int c = 0;
                for (; c < numChars; ++c)
                {
                    charLocation       = line[c];
                    charLocation.x     = scale * (charLocation.x + xOffset);
                    charLocation.y     = scale * (charLocation.y + yOffset);
                    charLocation.scale = scale;
                    if (charLocation._char.getWidth() > 0 && charLocation._char.getHeight() > 0)
                    {
                        finalLocations.push(charLocation);
                    }
                    mCharLocationPool.push(charLocation);
                }
            }
            return(finalLocations);
        }
 public virtual AsXML appendChild(AsXML child)
 {
     mElements.push(child);
     return(child);
 }
 public virtual AsVector<AsTouch> getTouches(AsDisplayObject target, String phase)
 {
     AsVector<AsTouch> touchesFound = new AsVector<AsTouch>();
     int numTouches = (int)(mTouches.getLength());
     int i = 0;
     for (; (i < numTouches); ++i)
     {
         AsTouch touch = mTouches[i];
         bool correctTarget = ((touch.getTarget() == target) || (target is AsDisplayObjectContainer && ((target is AsDisplayObjectContainer) ? ((AsDisplayObjectContainer)(target)) : null).contains(touch.getTarget())));
         bool correctPhase = ((phase == null) || (phase == touch.getPhase()));
         if((correctTarget && correctPhase))
         {
             touchesFound.push(touch);
         }
     }
     return touchesFound;
 }
 public virtual void removeEventListener(String type, AsEventListenerCallback listener)
 {
     if(mEventListeners != null)
     {
         AsVector<AsEventListenerCallback> listeners = mEventListeners[type] as AsVector<AsEventListenerCallback>;
         if(listeners != null)
         {
             int numListeners = (int)(listeners.getLength());
             AsVector<AsEventListenerCallback> remainingListeners = new AsVector<AsEventListenerCallback>();
             int i = 0;
             for (; i < numListeners; ++i)
             {
                 if(listeners[i] != listener)
                 {
                     remainingListeners.push(listeners[i]);
                 }
             }
             mEventListeners[type] = remainingListeners;
         }
     }
 }
        public virtual AsMatrix getTransformationMatrix(AsDisplayObject targetSpace, AsMatrix resultMatrix)
        {
            AsDisplayObject commonParent  = null;
            AsDisplayObject currentObject = null;

            if (resultMatrix != null)
            {
                resultMatrix.identity();
            }
            else
            {
                resultMatrix = new AsMatrix();
            }
            if (targetSpace == this)
            {
                return(resultMatrix);
            }
            else
            {
                if (targetSpace == mParent || (targetSpace == null && mParent == null))
                {
                    resultMatrix.copyFrom(getTransformationMatrix());
                    return(resultMatrix);
                }
                else
                {
                    if (targetSpace == null || targetSpace == get_base())
                    {
                        currentObject = this;
                        while (currentObject != targetSpace)
                        {
                            resultMatrix.concat(currentObject.getTransformationMatrix());
                            currentObject = currentObject.mParent;
                        }
                        return(resultMatrix);
                    }
                    else
                    {
                        if (targetSpace.mParent == this)
                        {
                            targetSpace.getTransformationMatrix(this, resultMatrix);
                            resultMatrix.invert();
                            return(resultMatrix);
                        }
                    }
                }
            }
            commonParent  = null;
            currentObject = this;
            while (currentObject != null)
            {
                sAncestors.push(currentObject);
                currentObject = currentObject.mParent;
            }
            currentObject = targetSpace;
            while (currentObject != null && sAncestors.indexOf(currentObject) == -1)
            {
                currentObject = currentObject.mParent;
            }
            sAncestors.setLength(0);
            if (currentObject != null)
            {
                commonParent = currentObject;
            }
            else
            {
                throw new AsArgumentError("Object not connected to target");
            }
            currentObject = this;
            while (currentObject != commonParent)
            {
                resultMatrix.concat(currentObject.getTransformationMatrix());
                currentObject = currentObject.mParent;
            }
            if (commonParent == targetSpace)
            {
                return(resultMatrix);
            }
            sHelperMatrix.identity();
            currentObject = targetSpace;
            while (currentObject != commonParent)
            {
                sHelperMatrix.concat(currentObject.getTransformationMatrix());
                currentObject = currentObject.mParent;
            }
            sHelperMatrix.invert();
            resultMatrix.concat(sHelperMatrix);
            return(resultMatrix);
        }
 private void concatValues(float m0, float m1, float m2, float m3, float m4, float m5, float m6, float m7, float m8, float m9, float m10, float m11, float m12, float m13, float m14, float m15, float m16, float m17, float m18, float m19)
 {
     sTmpMatrix2.setLength(0);
     sTmpMatrix2.push(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19);
     concat(sTmpMatrix2);
 }
 public virtual AsVector<AsTexture> getTextures(String prefix)
 {
     AsVector<AsTexture> textures = new AsVector<AsTexture>();
     AsVector<String> names = new AsVector<String>();
     AsDictionary __names_ = mTextureRegions;
     if (__names_ != null)
     {
         foreach (String name in __names_)
         {
             if(AsString.indexOf(name, prefix) == 0)
             {
                 names.push(name);
             }
         }
     }
     names.sort(AsArray.CASEINSENSITIVE);
     AsVector<String> __names_ = names;
     if (__names_ != null)
     {
         foreach (String name in __names_)
         {
             textures.push(getTexture(name));
         }
     }
     return textures;
 }
 public virtual void removeEventListener(String type, AsEventListenerCallback listener)
 {
     if(mEventListeners != null)
     {
         AsVector<AsEventListenerCallback> listeners = (AsVector<AsEventListenerCallback>)(mEventListeners[type]);
         if(listeners != null)
         {
             AsVector<AsEventListenerCallback> remainListeners = new AsVector<AsEventListenerCallback>();
             AsVector<AsEventListenerCallback> __eventListeners_ = listeners;
             if (__eventListeners_ != null)
             {
                 foreach (AsEventListenerCallback eventListener in __eventListeners_)
                 {
                     if((eventListener != listener))
                     {
                         remainListeners.push(eventListener);
                     }
                 }
             }
             if((remainListeners.getLength() > 0))
             {
                 mEventListeners[type] = remainListeners;
             }
             else
             {
                 mEventListeners.remove(type);
             }
         }
     }
 }
 private AsVector<AsCharLocation> arrangeChars(float width, float height, String text, float fontSize, String hAlign, String vAlign, bool autoScale, bool kerning)
 {
     if(text == null || text.Length == 0)
     {
         return new AsVector<AsCharLocation>();
     }
     if(fontSize < 0)
     {
         fontSize = fontSize * -mSize;
     }
     AsVector<AsVector<AsCharLocation>> lines = null;
     bool finished = false;
     AsCharLocation charLocation = null;
     int numChars = 0;
     float containerWidth = 0;
     float containerHeight = 0;
     float scale = 0;
     while(!finished)
     {
         scale = fontSize / mSize;
         containerWidth = width / scale;
         containerHeight = height / scale;
         lines = new AsVector<AsVector<AsCharLocation>>();
         if(mLineHeight <= containerHeight)
         {
             int lastWhiteSpace = -1;
             int lastCharID = -1;
             float currentX = 0;
             float currentY = 0;
             AsVector<AsCharLocation> currentLine = new AsVector<AsCharLocation>();
             numChars = text.Length;
             int i = 0;
             for (; i < numChars; ++i)
             {
                 bool lineFull = false;
                 int charID = (int)(AsString.charCodeAt(text, i));
                 AsBitmapChar _char = getChar(charID);
                 if(charID == CHAR_NEWLINE || charID == CHAR_CARRIAGE_RETURN)
                 {
                     lineFull = true;
                 }
                 else
                 {
                     if(_char == null)
                     {
                         AsGlobal.trace("[Starling] Missing character: " + charID);
                     }
                     else
                     {
                         if(charID == CHAR_SPACE || charID == CHAR_TAB)
                         {
                             lastWhiteSpace = i;
                         }
                         if(kerning)
                         {
                             currentX = currentX + _char.getKerning(lastCharID);
                         }
                         charLocation = mCharLocationPool.getLength() != 0 ? mCharLocationPool.pop() : new AsCharLocation(_char);
                         charLocation._char = _char;
                         charLocation.x = currentX + _char.getXOffset();
                         charLocation.y = currentY + _char.getYOffset();
                         currentLine.push(charLocation);
                         currentX = currentX + _char.getXAdvance();
                         lastCharID = charID;
                         if(currentLine.getLength() == 1)
                         {
                             currentX = currentX - _char.getXOffset();
                             charLocation.x = charLocation.x - _char.getXOffset();
                         }
                         if(charLocation.x + _char.getWidth() > containerWidth)
                         {
                             int numCharsToRemove = lastWhiteSpace == -1 ? 1 : i - lastWhiteSpace;
                             int removeIndex = (int)(currentLine.getLength() - numCharsToRemove);
                             currentLine.splice(removeIndex, (uint)(numCharsToRemove));
                             if(currentLine.getLength() == 0)
                             {
                                 break;
                             }
                             i = i - numCharsToRemove;
                             lineFull = true;
                         }
                     }
                 }
                 if(i == numChars - 1)
                 {
                     lines.push(currentLine);
                     finished = true;
                 }
                 else
                 {
                     if(lineFull)
                     {
                         lines.push(currentLine);
                         if(lastWhiteSpace == i)
                         {
                             currentLine.pop();
                         }
                         if(currentY + 2 * mLineHeight <= containerHeight)
                         {
                             currentLine = new AsVector<AsCharLocation>();
                             currentX = 0;
                             currentY = currentY + mLineHeight;
                             lastWhiteSpace = -1;
                             lastCharID = -1;
                         }
                         else
                         {
                             break;
                         }
                     }
                 }
             }
         }
         if(autoScale && !finished)
         {
             fontSize = fontSize - 1;
             lines.setLength(0);
         }
         else
         {
             finished = true;
         }
     }
     AsVector<AsCharLocation> finalLocations = new AsVector<AsCharLocation>();
     int numLines = (int)(lines.getLength());
     float bottom = currentY + mLineHeight;
     int yOffset = 0;
     if(vAlign == AsVAlign.BOTTOM)
     {
         yOffset = (int)(containerHeight - bottom);
     }
     else
     {
         if(vAlign == AsVAlign.CENTER)
         {
             yOffset = (int)((containerHeight - bottom) / 2);
         }
     }
     int lineID = 0;
     for (; lineID < numLines; ++lineID)
     {
         AsVector<AsCharLocation> line = lines[lineID];
         numChars = (int)(line.getLength());
         if(numChars == 0)
         {
             continue;
         }
         AsCharLocation lastLocation = line[line.getLength() - 1];
         float right = lastLocation.x + lastLocation._char.getWidth();
         int xOffset = 0;
         if(hAlign == AsHAlign.RIGHT)
         {
             xOffset = (int)(containerWidth - right);
         }
         else
         {
             if(hAlign == AsHAlign.CENTER)
             {
                 xOffset = (int)((containerWidth - right) / 2);
             }
         }
         int c = 0;
         for (; c < numChars; ++c)
         {
             charLocation = line[c];
             charLocation.x = scale * (charLocation.x + xOffset);
             charLocation.y = scale * (charLocation.y + yOffset);
             charLocation.scale = scale;
             if(charLocation._char.getWidth() > 0 && charLocation._char.getHeight() > 0)
             {
                 finalLocations.push(charLocation);
             }
             mCharLocationPool.push(charLocation);
         }
     }
     return finalLocations;
 }