GTGE API

com.golden.gamedev.object
Interface GameFont

All Known Implementing Classes:
AdvanceBitmapFont, BitmapFont, SystemFont

public interface GameFont

GameFont interface is an interface to draw text with alignment.


Field Summary
static int CENTER
          Text alignment: center alignment.
static int JUSTIFY
          Text alignment: justify alignment.
static int LEFT
          Text alignment: left alignment.
static int RIGHT
          Text alignment: right alignment.
 
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.
 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.
 

Field Detail

LEFT

static final int LEFT
Text alignment: left alignment.

See Also:
Constant Field Values

RIGHT

static final int RIGHT
Text alignment: right alignment.

See Also:
Constant Field Values

CENTER

static final int CENTER
Text alignment: center alignment.

See Also:
Constant Field Values

JUSTIFY

static final int JUSTIFY
Text alignment: justify alignment.

See Also:
Constant Field Values
Method Detail

drawString

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

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

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.

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

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

getWidth

int getWidth(String st)
Returns the width of String st in pixel.

Returns:
String width, in pixel.

getWidth

int getWidth(char c)
Returns the width of char c in pixel.

Returns:
Char width, in pixel.

getHeight

int getHeight()
Returns the height of this font in pixel.

Returns:
Font height, in pixel.

isAvailable

boolean isAvailable(char c)
Returns whether the specified char c is available to draw by this game font.


GTGE API

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