Search in sources :

Example 1 with NinePatchDrawable

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

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

use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project Eidolons by IDemiurge.

the class PlaceTooltip method updateAct.

@Override
public void updateAct(float delta) {
    clearChildren();
    TextureRegion r = TextureCache.getOrCreateR(place.getImagePath());
    ValueContainer container = new ValueContainer(r, place.getName());
    float size = GdxMaster.adjustSize(128);
    if (size < r.getRegionHeight() && size < r.getRegionWidth())
        container.overrideImageSize(size, size);
    add(container);
    setBackground(new NinePatchDrawable(NinePatchFactory.getTooltip()));
    // return ;
    if (place.getRoutes().isEmpty()) {
        return;
    }
    row();
    TablePanel<ValueContainer> routesInfo = new TablePanel<>();
    routesInfo.defaults().space(5);
    add(routesInfo);
    routesInfo.addListener(new ClickListener() {

        @Override
        public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
            if (toActor == routesInfo)
                return;
            if (toActor == null) {
                if (getWidth() >= x)
                    return;
                if (getWidth() >= y)
                    return;
            }
            if (GdxMaster.getAncestors(toActor).contains(routesInfo))
                return;
            if (!checkActorExitRemoves(toActor))
                return;
            super.exit(event, x, y, pointer, toActor);
            GuiEventManager.trigger(MapEvent.ROUTES_PANEL_HOVER_OFF);
        }
    });
    int i = 0;
    for (Route sub : place.getRoutes()) {
        // reverse pic pos
        TextureRegion tex = TextureCache.getOrCreateR(sub.getImagePath());
        ValueContainer routeInfo = new ValueContainer(tex, sub.getName(), sub.getLength() + " leagues");
        routeInfo.setBackground(new NinePatchDrawable(NinePatchFactory.getTooltip()));
        routesInfo.add(routeInfo).left().padLeft(5).uniform(true, false);
        routeInfo.setUserObject(sub);
        routeInfo.addListener(new ClickListener() {

            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                // getTapCount()
                GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, sub);
                return super.touchDown(event, x, y, pointer, button);
            }

            @Override
            public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
                super.exit(event, x, y, pointer, toActor);
                GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, null);
            }

            @Override
            public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
                super.enter(event, x, y, pointer, fromActor);
                GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, sub);
            }
        });
        if (i % 2 == 1)
            routesInfo.row();
        i++;
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PlaceActor(eidolons.libgdx.screens.map.obj.PlaceActor) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ValueContainer(eidolons.libgdx.gui.generic.ValueContainer) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Route(eidolons.game.module.adventure.map.Route) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TablePanel(eidolons.libgdx.gui.panels.TablePanel)

Example 4 with NinePatchDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project Eidolons by IDemiurge.

the class EmitterPalette method init.

public void init() {
    clear();
    setSize(GdxMaster.getWidth() - 300, 256);
    // int columns = (int) (getWidth() / 64);
    defaults().padLeft(200).top().right().width(GdxMaster.getWidth() - 300);
    Map<String, List<File>> presets = new LinkedHashMap<>();
    List<File> subfolders = FileManager.getFilesFromDirectory(PathFinder.getSfxPath(), true);
    subfolders.forEach(file -> {
        if (!file.isDirectory()) {
            MapMaster.addToListMap(presets, "main", file);
        } else
            presets.put(file.getName(), FileManager.getFilesFromDirectory(file.getPath(), false));
    });
    LabelStyle style = StyleHolder.getSizedLabelStyle(FONT.MAIN, 15);
    for (String sub : presets.keySet()) {
        HorizontalFlowGroup table = new HorizontalFlowGroup(0);
        table.setWidth(getWidth() - 100);
        boolean bg = presets.get(sub).size() < 55;
        for (File preset : presets.get(sub)) {
            // textButton?
            ValueContainer label = new ValueContainer(new Label(preset.getName(), style));
            NinePatch patch = NinePatchFactory.getTooltip();
            patch.scale(0.7f, 0.7f);
            if (bg)
                label.setBackground(new NinePatchDrawable(patch));
            label.addListener(new ClickListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) {
                    // EmitterMaster.
                    }
                    EditorManager.setMode(MAP_EDITOR_MOUSE_MODE.EMITTER);
                    if (selectedLabel != null)
                        selectedLabel.setColor(1, 1, 1, 1);
                    if (sub.equals("main"))
                        selected = preset.getName();
                    else
                        selected = StrPathBuilder.build(sub, preset.getName());
                    selectedLabel = label;
                    label.setColor(1, 0.3f, 0.8f, 1);
                    return super.touchDown(event, x, y, pointer, button);
                }
            });
            table.addActor(label);
        }
        addTab(table, sub);
    }
}
Also used : NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) HorizontalFlowGroup(com.kotcrab.vis.ui.layout.HorizontalFlowGroup) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ValueContainer(eidolons.libgdx.gui.generic.ValueContainer) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) File(java.io.File) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 5 with NinePatchDrawable

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

Aggregations

NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)18 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)8 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)7 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)6 TiledDrawable (com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)4 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)4 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 DrawableData (com.ray3k.skincomposer.data.DrawableData)4 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)3 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)3 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)3 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)3 ValueContainer (eidolons.libgdx.gui.generic.ValueContainer)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 Color (com.badlogic.gdx.graphics.Color)2