/** Returns a tinted copy of a drawable found in the skin via {@link #getDrawable(String)}. */
public Drawable newDrawable (Drawable drawable, Color tint) {
if (drawable instanceof TextureRegionDrawable) {
TextureRegion region = ((TextureRegionDrawable)drawable).getRegion();
Sprite sprite;
if (region instanceof AtlasRegion)
sprite = new AtlasSprite((AtlasRegion)region);
else
sprite = new Sprite(region);
sprite.setColor(tint);
return new SpriteDrawable(sprite);
}
if (drawable instanceof NinePatchDrawable) {
NinePatchDrawable patchDrawable = new NinePatchDrawable((NinePatchDrawable)drawable);
patchDrawable.setPatch(new NinePatch(patchDrawable.getPatch(), tint));
return patchDrawable;
}
if (drawable instanceof SpriteDrawable) {
SpriteDrawable spriteDrawable = new SpriteDrawable((SpriteDrawable)drawable);
Sprite sprite = spriteDrawable.getSprite();
if (sprite instanceof AtlasSprite)
sprite = new AtlasSprite((AtlasSprite)sprite);
else
sprite = new Sprite(sprite);
sprite.setColor(tint);
spriteDrawable.setSprite(sprite);
return spriteDrawable;
}
throw new GdxRuntimeException("Unable to copy, unknown drawable type: " + drawable.getClass());
}