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())); } }
public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { if((resultRect == null)) { resultRect = new AsRectangle(); } if((targetSpace == this)) { resultRect.x = getX(); resultRect.y = getY(); resultRect.width = mBitmapData.getWidth(); resultRect.height = mBitmapData.getHeight(); return resultRect; } float minX = AsMathHelper.MAX_NUMBER; float maxX = -AsMathHelper.MAX_NUMBER; float minY = AsMathHelper.MAX_NUMBER; float maxY = -AsMathHelper.MAX_NUMBER; getTransformationMatrix(targetSpace, sHelperMatrix); sPosition.x = getX(); sPosition.y = getY(); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.x = (sPosition.x + getBitmapData().getWidth()); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.y = (sPosition.y + getBitmapData().getHeight()); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.x = getX(); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); resultRect.x = minX; resultRect.y = minY; resultRect.width = (maxX - minX); resultRect.height = (maxY - minY); return resultRect; }
public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { if(resultRect == null) { resultRect = new AsRectangle(); } if(targetSpace == this) { mVertexData.getPosition(3, sHelperPoint); resultRect.setTo(0.0f, 0.0f, sHelperPoint.x, sHelperPoint.y); } else { if(targetSpace == getParent() && getRotation() == 0.0f) { float scaleX = this.getScaleX(); float scaleY = this.getScaleY(); mVertexData.getPosition(3, sHelperPoint); resultRect.setTo(getX() - getPivotX() * scaleX, getY() - getPivotY() * scaleY, sHelperPoint.x * scaleX, sHelperPoint.y * scaleY); if(scaleX < 0) { resultRect.width = resultRect.width * -1; resultRect.x = resultRect.x - resultRect.width; } if(scaleY < 0) { resultRect.height = resultRect.height * -1; resultRect.y = resultRect.y - resultRect.height; } } else { getTransformationMatrix(targetSpace, sHelperMatrix); mVertexData.getBounds(sHelperMatrix, 0, 4, resultRect); } } return resultRect; }
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); } }
public virtual AsRectangle union(AsRectangle toUnion) { throw new AsNotImplementedError(); }
public virtual bool equals(AsRectangle toCompare) { return(x == toCompare.x && y == toCompare.y && width == toCompare.width && height == toCompare.height); }
public virtual void draw(AsIBitmapDrawable source, AsMatrix matrix, AsColorTransform colorTransform, String blendMode, AsRectangle clipRect, bool smoothing) { }
public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { if(resultRect == null) { resultRect = new AsRectangle(); } AsMatrix transformationMatrix = targetSpace == this ? null : getTransformationMatrix(targetSpace, sHelperMatrix); return mVertexData.getBounds(transformationMatrix, 0, mNumQuads * 4, resultRect); }
public virtual void setScrollRect(AsRectangle _value) { mScrollRect = _value; }
public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { if(resultRect == null) { resultRect = new AsRectangle(); } int numChildren = (int)(mChildren.getLength()); if(numChildren == 0) { getTransformationMatrix(targetSpace, sHelperMatrix); AsMatrixUtil.transformCoords(sHelperMatrix, 0.0f, 0.0f, sHelperPoint); resultRect.setTo(sHelperPoint.x, sHelperPoint.y, 0, 0); return resultRect; } else { if(numChildren == 1) { return mChildren[0].getBounds(targetSpace, resultRect); } else { float minX = AsNumber.MAX_VALUE; float maxX = -AsNumber.MAX_VALUE; float minY = AsNumber.MAX_VALUE; float maxY = -AsNumber.MAX_VALUE; int i = 0; for (; i < numChildren; ++i) { mChildren[i].getBounds(targetSpace, resultRect); minX = minX < resultRect.x ? minX : resultRect.x; maxX = maxX > resultRect.getRight() ? maxX : resultRect.getRight(); minY = minY < resultRect.y ? minY : resultRect.y; maxY = maxY > resultRect.getBottom() ? maxY : resultRect.getBottom(); } resultRect.setTo(minX, minY, maxX - minX, maxY - minY); return resultRect; } } }
public virtual void setFullScreenSourceRect(AsRectangle _value) { mFullScreenSourceRect = _value; }
public void copyPixels(AsBitmapData data, AsRectangle asRectangle, AsPoint sOrigin) { throw new NotImplementedException(); }
public virtual bool equals(AsRectangle toCompare) { return ((((x == toCompare.x) && (y == toCompare.y)) && (width == toCompare.width)) && (height == toCompare.height)); }
public virtual void setTextBounds(AsRectangle _value) { mTextBounds = _value.clone(); createTextField(); }
public AsSubTexture(AsTexture parentTexture, AsRectangle region) : this(parentTexture, region, false) { }
public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { if(resultRect == null) { resultRect = new AsRectangle(); } int childsCount = getNumChildren(); if(childsCount == 0) { getTransformationMatrix(targetSpace, sHelperMatrix); AsGlobal.transformCoords(sHelperMatrix, 0.0f, 0.0f, sHelperPoint); resultRect.x = sHelperPoint.x; resultRect.y = sHelperPoint.y; resultRect.width = resultRect.height = 0; return resultRect; } else { if(childsCount == 1) { return mChildren[0].getBounds(targetSpace, resultRect); } else { float minX = AsMathHelper.MAX_NUMBER; float maxX = -AsMathHelper.MAX_NUMBER; float minY = AsMathHelper.MAX_NUMBER; float maxY = -AsMathHelper.MAX_NUMBER; int i = 0; for (; i < childsCount; ++i) { mChildren[i].getBounds(targetSpace, resultRect); minX = minX < resultRect.x ? minX : resultRect.x; maxX = maxX > resultRect.getRight() ? maxX : resultRect.getRight(); minY = minY < resultRect.y ? minY : resultRect.y; maxY = maxY > resultRect.getBottom() ? maxY : resultRect.getBottom(); } resultRect.x = minX; resultRect.y = minY; resultRect.width = maxX - minX; resultRect.height = maxY - minY; return resultRect; } } }
private void setClipping(AsRectangle _value) { mClipping = _value; mRootClipping = _value.clone(); AsSubTexture parentTexture = mParent as AsSubTexture; while(parentTexture != null) { AsRectangle parentClipping = parentTexture.mClipping; mRootClipping.x = parentClipping.x + mRootClipping.x * parentClipping.width; mRootClipping.y = parentClipping.y + mRootClipping.y * parentClipping.height; mRootClipping.width = mRootClipping.width * parentClipping.width; mRootClipping.height = mRootClipping.height * parentClipping.height; parentTexture = parentTexture.mParent as AsSubTexture; } }
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); } } } }
protected virtual void parseAtlasXml(AsXML atlasXml) { float scale = mAtlasTexture.getScale(); AsSubTexture __subTextures_ = atlasXml.SubTexture; if (__subTextures_ != null) { foreach (AsXML subTexture in __subTextures_) { String name = subTexture.attribute("name"); float x = AsGlobal.parseFloat(subTexture.attribute("x")) / scale; float y = AsGlobal.parseFloat(subTexture.attribute("y")) / scale; float width = AsGlobal.parseFloat(subTexture.attribute("width")) / scale; float height = AsGlobal.parseFloat(subTexture.attribute("height")) / scale; float frameX = AsGlobal.parseFloat(subTexture.attribute("frameX")) / scale; float frameY = AsGlobal.parseFloat(subTexture.attribute("frameY")) / scale; float frameWidth = AsGlobal.parseFloat(subTexture.attribute("frameWidth")) / scale; float frameHeight = AsGlobal.parseFloat(subTexture.attribute("frameHeight")) / scale; AsRectangle region = new AsRectangle(x, y, width, height); AsRectangle frame = frameWidth > 0 && frameHeight > 0 ? new AsRectangle(frameX, frameY, frameWidth, frameHeight) : null; addRegion(name, region, frame); } } }
public void setPixels(AsRectangle rect, AsByteArray bytes) { throw new NotImplementedException(); }
public virtual void addRegion(String name, AsRectangle region, AsRectangle frame) { mTextureRegions[name] = region; mTextureFrames[name] = frame; }
public void fillRect(AsRectangle bounds, uint p) { throw new NotImplementedException(); }
public virtual void addRegion(String name, AsRectangle region) { addRegion(name, region, null); }
public virtual AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { throw new AsAbstractMethodError("Method needs to be implemented in subclass"); }
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 void uploadBitmapData(bc.flash.display3D.textures.AsTexture nativeTexture, AsBitmapData data, bool generateMipmaps) { nativeTexture.uploadFromBitmapData(data); if(generateMipmaps && data.getWidth() > 1 && data.getHeight() > 1) { int currentWidth = data.getWidth() >> 1; int currentHeight = data.getHeight() >> 1; int level = 1; AsBitmapData canvas = new AsBitmapData(currentWidth, currentHeight, true, 0); AsMatrix transform = new AsMatrix(.5f, 0, 0, .5f); AsRectangle bounds = new AsRectangle(); while(currentWidth >= 1 || currentHeight >= 1) { bounds.width = currentWidth; bounds.height = currentHeight; canvas.fillRect(bounds, (uint)(0)); canvas.draw(data, transform, null, null, null, true); nativeTexture.uploadFromBitmapData(canvas, (uint)(level++)); transform.scale(0.5f, 0.5f); currentWidth = currentWidth >> 1; currentHeight = currentHeight >> 1; } canvas.dispose(); } }
public virtual void draw(AsIBitmapDrawable source, AsMatrix matrix, AsColorTransform colorTransform, String blendMode, AsRectangle clipRect) { draw(source, null, null, null, null, false); }
public virtual void setScissorRectangle(AsRectangle rectangle) { throw new AsNotImplementedError(); }
public virtual bool intersects(AsRectangle toIntersect) { throw new AsNotImplementedError(); }
private void calculateBounds(AsDisplayObject _object, AsStage stage, AsRectangle resultRect) { if(_object == stage || _object == AsStarling.getCurrent().getRoot()) { resultRect.setTo(0, 0, stage.getStageWidth(), stage.getStageHeight()); } else { _object.getBounds(stage, resultRect); } float deltaMargin = mResolution == 1.0f ? 0.0f : 1.0f / mResolution; resultRect.x = resultRect.x - mMarginX + deltaMargin; resultRect.y = resultRect.y - mMarginY + deltaMargin; resultRect.width = resultRect.width + 2 * (mMarginX + deltaMargin); resultRect.height = resultRect.height + 2 * (mMarginY + deltaMargin); resultRect.width = AsGlobal.getNextPowerOfTwo((int)(resultRect.width * mResolution)) / mResolution; resultRect.height = AsGlobal.getNextPowerOfTwo((int)(resultRect.height * mResolution)) / mResolution; }
public virtual bool containsRect(AsRectangle rect) { throw new AsNotImplementedError(); }
private void updateBuffers(AsContext3D context, AsRectangle bounds) { mVertexData.setPosition(0, bounds.x, bounds.y); mVertexData.setPosition(1, bounds.getRight(), bounds.y); mVertexData.setPosition(2, bounds.x, bounds.getBottom()); mVertexData.setPosition(3, bounds.getRight(), bounds.getBottom()); if(mVertexBuffer == null) { mVertexBuffer = context.createVertexBuffer(4, AsVertexData.ELEMENTS_PER_VERTEX); mIndexBuffer = context.createIndexBuffer(6); mIndexBuffer.uploadFromVector(mIndexData, 0, 6); } mVertexBuffer.uploadFromVector(mVertexData.getRawData(), 0, 4); }
public virtual AsRectangle intersection(AsRectangle toIntersect) { throw new AsNotImplementedError(); }