Ejemplo n.º 1
0
        private void createComposedContents()
        {
            if (mImage != null)
            {
                mImage.removeFromParent(true);
                mImage = null;
            }
            if (mQuadBatch == null)
            {
                mQuadBatch = new AsQuadBatch();
                mQuadBatch.setTouchable(false);
                addChild(mQuadBatch);
            }
            else
            {
                mQuadBatch.reset();
            }
            AsBitmapFont bitmapFont = (AsBitmapFont)(getBitmapFonts()[mFontName]);

            if (bitmapFont == null)
            {
                throw new AsError("Bitmap font not registered: " + mFontName);
            }
            bitmapFont.fillQuadBatch(mQuadBatch, mHitArea.getWidth(), mHitArea.getHeight(), mText, mFontSize, mColor, mHAlign, mVAlign, mAutoScale, mKerning);
            mTextBounds = null;
        }
        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 AsRenderTexture(int width, int height, bool persistent, float scale)
            : base(mActiveTexture = AsTexture.empty(width, height, PMA, true, scale = scale <= 0 ? AsStarling.getContentScaleFactor() : scale), new AsRectangle(0, 0, width, height), true)
        {
            int nativeWidth  = AsGlobal.getNextPowerOfTwo((int)(width * scale));
            int nativeHeight = AsGlobal.getNextPowerOfTwo((int)(height * scale));

            mSupport = new AsRenderSupport();
            mSupport.setOrthographicProjection(0, 0, nativeWidth / scale, nativeHeight / scale);
            if (persistent)
            {
                mBufferTexture = AsTexture.empty(width, height, PMA, true, scale);
                mHelperImage   = new AsImage(mBufferTexture);
                mHelperImage.setSmoothing(AsTextureSmoothing.NONE);
            }
        }
Ejemplo n.º 4
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);
     }
 }
Ejemplo n.º 5
0
        public virtual AsSprite createSprite(float width, float height, String text, float fontSize, uint color, String hAlign, String vAlign, bool autoScale, bool kerning)
        {
            AsVector <AsCharLocation> charLocations = arrangeChars(width, height, text, fontSize, hAlign, vAlign, autoScale, kerning);
            int      numChars = (int)(charLocations.getLength());
            AsSprite sprite   = new AsSprite();
            int      i        = 0;

            for (; i < numChars; ++i)
            {
                AsCharLocation charLocation = charLocations[i];
                AsImage        _char        = charLocation._char.createImage();
                _char.setX(charLocation.x);
                _char.setY(charLocation.y);
                _char.setScaleX(_char.setScaleY(charLocation.scale));
                _char.setColor(color);
                sprite.addChild(_char);
            }
            return(sprite);
        }
Ejemplo n.º 6
0
        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 AsQuadBatch renderPasses(AsDisplayObject _object, AsRenderSupport support, float parentAlpha, bool intoCache)
        {
            AsTexture   cacheTexture = null;
            AsStage     stage        = _object.getStage();
            AsContext3D context      = AsStarling.getContext();
            float       scale        = AsStarling.getCurrent().getContentScaleFactor();

            if (stage == null)
            {
                throw new AsError("Filtered object must be on the stage.");
            }
            if (context == null)
            {
                throw new AsMissingContextError();
            }
            support.finishQuadBatch();
            support.raiseDrawCount((uint)(mNumPasses));
            support.pushMatrix();
            support.setBlendMode(AsBlendMode.NORMAL);
            AsRenderSupport.setBlendFactors(PMA);
            mProjMatrix.copyFrom(support.getProjectionMatrix());
            AsTexture previousRenderTarget = support.getRenderTarget();

            if (previousRenderTarget != null)
            {
                throw new AsIllegalOperationError("It's currently not possible to stack filters! " + "This limitation will be removed in a future Stage3D version.");
            }
            calculateBounds(_object, stage, sBounds);
            updateBuffers(context, sBounds);
            updatePassTextures((int)(sBounds.width), (int)(sBounds.height), mResolution * scale);
            if (intoCache)
            {
                cacheTexture = AsTexture.empty((int)(sBounds.width), (int)(sBounds.height), PMA, true, mResolution * scale);
            }
            support.setRenderTarget(mPassTextures[0]);
            support.clear();
            support.setOrthographicProjection(sBounds.x, sBounds.y, sBounds.width, sBounds.height);
            _object.render(support, parentAlpha);
            support.finishQuadBatch();
            AsRenderSupport.setBlendFactors(PMA);
            support.loadIdentity();
            context.setVertexBufferAt(0, mVertexBuffer, AsVertexData.POSITION_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
            context.setVertexBufferAt(1, mVertexBuffer, AsVertexData.TEXCOORD_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
            int i = 0;

            for (; i < mNumPasses; ++i)
            {
                if (i < mNumPasses - 1)
                {
                    support.setRenderTarget(getPassTexture(i + 1));
                    support.clear();
                }
                else
                {
                    if (intoCache)
                    {
                        support.setRenderTarget(cacheTexture);
                        support.clear();
                    }
                    else
                    {
                        support.setRenderTarget(previousRenderTarget);
                        support.getProjectionMatrix().copyFrom(mProjMatrix);
                        support.translateMatrix(mOffsetX, mOffsetY);
                        support.setBlendMode(_object.getBlendMode());
                        support.applyBlendMode(PMA);
                    }
                }
                AsTexture passTexture = getPassTexture(i);
                context.setProgramConstantsFromMatrix(AsContext3DProgramType.VERTEX, 0, support.getMvpMatrix3D(), true);
                context.setTextureAt(0, passTexture.get_base());
                activate(i, context, passTexture);
                context.drawTriangles(mIndexBuffer, 0, 2);
                deactivate(i, context, passTexture);
            }
            context.setVertexBufferAt(0, null);
            context.setVertexBufferAt(1, null);
            context.setTextureAt(0, null);
            support.popMatrix();
            if (intoCache)
            {
                support.setRenderTarget(previousRenderTarget);
                support.getProjectionMatrix().copyFrom(mProjMatrix);
                AsQuadBatch quadBatch = new AsQuadBatch();
                AsImage     image     = new AsImage(cacheTexture);
                stage.getTransformationMatrix(_object, sTransformationMatrix);
                AsMatrixUtil.prependTranslation(sTransformationMatrix, sBounds.x + mOffsetX, sBounds.y + mOffsetY);
                quadBatch.addImage(image, 1.0f, sTransformationMatrix);
                return(quadBatch);
            }
            else
            {
                return(null);
            }
        }