Code example for Rect

Methods: set

0
	private int mTextSize;
	private String mText;
	private Typeface mTypeface;
	private Texture mTexture = new Texture();
	 
	private final Rect mRect = new Rect();
	 
	private int mColor = 0xffffffff;
	 
	private static final Canvas mCanvas = new Canvas();
	private final Paint mPaint = new Paint();
	 
	private FloatBuffer mVertexBuffer = AtlasGraphic.getDirectFloatBuffer(8);
	private FloatBuffer mTextureBuffer = AtlasGraphic.getDirectFloatBuffer(8);
	 
	public Text(String text) {
		this(text, 20, null);
	} 
	 
	public Text(String text, int textSize) {
		this(text, textSize, null);
	} 
	public Text(String text, int textSize, Typeface tf) {
		super(); 
		mText = text;
		mTextSize = textSize;
		mTypeface = tf;
		 
		updateTexture(); 
	} 
	 
	public void setTypeFace(Typeface tf) {
		mTypeface = tf;
		 
		updateTexture(); 
	} 
	 
	public void setText(String text) {
		if (text.equals(mText)) {
			return; 
		} 
		mText = text;
		 
		updateTexture(); 
	} 
 
	private void updateTexture() { 
		if (mTexture.isLoaded()) {
			// Will allow us to load on this texture again. 
			mTexture.release();
		} 
		mPaint.reset();
		if (mTypeface != null) {
			mPaint.setTypeface(mTypeface);
		} 
		mPaint.setTextSize(mTextSize);
		 
		mPaint.setColor(0xffffffff);
		mPaint.setStyle(Style.FILL);
		 
		int width = (int)mPaint.measureText(mText);
		int height = (int)(-mPaint.ascent() + mPaint.descent());
		Bitmap newBuffer = Bitmap.createBitmap(Texture.nextHigher2(width), Texture.nextHigher2(height), Config.ARGB_8888);
		mCanvas.setBitmap(newBuffer);
		mCanvas.drawText(mText, 0, -mPaint.ascent(), mPaint);
		 
		mRect.set(0, 0, width, height);
		 
		mTexture.setTextureBitmap(newBuffer);
		 
		AtlasGraphic.setGeometryBuffer(mVertexBuffer, mRect);
		AtlasGraphic.setTextureBuffer(mTextureBuffer, mTexture, mRect);
	} 
	 
	@Override  
	public void reload() { 
		updateTexture();