com.badlogic.gdx.scenes.scene2d.ui
Class Skin

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.ui.Skin
All Implemented Interfaces:
Disposable

public class Skin
extends Object
implements Disposable

A skin stores resources for UI widgets to use (texture regions, ninepatches, fonts, colors, etc). Resources are named and can be looked up by name and type. Resources can be described in JSON. Skin provides useful conversions, such as allowing access to regions in the atlas as ninepatches, sprites, drawables, etc. The get* methods return an instance of the object in the skin. The new* methods return a copy of an instance in the skin.

See the documentation for more.

Author:
Nathan Sweet

Nested Class Summary
static class Skin.TintedDrawable
           
 
Constructor Summary
Skin()
          Creates an empty skin.
Skin(FileHandle skinFile)
          Creates a skin containing the resources in the specified skin JSON file.
Skin(FileHandle skinFile, TextureAtlas atlas)
          Creates a skin containing the resources in the specified skin JSON file and the texture regions from the specified atlas.
Skin(TextureAtlas atlas)
          Creates a skin containing the texture regions from the specified atlas.
 
Method Summary
 void add(String name, Object resource)
           
 void add(String name, Object resource, Class type)
           
 void addRegions(TextureAtlas atlas)
          Adds all named txeture regions from the atlas.
 void dispose()
          Disposes the TextureAtlas and all Disposable resources in the skin.
 String find(Object resource)
          Returns the name of the specified style object, or null if it is not in the skin.
<T> T
get(Class<T> type)
           
<T> T
get(String name, Class<T> type)
           
<T> ObjectMap<String,T>
getAll(Class<T> type)
          Returns the name to resource mapping for the specified type, or null if no resources of that type exist.
 TextureAtlas getAtlas()
          Returns the TextureAtlas that resources in this skin reference, or null.
 Color getColor(String name)
           
 Drawable getDrawable(String name)
          Returns a registered drawable.
 BitmapFont getFont(String name)
           
 NinePatch getPatch(String name)
          Returns a registered ninepatch.
 TextureRegion getRegion(String name)
          Returns a registered texture region.
 Sprite getSprite(String name)
          Returns a registered sprite.
 TiledDrawable getTiledDrawable(String name)
          Returns a registered tiled drawable.
 boolean has(String name, Class type)
           
 void load(FileHandle skinFile)
          Adds all resources in the specified skin JSON file.
 Drawable newDrawable(Drawable drawable)
          Returns a copy of the specified drawable.
 Drawable newDrawable(Drawable drawable, Color tint)
          Returns a tinted copy of a drawable found in the skin via getDrawable(String).
 Drawable newDrawable(Drawable drawable, float r, float g, float b, float a)
          Returns a tinted copy of a drawable found in the skin via getDrawable(String).
 Drawable newDrawable(String name)
          Returns a copy of a drawable found in the skin via getDrawable(String).
 Drawable newDrawable(String name, Color tint)
          Returns a tinted copy of a drawable found in the skin via getDrawable(String).
 Drawable newDrawable(String name, float r, float g, float b, float a)
          Returns a tinted copy of a drawable found in the skin via getDrawable(String).
<T> T
optional(String name, Class<T> type)
           
 void setEnabled(Actor actor, boolean enabled)
          Sets the style on the actor to disabled or enabled.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Skin

public Skin()
Creates an empty skin.


Skin

public Skin(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.


Skin

public Skin(FileHandle skinFile,
            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.


Skin

public Skin(TextureAtlas atlas)
Creates a skin containing the texture regions from the specified atlas. The atlas is automatically disposed when the skin is disposed.

Method Detail

load

public void load(FileHandle skinFile)
Adds all resources in the specified skin JSON file.


addRegions

public void addRegions(TextureAtlas atlas)
Adds all named txeture regions from the atlas. The atlas will not be automatically disposed when the skin is disposed.


add

public void add(String name,
                Object resource)

add

public void add(String name,
                Object resource,
                Class type)

get

public <T> T get(Class<T> type)

get

public <T> T get(String name,
                 Class<T> type)

optional

public <T> T optional(String name,
                      Class<T> type)

has

public boolean has(String name,
                   Class type)

getAll

public <T> ObjectMap<String,T> getAll(Class<T> type)
Returns the name to resource mapping for the specified type, or null if no resources of that type exist.


getColor

public Color getColor(String name)

getFont

public BitmapFont getFont(String name)

getRegion

public TextureRegion getRegion(String name)
Returns a registered texture region. If no region is found but a texture exists with the name, a region is created from the texture and stored in the skin.


getTiledDrawable

public TiledDrawable getTiledDrawable(String name)
Returns a registered tiled drawable. If no tiled drawable is found but a region exists with the name, a tiled drawable is created from the region and stored in the skin.


getPatch

public NinePatch getPatch(String name)
Returns a registered ninepatch. If no ninepatch is found but a region exists with the name, a ninepatch is created from the region and stored in the skin. If the region is an TextureAtlas.AtlasRegion then the TextureAtlas.AtlasRegion.splits are used, otherwise the ninepatch will have the region as the center patch.


getSprite

public Sprite getSprite(String name)
Returns a registered sprite. If no sprite is found but a region exists with the name, a sprite is created from the region and stored in the skin. If the region is an TextureAtlas.AtlasRegion then an TextureAtlas.AtlasSprite is used if the region has been whitespace stripped or packed rotated 90 degrees.


getDrawable

public Drawable getDrawable(String name)
Returns a registered drawable. If no drawable is found but a region, ninepatch, or sprite exists with the name, then the appropriate drawable is created and stored in the skin.


find

public String find(Object resource)
Returns the name of the specified style object, or null if it is not in the skin. This compares potentially every style object in the skin of the same type as the specified style, which may be a somewhat expensive operation.


newDrawable

public Drawable newDrawable(String name)
Returns a copy of a drawable found in the skin via getDrawable(String).


newDrawable

public Drawable newDrawable(String name,
                            float r,
                            float g,
                            float b,
                            float a)
Returns a tinted copy of a drawable found in the skin via getDrawable(String).


newDrawable

public Drawable newDrawable(String name,
                            Color tint)
Returns a tinted copy of a drawable found in the skin via getDrawable(String).


newDrawable

public Drawable newDrawable(Drawable drawable)
Returns a copy of the specified drawable.


newDrawable

public Drawable newDrawable(Drawable drawable,
                            float r,
                            float g,
                            float b,
                            float a)
Returns a tinted copy of a drawable found in the skin via getDrawable(String).


newDrawable

public Drawable newDrawable(Drawable drawable,
                            Color tint)
Returns a tinted copy of a drawable found in the skin via getDrawable(String).


setEnabled

public void setEnabled(Actor actor,
                       boolean enabled)
Sets the style on the actor to disabled or enabled. This is done by appending "-disabled" to the style name when enabled is false, and removing "-disabled" from the style name when enabled is true. A method named "getStyle" is called the actor via reflection and the name of that style is found in the skin. If the actor doesn't have a "getStyle" method or the style was not found in the skin, no exception is thrown and the actor is left unchanged.


getAtlas

public TextureAtlas getAtlas()
Returns the TextureAtlas that resources in this skin reference, or null.


dispose

public void dispose()
Disposes the TextureAtlas and all Disposable resources in the skin.

Specified by:
dispose in interface Disposable


Copyright © 2013. All Rights Reserved.