Java Code Examples for com.badlogic.gdx.graphics.g2d.BitmapFont#getData()

The following examples show how to use com.badlogic.gdx.graphics.g2d.BitmapFont#getData() . 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: PatchedVisTextField.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawText(Batch batch, BitmapFont font, float x, float y) {
	//PATCH: Disabled color markup for BitmapFont when updating GlyphLayout https://github.com/libgdx/libgdx/issues/4576
	BitmapFontData fontData = font.getData();
	boolean markupEnabled = fontData.markupEnabled;
	fontData.markupEnabled = false;
	super.drawText(batch, font, x, y);
	fontData.markupEnabled = markupEnabled;
}
 
Example 2
Source File: VisTextArea.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) {
	float textOffset = cursor >= glyphPositions.size || cursorLine * 2 >= linesBreak.size ? 0
			: glyphPositions.get(cursor) - glyphPositions.get(linesBreak.items[cursorLine * 2]);
	cursorX = textOffset + fontOffset + font.getData().cursorX;
	cursorPatch.draw(batch, x + cursorX,
			y - font.getDescent() / 2 - (cursorLine - firstLineShowing + 1) * font.getLineHeight(), cursorPatch.getMinWidth(),
			font.getLineHeight());
}
 
Example 3
Source File: AndroidPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BitmapFont getFont(int size, String text) {
	FreeTypeFontGenerator generator = getGeneratorForString(text);
	
	if (generator == null){
		return null;
	}
	
	if (!fonts.get(generator).containsKey(size)) {
		FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter();
		parameters.size = size;
		parameters.flip = true;
		parameters.borderWidth = parameters.size / 10f;
		parameters.renderCount = 3;
		parameters.hinting = FreeTypeFontGenerator.Hinting.None;
		parameters.spaceX = -(int) parameters.borderWidth;
		parameters.incremental = true;
		if (generator == basicFontGenerator){
			//if we're using latin/cyrillic, we can safely pre-generate some common letters
			//(we define common as >4% frequency in english)
			parameters.characters = "�etaoinshrdl";
		} else {
			parameters.characters = "�";
		}
		parameters.packer = packer;
		
		try {
			BitmapFont font = generator.generateFont(parameters);
			font.getData().missingGlyph = font.getData().getGlyph('�');
			fonts.get(generator).put(size, font);
		} catch ( Exception e ){
			Game.reportException(e);
			return null;
		}
	}
	
	return fonts.get(generator).get(size);
}
 
Example 4
Source File: DesktopPlatformSupport.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BitmapFont getFont(int size, String text) {
	FreeTypeFontGenerator generator = getGeneratorForString(text);
	
	if (generator == null){
		return null;
	}
	
	if (!fonts.get(generator).containsKey(size)) {
		FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter();
		parameters.size = size;
		parameters.flip = true;
		parameters.borderWidth = parameters.size / 10f;
		parameters.renderCount = 3;
		parameters.hinting = FreeTypeFontGenerator.Hinting.None;
		parameters.spaceX = -(int) parameters.borderWidth;
		parameters.incremental = true;
		if (generator == basicFontGenerator){
			//if we're using latin/cyrillic, we can safely pre-generate some common letters
			//(we define common as >4% frequency in english)
			parameters.characters = "�etaoinshrdl";
		} else {
			parameters.characters = "�";
		}
		parameters.packer = packer;
		
		try {
			BitmapFont font = generator.generateFont(parameters);
			font.getData().missingGlyph = font.getData().getGlyph('�');
			fonts.get(generator).put(size, font);
		} catch ( Exception e ){
			Game.reportException(e);
			return null;
		}
	}
	
	return fonts.get(generator).get(size);
}
 
Example 5
Source File: FilteredSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
	validate();

	Drawable background;
	if (disabled && style.backgroundDisabled != null)
		background = style.backgroundDisabled;
	else if (selectBoxList.hasParent() && style.backgroundOpen != null)
		background = style.backgroundOpen;
	else if (clickListener.isOver() && style.backgroundOver != null)
		background = style.backgroundOver;
	else if (style.background != null)
		background = style.background;
	else
		background = null;
	BitmapFont font = style.font;
	Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : style.fontColor;

	Color color = getColor();
	float x = getX(), y = getY();
	float width = getWidth(), height = getHeight();

	batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
	if (background != null)
		background.draw(batch, x, y, width, height);

	T selected = selection.first();
	if (selected != null) {
		if (background != null) {
			width -= background.getLeftWidth() + background.getRightWidth();
			height -= background.getBottomHeight() + background.getTopHeight();
			x += background.getLeftWidth();
			y += (int) (height / 2 + background.getBottomHeight() + font.getData().capHeight / 2);
		} else {
			y += (int) (height / 2 + font.getData().capHeight / 2);
		}
		font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
		drawItem(batch, font, selected, x, y, width);
	}
}
 
Example 6
Source File: PathFinderTests.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void create () {
	Gdx.gl.glClearColor(.3f, .3f, .3f, 1);

	skin = new Skin(Gdx.files.internal("data/uiskin.json"));

	// Enable color markup
	BitmapFont font = skin.get("default-font", BitmapFont.class);
	font.getData().markupEnabled = true;

	stage = new Stage();
	stage.setDebugAll(DEBUG_STAGE);
	stageWidth = stage.getWidth();
	stageHeight = stage.getHeight();

	Gdx.input.setInputProcessor(new InputMultiplexer(stage));

	Stack stack = new Stack();
	stage.addActor(stack);
	stack.setSize(stageWidth, stageHeight);
	testsTable = new Table();
	stack.add(testsTable);

	// Create behavior selection window
	List<String> testList = createTestList();
	algorithmSelectionWindow = addBehaviorSelectionWindow("Path Finder Tests", testList, 0, -1);

	// Set selected test
	changeTest(0);

	stage.addActor(new FpsLabel("FPS: ", skin));
}