FileDocCategorySizeDatePackage
NumericSprite.javaAPI DocAndroid 1.5 API3030Wed May 06 22:41:08 BST 2009com.example.android.apis.graphics.spritetext

NumericSprite

public class NumericSprite extends Object

Fields Summary
private LabelMaker
mLabelMaker
private String
mText
private int[]
mWidth
private int[]
mLabelId
private static final String
sStrike
Constructors Summary
public NumericSprite()

        mText = "";
        mLabelMaker = null;
    
Methods Summary
public voiddraw(javax.microedition.khronos.opengles.GL10 gl, float x, float y, float viewWidth, float viewHeight)

        int length = mText.length();
        mLabelMaker.beginDrawing(gl, viewWidth, viewHeight);
        for(int i = 0; i < length; i++) {
            char c = mText.charAt(i);
            int digit = c - '0";
            mLabelMaker.draw(gl, x, y, mLabelId[digit]);
            x += mWidth[digit];
        }
        mLabelMaker.endDrawing(gl);
    
private java.lang.Stringformat(int value)

        return Integer.toString(value);
    
public voidinitialize(javax.microedition.khronos.opengles.GL10 gl, android.graphics.Paint paint)

        int height = roundUpPower2((int) paint.getFontSpacing());
        final float interDigitGaps = 9 * 1.0f;
        int width = roundUpPower2((int) (interDigitGaps + paint.measureText(sStrike)));
        mLabelMaker = new LabelMaker(true, width, height);
        mLabelMaker.initialize(gl);
        mLabelMaker.beginAdding(gl);
        for (int i = 0; i < 10; i++) {
            String digit = sStrike.substring(i, i+1);
            mLabelId[i] = mLabelMaker.add(gl, digit, paint);
            mWidth[i] = (int) Math.ceil(mLabelMaker.getWidth(i));
        }
        mLabelMaker.endAdding(gl);
    
private introundUpPower2(int x)
Find the smallest power of two >= the input value. (Doesn't work for negative numbers.)

        x = x - 1;
        x = x | (x >> 1);
        x = x | (x >> 2);
        x = x | (x >> 4);
        x = x | (x >> 8);
        x = x | (x >>16);
        return x + 1;
    
public voidsetValue(int value)

        mText = format(value);
    
public voidshutdown(javax.microedition.khronos.opengles.GL10 gl)

        mLabelMaker.shutdown(gl);
        mLabelMaker = null;
    
public floatwidth()

        float width = 0.0f;
        int length = mText.length();
        for(int i = 0; i < length; i++) {
            char c = mText.charAt(i);
            width += mWidth[c - '0"];
        }
        return width;