APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.ui

public Class Skin

extends Object
implements Disposable
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.utils.Disposable
Imports
com.badlogic.gdx.Gdx, com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.graphics.Color, .Texture, com.badlogic.gdx.graphics.g2d.BitmapFont, .BitmapFont.BitmapFontData, .NinePatch, .Sprite, .TextureAtlas, .TextureAtlas.AtlasRegion, .TextureAtlas.AtlasSprite, .TextureRegion, com.badlogic.gdx.scenes.scene2d.Actor, com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable, .Drawable, .NinePatchDrawable, .SpriteDrawable, .TextureRegionDrawable, .TiledDrawable, com.badlogic.gdx.utils.Array, .Disposable, .GdxRuntimeException, .IdentityMap, .Json, .Json.ReadOnlySerializer, .JsonValue, .Null, .ObjectMap, .SerializationException, com.badlogic.gdx.utils.reflect.ClassReflection, .Method, .ReflectionException

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
pack-priv TextureAtlas
private static final Class<T>[]
private final ObjectMap<String, Class<T>>
pack-priv IdentityMap<Class<T>, ObjectMap<String, Object>>
pack-priv float

Constructor Summary

AccessConstructor and Description
public
Skin()

Creates an empty skin.

public
Skin(FileHandle skinFile)

Creates a skin containing the resources in the specified skin JSON file.

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.

public
Skin(TextureAtlas atlas)

Creates a skin containing the texture regions from the specified atlas.

Method Summary

Modifier and TypeMethod and Description
public void
add(String name, Object resource)

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

public void
addRegions(TextureAtlas atlas)

Adds all named texture regions from the atlas.

public void
dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Disposes the TextureAtlas and all Disposable resources in the skin.

public String
find(Object resource)

Returns the name of the specified style object, or null if it is not in the skin.

private static Method
findMethod(Class<T> type, String name)

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

Returns a resource named "default" for the specified type.

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

Returns a named resource of the specified type.

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.

public TextureAtlas
getAtlas()

Returns the TextureAtlas passed to this skin constructor, or null.

public Color
public Drawable
getDrawable(String name)

Returns a registered drawable.

public BitmapFont
public ObjectMap<String, Class<T>>
getJsonClassTags()

Returns a map of class tags that will be used when loading skin JSON.

protected Json
getJsonLoader(final FileHandle skinFile)

public NinePatch
getPatch(String name)

Returns a registered ninepatch.

public TextureRegion
getRegion(String name)

Returns a registered texture region.

public Array<TextureRegion>
getRegions(String regionName)

Returns: an array with the TextureRegion that have an index != -1, or null if none are found.

public Sprite
getSprite(String name)

Returns a registered sprite.

public TiledDrawable
getTiledDrawable(String name)

Returns a registered tiled drawable.

public boolean
has(String name, Class<T> type)

public void
load(FileHandle skinFile)

Adds all resources in the specified skin JSON file.

public Drawable
newDrawable(String name)

Returns a copy of a drawable found in the skin via getDrawable(String).

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).

public Drawable
newDrawable(String name, Color tint)

Returns a tinted copy of a drawable found in the skin via getDrawable(String).

public Drawable
newDrawable(Drawable drawable)

Returns a copy of the specified drawable.

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).

public Drawable
newDrawable(Drawable drawable, Color tint)

Returns a tinted copy of a drawable found in the skin via getDrawable(String).

public <T> T

Returns:

null if not found.
optional
(String name, Class<T> type)

Returns a named resource of the specified type.

public void
remove(String name, Class<T> type)

public void
public <V> void
setEnabled(Styleable<V> styleable, boolean enabled)

Sets the style on the actor to disabled or enabled.

public void
setEnabledReflection(Actor actor, boolean enabled)
Deprecated

Sets the style on the actor to disabled or enabled.

public void
setScale(float scale)

The scale used to size drawables created by this skin.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

atlasback to summary
pack-priv TextureAtlas atlas
defaultTagClassesback to summary
private static final Class<T>[] defaultTagClasses
jsonClassTagsback to summary
private final ObjectMap<String, Class<T>> jsonClassTags
resourcesback to summary
pack-priv IdentityMap<Class<T>, ObjectMap<String, Object>> resources
scaleback to summary
pack-priv float scale

Constructor Detail

Skinback to summary
public Skin()

Creates an empty skin.

Skinback to summary
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.

Skinback to summary
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.

Skinback to summary
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

addback to summary
public void add(String name, Object resource)
addback to summary
public void add(String name, Object resource, Class<T> type)
addRegionsback to summary
public void addRegions(TextureAtlas atlas)

Adds all named texture regions from the atlas. The atlas will not be automatically disposed when the skin is disposed.

disposeback to summary
public void dispose()

Implements com.badlogic.gdx.utils.Disposable.dispose.

Disposes the TextureAtlas and all Disposable resources in the skin.

findback to summary
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.

Annotations
@Null
findMethodback to summary
private static Method findMethod(Class<T> type, String name)
Annotations
@Null
getback to summary
public <T> T get(Class<T> type)

Returns a resource named "default" for the specified type.

Exceptions
GdxRuntimeException:
if the resource was not found.
getback to summary
public <T> T get(String name, Class<T> type)

Returns a named resource of the specified type.

Exceptions
GdxRuntimeException:
if the resource was not found.
getAllback to summary
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.

Annotations
@Null
getAtlasback to summary
public TextureAtlas getAtlas()

Returns the TextureAtlas passed to this skin constructor, or null.

Annotations
@Null
getColorback to summary
public Color getColor(String name)
getDrawableback to summary
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.

getFontback to summary
public BitmapFont getFont(String name)
getJsonClassTagsback to summary
public ObjectMap<String, Class<T>> getJsonClassTags()

Returns a map of class tags that will be used when loading skin JSON. The map can be modified before calling load(FileHandle). By default the map is populated with the simple class names of libGDX classes commonly used in skins.

getJsonLoaderback to summary
protected Json getJsonLoader(final FileHandle skinFile)
getPatchback to summary
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 AtlasRegion then its split AtlasRegion#values are used, otherwise the ninepatch will have the region as the center patch.

getRegionback to summary
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.

getRegionsback to summary
public Array<TextureRegion> getRegions(String regionName)
Returns:Array<TextureRegion>

an array with the TextureRegion that have an index != -1, or null if none are found.

Annotations
@Null
getSpriteback to summary
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 AtlasRegion then an AtlasSprite is used if the region has been whitespace stripped or packed rotated 90 degrees.

getTiledDrawableback to summary
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.

hasback to summary
public boolean has(String name, Class<T> type)
loadback to summary
public void load(FileHandle skinFile)

Adds all resources in the specified skin JSON file.

newDrawableback to summary
public Drawable newDrawable(String name)

Returns a copy of a drawable found in the skin via getDrawable(String).

newDrawableback to summary
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).

newDrawableback to summary
public Drawable newDrawable(String name, Color tint)

Returns a tinted copy of a drawable found in the skin via getDrawable(String).

newDrawableback to summary
public Drawable newDrawable(Drawable drawable)

Returns a copy of the specified drawable.

newDrawableback to summary
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).

newDrawableback to summary
public Drawable newDrawable(Drawable drawable, Color tint)

Returns a tinted copy of a drawable found in the skin via getDrawable(String).

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

Returns a named resource of the specified type.

Returns:T

null if not found.

Annotations
@Null
removeback to summary
public void remove(String name, Class<T> type)
scaleback to summary
public void scale(Drawable drawble)

Scales the drawable's Drawable#getLeftWidth(), Drawable#getRightWidth(), Drawable#getBottomHeight(), Drawable#getTopHeight(), Drawable#getMinWidth(), and Drawable#getMinHeight().

setEnabledback to summary
public <V> void setEnabled(Styleable<V> styleable, 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. If the style was not found in the skin, an exception is thrown.

setEnabledReflectionback to summary
public void setEnabledReflection(Actor actor, boolean enabled)

Deprecated

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" and "setStyle" method the actor is left unchanged. If the style was not found in the skin, an exception is thrown.

Annotations
@Deprecated
setScaleback to summary
public void setScale(float scale)

The scale used to size drawables created by this skin.

This can be useful when scaling an entire UI (eg with a stage's viewport) then using an atlas with images whose resolution matches the UI scale. The skin can then be scaled the opposite amount so that the larger or smaller images are drawn at the original size. For example, if the UI is scaled 2x, the atlas would have images that are twice the size, then the skin's scale would be set to 0.5.

com.badlogic.gdx.scenes.scene2d.ui back to summary

public Class Skin.TintedDrawable

extends Object
Class Inheritance

Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
public Color
public String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

colorback to summary
public Color color
nameback to summary
public String name

Constructor Detail

TintedDrawableback to summary
public TintedDrawable()