GTGE API

com.golden.gamedev.object.font
Class SystemFont

java.lang.Object
  extended by com.golden.gamedev.object.font.SystemFont
All Implemented Interfaces:
GameFont

public class SystemFont
extends Object
implements GameFont

SystemFont is standard AWT Font wrapped in game font interface to be able to draw AWT Font in alignment and other technique.


Field Summary
 
Fields inherited from interface com.golden.gamedev.object.GameFont
CENTER, JUSTIFY, LEFT, RIGHT
 
Constructor Summary
SystemFont(Font font)
          Creates new SystemFont with specified AWT Font, and the color is following graphics context active color.
SystemFont(Font font, Color color)
          Creates new SystemFont with specified AWT Font, and color.
 
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.
 Color getColor()
          Returns the color of this font, or null if the font is drawn following the graphics context active color.
 Font getFont()
          Returns the AWT Font used to draw this SystemFont.
 FontMetrics getFontMetrics()
          Returns the font metrics used to measure this SystemFont.
 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.
 void setColor(Color c)
          Sets the color of this font, or null to draw the font following the graphics context active color.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SystemFont

public SystemFont(Font font,
                  Color color)
Creates new SystemFont with specified AWT Font, and color.

Parameters:
font - AWT Font that used to draw this game font
color - the color to draw the text, or null if the color should follow the graphics context active color

SystemFont

public SystemFont(Font font)
Creates new SystemFont with specified AWT Font, and the color is following graphics context active color.

Parameters:
font - AWT Font that used to draw this game font
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

getFont

public Font getFont()
Returns the AWT Font used to draw this SystemFont.


getFontMetrics

public FontMetrics getFontMetrics()
Returns the font metrics used to measure this SystemFont.


getColor

public Color getColor()
Returns the color of this font, or null if the font is drawn following the graphics context active color.


setColor

public void setColor(Color c)
Sets the color of this font, or null to draw the font following the graphics context active color.


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.

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.

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