org.andengine.opengl.font.IFont Java Examples

The following examples show how to use org.andengine.opengl.font.IFont. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceLoader.java    From sopa with Apache License 2.0 5 votes vote down vote up
IFont getFont(final String name, float size, int color, float strokeWidth, int strokeColor) {

        FontFactory.setAssetBasePath("fonts/");

        final ITexture mainFontTexture = new BitmapTextureAtlas(textureManager, 1024, 1024, TextureOptions.BILINEAR);
        IFont font = FontFactory.createStrokeFromAsset(fontManager, mainFontTexture, assetManager, name, size, true,
                color, strokeWidth, strokeColor);
        font.load();

        return font;
    }
 
Example #2
Source File: Text.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * @param pText
 * @throws OutOfCharactersException leaves this {@link Text} object in an undefined state, until {@link #setText(CharSequence)} is called again and no {@link OutOfCharactersException} is thrown.
 */
public void setText(final CharSequence pText) throws OutOfCharactersException {
	this.mText = pText;
	final IFont font = this.mFont;

	this.mLines.clear();
	this.mLineWidths.clear();

	if (this.mTextOptions.mAutoWrap == AutoWrap.NONE) {
		this.mLines = FontUtils.splitLines(this.mText, this.mLines); // TODO Add whitespace-trimming.
	} else {
		this.mLines = FontUtils.splitLines(this.mFont, this.mText, this.mLines, this.mTextOptions.mAutoWrap, this.mTextOptions.mAutoWrapWidth);
	}

	final int lineCount = this.mLines.size();
	float maximumLineWidth = 0;
	for (int i = 0; i < lineCount; i++) {
		final float lineWidth = FontUtils.measureText(font, this.mLines.get(i));
		maximumLineWidth = Math.max(maximumLineWidth, lineWidth);

		this.mLineWidths.add(lineWidth);
	}
	this.mLineWidthMaximum = maximumLineWidth;

	if (this.mTextOptions.mAutoWrap == AutoWrap.NONE) {
		this.mLineAlignmentWidth = this.mLineWidthMaximum;
	} else {
		this.mLineAlignmentWidth = this.mTextOptions.mAutoWrapWidth;
	}

	final float width = this.mLineAlignmentWidth;
	final float height = lineCount * font.getLineHeight() + (lineCount - 1) * this.mTextOptions.mLeading;

	this.setSize(width, height);
}
 
Example #3
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final ITextVertexBufferObject pTextVertexBufferObject, final ShaderProgram pShaderProgram) {
	super(pX, pY, 0, 0, pShaderProgram);

	this.mFont = pFont;
	this.mTextOptions = pTextOptions;
	this.mCharactersMaximum = pCharactersMaximum;
	this.mVertexCount = Text.VERTICES_PER_LETTER * this.mCharactersMaximum;
	this.mTextVertexBufferObject = pTextVertexBufferObject;

	this.onUpdateColor();
	this.setText(pText);

	this.setBlendingEnabled(true);
	this.initBlendFunction(this.mFont.getTexture());
}
 
Example #4
Source File: Text.java    From tilt-game-android with MIT License 5 votes vote down vote up
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final ITextVertexBufferObject pTextVertexBufferObject, final ShaderProgram pShaderProgram) {
	super(pX, pY, pShaderProgram);

	this.mFont = pFont;
	this.mTextOptions = pTextOptions;
	this.mCharactersMaximum = pCharactersMaximum;
	this.mVertexCount = Text.VERTICES_PER_LETTER * this.mCharactersMaximum;
	this.mTextVertexBufferObject = pTextVertexBufferObject;

	this.onUpdateColor();
	this.setText(pText);

	this.setBlendingEnabled(true);
	this.initBlendFunction(this.mFont.getTexture());
}
 
Example #5
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType, final ShaderProgram pShaderProgram) {
	super(0, 0, pFont, pText, pCharactersMaximum, pTextOptions, pVertexBufferObjectManager, pDrawType, pShaderProgram);

	this.mID = pID;
}
 
Example #6
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public IFont getFont() {
	return this.mFont;
}
 
Example #7
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final ITextVertexBufferObject pTextVertexBufferObject) {
	super(0, 0, pFont, pText, pCharactersMaximum, pTextOptions, pTextVertexBufferObject);

	this.mID = pID;
}
 
Example #8
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final ITextVertexBufferObject pTextVertexBufferObject, final ShaderProgram pShaderProgram) {
	super(0, 0, pFont, pText, pCharactersMaximum, pTextOptions, pTextVertexBufferObject, pShaderProgram);

	this.mID = pID;
}
 
Example #9
Source File: HighPerformanceTextVertexBufferObject.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public void onUpdateVertices(final Text pText) {
	final float[] bufferData = this.mBufferData;

	// TODO Optimize with field access?
	final IFont font = pText.getFont();
	final ArrayList<CharSequence> lines = pText.getLines();
	final float lineHeight = font.getLineHeight();
	final IFloatList lineWidths = pText.getLineWidths();

	final float lineAlignmentWidth = pText.getLineAlignmentWidth();

	int charactersToDraw = 0;
	int bufferDataOffset = 0;

	final int lineCount = lines.size();
	for (int row = 0; row < lineCount; row++) {
		final CharSequence line = lines.get(row);

		float xBase;
		switch(pText.getHorizontalAlign()) {
			case RIGHT:
				xBase = lineAlignmentWidth - lineWidths.get(row);
				break;
			case CENTER:
				xBase = (lineAlignmentWidth - lineWidths.get(row)) * 0.5f;
				break;
			case LEFT:
			default:
				xBase = 0;
		}

		final float yBase = row * (lineHeight + pText.getLeading());

		final int lineLength = line.length();
		Letter previousLetter = null;
		for(int i = 0; i < lineLength; i++) {
			final Letter letter = font.getLetter(line.charAt(i));
			if(previousLetter != null) {
				xBase += previousLetter.getKerning(letter.mCharacter);
			}

			if(!letter.isWhitespace()) {
				final float x = xBase + letter.mOffsetX;
				final float y = yBase + letter.mOffsetY;

				final float y2 = y + letter.mHeight;
				final float x2 = x + letter.mWidth;

				final float u = letter.mU;
				final float v = letter.mV;
				final float u2 = letter.mU2;
				final float v2 = letter.mV2;

				bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x;
				bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y;
				bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u;
				bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v;

				bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x;
				bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2;
				bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u;
				bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2;

				bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2;
				bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2;
				bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2;
				bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2;

				bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2;
				bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2;
				bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2;
				bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2;

				bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2;
				bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y;
				bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2;
				bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v;

				bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x;
				bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y;
				bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u;
				bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v;

				bufferDataOffset += Text.LETTER_SIZE;
				charactersToDraw++;
			}

			xBase += letter.mAdvance;

			previousLetter = letter;
		}
	}
	pText.setCharactersToDraw(charactersToDraw);

	this.setDirtyOnHardware();
}
 
Example #10
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
	this(pX, pY, pFont, pText, pCharactersMaximum, pTextOptions, new HighPerformanceTextVertexBufferObject(pVertexBufferObjectManager, Text.LETTER_SIZE * pCharactersMaximum, pDrawType, true, Text.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT));
}
 
Example #11
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
	this(pX, pY, pFont, pText, pCharactersMaximum, pVertexBufferObjectManager, DrawType.STATIC, pShaderProgram);
}
 
Example #12
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
	this(pX, pY, pFont, pText, pCharactersMaximum, new TextOptions(), pVertexBufferObjectManager, pDrawType);
}
 
Example #13
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType, final ShaderProgram pShaderProgram) {
	this(pX, pY, pFont, pText, pCharactersMaximum, new TextOptions(), pVertexBufferObjectManager, pDrawType, pShaderProgram);
}
 
Example #14
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager) {
	this(pX, pY, pFont, pText, pCharactersMaximum, pTextOptions, pVertexBufferObjectManager, DrawType.STATIC);
}
 
Example #15
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public Text(final float pX, final float pY, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final ITextVertexBufferObject pTextVertexBufferObject) {
	this(pX, pY, pFont, pText, pCharactersMaximum, pTextOptions, pTextVertexBufferObject, PositionColorTextureCoordinatesShaderProgram.getInstance());
}
 
Example #16
Source File: Text.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
/**
 * @param pText
 * @throws OutOfCharactersException leaves this {@link Text} object in an undefined state, until {@link Text#setText(CharSequence)} is called again and no {@link OutOfCharactersException} is thrown.
 */
public void setText(final CharSequence pText) throws OutOfCharactersException {
	this.mText = pText;
	final IFont font = this.mFont;

	this.mLines.clear();
	this.mLineWidths.clear();

	if(this.mTextOptions.mAutoWrap == AutoWrap.NONE) {
		this.mLines = FontUtils.splitLines(this.mText, this.mLines); // TODO Add whitespace-trimming.
	} else {
		this.mLines = FontUtils.splitLines(this.mFont, this.mText, this.mLines, this.mTextOptions.mAutoWrap, this.mTextOptions.mAutoWrapWidth);
	}

	final int lineCount = this.mLines.size();
	float maximumLineWidth = 0;
	for (int i = 0; i < lineCount; i++) {
		final float lineWidth = FontUtils.measureText(font, this.mLines.get(i));
		maximumLineWidth = Math.max(maximumLineWidth, lineWidth);

		this.mLineWidths.add(lineWidth);
	}
	this.mLineWidthMaximum = maximumLineWidth;

	if(this.mTextOptions.mAutoWrap == AutoWrap.NONE) {
		this.mLineAlignmentWidth = this.mLineWidthMaximum;
	} else {
		this.mLineAlignmentWidth = this.mTextOptions.mAutoWrapWidth;
	}

	super.mWidth = this.mLineAlignmentWidth;
	super.mHeight = lineCount * font.getLineHeight() + (lineCount - 1) * this.mTextOptions.mLeading;

	this.mRotationCenterX = super.mWidth * 0.5f;
	this.mRotationCenterY = super.mHeight * 0.5f;

	this.mScaleCenterX = this.mRotationCenterX;
	this.mScaleCenterY = this.mRotationCenterY;

	this.onUpdateVertices();
}
 
Example #17
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
	super(0, 0, pFont, pText, pVertexBufferObjectManager, pShaderProgram);

	this.mID = pID;
}
 
Example #18
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
	super(0, 0, pFont, pText, pCharactersMaximum, pTextOptions, pVertexBufferObjectManager, pDrawType);

	this.mID = pID;
}
 
Example #19
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager) {
	super(0, 0, pFont, pText, pCharactersMaximum, pTextOptions, pVertexBufferObjectManager);

	this.mID = pID;
}
 
Example #20
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType, final ShaderProgram pShaderProgram) {
	super(0, 0, pFont, pText, pCharactersMaximum, pVertexBufferObjectManager, pDrawType, pShaderProgram);

	this.mID = pID;
}
 
Example #21
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
	super(0, 0, pFont, pText, pCharactersMaximum, pVertexBufferObjectManager, pDrawType);

	this.mID = pID;
}
 
Example #22
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
	super(0, 0, pFont, pText, pCharactersMaximum, pVertexBufferObjectManager, pShaderProgram);

	this.mID = pID;
}
 
Example #23
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType, final ShaderProgram pShaderProgram) {
	super(0, 0, pFont, pText, pTextOptions, pVertexBufferObjectManager, pDrawType, pShaderProgram);

	this.mID = pID;
}
 
Example #24
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final int pCharactersMaximum, final VertexBufferObjectManager pVertexBufferObjectManager) {
	super(0, 0, pFont, pText, pCharactersMaximum, pVertexBufferObjectManager);

	this.mID = pID;
}
 
Example #25
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
	super(0, 0, pFont, pText, pTextOptions, pVertexBufferObjectManager, pDrawType);

	this.mID = pID;
}
 
Example #26
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
	super(0, 0, pFont, pText, pTextOptions, pVertexBufferObjectManager, pShaderProgram);

	this.mID = pID;
}
 
Example #27
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final TextOptions pTextOptions, final VertexBufferObjectManager pVertexBufferObjectManager) {
	super(0, 0, pFont, pText, pTextOptions, pVertexBufferObjectManager);

	this.mID = pID;
}
 
Example #28
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType, final ShaderProgram pShaderProgram) {
	super(0, 0, pFont, pText, pVertexBufferObjectManager, pDrawType, pShaderProgram);

	this.mID = pID;
}
 
Example #29
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final VertexBufferObjectManager pVertexBufferObjectManager, final DrawType pDrawType) {
	super(0, 0, pFont, pText, pVertexBufferObjectManager, pDrawType);

	this.mID = pID;
}
 
Example #30
Source File: TextMenuItem.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public TextMenuItem(final int pID, final IFont pFont, final CharSequence pText, final VertexBufferObjectManager pVertexBufferObjectManager) {
	super(0, 0, pFont, pText, pVertexBufferObjectManager);

	this.mID = pID;
}