com.golden.gamedev.object
Interface GameFont

All Known Implementing Classes:
BitmapFont, MultipleGameFont, SystemFont

public interface GameFont

The GameFont interface is an abstraction for drawing text into screen.


Field Summary
static int CENTER
           
static int JUSTIFY
           
static int LEFT
           
static int RIGHT
           
 
Method Summary
 int drawString(Graphics2D g, String s, int x, int y)
          Draw single line text into graphics context.
 int drawString(Graphics2D g, String s, int alignment, int x, int y, int width)
           
 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 height of this font.
 int getWidth(char c)
          Returns width of char c using this font.
 int getWidth(String st)
          Returns width of String st using this font.
 

Field Detail

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

CENTER

public static final int CENTER
See Also:
Constant Field Values

JUSTIFY

public static final int JUSTIFY
See Also:
Constant Field Values
Method Detail

drawString

public int drawString(Graphics2D g,
                      String s,
                      int x,
                      int y)
Draw single line text into graphics context.

Returns:
bottom x coordinate, used to draw next text.

drawString

public int drawString(Graphics2D g,
                      String s,
                      int alignment,
                      int x,
                      int y,
                      int width)

drawText

public 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.

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
 

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:
bottom y coordinate, used to draw next paragraph.
See Also:
LEFT, RIGHT, CENTER, JUSTIFY

getWidth

public int getWidth(String st)
Returns width of String st using this font.

Returns:
String width, in pixel

getWidth

public int getWidth(char c)
Returns width of char c using this font.

Returns:
char width, in pixel

getHeight

public int getHeight()
Returns height of this font.

Returns:
font height, in pixel