• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 package com.badlogic.gdx.tests;
18 
19 import com.badlogic.gdx.Gdx;
20 import com.badlogic.gdx.graphics.GL20;
21 import com.badlogic.gdx.graphics.g2d.BitmapFont;
22 import com.badlogic.gdx.graphics.g2d.BitmapFontCache;
23 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
24 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
25 import com.badlogic.gdx.tests.utils.GdxTest;
26 import com.badlogic.gdx.utils.Align;
27 
28 public class IntegerBitmapFontTest extends GdxTest {
29 
30 	BitmapFont font;
31 	BitmapFontCache singleLineCacheNonInteger;
32 	BitmapFontCache multiLineCacheNonInteger;
33 	BitmapFontCache singleLineCache;
34 	BitmapFontCache multiLineCache;
35 	SpriteBatch batch;
36 
create()37 	public void create () {
38 		TextureAtlas textureAtlas = new TextureAtlas("data/pack");
39 		font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), textureAtlas.findRegion("verdana39"), false);
40 		singleLineCache = new BitmapFontCache(font, true);
41 		multiLineCache = new BitmapFontCache(font, true);
42 		singleLineCacheNonInteger = new BitmapFontCache(font, false);
43 		multiLineCacheNonInteger = new BitmapFontCache(font, false);
44 		batch = new SpriteBatch();
45 		fillCaches();
46 	}
47 
48 	@Override
dispose()49 	public void dispose () {
50 		batch.dispose();
51 		font.dispose();
52 	}
53 
render()54 	public void render () {
55 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
56 		batch.begin();
57 		font.setUseIntegerPositions(false);
58 		font.setColor(1, 0, 0, 1);
59 		singleLineCacheNonInteger.draw(batch);
60 		multiLineCacheNonInteger.draw(batch);
61 		drawTexts();
62 		font.setUseIntegerPositions(true);
63 		font.setColor(1, 1, 1, 1);
64 		singleLineCache.draw(batch);
65 		multiLineCache.draw(batch);
66 		drawTexts();
67 		batch.end();
68 	}
69 
fillCaches()70 	private void fillCaches () {
71 		String text = "This is a TEST\nxahsdhwekjhasd23���$%$%/%&";
72 		singleLineCache.setColor(0, 0, 1, 1);
73 		singleLineCache.setText(text, 10.2f, 30.5f);
74 		multiLineCache.setColor(0, 0, 1, 1);
75 		multiLineCache.setText(text, 10.5f, 180.5f, 200, Align.center, false);
76 		singleLineCacheNonInteger.setColor(0, 1, 0, 1);
77 		singleLineCacheNonInteger.setText(text, 10.2f, 30.5f);
78 		multiLineCacheNonInteger.setColor(0, 1, 0, 1);
79 		multiLineCacheNonInteger.setText(text, 10.5f, 180.5f, 200, Align.center, false);
80 	}
81 
drawTexts()82 	private void drawTexts () {
83 		String text = "This is a TEST\nxahsdhwekjhasd23���$%$%/%&";
84 		font.draw(batch, text, 10.2f, 30.5f);
85 		font.draw(batch, text, 10.5f, 120.5f);
86 		font.draw(batch, text, 10.5f, 180.5f, 200, Align.center, false);
87 	}
88 }
89