Versatile Java game engine with pluggable backends (this was used in Rogue, I think)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
2.7 KiB

10 years ago
package mightypork.gamecore.graphics.fonts;
import mightypork.gamecore.graphics.textures.FilterMode;
import mightypork.gamecore.resources.BaseDeferredResource;
/**
* Deferred font stub.
*
10 years ago
* @author Ondřej Hruška (MightyPork)
*/
public abstract class DeferredFont extends BaseDeferredResource implements IFont {
/**
* Requested font size. For bitmap fonts, this should match the actual font
* size (in pixels). The font can be scaled after loaded, but it may be
* cached with this size.
*/
10 years ago
protected double size = 12;
/** Requested font style. If not applicable, fall back to PLAIN */
10 years ago
protected FontStyle style = FontStyle.PLAIN;
/**
* Chars that are required to be loaded in the font. A space glyph must be
* also added when loading.
*/
10 years ago
protected String chars = Glyphs.basic;
/** Requested filtering mode */
10 years ago
protected FilterMode filter = FilterMode.NEAREST;
/** Whether to use anti-aliasing for the font. */
10 years ago
protected boolean antialias = false;
/**
* Ratio of the font to discard at the top (how much of the glyphs height is
* blank from top)
*/
10 years ago
protected double discardTop = 0;
/**
* Ratio of the font to discard at the bottom (how much of the glyphs height
* is blank from bottom)
*/
10 years ago
protected double discardBottom = 0;
/**
* Make a font from resource
*
* @param resource the font resource
*/
public DeferredFont(String resource)
{
10 years ago
super(resource);
}
/**
* Set font size. If the font is backed by a texture, this is the size at
* which the font is rendered to the texture. For bitmap fonts, this should
* match the font height in px.
*
* @param size font size
*/
public final void setSize(double size)
10 years ago
{
this.size = size;
}
/**
* Set desired font style
*
* @param style style
*/
public final void setStyle(FontStyle style)
10 years ago
{
this.style = style;
}
/**
* Set what chars are to be loaded. The space glyph will be loaded always.
*
* @param chars String containing chars to load (duplicates are ignored)
*/
public final void setChars(String chars)
10 years ago
{
this.chars = chars;
}
/**
* Set texture filtering mode. For bitmap fonts, set to NEAREST.
*
* @param filter filter mode.
*/
public final void setFilter(FilterMode filter)
10 years ago
{
this.filter = filter;
}
/**
* Set whether to use antialiasing.
*
* @param antialias antialias
*/
public final void setAntialias(boolean antialias)
10 years ago
{
this.antialias = antialias;
}
10 years ago
@Override
public final void setDiscardRatio(double top, double bottom)
10 years ago
{
discardTop = top;
discardBottom = bottom;
}
10 years ago
@Override
public final double getTopDiscardRatio()
10 years ago
{
return discardTop;
}
10 years ago
@Override
public final double getBottomDiscardRatio()
10 years ago
{
return discardBottom;
}
10 years ago
}