If you think the Android project DiceInDark listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/* Dice in the dark. D & D app for the blind and seeing impaired,
* Copyright (C) <2013r> <Lovisa Irpa Helgadottir>
*//fromwww.java2s.com
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package com.plovergames.framework.gl;
publicclass Font {
publicfinal Texture texture;
publicfinalint glyphWidth;
publicfinalint glyphHeight;
publicfinal TextureRegion[] glyphs = new TextureRegion[96];
public Font(Texture texture,
int offsetX, int offsetY,
int glyphsPerRow, int glyphWidth, int glyphHeight) {
this.texture = texture;
this.glyphWidth = glyphWidth;
this.glyphHeight = glyphHeight;
int x = offsetX;
int y = offsetY;
for(int i = 0; i < 96; i++) {
glyphs[i] = new TextureRegion(texture, x, y, glyphWidth, glyphHeight);
x += glyphWidth;
if(x == offsetX + glyphsPerRow * glyphWidth) {
x = offsetX;
y += glyphHeight;
}
}
}
publicvoid drawText(SpriteBatcher batcher, String text, float x, float y) {
int len = text.length();
for(int i = 0; i < len; i++) {
int c = text.charAt(i) - ' ';
if(c < 0 || c > glyphs.length - 1)
continue;
TextureRegion glyph = glyphs[c];
batcher.drawSprite(x, y, glyphWidth, glyphHeight, glyph);
x += glyphWidth;
}
}
}