Search in sources :

Example 1 with TiledDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable in project skin-composer by raeleus.

the class RootTable method produceAtlas.

/**
 * Writes a TextureAtlas based on drawables list. Creates drawables to be
 * displayed on screen
 * @return
 */
public boolean produceAtlas() {
    try {
        if (atlas != null) {
            atlas.dispose();
            atlas = null;
        }
        if (!main.getProjectData().getAtlasData().atlasCurrent) {
            main.getProjectData().getAtlasData().writeAtlas();
            main.getProjectData().getAtlasData().atlasCurrent = true;
        }
        atlas = main.getProjectData().getAtlasData().getAtlas();
        for (DrawableData data : main.getProjectData().getAtlasData().getDrawables()) {
            Drawable drawable;
            if (data.customized) {
                drawable = getSkin().getDrawable("custom-drawable-skincomposer-image");
            } else if (data.tiled) {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new TiledDrawable(atlas.findRegion(name));
                drawable.setMinWidth(data.minWidth);
                drawable.setMinHeight(data.minHeight);
                ((TiledDrawable) drawable).getColor().set(main.getJsonData().getColorByName(data.tintName).color);
            } else if (data.file.name().matches(".*\\.9\\.[a-zA-Z0-9]*$")) {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new NinePatchDrawable(atlas.createPatch(name));
                if (data.tint != null) {
                    drawable = ((NinePatchDrawable) drawable).tint(data.tint);
                } else if (data.tintName != null) {
                    drawable = ((NinePatchDrawable) drawable).tint(main.getProjectData().getJsonData().getColorByName(data.tintName).color);
                }
            } else {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new SpriteDrawable(atlas.createSprite(name));
                if (data.tint != null) {
                    drawable = ((SpriteDrawable) drawable).tint(data.tint);
                } else if (data.tintName != null) {
                    drawable = ((SpriteDrawable) drawable).tint(main.getProjectData().getJsonData().getColorByName(data.tintName).color);
                }
            }
            drawablePairs.put(data.name, drawable);
        }
        return true;
    } catch (Exception e) {
        Gdx.app.error(getClass().getName(), "Error while attempting to generate drawables.", e);
        main.getDialogFactory().showDialogError("Atlas Error...", "Error while attempting to generate drawables.\n\nOpen log?");
        return false;
    }
}
Also used : SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) DrawableData(com.ray3k.skincomposer.data.DrawableData) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) 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) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 2 with TiledDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable in project skin-composer by raeleus.

the class DialogDrawables method produceAtlas.

/**
 * Writes a TextureAtlas based on drawables list. Creates drawables to be
 * displayed on screen
 * @return
 */
private boolean produceAtlas() {
    try {
        if (atlas != null) {
            atlas.dispose();
            atlas = null;
        }
        if (!main.getAtlasData().atlasCurrent) {
            main.getAtlasData().writeAtlas();
            main.getAtlasData().atlasCurrent = true;
        }
        atlas = main.getAtlasData().getAtlas();
        for (DrawableData data : main.getAtlasData().getDrawables()) {
            Drawable drawable;
            if (data.customized) {
                drawable = getSkin().getDrawable("custom-drawable-skincomposer-image");
            } else if (data.tiled) {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new TiledDrawable(atlas.findRegion(name));
                drawable.setMinWidth(data.minWidth);
                drawable.setMinHeight(data.minHeight);
                ((TiledDrawable) drawable).getColor().set(main.getJsonData().getColorByName(data.tintName).color);
            } else if (data.file.name().matches(".*\\.9\\.[a-zA-Z0-9]*$")) {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new NinePatchDrawable(atlas.createPatch(name));
                if (data.tint != null) {
                    drawable = ((NinePatchDrawable) drawable).tint(data.tint);
                } else if (data.tintName != null) {
                    drawable = ((NinePatchDrawable) drawable).tint(main.getJsonData().getColorByName(data.tintName).color);
                }
            } else {
                String name = data.file.name();
                name = DrawableData.proper(name);
                drawable = new SpriteDrawable(atlas.createSprite(name));
                if (data.tint != null) {
                    drawable = ((SpriteDrawable) drawable).tint(data.tint);
                } else if (data.tintName != null) {
                    drawable = ((SpriteDrawable) drawable).tint(main.getJsonData().getColorByName(data.tintName).color);
                }
            }
            drawablePairs.put(data, drawable);
        }
        return true;
    } catch (Exception e) {
        Gdx.app.error(getClass().getName(), "Error while attempting to generate drawables.", e);
        main.getDialogFactory().showDialogError("Atlas Error...", "Error while attempting to generate drawables.\n\nOpen log?");
        return false;
    }
}
Also used : SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) DrawableData(com.ray3k.skincomposer.data.DrawableData) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) 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) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 3 with TiledDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable in project gdx-skineditor by cobolfoo.

the class Skin method getTiledDrawable.

/**
 * Returns a registered tiled drawable. If no tiled drawable is found but a
 * region exists with the name, a tiled drawable is created from the region
 * and stored in the skin.
 */
public TiledDrawable getTiledDrawable(String name) {
    TiledDrawable tiled = optional(name, TiledDrawable.class);
    if (tiled != null)
        return tiled;
    Drawable drawable = optional(name, Drawable.class);
    if (drawable != null) {
        if (!(drawable instanceof TiledDrawable)) {
            throw new GdxRuntimeException("Drawable found but is not a TiledDrawable: " + name + ", " + drawable.getClass().getName());
        }
        return (TiledDrawable) drawable;
    }
    tiled = new TiledDrawable(getRegion(name));
    add(name, tiled, TiledDrawable.class);
    return tiled;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) 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)

Example 4 with TiledDrawable

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

the class Skin method getTiledDrawable.

/** Returns a registered tiled drawable. If no tiled drawable is found but a region exists with the name, a tiled drawable is
	 * created from the region and stored in the skin. */
public TiledDrawable getTiledDrawable(String name) {
    TiledDrawable tiled = optional(name, TiledDrawable.class);
    if (tiled != null)
        return tiled;
    tiled = new TiledDrawable(getRegion(name));
    tiled.setName(name);
    add(name, tiled, TiledDrawable.class);
    return tiled;
}
Also used : TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)

Example 5 with TiledDrawable

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

the class Scene2dTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    final TextureRegion region = new TextureRegion(new Texture("data/badlogic.jpg"));
    final Actor actor = new Actor() {

        public void draw(Batch batch, float parentAlpha) {
            Color color = getColor();
            batch.setColor(color.r, color.g, color.b, parentAlpha);
            batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
        }
    };
    actor.setBounds(15, 15, 100, 100);
    actor.setOrigin(50, 50);
    stage.addActor(actor);
    actor.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("down");
            return true;
        }

        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("up " + event.getTarget());
        }
    });
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    VerticalGroup g = new VerticalGroup().space(5).reverse().pad(5).fill();
    for (int i = 0; i < 10; i++) g.addActor(new TextButton("button " + i, skin));
    g.addActor(new TextButton("longer button", skin));
    Table table = new Table().debug();
    table.add(g);
    table.pack();
    table.setPosition(5, 100);
    stage.addActor(table);
    HorizontalGroup h = new HorizontalGroup().space(5).reverse().pad(5).fill();
    for (int i = 0; i < 5; i++) h.addActor(new TextButton("button " + i, skin));
    h.addActor(new TextButton("some taller\nbutton", skin));
    table = new Table().debug();
    table.add(h);
    table.pack();
    table.setPosition(130, 100);
    stage.addActor(table);
    table.toFront();
    final TextButton button = new TextButton("Fancy Background", skin);
    // button.addListener(new ClickListener() {
    // public void clicked (InputEvent event, float x, float y) {
    // System.out.println("click! " + x + " " + y);
    // }
    // });
    button.addListener(new ActorGestureListener() {

        public boolean longPress(Actor actor, float x, float y) {
            System.out.println("long press " + x + ", " + y);
            return true;
        }

        public void fling(InputEvent event, float velocityX, float velocityY, int button) {
            System.out.println("fling " + velocityX + ", " + velocityY);
        }

        public void zoom(InputEvent event, float initialDistance, float distance) {
            System.out.println("zoom " + initialDistance + ", " + distance);
        }

        public void pan(InputEvent event, float x, float y, float deltaX, float deltaY) {
            event.getListenerActor().moveBy(deltaX, deltaY);
            if (deltaX < 0)
                System.out.println("panning " + deltaX + ", " + deltaY + " " + event.getTarget());
        }
    });
    // button.addListener(new ChangeListener() {
    // public void changed (ChangeEvent event, Actor actor) {
    // // event.cancel();
    // }
    // });
    button.setPosition(50, 50);
    stage.addActor(button);
    // List select = new List(skin);
    // select.setBounds(200, 200, 100, 100);
    // select.setItems(new Object[] {1, 2, 3, 4, 5});
    // stage.addActor(select);
    // stage.addListener(new ChangeListener() {
    // public void changed (ChangeEvent event, Actor actor) {
    // System.out.println(actor);
    // }
    // });
    meow.setDuration(2);
    actor.addAction(forever(sequence(moveBy(50, 0, 2), moveBy(-50, 0, 2), run(new Runnable() {

        public void run() {
            actor.setZIndex(0);
        }
    }))));
    // actor.addAction(parallel(rotateBy(90, 2), rotateBy(90, 2)));
    // actor.addAction(parallel(moveTo(250, 250, 2, elasticOut), color(RED, 6), delay(0.5f), rotateTo(180, 5, swing)));
    // actor.addAction(forever(sequence(scaleTo(2, 2, 0.5f), scaleTo(1, 1, 0.5f), delay(0.5f))));
    patch = new TiledDrawable(skin.getRegion("default-round"));
    Window window = new Window("Moo", skin);
    Label lbl = new Label("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ", skin);
    lbl.setWrap(true);
    window.row();
    window.add(lbl).width(400);
    window.pack();
    window.pack();
    stage.addActor(window);
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.get("default", TextButtonStyle.class));
    style.imageUp = skin.getDrawable("default-round");
    ImageTextButton buttonLeft = new ImageTextButton("HI IM LEFT", style);
    ImageTextButton buttonRight = new ImageTextButton("HI IM RIGHT", style) {

        {
            clearChildren();
            add(getLabel());
            add(getImage());
        }
    };
    CheckBox checkBoxLeft = new CheckBox("HI IM LEFT", skin, "default");
    CheckBox checkBoxRight = new CheckBox("HI IM RIGHT", skin, "default") {

        {
            clearChildren();
            add(getLabel());
            add(getImage());
        }
    };
    buttonLeft.setPosition(300, 400);
    buttonRight.setPosition(300, 370);
    checkBoxLeft.setPosition(150, 400);
    checkBoxRight.setPosition(150, 370);
    stage.addActor(buttonLeft);
    stage.addActor(buttonRight);
    stage.addActor(checkBoxLeft);
    stage.addActor(checkBoxRight);
    buttonLeft.debug();
    buttonRight.debug();
    checkBoxLeft.debug();
    checkBoxRight.debug();
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Color(com.badlogic.gdx.graphics.Color) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) VerticalGroup(com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup) Texture(com.badlogic.gdx.graphics.Texture) ActorGestureListener(com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Batch(com.badlogic.gdx.graphics.g2d.Batch) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ImageTextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.ImageTextButtonStyle) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ImageTextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.ImageTextButtonStyle)

Aggregations

TiledDrawable (com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)5 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)3 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)3 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)3 DrawableData (com.ray3k.skincomposer.data.DrawableData)2 Color (com.badlogic.gdx.graphics.Color)1 Texture (com.badlogic.gdx.graphics.Texture)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)1 HorizontalGroup (com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)1 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)1 ImageTextButtonStyle (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton.ImageTextButtonStyle)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1