Search in sources :

Example 6 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 7 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)

Example 8 with NinePatchDrawable

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

the class DialogDrawables method colorSwatchesDialog.

private void colorSwatchesDialog(DrawableData drawableData) {
    DialogColors dialog = new DialogColors(main, (StyleProperty) null, true, (ColorData colorData) -> {
        if (colorData != null) {
            final DrawableData tintedDrawable = new DrawableData(drawableData.file);
            tintedDrawable.tintName = colorData.getName();
            // Fix background color for new, tinted drawable
            Color temp = Utils.averageEdgeColor(tintedDrawable.file, colorData.color);
            if (Utils.brightness(temp) > .5f) {
                tintedDrawable.bgColor = Color.BLACK;
            } else {
                tintedDrawable.bgColor = Color.WHITE;
            }
            final TextField textField = new TextField(drawableData.name, getSkin());
            final TextButton button = new TextButton("OK", getSkin());
            button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
            button.addListener(main.getHandListener());
            textField.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
                }
            });
            textField.addListener(main.getIbeamListener());
            Dialog approveDialog = new Dialog("TintedDrawable...", getSkin(), "bg") {

                @Override
                protected void result(Object object) {
                    if (object instanceof Boolean && (boolean) object) {
                        tintedDrawable.name = textField.getText();
                        main.getAtlasData().getDrawables().add(tintedDrawable);
                        main.getProjectData().setChangesSaved(false);
                    }
                }

                @Override
                public boolean remove() {
                    gatherDrawables();
                    produceAtlas();
                    sortBySelectedMode();
                    getStage().setScrollFocus(scrollPane);
                    return super.remove();
                }
            };
            approveDialog.addCaptureListener(new InputListener() {

                @Override
                public boolean keyDown(InputEvent event, int keycode2) {
                    if (keycode2 == Input.Keys.ENTER) {
                        if (!button.isDisabled()) {
                            tintedDrawable.name = textField.getText();
                            main.getAtlasData().getDrawables().add(tintedDrawable);
                            main.getProjectData().setChangesSaved(false);
                            approveDialog.hide();
                        }
                    }
                    return false;
                }
            });
            approveDialog.getTitleTable().padLeft(5.0f);
            approveDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
            approveDialog.getButtonTable().padBottom(15.0f);
            approveDialog.text("What is the name of the new tinted drawable?");
            Drawable drawable = drawablePairs.get(drawableData);
            Drawable preview = null;
            if (drawable instanceof SpriteDrawable) {
                preview = ((SpriteDrawable) drawable).tint(colorData.color);
            } else if (drawable instanceof NinePatchDrawable) {
                preview = ((NinePatchDrawable) drawable).tint(colorData.color);
            }
            if (preview != null) {
                approveDialog.getContentTable().row();
                Table table = new Table();
                table.setBackground(preview);
                approveDialog.getContentTable().add(table);
            }
            approveDialog.getContentTable().row();
            approveDialog.getContentTable().add(textField).growX();
            approveDialog.button(button, true);
            approveDialog.button("Cancel", false);
            approveDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
            approveDialog.key(Input.Keys.ESCAPE, false);
            approveDialog.show(getStage());
            getStage().setKeyboardFocus(textField);
            textField.selectAll();
            textField.setFocusTraversal(false);
        }
    });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.refreshTable();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Color(com.badlogic.gdx.graphics.Color) 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) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 9 with NinePatchDrawable

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

the class DialogDrawables method newTintedDrawable.

/**
 * Creates a TintedDrawable based on the provided DrawableData. Prompts
 * user for a Color and name.
 * @param drawableData
 */
private void newTintedDrawable(DrawableData drawableData) {
    Color previousColor = Color.WHITE;
    if (drawableData.tint != null) {
        previousColor = drawableData.tint;
    }
    main.getDialogFactory().showDialogColorPicker(previousColor, new DialogColorPicker.ColorListener() {

        @Override
        public void selected(Color color) {
            if (color != null) {
                final DrawableData tintedDrawable = new DrawableData(drawableData.file);
                tintedDrawable.tint = color;
                // Fix background color for new, tinted drawable
                Color temp = Utils.averageEdgeColor(tintedDrawable.file, tintedDrawable.tint);
                if (Utils.brightness(temp) > .5f) {
                    tintedDrawable.bgColor = Color.BLACK;
                } else {
                    tintedDrawable.bgColor = Color.WHITE;
                }
                final TextField textField = new TextField(drawableData.name, getSkin());
                final TextButton button = new TextButton("OK", getSkin());
                button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
                textField.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
                    }
                });
                textField.addListener(main.getIbeamListener());
                Dialog dialog = new Dialog("TintedDrawable...", getSkin(), "bg") {

                    @Override
                    protected void result(Object object) {
                        if (object instanceof Boolean && (boolean) object) {
                            tintedDrawable.name = textField.getText();
                            main.getAtlasData().getDrawables().add(tintedDrawable);
                            main.getProjectData().setChangesSaved(false);
                        }
                    }

                    @Override
                    public boolean remove() {
                        gatherDrawables();
                        produceAtlas();
                        sortBySelectedMode();
                        getStage().setScrollFocus(scrollPane);
                        return super.remove();
                    }
                };
                dialog.getTitleTable().getCells().first().padLeft(5.0f);
                dialog.addCaptureListener(new InputListener() {

                    @Override
                    public boolean keyDown(InputEvent event, int keycode2) {
                        if (keycode2 == Input.Keys.ENTER) {
                            if (!button.isDisabled()) {
                                tintedDrawable.name = textField.getText();
                                main.getAtlasData().getDrawables().add(tintedDrawable);
                                main.getProjectData().setChangesSaved(false);
                                dialog.hide();
                            }
                        }
                        return false;
                    }
                });
                dialog.text("What is the name of the new tinted drawable?");
                dialog.getContentTable().getCells().first().pad(10.0f);
                Drawable drawable = drawablePairs.get(drawableData);
                Drawable preview = null;
                if (drawable instanceof SpriteDrawable) {
                    preview = ((SpriteDrawable) drawable).tint(color);
                } else if (drawable instanceof NinePatchDrawable) {
                    preview = ((NinePatchDrawable) drawable).tint(color);
                }
                if (preview != null) {
                    dialog.getContentTable().row();
                    Table table = new Table();
                    table.setBackground(preview);
                    dialog.getContentTable().add(table);
                }
                dialog.getContentTable().row();
                dialog.getContentTable().add(textField).growX().pad(10.0f);
                dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
                dialog.button(button, true);
                button.addListener(main.getHandListener());
                dialog.button("Cancel", false);
                dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
                dialog.key(Input.Keys.ESCAPE, false);
                dialog.show(getStage());
                getStage().setKeyboardFocus(textField);
                textField.selectAll();
                textField.setFocusTraversal(false);
            }
        }
    });
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Color(com.badlogic.gdx.graphics.Color) 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) DrawableData(com.ray3k.skincomposer.data.DrawableData) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 10 with NinePatchDrawable

use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project var3dframe by Var3D.

the class VGame method getRectLineDrawable.

// 创建钜形线条Drawable
public Drawable getRectLineDrawable(Color color, Color out, int w, int h) {
    Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
    pixmap.setColor(color);
    pixmap.fill();
    pixmap.setColor(out);
    pixmap.drawRectangle(0, 0, w, h);
    Texture colorPoint = new Texture(pixmap);
    colorPoint.setFilter(filter, filter);
    pixmap.dispose();
    NinePatchDrawable nine = new NinePatchDrawable(new NinePatch(colorPoint, 2, 2, 2, 2));
    return nine;
}
Also used : NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap) 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