use of com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable 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.scenes.scene2d.utils.SpriteDrawable in project Entitas-Java by Rubentxu.
the class SMGUIManager method createSkin.
public Skin createSkin(BaseAssetsManager assetsManager) {
defaultFont = assetsManager.getFont(DEFAULT_FONT);
defaultFont.getData().setScale(ScaleUtil.getSizeRatio());
defaultFont.setUseIntegerPositions(false);
font2 = assetsManager.getFont(HEADER_FONT);
font2.getData().setScale(ScaleUtil.getSizeRatio());
font2.setUseIntegerPositions(false);
skin.add("default", defaultFont);
skin.add("header", font2);
skin.add("lt-blue", new Color(.62f, .76f, .99f, 1f));
skin.add("lt-green", new Color(.39f, .9f, .6f, 1f));
skin.add("dark-blue", new Color(.79f, .95f, 91f, 1f));
skin.addRegions(assetsManager.getTextureAtlas(GUI_ATLAS));
skin.addRegions(assetsManager.getTextureAtlas(GUI_PACK_ATLAS));
TextureRegionDrawable touchpad_background = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(GUI_ATLAS)).findRegion("touchpad_background"));
TextureRegionDrawable touchpad_thumb = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(GUI_ATLAS)).findRegion("touchpad_thumb"));
TextureRegionDrawable checkox_true = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(UISKIN_ATLAS)).findRegion("check-on"));
TextureRegionDrawable checkox_false = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(UISKIN_ATLAS)).findRegion("check-off"));
TextureRegionDrawable slider_knob = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(UISKIN_ATLAS)).findRegion("default-slider-knob"));
TextureRegionDrawable slider = new TextureRegionDrawable(((TextureAtlas) assetsManager.getTextureAtlas(UISKIN_ATLAS)).findRegion("default-slider"));
CheckBox.CheckBoxStyle checkBoxStyle = new CheckBox.CheckBoxStyle(checkox_false, checkox_true, defaultFont, Color.WHITE);
SpriteDrawable stats = new SpriteDrawable(new Sprite((Texture) assetsManager.getTexture(STATS_BACKGROUND)));
Slider.SliderStyle sliderStyle = new Slider.SliderStyle(slider, slider_knob);
skin.add("default", new Window.WindowStyle(font2, Color.ORANGE, skin.getDrawable("debug")));
skin.add("stats", stats);
Label.LabelStyle lbs = new Label.LabelStyle();
lbs.font = defaultFont;
lbs.fontColor = Color.WHITE;
skin.add("default", lbs);
Label.LabelStyle lbsHeader = new Label.LabelStyle();
lbsHeader.font = font2;
lbsHeader.fontColor = Color.WHITE;
skin.add("header", lbsHeader);
TextButton.TextButtonStyle tbs = new TextButton.TextButtonStyle(skin.getDrawable("btnMenu"), skin.getDrawable("btnMenuPress"), skin.getDrawable("btnMenu"), defaultFont);
tbs.fontColor = skin.getColor("dark-blue");
tbs.pressedOffsetX = Math.round(1f * Gdx.graphics.getDensity());
tbs.pressedOffsetY = tbs.pressedOffsetX * -1f;
ImageButton.ImageButtonStyle ImageButtonLeft = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonLeft"), skin.getDrawable("buttonLeftPress"), skin.getDrawable("buttonLeft"), null, null, null);
ImageButton.ImageButtonStyle ImageButtonRight = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonRight"), skin.getDrawable("buttonRightPress"), skin.getDrawable("buttonRight"), null, null, null);
ImageButton.ImageButtonStyle ImageButtonUp = new ImageButton.ImageButtonStyle(skin.getDrawable("buttonUp"), skin.getDrawable("buttonUpPress"), skin.getDrawable("buttonUp"), null, null, null);
Touchpad.TouchpadStyle touchpadStyle = new Touchpad.TouchpadStyle();
touchpadStyle.background = touchpad_background;
touchpadStyle.knob = touchpad_thumb;
skin.add("default", tbs);
skin.add("buttonLeft", ImageButtonLeft);
skin.add("buttonRight", ImageButtonRight);
skin.add("buttonUp", ImageButtonUp);
skin.add("default", touchpadStyle);
skin.add("default", checkBoxStyle);
skin.add("default-horizontal", sliderStyle);
return skin;
}
use of com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable in project gdx-skineditor by cobolfoo.
the class Skin method newDrawable.
/**
* 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());
}
use of com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable in project gdx-skineditor by cobolfoo.
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;
drawable = optional(name, TiledDrawable.class);
if (drawable != null)
return drawable;
// 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) {
}
// 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);
}
}
add(name, drawable, Drawable.class);
return drawable;
}
use of com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable in project Entitas-Java by Rubentxu.
the class MenuState method init.
@Override
public void init() {
Gdx.app.log("Menu", "Init");
int pad = (int) (20 * SMGUIManager.ScaleUtil.getSizeRatio());
int pad2 = (int) (60 * SMGUIManager.ScaleUtil.getSizeRatio());
final TextButton btnStart = new TextButton("Comenzar", skin);
btnStart.pad(pad, pad2, pad, pad2);
final TextButton btnOptions = new TextButton("Opciones", skin);
btnOptions.pad(pad, pad2, pad, pad2);
final TextButton btnScores = new TextButton("Puntuaciones", skin);
btnScores.pad(pad, pad2, pad, pad2);
final TextButton button3 = new TextButton("Creditos", skin);
button3.pad(pad, pad2, pad, pad2);
button3.setChecked(false);
btnStart.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click Comenzar...");
}
});
btnOptions.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click optionScreen...");
SMGame.ebus.post((ChangeStateCommand<SMGame>) (nameState, game) -> game.changeState(game.getOptionState(), game.getFadeTransition()));
}
});
btnScores.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click highScoreScreen...");
SMGame.ebus.post((ChangeStateCommand<SMGame>) (nameState, game) -> game.changeState(game.getScoresState(), game.getSlideTransition()));
}
});
Label label = new Label("SUPER MARIANO", skin, "header", Color.CYAN);
label.setAlignment(Align.center, Align.center);
mainTable.defaults().padBottom(pad);
if (Gdx.graphics.getHeight() < 480)
mainTable.defaults().height(Gdx.graphics.getHeight() / 5f - pad);
mainTable.add(label);
mainTable.row();
mainTable.add(btnStart);
mainTable.row();
mainTable.add(btnOptions);
mainTable.row();
mainTable.add(btnScores);
mainTable.row();
mainTable.add(button3);
mainTable.row();
mainTable.setBackground(new SpriteDrawable(new Sprite((Texture) assetsManager.getTexture(SMGUIManager.MENU_BACKGROUND))));
mainTable.row();
}
Aggregations