Search in sources :

Example 1 with TextureRegionDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable 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 TextureRegionDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable in project libgdx by libgdx.

the class ContainerTest method create.

@Override
public void create() {
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    TextureRegionDrawable logo = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("data/badlogic.jpg"))));
    Table root = new Table();
    root.setFillParent(true);
    root.debug().defaults().space(6).size(110);
    stage.addActor(root);
    root.add(new Container(label("center")));
    root.add(new Container(label("top")).top());
    root.add(new Container(label("right")).right());
    root.add(new Container(label("bottom")).bottom());
    root.add(new Container(label("left")).left());
    root.row();
    root.add(new Container(label("fill")).fill());
    root.add(new Container(label("fillX")).fillX());
    root.add(new Container(label("fillY")).fillY());
    root.add(new Container(label("fill 75%")).fill(0.75f, 0.75f));
    root.add(new Container(label("fill 75% br")).fill(0.75f, 0.75f).bottom().right());
    root.row();
    root.add(new Container(label("padTop 5\ntop")).padTop(5).top());
    root.add(new Container(label("padBottom 5\nbottom")).padBottom(5).bottom());
    root.add(new Container(label("padLeft 15")).padLeft(15));
    root.add(new Container(label("pad 10 fill")).pad(10).fill());
    root.add(new Container(label("pad 10 tl")).pad(10).top().left());
    root.row();
    root.add(new Container(label("bg")).background(logo));
    root.add(new Container(label("bg height 50")).background(logo).height(50));
    Container transformBG = new Container(label("bg transform")).background(logo);
    transformBG.setTransform(true);
    transformBG.setOrigin(55, 55);
    transformBG.rotateBy(90);
    root.add(transformBG);
    Container transform = new Container(label("transform"));
    transform.setTransform(true);
    transform.setOrigin(55, 55);
    transform.rotateBy(90);
    root.add(transform);
    Container clip = new Container(label("clip1clip2clip3clip4"));
    clip.setClip(true);
    root.add(clip);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Container(com.badlogic.gdx.scenes.scene2d.ui.Container) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Texture(com.badlogic.gdx.graphics.Texture)

Example 3 with TextureRegionDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable in project libgdx by libgdx.

the class CpuSpriteBatchTest method create.

public void create() {
    Batch batch = new CpuSpriteBatch();
    // batch = new SpriteBatch();
    stage = new Stage(new ExtendViewport(500, 500), batch);
    Gdx.input.setInputProcessor(stage);
    texture = new Texture("data/bobargb8888-32x32.png");
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(texture));
    for (int i = 0; i < NUM_GROUPS; i++) {
        Group group = createActorGroup(drawable);
        stage.addActor(group);
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Group(com.badlogic.gdx.scenes.scene2d.Group) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Batch(com.badlogic.gdx.graphics.g2d.Batch) CpuSpriteBatch(com.badlogic.gdx.graphics.g2d.CpuSpriteBatch) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) CpuSpriteBatch(com.badlogic.gdx.graphics.g2d.CpuSpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 4 with TextureRegionDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable in project AmazingMaze by TheVirtualMachine.

the class MainMenuScreen method layoutMenu.

/**
	 * Adds buttons and the title as well as set layout for the menu.
	 *
	 * @param width The width of the screen.
	 * @param height The height of the screen.
	 */
private void layoutMenu(int width, int height) {
    table.clear();
    table.background(new TextureRegionDrawable(new TextureRegion(this.game.assets.manager.get(Assets.MENU_BACKGROUND_IMAGE, Texture.class))));
    // Add title
    table.add(menuTitle).expand();
    table.row();
    // Add buttons.
    table.add(playButton).minSize(width / 4, height / 22).maxSize(width, height / 6).prefSize(width / 2.5f, height / 10).padBottom(10);
    table.row();
    table.add(helpButton).minSize(width / 4, height / 22).maxSize(width, height / 8).prefSize(width / 2.5f, height / 10).padBottom(10);
    table.row();
    table.add(highScoresButton).minSize(width / 4, height / 22).maxSize(width, height / 8).prefSize(width / 2.5f, height / 10).padBottom(10);
    table.row();
    table.add(settingsButton).minSize(width / 4, height / 22).maxSize(width, height / 8).prefSize(width / 2.5f, height / 10).padBottom(10);
    table.row();
    table.add(creditsButton).minSize(width / 4, height / 22).maxSize(width, height / 8).prefSize(width / 2.5f, height / 10).padBottom(10);
    table.row();
    table.add(licenseButton).minSize(width / 4, height / 22).maxSize(width, height / 8).prefSize(width / 2.5f, height / 10).padBottom(10);
    table.row();
    table.add(quitButton).minSize(width / 4, height / 22).maxSize(width, height / 8).prefSize(width / 2.5f, height / 10).padBottom(10);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture)

Example 5 with TextureRegionDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable 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)

Aggregations

TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)9 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)8 Texture (com.badlogic.gdx.graphics.Texture)6 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)4 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)4 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)3 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)3 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)3 Stage (com.badlogic.gdx.scenes.scene2d.Stage)3 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)3 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)2 TiledDrawable (com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)2 Color (com.badlogic.gdx.graphics.Color)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 CpuSpriteBatch (com.badlogic.gdx.graphics.g2d.CpuSpriteBatch)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1