use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class Skin method getDrawable.
/** 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. */
public Drawable getDrawable(String name) {
Drawable drawable = optional(name, Drawable.class);
if (drawable != null)
return drawable;
// Use texture or texture region. If it has splits, use ninepatch. If it has rotation or whitespace stripping, use sprite.
try {
TextureRegion textureRegion = getRegion(name);
if (textureRegion instanceof AtlasRegion) {
AtlasRegion region = (AtlasRegion) textureRegion;
if (region.splits != null)
drawable = new NinePatchDrawable(getPatch(name));
else if (region.rotate || region.packedWidth != region.originalWidth || region.packedHeight != region.originalHeight)
drawable = new SpriteDrawable(getSprite(name));
}
if (drawable == null)
drawable = new TextureRegionDrawable(textureRegion);
} catch (GdxRuntimeException ignored) {
}
// Check for explicit registration of ninepatch, sprite, or tiled drawable.
if (drawable == null) {
NinePatch patch = optional(name, NinePatch.class);
if (patch != null)
drawable = new NinePatchDrawable(patch);
else {
Sprite sprite = optional(name, Sprite.class);
if (sprite != null)
drawable = new SpriteDrawable(sprite);
else
throw new GdxRuntimeException("No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: " + name);
}
}
if (drawable instanceof BaseDrawable)
((BaseDrawable) drawable).setName(name);
add(name, drawable, Drawable.class);
return drawable;
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class Skin method getSprite.
/** 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 {@link AtlasRegion} then an {@link AtlasSprite} is used if the region has been
* whitespace stripped or packed rotated 90 degrees. */
public Sprite getSprite(String name) {
Sprite sprite = optional(name, Sprite.class);
if (sprite != null)
return sprite;
try {
TextureRegion textureRegion = getRegion(name);
if (textureRegion instanceof AtlasRegion) {
AtlasRegion region = (AtlasRegion) textureRegion;
if (region.rotate || region.packedWidth != region.originalWidth || region.packedHeight != region.originalHeight)
sprite = new AtlasSprite(region);
}
if (sprite == null)
sprite = new Sprite(textureRegion);
add(name, sprite, Sprite.class);
return sprite;
} catch (GdxRuntimeException ex) {
throw new GdxRuntimeException("No NinePatch, TextureRegion, or Texture registered with name: " + name);
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class Skin method getPatch.
/** 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 {@link AtlasRegion} then the {@link AtlasRegion#splits} are used,
* otherwise the ninepatch will have the region as the center patch. */
public NinePatch getPatch(String name) {
NinePatch patch = optional(name, NinePatch.class);
if (patch != null)
return patch;
try {
TextureRegion region = getRegion(name);
if (region instanceof AtlasRegion) {
int[] splits = ((AtlasRegion) region).splits;
if (splits != null) {
patch = new NinePatch(region, splits[0], splits[1], splits[2], splits[3]);
int[] pads = ((AtlasRegion) region).pads;
if (pads != null)
patch.setPadding(pads[0], pads[1], pads[2], pads[3]);
}
}
if (patch == null)
patch = new NinePatch(region);
add(name, patch, NinePatch.class);
return patch;
} catch (GdxRuntimeException ex) {
throw new GdxRuntimeException("No NinePatch, TextureRegion, or Texture registered with name: " + name);
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class NetJavaServerSocketImpl method dispose.
@Override
public void dispose() {
if (server != null) {
try {
server.close();
server = null;
} catch (Exception e) {
throw new GdxRuntimeException("Error closing server.", e);
}
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class NetJavaSocketImpl method dispose.
@Override
public void dispose() {
if (socket != null) {
try {
socket.close();
socket = null;
} catch (Exception e) {
throw new GdxRuntimeException("Error closing socket.", e);
}
}
}
Aggregations