コード例 #1
0
 public static AsEvent fromPool(String type, bool bubbles, Object data)
 {
     if (sEventPool.getLength() != 0)
     {
         return(sEventPool.pop().reset(type, bubbles, data));
     }
     else
     {
         return(new AsEvent(type, bubbles, data));
     }
 }
コード例 #2
0
 public static AsTween fromPool(Object target, float time, Object transition)
 {
     if (sTweenPool.getLength() != 0)
     {
         return(sTweenPool.pop().reset(target, time, transition));
     }
     else
     {
         return(new AsTween(target, time, transition));
     }
 }
コード例 #3
0
        public virtual void purge()
        {
            int i = (int)(mObjects.getLength() - 1);

            for (; i >= 0; --i)
            {
                AsEventDispatcher dispatcher = mObjects.pop() as AsEventDispatcher;
                if (dispatcher != null)
                {
                    dispatcher.removeEventListener(AsEvent.REMOVE_FROM_JUGGLER, onRemove);
                }
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
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;
 }
コード例 #6
0
        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);
        }
コード例 #7
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);
        }
コード例 #8
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;
 }
コード例 #9
0
 public virtual void testVectorPop()
 {
     AsVector<String> v = new AsVector<String>();
     String element = v.pop();
 }
コード例 #10
0
 public virtual void testVectorPop()
 {
     AsVector <String> v       = new AsVector <String>();
     String            element = v.pop();
 }
コード例 #11
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);
        }