Exemplo n.º 1
0
        public virtual void advanceTime(float time)
        {
            int numObjects   = (int)(mObjects.getLength());
            int currentIndex = 0;
            int i            = 0;

            mElapsedTime = mElapsedTime + time;
            if (numObjects == 0)
            {
                return;
            }
            for (i = 0; i < numObjects; ++i)
            {
                AsIAnimatable _object = mObjects[i];
                if (_object != null)
                {
                    if (currentIndex != i)
                    {
                        mObjects[currentIndex] = _object;
                        mObjects[i]            = null;
                    }
                    _object.advanceTime(time);
                    ++currentIndex;
                }
            }
            if (currentIndex != i)
            {
                numObjects = (int)(mObjects.getLength());
                while (i < numObjects)
                {
                    mObjects[currentIndex++] = mObjects[i++];
                }
                mObjects.setLength(currentIndex);
            }
        }
        private void onInterruption(Object _event)
        {
            AsTouch            touch     = null;
            String             phase     = null;
            AsVector <AsTouch> __touchs_ = mCurrentTouches;

            if (__touchs_ != null)
            {
                foreach (AsTouch touch in __touchs_)
                {
                    if (touch.getPhase() == AsTouchPhase.BEGAN || touch.getPhase() == AsTouchPhase.MOVED || touch.getPhase() == AsTouchPhase.STATIONARY)
                    {
                        touch.setPhase(AsTouchPhase.ENDED);
                    }
                }
            }
            AsTouchEvent       touchEvent = new AsTouchEvent(AsTouchEvent.TOUCH, mCurrentTouches, mShiftDown, mCtrlDown);
            AsVector <AsTouch> __touchs_  = mCurrentTouches;

            if (__touchs_ != null)
            {
                foreach (AsTouch touch in __touchs_)
                {
                    touch.dispatchEvent(touchEvent);
                }
            }
            mCurrentTouches.setLength(0);
        }
        private void updatePassTextures(int width, int height, float scale)
        {
            int  numPassTextures = mNumPasses > 1 ? 2 : 1;
            bool needsUpdate     = mPassTextures == null || mPassTextures.getLength() != numPassTextures || mPassTextures[0].getWidth() != width || mPassTextures[0].getHeight() != height;

            if (needsUpdate)
            {
                if (mPassTextures != null)
                {
                    AsVector <AsTexture> __textures_ = mPassTextures;
                    if (__textures_ != null)
                    {
                        foreach (AsTexture texture in __textures_)
                        {
                            texture.dispose();
                        }
                    }
                    mPassTextures.setLength(numPassTextures);
                }
                else
                {
                    mPassTextures = new AsVector <AsTexture>(numPassTextures);
                }
                int i = 0;
                for (; i < numPassTextures; ++i)
                {
                    mPassTextures[i] = AsTexture.empty(width, height, PMA, true, scale);
                }
            }
        }
Exemplo n.º 4
0
 private void updateBubbleChain()
 {
     if (mTarget != null)
     {
         int             length  = 1;
         AsDisplayObject element = mTarget;
         mBubbleChain.setLength(0);
         mBubbleChain[0] = element;
         while ((element = element.getParent()) != null)
         {
             mBubbleChain[length++] = element;
         }
     }
     else
     {
         mBubbleChain.setLength(0);
     }
 }
        public override void dispatchEventOnChildren(AsEvent _event)
        {
            getChildEventListeners(this, _event.getType(), sListenersList);
            int numListeners = (int)(sListenersList.getLength());
            int i            = 0;

            for (; i < numListeners; ++i)
            {
                sListenersList[i].dispatchEvent(_event);
            }
            sListenersList.setLength(0);
        }
Exemplo n.º 6
0
 public virtual AsTween reset(Object target, float time, Object transition)
 {
     mTarget       = target;
     mCurrentTime  = 0;
     mTotalTime    = AsMath.max(0.0001f, time);
     mDelay        = mRepeatDelay = 0.0f;
     mOnStart      = mOnUpdate = mOnComplete = null;
     mOnStartArgs  = mOnUpdateArgs = mOnCompleteArgs = null;
     mRoundToInt   = mReverse = false;
     mRepeatCount  = 1;
     mCurrentCycle = -1;
     if (transition is String)
     {
         this.setTransition(transition as String);
     }
     else
     {
         if (transition is AsTransitionCallback)
         {
             this.setTransitionFunc(transition as AsTransitionCallback);
         }
         else
         {
             throw new AsArgumentError("Transition must be either a string or a function");
         }
     }
     if (mProperties != null)
     {
         mProperties.setLength(0);
     }
     else
     {
         mProperties = new AsVector <String>();
     }
     if (mStartValues != null)
     {
         mStartValues.setLength(0);
     }
     else
     {
         mStartValues = new AsVector <float>();
     }
     if (mEndValues != null)
     {
         mEndValues.setLength(0);
     }
     else
     {
         mEndValues = new AsVector <float>();
     }
     return(this);
 }
        private AsVector <AsEventDispatcher> getBubbleChain(AsDisplayObject target, AsVector <AsEventDispatcher> result)
        {
            AsDisplayObject element = target;
            int             length  = 1;

            result.setLength(length);
            result[0] = target;
            while ((element = element.getParent()) != null)
            {
                result[length++] = element;
            }
            return(result);
        }
Exemplo n.º 8
0
        private void updateStartTimes()
        {
            int numFrames = this.getNumFrames();

            mStartTimes.setLength(0);
            mStartTimes[0] = 0;
            int i = 1;

            for (; i < numFrames; ++i)
            {
                mStartTimes[i] = mStartTimes[i - 1] + mDurations[i - 1];
            }
        }
 public virtual AsTouch getTouch(AsDisplayObject target, String phase)
 {
     getTouches(target, phase, sTouches);
     if (sTouches.getLength() != 0)
     {
         AsTouch touch = sTouches[0];
         sTouches.setLength(0);
         return(touch);
     }
     else
     {
         return(null);
     }
 }
 public virtual void setMatrix(AsVector <float> _value)
 {
     if (_value != null && _value.getLength() != 20)
     {
         throw new AsArgumentError("Invalid matrix length: must be 20");
     }
     if (_value == null)
     {
         mUserMatrix.setLength(0);
         mUserMatrix(IDENTITY);
     }
     else
     {
         copyMatrix(_value, mUserMatrix);
     }
     updateShaderMatrix();
 }
        public virtual void broadcastEvent(AsEvent _event)
        {
            if (_event.getBubbles())
            {
                throw new AsArgumentError("Broadcast of bubbling events is prohibited");
            }
            int fromIndex = (int)(sBroadcastListeners.getLength());

            getChildEventListeners(this, _event.getType(), sBroadcastListeners);
            int toIndex = (int)(sBroadcastListeners.getLength());
            int i       = fromIndex;

            for (; i < toIndex; ++i)
            {
                sBroadcastListeners[i].dispatchEvent(_event);
            }
            sBroadcastListeners.setLength(fromIndex);
        }
        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 AsVector<AsEventDispatcher> getBubbleChain(AsDisplayObject target, AsVector<AsEventDispatcher> result)
 {
     AsDisplayObject element = target;
     int length = 1;
     result.setLength(length);
     result[0] = target;
     while((element = element.getParent()) != null)
     {
         result[length++] = element;
     }
     return result;
 }
Exemplo n.º 14
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;
 }
Exemplo n.º 15
0
        public virtual void advanceTime(float passedTime)
        {
            int     i     = 0;
            AsTouch touch = null;

            mElapsedTime = mElapsedTime + passedTime;
            mOffsetTime  = 0.0f;
            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(0);
                sHoveringTouchData.setLength(0);
                AsVector <AsTouch> __currentTouchs_ = mCurrentTouches;
                if (__currentTouchs_ != null)
                {
                    foreach (AsTouch currentTouch in __currentTouchs_)
                    {
                        if (currentTouch.getPhase() == AsTouchPhase.BEGAN || currentTouch.getPhase() == AsTouchPhase.MOVED)
                        {
                            currentTouch.setPhase(AsTouchPhase.STATIONARY);
                        }
                    }
                }
                AsVector <AsTouchData> __touchDatas_ = sHoveringTouchData;
                if (__touchDatas_ != null)
                {
                    foreach (AsTouchData touchData in __touchDatas_)
                    {
                        if (touchData.touch.getTarget() != touchData.target)
                        {
                            touchData.target.dispatchEvent(new AsTouchEvent(AsTouchEvent.TOUCH, mCurrentTouches, mShiftDown, mCtrlDown));
                        }
                    }
                }
                AsVector <int> __touchIDs_ = sProcessedTouchIDs;
                if (__touchIDs_ != null)
                {
                    foreach (int touchID in __touchIDs_)
                    {
                        touch = getCurrentTouch(touchID);
                        if (touch.getTarget() != null)
                        {
                            touch.getTarget().dispatchEvent(new AsTouchEvent(AsTouchEvent.TOUCH, mCurrentTouches, mShiftDown, mCtrlDown));
                        }
                    }
                }
                for (i = (int)(mCurrentTouches.getLength() - 1); i >= 0; --i)
                {
                    if (mCurrentTouches[i].getPhase() == AsTouchPhase.ENDED)
                    {
                        mCurrentTouches.splice(i, (uint)(1));
                    }
                }
                mOffsetTime = mOffsetTime + 0.00001f;
            }
        }
        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);
        }
 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 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 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);
        }
Exemplo n.º 20
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);
        }