public virtual void reset()
 {
     mNumQuads     = 0;
     mTexture      = null;
     mSmoothing    = null;
     mSyncRequired = true;
 }
        public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha, AsMatrix modelViewMatrix, String blendMode)
        {
            if (modelViewMatrix == null)
            {
                modelViewMatrix = quadBatch.getTransformationMatrix();
            }
            bool  tinted   = quadBatch.mTinted || parentAlpha != 1.0f;
            float alpha    = parentAlpha * quadBatch.getAlpha();
            int   vertexID = mNumQuads * 4;
            int   numQuads = quadBatch.getNumQuads();

            if (mNumQuads + numQuads > getCapacity())
            {
                expand(mNumQuads + numQuads);
            }
            if (mNumQuads == 0)
            {
                this.setBlendMode(blendMode != null ? blendMode : quadBatch.getBlendMode());
                mTexture   = quadBatch.mTexture;
                mTinted    = tinted;
                mSmoothing = quadBatch.mSmoothing;
                mVertexData.setPremultipliedAlpha(quadBatch.mVertexData.getPremultipliedAlpha(), false);
            }
            quadBatch.mVertexData.copyTo(mVertexData, vertexID, 0, numQuads * 4);
            mVertexData.transformVertex(vertexID, modelViewMatrix, numQuads * 4);
            if (alpha != 1.0f)
            {
                mVertexData.scaleAlpha(vertexID, alpha, numQuads * 4);
            }
            mSyncRequired = true;
            mNumQuads     = mNumQuads + numQuads;
        }
        public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing, AsMatrix modelViewMatrix, String blendMode)
        {
            if (modelViewMatrix == null)
            {
                modelViewMatrix = quad.getTransformationMatrix();
            }
            bool tinted = texture != null?quad.getTinted() || parentAlpha != 1.0f : false;

            float alpha    = parentAlpha * quad.getAlpha();
            int   vertexID = mNumQuads * 4;

            if (mNumQuads + 1 > mVertexData.getNumVertices() / 4)
            {
                expand();
            }
            if (mNumQuads == 0)
            {
                this.setBlendMode(blendMode != null ? blendMode : quad.getBlendMode());
                mTexture   = texture;
                mTinted    = tinted;
                mSmoothing = smoothing;
                mVertexData.setPremultipliedAlpha(texture != null ? texture.getPremultipliedAlpha() : true, false);
            }
            quad.copyVertexDataTo(mVertexData, vertexID);
            mVertexData.transformVertex(vertexID, modelViewMatrix, 4);
            if (alpha != 1.0f)
            {
                mVertexData.scaleAlpha(vertexID, alpha, 4);
            }
            mSyncRequired = true;
            mNumQuads++;
        }
 public virtual bool isStateChange(bool tinted, float parentAlpha, AsTexture texture, String smoothing, String blendMode, int numQuads)
 {
     if (mNumQuads == 0)
     {
         return(false);
     }
     else
     {
         if (mNumQuads + numQuads > 8192)
         {
             return(true);
         }
         else
         {
             if (mTexture == null && texture == null)
             {
                 return(false);
             }
             else
             {
                 if (mTexture != null && texture != null)
                 {
                     return(mTexture.get_base() != texture.get_base() || mTexture.getRepeat() != texture.getRepeat() || mSmoothing != smoothing || mTinted != (tinted || parentAlpha != 1.0f) || this.getBlendMode() != blendMode);
                 }
                 else
                 {
                     return(true);
                 }
             }
         }
     }
 }
        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);
                }
            }
        }
 public virtual void setFrameTexture(int frameID, AsTexture texture)
 {
     if (frameID < 0 || frameID >= getNumFrames())
     {
         throw new AsArgumentError("Invalid frame id");
     }
     mTextures[frameID] = texture;
 }
 public virtual void batchQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing)
 {
     if (mQuadBatches[mCurrentQuadBatchID].isStateChange(quad.getTinted(), parentAlpha, texture, smoothing, mBlendMode))
     {
         finishQuadBatch();
     }
     mQuadBatches[mCurrentQuadBatchID].addQuad(quad, parentAlpha, texture, smoothing, mModelViewMatrix, mBlendMode);
 }
 public AsBitmapChar(int id, AsTexture texture, float xOffset, float yOffset, float xAdvance)
 {
     mCharID   = id;
     mTexture  = texture;
     mXOffset  = xOffset;
     mYOffset  = yOffset;
     mXAdvance = xAdvance;
     mKernings = null;
 }
Example #9
0
 public virtual void setDownState(AsTexture _value)
 {
     if (mDownState != _value)
     {
         mDownState = _value;
         if (mIsDown)
         {
             mBackground.setTexture(_value);
         }
     }
 }
Example #10
0
        private void parseFontXml(AsXML fontXml)
        {
            float       scale = mTexture.getScale();
            AsRectangle frame = mTexture.getFrame();

            mName       = fontXml.elements("info").attribute("face");
            mSize       = AsGlobal.parseFloat(fontXml.elements("info").attribute("size")) / scale;
            mLineHeight = AsGlobal.parseFloat(fontXml.elements("common").attribute("lineHeight")) / scale;
            mBaseline   = AsGlobal.parseFloat(fontXml.elements("common").attribute("base")) / scale;
            if (fontXml.elements("info").attribute("smooth").ToString() == "0")
            {
                setSmoothing(AsTextureSmoothing.NONE);
            }
            if (mSize <= 0)
            {
                AsGlobal.trace("[Starling] Warning: invalid font size in '" + mName + "' font.");
                mSize = mSize == 0.0f ? 16.0f : mSize * -1.0f;
            }
            AsXMLList __charElements_ = fontXml.elements("chars").elements("_char");

            if (__charElements_ != null)
            {
                foreach (AsXML charElement in __charElements_)
                {
                    int         id       = (int)(AsGlobal.parseInt(charElement.attribute("id")));
                    float       xOffset  = AsGlobal.parseFloat(charElement.attribute("xoffset")) / scale;
                    float       yOffset  = AsGlobal.parseFloat(charElement.attribute("yoffset")) / scale;
                    float       xAdvance = AsGlobal.parseFloat(charElement.attribute("xadvance")) / scale;
                    AsRectangle region   = new AsRectangle();
                    region.x      = AsGlobal.parseFloat(charElement.attribute("x")) / scale + frame.x;
                    region.y      = AsGlobal.parseFloat(charElement.attribute("y")) / scale + frame.y;
                    region.width  = AsGlobal.parseFloat(charElement.attribute("width")) / scale;
                    region.height = AsGlobal.parseFloat(charElement.attribute("height")) / scale;
                    AsTexture    texture    = AsTexture.fromTexture(mTexture, region);
                    AsBitmapChar bitmapChar = new AsBitmapChar(id, texture, xOffset, yOffset, xAdvance);
                    addChar(id, bitmapChar);
                }
            }
            AsXMLList __kerningElements_ = fontXml.elements("kernings").elements("kerning");

            if (__kerningElements_ != null)
            {
                foreach (AsXML kerningElement in __kerningElements_)
                {
                    int   first  = (int)(AsGlobal.parseInt(kerningElement.attribute("first")));
                    int   second = (int)(AsGlobal.parseInt(kerningElement.attribute("second")));
                    float amount = AsGlobal.parseFloat(kerningElement.attribute("amount")) / scale;
                    if (mChars.containsKey(second))
                    {
                        getChar(second).addKerning(first, amount);
                    }
                }
            }
        }
 public virtual void setRenderTarget(AsTexture target)
 {
     mRenderTarget = target;
     if (target != null)
     {
         AsStarling.getContext().setRenderToTexture(target.get_base());
     }
     else
     {
         AsStarling.getContext().setRenderToBackBuffer();
     }
 }
Example #12
0
        public AsImage(AsTexture texture)
            : base(texture.getFrame() != null ? texture.getFrame().width : texture.getWidth(), texture.getFrame() != null ? texture.getFrame().height : texture.getHeight(), 0xffffff, texture.getPremultipliedAlpha())
        {
            bool pma = texture.getPremultipliedAlpha();

            mVertexData.setTexCoords(0, 0.0f, 0.0f);
            mVertexData.setTexCoords(1, 1.0f, 0.0f);
            mVertexData.setTexCoords(2, 0.0f, 1.0f);
            mVertexData.setTexCoords(3, 1.0f, 1.0f);
            mTexture                = texture;
            mSmoothing              = AsTextureSmoothing.BILINEAR;
            mVertexDataCache        = new AsVertexData(4, pma);
            mVertexDataCacheInvalid = true;
        }
 protected override void activate(int pass, AsContext3D context, AsTexture texture)
 {
     updateParameters(pass, (int)(texture.getWidth() * texture.getScale()), (int)(texture.getHeight() * texture.getScale()));
     context.setProgramConstantsFromVector(AsContext3DProgramType.VERTEX, 4, mOffsets);
     context.setProgramConstantsFromVector(AsContext3DProgramType.FRAGMENT, 0, mWeights);
     if (mUniformColor && pass == getNumPasses() - 1)
     {
         context.setProgramConstantsFromVector(AsContext3DProgramType.FRAGMENT, 1, mColor);
         context.setProgram(mTintedProgram);
     }
     else
     {
         context.setProgram(mNormalProgram);
     }
 }
        public static AsTexture getTexture()
        {
            AsBitmapData bmpData  = new AsBitmapData(BITMAP_WIDTH, BITMAP_HEIGHT);
            AsByteArray  bmpBytes = new AsByteArray();
            int          numBytes = (int)(BITMAP_DATA.getLength());
            int          i        = 0;

            for (; i < numBytes; ++i)
            {
                bmpBytes.writeUnsignedInt((uint)(BITMAP_DATA[i]));
            }
            bmpBytes.uncompress();
            bmpData.setPixels(new AsRectangle(0, 0, BITMAP_WIDTH, BITMAP_HEIGHT), bmpBytes);
            return(AsTexture.fromBitmapData(bmpData, false));
        }
        public AsTouchMarker()
        {
            mCenter  = new AsPoint();
            mTexture = createTexture();
            int i = 0;

            for (; i < 2; ++i)
            {
                AsImage marker = new AsImage(mTexture);
                marker.setPivotX(mTexture.getWidth() / 2);
                marker.setPivotY(mTexture.getHeight() / 2);
                marker.setTouchable(false);
                addChild(marker);
            }
        }
 public AsRenderSupport()
 {
     mProjectionMatrix   = new AsMatrix();
     mModelViewMatrix    = new AsMatrix();
     mMvpMatrix          = new AsMatrix();
     mMvpMatrix3D        = new AsMatrix3D();
     mMatrixStack        = new AsVector <AsMatrix>();
     mMatrixStackSize    = 0;
     mDrawCount          = 0;
     mRenderTarget       = null;
     mBlendMode          = AsBlendMode.NORMAL;
     mCurrentQuadBatchID = 0;
     mQuadBatches        = new AsVector <AsQuadBatch>();
     loadIdentity();
     setOrthographicProjection(0, 0, 400, 300);
 }
Example #17
0
 public virtual void setTexture(AsTexture _value)
 {
     if (_value == null)
     {
         throw new AsArgumentError("Texture cannot be null");
     }
     else
     {
         if (_value != mTexture)
         {
             mTexture = _value;
             mVertexData.setPremultipliedAlpha(mTexture.getPremultipliedAlpha());
             onVertexDataChanged();
         }
     }
 }
Example #18
0
 public AsBitmapFont(AsTexture texture, AsXML fontXml)
 {
     if (texture == null && fontXml == null)
     {
         texture = AsMiniBitmapFont.getTexture();
         fontXml = AsMiniBitmapFont.getXml();
     }
     mName             = "unknown";
     mLineHeight       = mSize = mBaseline = 14;
     mTexture          = texture;
     mChars            = new AsDictionary();
     mHelperImage      = new AsImage(texture);
     mCharLocationPool = new AsVector <AsCharLocation>();
     if (fontXml != null)
     {
         parseFontXml(fontXml);
     }
 }
 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();
     }
 }
Example #20
0
 public AsButton(AsTexture upState, String text, AsTexture downState)
 {
     if (upState == null)
     {
         throw new AsArgumentError("Texture cannot be null");
     }
     mUpState           = upState;
     mDownState         = downState != null ? downState : upState;
     mBackground        = new AsImage(upState);
     mScaleWhenDown     = downState != null ? 1.0f : 0.9f;
     mAlphaWhenDisabled = 0.5f;
     mEnabled           = true;
     mIsDown            = false;
     mUseHandCursor     = true;
     mTextBounds        = new AsRectangle(0, 0, upState.getWidth(), upState.getHeight());
     mContents          = new AsSprite();
     mContents.addChild(mBackground);
     addChild(mContents);
     addEventListener(AsTouchEvent.TOUCH, onTouch);
     if (text.Length != 0)
     {
         this.setText(text);
     }
 }
 protected override void activate(int pass, AsContext3D context, AsTexture texture)
 {
     context.setProgram(mShaderProgram);
 }
        private void createRenderedContents()
        {
            if (mQuadBatch != null)
            {
                mQuadBatch.removeFromParent(true);
                mQuadBatch = null;
            }
            float        scale      = AsStarling.getContentScaleFactor();
            float        width      = mHitArea.getWidth() * scale;
            float        height     = mHitArea.getHeight() * scale;
            AsTextFormat textFormat = new AsTextFormat(mFontName, mFontSize * scale, mColor, mBold, mItalic, mUnderline, null, null, mHAlign);

            textFormat.setKerning(mKerning);
            sNativeTextField.setDefaultTextFormat(textFormat);
            sNativeTextField.setWidth(width);
            sNativeTextField.setHeight(height);
            sNativeTextField.setAntiAliasType(AsAntiAliasType.ADVANCED);
            sNativeTextField.setSelectable(false);
            sNativeTextField.setMultiline(true);
            sNativeTextField.setWordWrap(true);
            sNativeTextField.setText(mText);
            sNativeTextField.setEmbedFonts(true);
            sNativeTextField.setOwnProperty("filters", mNativeFilters);
            if (sNativeTextField.getTextWidth() == 0.0f || sNativeTextField.getTextHeight() == 0.0f)
            {
                sNativeTextField.setEmbedFonts(false);
            }
            if (mAutoScale)
            {
                autoScaleNativeTextField(sNativeTextField);
            }
            float textWidth  = sNativeTextField.getTextWidth();
            float textHeight = sNativeTextField.getTextHeight();
            float xOffset    = 0.0f;

            if (mHAlign == AsHAlign.LEFT)
            {
                xOffset = 2;
            }
            else
            {
                if (mHAlign == AsHAlign.CENTER)
                {
                    xOffset = (width - textWidth) / 2.0f;
                }
                else
                {
                    if (mHAlign == AsHAlign.RIGHT)
                    {
                        xOffset = width - textWidth - 2;
                    }
                }
            }
            float yOffset = 0.0f;

            if (mVAlign == AsVAlign.TOP)
            {
                yOffset = 2;
            }
            else
            {
                if (mVAlign == AsVAlign.CENTER)
                {
                    yOffset = (height - textHeight) / 2.0f;
                }
                else
                {
                    if (mVAlign == AsVAlign.BOTTOM)
                    {
                        yOffset = height - textHeight - 2;
                    }
                }
            }
            AsBitmapData bitmapData = new AsBitmapData(width, height, true, 0x0);

            bitmapData.draw(sNativeTextField, new AsMatrix(1, 0, 0, 1, 0, ((int)(yOffset)) - 2));
            sNativeTextField.setText("");
            if (mTextBounds == null)
            {
                mTextBounds = new AsRectangle();
            }
            mTextBounds.setTo(xOffset / scale, yOffset / scale, textWidth / scale, textHeight / scale);
            AsTexture texture = AsTexture.fromBitmapData(bitmapData, false, false, scale);

            if (mImage == null)
            {
                mImage = new AsImage(texture);
                mImage.setTouchable(false);
                addChild(mImage);
            }
            else
            {
                mImage.getTexture().dispose();
                mImage.setTexture(texture);
                mImage.readjustSize();
            }
        }
        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);
        }
 public virtual bool isStateChange(bool tinted, float parentAlpha, AsTexture texture, String smoothing, String blendMode)
 {
     return(isStateChange(tinted, parentAlpha, texture, smoothing, blendMode, 1));
 }
 public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing)
 {
     addQuad(quad, parentAlpha, texture, smoothing, null, null);
 }
 public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture)
 {
     addQuad(quad, parentAlpha, texture, null, null, null);
 }
 public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing, AsMatrix modelViewMatrix)
 {
     addQuad(quad, parentAlpha, texture, smoothing, modelViewMatrix, null);
 }
 public static AsTexture fromTexture(AsTexture texture, AsRectangle region, AsRectangle frame)
 {
     AsTexture subTexture = new AsSubTexture(texture, region);
     subTexture.mFrame = frame;
     return subTexture;
 }
 public static AsTexture fromTexture(AsTexture texture, AsRectangle region)
 {
     return fromTexture(texture, region, null);
 }
 public static AsTexture fromTexture(AsTexture texture)
 {
     return fromTexture(texture, null, null);
 }
 protected virtual void deactivate(int pass, AsContext3D context, AsTexture texture)
 {
 }
Example #32
0
 public static AsImage fromBitmap(AsBitmap bitmap, bool generateMipMaps, float scale)
 {
     return(new AsImage(AsTexture.fromBitmap(bitmap, generateMipMaps, false, scale)));
 }
 protected virtual void activate(int pass, AsContext3D context, AsTexture texture)
 {
     throw new AsError("Method has to be implemented in subclass!");
 }