Ejemplo n.º 1
0
        public static AsTexture fromTexture(AsTexture texture, AsRectangle region, AsRectangle frame)
        {
            AsTexture subTexture = new AsSubTexture(texture, region);

            subTexture.mFrame = frame;
            return(subTexture);
        }
Ejemplo n.º 2
0
 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++;
 }
Ejemplo n.º 3
0
 public AsBitmapChar(int id, AsTexture texture, float xOffset, float yOffset, float xAdvance)
 {
     mCharID = id;
     mTexture = texture;
     mXOffset = xOffset;
     mYOffset = yOffset;
     mXAdvance = xAdvance;
     mKernings = null;
 }
 public AsTextureAtlas(AsTexture texture, AsXML atlasXml)
 {
     mTextureRegions = new AsDictionary();
     mTextureFrames = new AsDictionary();
     mAtlasTexture = texture;
     if(atlasXml != null)
     {
         parseAtlasXml(atlasXml);
     }
 }
Ejemplo n.º 5
0
 public AsTextureAtlas(AsTexture texture, AsXML atlasXml)
 {
     mTextureRegions = new AsDictionary();
     mTextureFrames  = new AsDictionary();
     mAtlasTexture   = texture;
     if (atlasXml != null)
     {
         parseAtlasXml(atlasXml);
     }
 }
Ejemplo n.º 6
0
 public AsSubTexture(AsTexture parentTexture, AsRectangle region, bool ownsParent)
 {
     mParent     = parentTexture;
     mOwnsParent = ownsParent;
     if (region == null)
     {
         setClipping(new AsRectangle(0, 0, 1, 1));
     }
     else
     {
         setClipping(new AsRectangle(region.x / parentTexture.getWidth(), region.y / parentTexture.getHeight(), region.width / parentTexture.getWidth(), region.height / parentTexture.getHeight()));
     }
 }
Ejemplo n.º 7
0
        public virtual AsTexture getTexture(String name)
        {
            AsRectangle region = (AsRectangle)(mTextureRegions[name]);

            if (region == null)
            {
                return(null);
            }
            else
            {
                return(AsTexture.fromTexture(mAtlasTexture, region, (AsRectangle)(mTextureFrames[name])));
            }
        }
Ejemplo n.º 8
0
 public AsSubTexture(AsTexture parentTexture, AsRectangle region, bool ownsParent)
 {
     mParent = parentTexture;
     mOwnsParent = ownsParent;
     if(region == null)
     {
         setClipping(new AsRectangle(0, 0, 1, 1));
     }
     else
     {
         setClipping(new AsRectangle(region.x / parentTexture.getWidth(), region.y / parentTexture.getHeight(), region.width / parentTexture.getWidth(), region.height / parentTexture.getHeight()));
     }
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 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);
     }
 }
        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.º 13
0
        public static AsTexture fromColor(int width, int height, uint color, bool optimizeForRenderTexture, float scale)
        {
            if (scale <= 0)
            {
                scale = AsStarling.getContentScaleFactor();
            }
            AsBitmapData bitmapData = new AsBitmapData(width * scale, height * scale, true, color);
            AsTexture    texture    = fromBitmapData(bitmapData, false, optimizeForRenderTexture, scale);

            if (!AsStarling.getHandleLostContext())
            {
                bitmapData.dispose();
            }
            return(texture);
        }
 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);
 }
        public virtual void drawBundled(AsDrawingBlockCallback drawingBlock, int antiAliasing)
        {
            float       scale   = mActiveTexture.getScale();
            AsContext3D context = AsStarling.getContext();

            if (context == null)
            {
                throw new AsMissingContextError();
            }
            sScissorRect.setTo(0, 0, mActiveTexture.getWidth() * scale, mActiveTexture.getHeight() * scale);
            context.setScissorRectangle(sScissorRect);
            if (getIsPersistent())
            {
                AsTexture tmpTexture = mActiveTexture;
                mActiveTexture = mBufferTexture;
                mBufferTexture = tmpTexture;
                mHelperImage.setTexture(mBufferTexture);
            }
            mSupport.setRenderTarget(mActiveTexture);
            mSupport.clear();
            if (getIsPersistent() && mBufferReady)
            {
                mHelperImage.render(mSupport, 1.0f);
            }
            else
            {
                mBufferReady = true;
            }
            try
            {
                mDrawing = true;
                if (drawingBlock != null)
                {
                    drawingBlock();
                }
            }
            finally
            {
                mDrawing = false;
                mSupport.finishQuadBatch();
                mSupport.nextFrame();
                mSupport.setRenderTarget(null);
                context.setScissorRectangle(null);
            }
        }
Ejemplo n.º 16
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);
     }
 }
        private void onContextCreated(AsEvent _event)
        {
            AsContext3D  context    = AsStarling.getContext();
            AsBitmapData bitmapData = mData as AsBitmapData;
            AsAtfData    atfData    = mData as AsAtfData;

            bc.flash.display3D.textures.AsTexture nativeTexture = null;
            if (bitmapData != null)
            {
                nativeTexture = context.createTexture(mWidth, mHeight, AsContext3DTextureFormat.BGRA, mOptimizedForRenderTexture);
                AsTexture.uploadBitmapData(nativeTexture, bitmapData, mMipMapping);
            }
            else
            {
                if (atfData != null)
                {
                    nativeTexture = context.createTexture(atfData.getWidth(), atfData.getHeight(), atfData.getFormat(), mOptimizedForRenderTexture);
                    AsTexture.uploadAtfData(nativeTexture, atfData.getData());
                }
            }
            mBase = nativeTexture;
        }
Ejemplo n.º 18
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();
     }
 }
Ejemplo n.º 19
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);
     }
 }
Ejemplo n.º 20
0
 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);
     }
 }
Ejemplo n.º 21
0
 public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing, AsMatrix modelViewMatrix)
 {
     addQuad(quad, parentAlpha, texture, smoothing, modelViewMatrix, null);
 }
Ejemplo n.º 22
0
 public static AsTexture fromTexture(AsTexture texture, AsRectangle region)
 {
     return(fromTexture(texture, region, null));
 }
Ejemplo n.º 23
0
 public AsSubTexture(AsTexture parentTexture, AsRectangle region)
     : this(parentTexture, region, false)
 {
 }
Ejemplo n.º 24
0
 public virtual void setUpState(AsTexture _value)
 {
     if(mUpState != _value)
     {
         mUpState = _value;
         if(!mIsDown)
         {
             mBackground.setTexture(_value);
         }
     }
 }
 protected override void activate(int pass, AsContext3D context, AsTexture texture)
 {
     context.setProgramConstantsFromVector(AsContext3DProgramType.FRAGMENT, 0, mShaderMatrix);
     context.setProgramConstantsFromVector(AsContext3DProgramType.FRAGMENT, 5, MIN_COLOR);
     context.setProgram(mShaderProgram);
 }
 protected override void activate(int pass, AsContext3D context, AsTexture texture)
 {
     context.setProgram(mShaderProgram);
 }
Ejemplo n.º 27
0
 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;
 }
 protected virtual void activate(int pass, AsContext3D context, AsTexture texture)
 {
     throw new AsError("Method has to be implemented in subclass!");
 }
 protected virtual void deactivate(int pass, AsContext3D context, AsTexture texture)
 {
 }
 public AsTextureAtlas(AsTexture texture)
     : this(texture, null)
 {
 }
Ejemplo n.º 31
0
 public AsTextureAtlas(AsTexture texture)
     : this(texture, null)
 {
 }
Ejemplo n.º 32
0
 public AsSubTexture(AsTexture parentTexture, AsRectangle region)
     : this(parentTexture, region, false)
 {
 }
Ejemplo n.º 33
0
 public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing)
 {
     addQuad(quad, parentAlpha, texture, smoothing, null, null);
 }
Ejemplo n.º 34
0
 public static AsTexture fromTexture(AsTexture texture)
 {
     return(fromTexture(texture, null, null));
 }
Ejemplo n.º 35
0
 public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture)
 {
     addQuad(quad, parentAlpha, texture, null, null, null);
 }
Ejemplo n.º 36
0
 public AsBitmapFont(AsTexture texture)
     : this(texture, null)
 {
 }
Ejemplo n.º 37
0
 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;
                 }
             }
         }
     }
 }
Ejemplo n.º 38
0
 public virtual bool isStateChange(bool tinted, float parentAlpha, AsTexture texture, String smoothing, String blendMode)
 {
     return isStateChange(tinted, parentAlpha, texture, smoothing, blendMode, 1);
 }
Ejemplo n.º 39
0
 public virtual void reset()
 {
     mNumQuads = 0;
     mTexture = null;
     mSmoothing = null;
     mSyncRequired = true;
 }
Ejemplo n.º 40
0
 public AsButton(AsTexture upState, String text)
     : this(upState, text, null)
 {
 }
 protected override void activate(int pass, AsContext3D context, AsTexture texture)
 {
     context.setProgramConstantsFromVector(AsContext3DProgramType.FRAGMENT, 0, mOnes, 1);
     context.setProgramConstantsFromVector(AsContext3DProgramType.FRAGMENT, 1, mMinColor, 1);
     context.setProgram(mShaderProgram);
 }
Ejemplo n.º 42
0
 public AsButton(AsTexture upState)
     : this(upState, "", null)
 {
 }