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); } }
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; }
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(); } }