Package com.github.tommyettinger.textra
Class FWSkin
java.lang.Object
com.badlogic.gdx.scenes.scene2d.ui.Skin
com.github.tommyettinger.textra.FWSkin
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
public class FWSkin
extends com.badlogic.gdx.scenes.scene2d.ui.Skin
A subclass of
To aid usage of distance field fonts, you can call
If you are using
Skin
that includes a serializer for Structured JSON Fonts, which are typically generated by
fontwriter (hence the "FW" in the name). This can load
FontWriter's JSON format into either Font
and BitmapFont
objects, from the same files. It can also
load Font
s from AngelCode BMFont files (with a ".fnt" extension), and continues to be able to load
BitmapFont
s from those files as well. This class is also important when using the styles in Styles
,
since it allows reading in a skin JSON's styles both as the scene2d.ui format and as styles for TextraTypist widgets.
To aid usage of distance field fonts, you can call
resizeDistanceFields(float, float)
on this skin (it may
need to be cast to FWSkin) in your ApplicationListener.resize(int, int)
method. This makes
all the distance field effects have their correct sizing information, and allows edges to be crisp without becoming
jagged or aliased. It only works on Font objects that use a distance field (SDF, MSDF, or SDF_OUTLINE).
If you are using
AssetManager
, use FWSkinLoader
. If you need to load FreeType
font parameters from a skin, use the related
FreeTypist dependency and
its FreeTypistSkin
or FreeTypistSkinLoader
.-
Nested Class Summary
Nested classes/interfaces inherited from class com.badlogic.gdx.scenes.scene2d.ui.Skin
com.badlogic.gdx.scenes.scene2d.ui.Skin.TintedDrawable
-
Constructor Summary
ConstructorDescriptionFWSkin()
Creates an empty skin.FWSkin
(com.badlogic.gdx.files.FileHandle skinFile) Creates a skin containing the resources in the specified skin JSON file.FWSkin
(com.badlogic.gdx.files.FileHandle skinFile, com.badlogic.gdx.graphics.g2d.TextureAtlas atlas) Creates a skin containing the resources in the specified skin JSON file and the texture regions from the specified atlas.FWSkin
(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas) Creates a skin containing the texture regions from the specified atlas. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.badlogic.gdx.utils.Json
getJsonLoader
(com.badlogic.gdx.files.FileHandle skinFile) Overrides the default JSON loader to process Structured JSON Fonts from a Skin JSON.void
resizeDistanceFields
(float width, float height) CallsFont.resizeDistanceField(float, float)
with the given width and height on every Font loaded by this skin.void
resizeDistanceFields
(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport) CallsFont.resizeDistanceField(float, float, Viewport)
with the given width and height on every Font loaded by this skin.Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Skin
add, add, addRegions, dispose, find, get, get, getAll, getAtlas, getColor, getDrawable, getFont, getJsonClassTags, getPatch, getRegion, getRegions, getSprite, getTiledDrawable, has, load, newDrawable, newDrawable, newDrawable, newDrawable, newDrawable, newDrawable, optional, remove, scale, setEnabled, setScale
-
Constructor Details
-
FWSkin
public FWSkin()Creates an empty skin. -
FWSkin
public FWSkin(com.badlogic.gdx.files.FileHandle skinFile) Creates a skin containing the resources in the specified skin JSON file. If a file in the same directory with a ".atlas" extension exists, it is loaded as aTextureAtlas
and the texture regions added to the skin. The atlas is automatically disposed when the skin is disposed.- Parameters:
skinFile
- The JSON file to be read.
-
FWSkin
public FWSkin(com.badlogic.gdx.files.FileHandle skinFile, com.badlogic.gdx.graphics.g2d.TextureAtlas atlas) Creates a skin containing the resources in the specified skin JSON file and the texture regions from the specified atlas. The atlas is automatically disposed when the skin is disposed.- Parameters:
skinFile
- The JSON file to be read.atlas
- The texture atlas to be associated with theSkin
.
-
FWSkin
public FWSkin(com.badlogic.gdx.graphics.g2d.TextureAtlas atlas) Creates a skin containing the texture regions from the specified atlas. The atlas is automatically disposed when the skin is disposed.- Parameters:
atlas
- The texture atlas to be associated with theSkin
.
-
-
Method Details
-
getJsonLoader
protected com.badlogic.gdx.utils.Json getJsonLoader(com.badlogic.gdx.files.FileHandle skinFile) Overrides the default JSON loader to process Structured JSON Fonts from a Skin JSON. This allows Font and BitmapFont items to be loaded from either .fnt or .json files. This also allows loading both standard scene2d.ui styles and styles for TextraTypist widgets from the same styles a skin JSON file normally uses.- Overrides:
getJsonLoader
in classcom.badlogic.gdx.scenes.scene2d.ui.Skin
- Parameters:
skinFile
- The JSON file to be processed.- Returns:
- The
Json
used to read the file.
-
resizeDistanceFields
public void resizeDistanceFields(float width, float height) CallsFont.resizeDistanceField(float, float)
with the given width and height on every Font loaded by this skin. If you are mainly loading Font values via a skin, this can be called instead of manually calling resizeDistanceField on each Font, and should be called inApplicationListener.resize(int, int)
(with width and height matching its parameters). Like Font's resizeDistanceField(), this only has an effect on distance field fonts -- those that use SDF, MSDF, or SDF_OUTLINE for theirFont.getDistanceField()
.- Parameters:
width
- should match the width inApplicationListener.resize(int, int)
height
- should match the height inApplicationListener.resize(int, int)
-
resizeDistanceFields
public void resizeDistanceFields(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport) CallsFont.resizeDistanceField(float, float, Viewport)
with the given width and height on every Font loaded by this skin. If you are mainly loading Font values via a skin, this can be called instead of manually calling resizeDistanceField on each Font, and should be called inApplicationListener.resize(int, int)
(with width and height matching its parameters). Like Font's resizeDistanceField(), this only has an effect on distance field fonts -- those that use SDF, MSDF, or SDF_OUTLINE for theirFont.getDistanceField()
. This overload takes a Viewport, which helps inform the calculation to make the edges the correct crispness. This does not change the given Viewport.- Parameters:
width
- should match the width inApplicationListener.resize(int, int)
height
- should match the height inApplicationListener.resize(int, int)
-