initial bmf Draw() implementation
This commit is contained in:
parent
f309d1df82
commit
8b406c8a9b
@ -4,6 +4,7 @@ import java.io.InputStream;
|
||||
|
||||
import javax.microedition.lcdui.Graphics;
|
||||
import javax.microedition.lcdui.Image;
|
||||
import javax.microedition.lcdui.game.Sprite;
|
||||
|
||||
public class BMF {
|
||||
public static final byte ID = 0;
|
||||
@ -128,6 +129,34 @@ public class BMF {
|
||||
public void Draw(Graphics g, String str, int x, int y)
|
||||
{
|
||||
short[] cursor = new short[]{0, 0};
|
||||
|
||||
for (int i=0; i<str.length(); i++)
|
||||
{
|
||||
char index = str.charAt(i);
|
||||
if (index != '\n' && (index < 32 || index > 127)) index = 127;
|
||||
|
||||
if (index == '\n')
|
||||
{
|
||||
cursor[1] += lineHeight;
|
||||
cursor[0] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
short[] ch = chars[index-32];
|
||||
int[] offset = new int[]{x+ch[XOFF]+cursor[0], y+ch[YOFF]+cursor[1]};
|
||||
g.drawRegion(
|
||||
img,
|
||||
ch[X], ch[Y], ch[WIDTH], ch[HEIGHT],
|
||||
Sprite.TRANS_NONE,
|
||||
x+offset[0], y+offset[1],
|
||||
Graphics.TOP | Graphics.LEFT);
|
||||
|
||||
cursor[0] += ch[XADV];
|
||||
|
||||
/*
|
||||
* TODO: handle kernings here
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,10 +16,11 @@ public class MainMenu extends Scene {
|
||||
private Image img_bg;
|
||||
private Image img_bandai;
|
||||
private Image img_ez;
|
||||
private BMF bmf;
|
||||
|
||||
public void Preload() {
|
||||
try {
|
||||
BMF bmf = new BMF("/silly/bmf/nds12.png", "/silly/bmf/nds12.fnt");
|
||||
bmf = new BMF("/silly/bmf/nds12.png", "/silly/bmf/nds12.fnt");
|
||||
Image img_loop = Image.createImage("/m_2.png");
|
||||
img_bandai = Image.createImage("/c_0.png");
|
||||
img_ez = Image.createImage("/pEZ.png");
|
||||
@ -63,6 +64,8 @@ public class MainMenu extends Scene {
|
||||
img_ez,
|
||||
Utils.GetScreenWidth()/2, (int)(Utils.GetScreenHeight()*0.75),
|
||||
Graphics.VCENTER | Graphics.HCENTER);
|
||||
|
||||
bmf.Draw(g, "hello world\nthis is test text!\nthe fox jumped over the lazy dog", 5, 10);
|
||||
|
||||
if (sagiri.input.IsKeyDownAny())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user