public virtual void addChildAt(AsDisplayObject child, int index)
 {
     if (mChildren == null)
     {
         mChildren = new AsVector <AsDisplayObject>();
     }
     if (index >= 0 && index <= getNumChildren())
     {
         child.removeFromParent();
         mChildren.splice(index, (uint)(0), child);
         child.setParent(this);
         child.dispatchEvent(sAddedEvent);
         if (getStage() != null)
         {
             child.dispatchEventOnChildren(sAddedToStageEvent);
         }
     }
     else
     {
         throw new AsRangeError("Invalid child index");
     }
 }
Exemplo n.º 2
0
 public virtual void addFrameAt(int frameID, AsTexture texture, AsSound sound, float duration)
 {
     if (frameID < 0 || frameID > getNumFrames())
     {
         throw new AsArgumentError("Invalid frame id");
     }
     if (duration < 0)
     {
         duration = mDefaultFrameDuration;
     }
     mTextures.splice(frameID, (uint)(0), texture);
     mSounds.splice(frameID, (uint)(0), sound);
     mDurations.splice(frameID, (uint)(0), duration);
     mTotalTime = mTotalTime + duration;
     if (frameID > 0 && frameID == getNumFrames())
     {
         mStartTimes[frameID] = mStartTimes[frameID - 1] + mDurations[frameID - 1];
     }
     else
     {
         updateStartTimes();
     }
 }
        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 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<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.º 6
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;
            }
        }
Exemplo n.º 7
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);
        }