Search in sources :

Example 1 with SpriteDrawable

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;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) BaseDrawable(com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) BaseDrawable(com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 2 with SpriteDrawable

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;
}
Also used : TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Color(com.badlogic.gdx.graphics.Color)

Example 3 with SpriteDrawable

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());
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 4 with SpriteDrawable

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;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 5 with SpriteDrawable

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();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) ChangeStateCommand(com.ilargia.games.entitas.egdx.api.ChangeStateCommand) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Sprite (com.badlogic.gdx.graphics.g2d.Sprite)7 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)7 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)4 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)4 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)4 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)3 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)3 Color (com.badlogic.gdx.graphics.Color)2 Texture (com.badlogic.gdx.graphics.Texture)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)2 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 TiledDrawable (com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1