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 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 Fonts from AngelCode BMFont files (with a ".fnt" extension), and continues to be able to load BitmapFonts 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

    Constructors
    Constructor
    Description
    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 Type
    Method
    Description
    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.
    void
    resizeDistanceFields(float width, float height)
    Calls Font.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)
    Calls Font.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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 a TextureAtlas 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 the Skin.
    • 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 the Skin.
  • 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 class com.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)
      Calls Font.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 in ApplicationListener.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 their Font.getDistanceField().
      Parameters:
      width - should match the width in ApplicationListener.resize(int, int)
      height - should match the height in ApplicationListener.resize(int, int)
    • resizeDistanceFields

      public void resizeDistanceFields(float width, float height, com.badlogic.gdx.utils.viewport.Viewport viewport)
      Calls Font.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 in ApplicationListener.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 their Font.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 in ApplicationListener.resize(int, int)
      height - should match the height in ApplicationListener.resize(int, int)