GTGE API

com.golden.gamedev.object.font
Class BitmapFont

java.lang.Object
  extended by com.golden.gamedev.object.font.BitmapFont
All Implemented Interfaces:
GameFont
Direct Known Subclasses:
AdvanceBitmapFont

public class BitmapFont
extends Object
implements GameFont

Game font that use images for the letter, all the images must have equal dimension (same width and height).

BitmapFont takes up two parameters, the array of images font and the sequence of the images, for example if the images font array sequence is ordered as follow: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", specify the parameter letter sequence as is.

If the images font has different width, use AdvanceBitmapFont instead.


Field Summary
protected  int[] charIndex
           
 
Fields inherited from interface com.golden.gamedev.object.GameFont
CENTER, JUSTIFY, LEFT, RIGHT
 
Constructor Summary
BitmapFont(BufferedImage[] imagefont)
          Creates new BitmapFont with specified images font and default letter sequence : !
BitmapFont(BufferedImage[] imagefont, String letterSequence)
          Creates new BitmapFont with specified images font and letter sequence.
 
Method Summary
 int drawString(Graphics2D g, String s, int x, int y)
          Draw a single line string into graphics context.
 int drawString(Graphics2D g, String s, int alignment, int x, int y, int width)
          Draw a single line string into graphics context with specified alignment.
 int drawText(Graphics2D g, String text, int alignment, int x, int y, int width, int vspace, int firstIndent)
          Draw multiple line text into graphics context.
 int getHeight()
          Returns the height of this font in pixel.
 BufferedImage[] getImageFont()
          Returns the images font used to draw this bitmap font.
 int getWidth(char c)
          Returns the width of char c in pixel.
 int getWidth(String st)
          Returns the width of String st in pixel.
 boolean isAvailable(char c)
          Returns whether the specified char c is available to draw by this game font.
 void setImageFont(BufferedImage[] imagefont, String letterSequence)
          Sets images font to draw this bitmap font.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

charIndex

protected int[] charIndex
Constructor Detail

BitmapFont

public BitmapFont(BufferedImage[] imagefont,
                  String letterSequence)
Creates new BitmapFont with specified images font and letter sequence.

Parameters:
imagefont - the images font, all images must have same size
letterSequence - the order sequence of the images font

BitmapFont

public BitmapFont(BufferedImage[] imagefont)
Creates new BitmapFont with specified images font and default letter sequence :
         ! " # $ % & ' ( ) * + , - . / 0 1 2 3
       4 5 6 7 8 9 : ; < = > ? @ A B C D E F G
       H I J K L M N O P Q R S T U V W X Y Z [
       \ ] ^ _ ' a b c d e f g h i j k l m n o
       p q r s t u v w x y z { | } ~
 

Parameters:
imagefont - the images font, all images must have same size
Method Detail

drawString

public int drawString(Graphics2D g,
                      String s,
                      int x,
                      int y)
Description copied from interface: GameFont
Draw a single line string into graphics context.

Specified by:
drawString in interface GameFont
Parameters:
g - the graphics context
s - the string to be drawn
x - the x screen coordinate to draw the text
y - the y screen coordinate to draw the text
Returns:
The right-edge of x coordinate to draw next text.

drawString

public int drawString(Graphics2D g,
                      String s,
                      int alignment,
                      int x,
                      int y,
                      int width)
Description copied from interface: GameFont
Draw a single line string into graphics context with specified alignment.

Specified by:
drawString in interface GameFont
Parameters:
g - the graphics context
s - the string to be drawn
alignment - text alignment: LEFT, RIGHT, CENTER, or JUSTIFY
x - the x screen coordinate to draw the text
y - the y screen coordinate to draw the text
width - width of the text
Returns:
The right-edge of x coordinate to draw next text.

drawText

public int drawText(Graphics2D g,
                    String text,
                    int alignment,
                    int x,
                    int y,
                    int width,
                    int vspace,
                    int firstIndent)
Description copied from interface: GameFont
Draw multiple line text into graphics context.

Example to write two paragraph text:

    // creates bounding box, to ensure the paragraph exactly in the box
    g.drawRect(10, 10, 620, 100);

    int nexty = GameFont.drawText(g,
        "Paragraph one, sample paragraph using GameFont drawText.",
        GameFont.LEFT, 10, 10, 620, 0, 50);

    GameFont.drawText(g,
        "Paragraph two, notice that each paragraph have 50 pixel indentation.",
        GameFont.LEFT,    // left alignment
        10,               // x
        nexty,            // y
        620,              // width
        0,                // no additional vertical spacing
        50);              // 50 pixel indentation
 

Specified by:
drawText in interface GameFont
Parameters:
g - graphics context where the text will be drawn
text - text to be drawn
alignment - text alignment: LEFT, RIGHT, CENTER, or JUSTIFY
x - text x coordinate
y - text y coordinate
width - width per line
vspace - additional vertical spacing, in pixel
firstIndent - first line indentation, in pixel
Returns:
The bottom-edge y coordinate to draw next paragraph.
See Also:
GameFont.LEFT, GameFont.RIGHT, GameFont.CENTER, GameFont.JUSTIFY

getImageFont

public BufferedImage[] getImageFont()
Returns the images font used to draw this bitmap font.


setImageFont

public void setImageFont(BufferedImage[] imagefont,
                         String letterSequence)
Sets images font to draw this bitmap font.


getWidth

public int getWidth(char c)
Description copied from interface: GameFont
Returns the width of char c in pixel.

Specified by:
getWidth in interface GameFont
Returns:
Char width, in pixel.

getWidth

public int getWidth(String st)
Description copied from interface: GameFont
Returns the width of String st in pixel.

Specified by:
getWidth in interface GameFont
Returns:
String width, in pixel.

getHeight

public int getHeight()
Description copied from interface: GameFont
Returns the height of this font in pixel.

Specified by:
getHeight in interface GameFont
Returns:
Font height, in pixel.

toString

public String toString()
Overrides:
toString in class Object

isAvailable

public boolean isAvailable(char c)
Description copied from interface: GameFont
Returns whether the specified char c is available to draw by this game font.

Specified by:
isAvailable in interface GameFont

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id