Search in sources :

Example 81 with ClickListener

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

the class DialogSceneComposer method rootAddTableListener.

private EventListener rootAddTableListener() {
    var popTableClickListener = new PopTableClickListener(skin, "dark");
    var popTable = popTableClickListener.getPopTable();
    popTable.key(Keys.ESCAPE, popTable::hide);
    var label = new Label("New Table:", skin, "scene-label");
    popTable.add(label);
    label.addListener(new TextTooltip("Creates a base Table and adds it directly to the stage. This will serve as the basis for the rest of your UI layout and will fill the entire screen.", tooltipManager, skin, "scene"));
    popTable.row();
    var table = new Table();
    popTable.add(table);
    table.pad(10).padTop(0);
    var buttons = new Button[6][6];
    for (int j = 0; j < 6; j++) {
        table.row();
        for (int i = 0; i < 6; i++) {
            var textButton = new Button(skin, "scene-table");
            textButton.setProgrammaticChangeEvents(false);
            textButton.setUserObject(new IntPair(i, j));
            table.add(textButton);
            buttons[i][j] = textButton;
            textButton.addListener(handListener);
            textButton.addListener(new ClickListener() {

                @Override
                public void clicked(InputEvent event, float x, float y) {
                    popTable.hide();
                    var intPair = (IntPair) textButton.getUserObject();
                    events.rootAddTable(intPair.x + 1, intPair.y + 1);
                }
            });
            textButton.addListener(new InputListener() {

                @Override
                public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
                    var intPair = (IntPair) textButton.getUserObject();
                    for (int y1 = 0; y1 < 6; y1++) {
                        for (int x1 = 0; x1 < 6; x1++) {
                            buttons[x1][y1].setChecked(y1 <= intPair.y && x1 <= intPair.x);
                        }
                    }
                    textButton.setChecked(true);
                }
            });
        }
    }
    table.setTouchable(Touchable.enabled);
    table.addListener(new InputListener() {

        @Override
        public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
            for (int y1 = 0; y1 < 6; y1++) {
                for (int x1 = 0; x1 < 6; x1++) {
                    buttons[x1][y1].setChecked(false);
                }
            }
        }
    });
    return popTableClickListener;
}
Also used : PopTable(com.ray3k.stripe.PopTable) IntPair(com.ray3k.skincomposer.utils.IntPair) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 82 with ClickListener

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

the class DialogImageFont method refreshTable.

private void refreshTable() {
    previewStyle = new TextFieldStyle(skin.get(TextFieldStyle.class));
    fadables = new Array<>();
    root.clearChildren();
    var scrollTable = new Table();
    scrollTable.defaults().space(10.0f);
    var scrollPane = new ScrollPane(scrollTable, skin);
    scrollPane.setName("scroll");
    scrollPane.setFlickScroll(false);
    scrollPane.setFadeScrollBars(false);
    root.add(scrollPane).growY().growX();
    var label = new Label("Settings", skin, "title-no-line");
    scrollTable.add(label);
    scrollTable.row();
    var content = new Table();
    content.defaults().space(10.0f).spaceBottom(15.0f);
    scrollTable.add(content).minWidth(500).growX();
    // characters and copy to clipboard
    label = new Label("Characters", skin);
    content.add(label).right().right();
    float width = label.getWidth();
    var table = new Table();
    table.defaults().space(10.0f);
    content.add(table).growX().colspan(3);
    var textField = new TextField(settings.characters, skin);
    textField.setName("characters");
    table.add(textField).growX();
    textField.addListener(new TextTooltip("Characters to be included in font", tooltipManager, skin));
    textField.addListener(ibeamListener);
    textField.setTextFieldFilter((TextField textField1, char c) -> textField1.getText().indexOf(c) == -1);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            settings.characters = ((TextField) actor).getText();
            ((SelectBox) findActor("characters select")).setSelected("custom");
        }
    });
    var selectBox = new SelectBox<String>(skin);
    selectBox.setItems("0-9", "a-zA-Z", "a-zA-Z0-9", "a-zA-Z0-9!-?*", "custom", "Load from file (UTF-8)...");
    switch(settings.characters) {
        case NUMBERS:
            selectBox.setSelectedIndex(0);
            break;
        case ALPHA:
            selectBox.setSelectedIndex(1);
            break;
        case ALPHA_NUMERIC:
            selectBox.setSelectedIndex(2);
            break;
        case ALL:
            selectBox.setSelectedIndex(3);
            break;
        default:
            selectBox.setSelectedIndex(4);
            break;
    }
    selectBox.setName("characters select");
    table.add(selectBox);
    selectBox.addListener(new TextTooltip("Character Presets", tooltipManager, skin));
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var textField = (TextField) findActor("characters");
            switch(selectBox.getSelectedIndex()) {
                case 0:
                    textField.setText(NUMBERS);
                    textField.setMessageText("");
                    settings.characters = NUMBERS;
                    break;
                case 1:
                    textField.setText(ALPHA);
                    textField.setMessageText("");
                    settings.characters = ALPHA;
                    break;
                case 2:
                    textField.setText(ALPHA_NUMERIC);
                    textField.setMessageText("");
                    settings.characters = ALPHA_NUMERIC;
                    break;
                case 3:
                    textField.setText(ALL);
                    textField.setMessageText("");
                    settings.characters = ALL;
                    break;
                case 4:
                    textField.setText(textField.getText());
                    textField.setMessageText("");
                    settings.characters = ((TextField) findActor("characters")).getText();
                    break;
                case 5:
                    textField.setText("");
                    textField.setMessageText("Characters loaded from text file...");
                    settings.characters = "";
                    showCharacterDialog();
                    break;
            }
        }
    });
    var textButton = new TextButton("Copy", skin);
    table.add(textButton);
    textButton.addListener(new TextTooltip("Copy characters to clipboard", tooltipManager, skin));
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var text = settings.characters;
            var append = "    ";
            for (int i = text.length() - 1; i > 0; i--) {
                text = text.substring(0, i) + append + text.substring(i);
            }
            Gdx.app.getClipboard().setContents(text);
        }
    });
    content.add().width(width);
    // source file
    content.row();
    label = new Label("Image File", skin);
    label.setName("image-label");
    content.add(label).right();
    width = label.getWidth();
    table = new Table();
    table.defaults().space(10.0f);
    content.add(table).growX().colspan(3);
    textField = new TextField("", skin);
    textField.setName("imagepath");
    textField.setDisabled(true);
    table.add(textField).growX();
    textField.addListener(new TextTooltip("Path to source image", tooltipManager, skin));
    textField.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            sourceFileBrowse();
        }
    });
    textField.addListener(handListener);
    textButton = new TextButton("Browse", skin);
    table.add(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            sourceFileBrowse();
        }
    });
    textButton.addListener(handListener);
    content.add().width(width);
    // target file
    content.row();
    label = new Label("Save File", skin);
    content.add(label).right();
    fadables.add(label);
    width = label.getWidth();
    table = new Table();
    table.defaults().space(10.0f);
    content.add(table).growX().colspan(3);
    fadables.add(table);
    textField = new TextField("", skin);
    textField.setName("targetpath");
    textField.setDisabled(true);
    table.add(textField).growX();
    textField.addListener(new TextTooltip("Path to save file", tooltipManager, skin));
    textField.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            saveFileBrowse();
        }
    });
    textField.addListener(handListener);
    textButton = new TextButton("Browse", skin);
    table.add(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            saveFileBrowse();
        }
    });
    content.add().width(width);
    // gap size
    content.row();
    label = new Label("Gap Detection Size", skin);
    content.add(label).right();
    fadables.add(label);
    width = label.getWidth();
    var spinner = new Spinner(settings.gap, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("gap");
    spinner.setMinimum(0);
    content.add(spinner).left().minWidth(100.0f);
    fadables.add(spinner);
    spinner.addListener(new TextTooltip("Minimum distance between opaque pixels to split characters", tooltipManager, skin));
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            settings.gap = ((Spinner) actor).getValueAsInt();
            var fileHandle = Gdx.files.absolute(((TextField) findActor("imagepath")).getText());
            try {
                loadPixmap(fileHandle, false);
                preview(true);
            } catch (InvalidFontImageException e) {
                Gdx.app.error(getClass().getName(), "Error processing font source image: " + fileHandle, e);
                dialogFactory.showDialogError("Error creating font from image...", "Error creating font from image.\nPlease ensure that the image has 100% transparent pixels\nto break the different characters.\nOpen log?");
                refreshTable();
            }
        }
    });
    textButton = new TextButton(settings.kerningPairsActivated ? "Kerning Pairs: ON" : "Kerning Pairs: OFF", skin);
    textButton.setName("kerning button");
    content.add(textButton).colspan(2).expandX().padLeft(10.0f).padRight(10.0f).minWidth(200.0f).left();
    fadables.add(textButton);
    textButton.addListener(new TextTooltip("Adjust auto kerning settings", tooltipManager, skin));
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            showKerningDialog();
        }
    });
    content.add().width(width);
    // kerning
    content.row();
    label = new Label("Kerning", skin);
    content.add(label).right();
    fadables.add(label);
    width = label.getWidth();
    spinner = new Spinner(settings.kerning, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("kerning");
    content.add(spinner).left().minWidth(100.0f);
    fadables.add(spinner);
    spinner.addListener(new TextTooltip("The horizontal spacing between characters", tooltipManager, skin));
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            settings.kerning = ((Spinner) actor).getValueAsInt();
            preview(false);
        }
    });
    // leading
    label = new Label("Line Height", skin);
    content.add(label).right();
    fadables.add(label);
    spinner = new Spinner(settings.leading, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("leading");
    content.add(spinner).expandX().left().minWidth(100.0f);
    fadables.add(spinner);
    spinner.addListener(new TextTooltip("The vertical spacing between each line", tooltipManager, skin));
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            settings.leading = ((Spinner) actor).getValueAsInt();
            preview(false);
        }
    });
    content.add().width(width);
    // baseline
    content.row();
    label = new Label("Baseline", skin);
    content.add(label).right();
    fadables.add(label);
    width = label.getWidth();
    spinner = new Spinner(settings.baseline, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("baseline");
    content.add(spinner).expandX().left().minWidth(100.0f).colspan(3);
    fadables.add(spinner);
    spinner.addListener(new TextTooltip("The distance to the line that the text rests on.", tooltipManager, skin));
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            settings.baseline = ((Spinner) actor).getValueAsInt();
            preview(false);
        }
    });
    content.add().width(width);
    // space width
    content.row();
    label = new Label("Space Width", skin);
    content.add(label).right();
    fadables.add(label);
    width = label.getWidth();
    spinner = new Spinner(settings.spaceWidth, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("space width");
    spinner.setMinimum(0);
    content.add(spinner).left().minWidth(100.0f);
    fadables.add(spinner);
    spinner.addListener(new TextTooltip("Set the width of a single space", tooltipManager, skin));
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            settings.spaceWidth = ((Spinner) actor).getValueAsInt();
            preview(false);
        }
    });
    // tab space count
    label = new Label("Tab Space Count", skin);
    content.add(label).right();
    fadables.add(label);
    spinner = new Spinner(settings.tabSpace, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("tab space count");
    spinner.setMinimum(0);
    content.add(spinner).expandX().left().minWidth(100.0f);
    fadables.add(spinner);
    spinner.addListener(new TextTooltip("The number of space characters to make a tab", tooltipManager, skin));
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            settings.tabSpace = ((Spinner) actor).getValueAsInt();
            preview(false);
        }
    });
    content.add().width(width);
    for (var fadable : fadables) {
        fadable.setColor(1.0f, 1.0f, 1.0f, .25f);
        fadable.setTouchable(Touchable.disabled);
    }
    // preview text
    scrollTable.row();
    var image = new Image(skin, "pressed");
    scrollTable.add(image).growX();
    scrollTable.row();
    label = new Label("Preview", skin, "title-no-line");
    scrollTable.add(label);
    scrollTable.row();
    var textArea = new TextArea(settings.preview, previewStyle);
    textArea.setName("preview");
    scrollTable.add(textArea).grow().minHeight(100.0f);
    textArea.addListener(ibeamListener);
    textArea.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            settings.preview = ((TextArea) actor).getText();
        }
    });
    scrollTable.row();
    table = new Table();
    table.defaults().space(10.0f);
    scrollTable.add(table).growX();
    textButton = new TextButton("View Characters", skin);
    textButton.setName("view characters");
    textButton.setDisabled(true);
    table.add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            try {
                Utils.openFileExplorer(Main.appFolder.child("imagefont/characters/"));
            } catch (IOException e) {
                Gdx.app.error(getClass().getName(), "Error opening characters folder", e);
                dialogFactory.showDialogError("Folder Error...", "Error opening characters folder.\n\nOpen log?");
            }
        }
    });
    textButton.addListener(handListener);
    textButton = new TextButton("Reset Text", skin);
    table.add(textButton).expandX().right();
    textButton.addListener(new TextTooltip("Reset preview text to default", tooltipManager, skin));
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var textArea = (TextArea) findActor("preview");
            textArea.setText(SAMPLE_TEXT);
        }
    });
    var imageButton = new ImageButton(skin, "color");
    table.add(imageButton);
    imageButton.addListener(new TextTooltip("Change preview color", tooltipManager, skin));
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    var textArea = (TextArea) findActor("preview");
                    previewStyle.fontColor = colorData.color;
                    settings.previewColor = colorData.color;
                }
            }, null);
        }
    });
    imageButton = new ImageButton(skin, "color-bg");
    table.add(imageButton);
    imageButton.addListener(new TextTooltip("Change background color", tooltipManager, skin));
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    var textArea = (TextArea) findActor("preview");
                    previewStyle.background = ((NinePatchDrawable) previewStyle.background).tint(colorData.color);
                    previewStyle.focusedBackground = ((NinePatchDrawable) previewStyle.focusedBackground).tint(colorData.color);
                    settings.previewBackgroundColor = colorData.color;
                }
            }, null);
        }
    });
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) MathUtils(com.badlogic.gdx.math.MathUtils) Utils(com.ray3k.skincomposer.utils.Utils) Spinner(com.ray3k.stripe.Spinner) Gdx(com.badlogic.gdx.Gdx) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) com.badlogic.gdx.utils(com.badlogic.gdx.utils) Actions(com.badlogic.gdx.scenes.scene2d.actions.Actions) PixmapIO(com.badlogic.gdx.graphics.PixmapIO) Interpolation(com.badlogic.gdx.math.Interpolation) TextFieldStyle(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) com.badlogic.gdx.scenes.scene2d(com.badlogic.gdx.scenes.scene2d) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) Pixmap(com.badlogic.gdx.graphics.Pixmap) IOException(java.io.IOException) FilesDroppedListener(com.ray3k.skincomposer.FilesDroppedListener) Color(com.badlogic.gdx.graphics.Color) File(java.io.File) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Stream(java.util.stream.Stream) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) Keys(com.badlogic.gdx.Input.Keys) Main(com.ray3k.skincomposer.Main) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) Spinner(com.ray3k.stripe.Spinner) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) IOException(java.io.IOException) TextFieldStyle(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle) StyleProperty(com.ray3k.skincomposer.data.StyleProperty)

Aggregations

ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)82 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)74 Stage (com.badlogic.gdx.scenes.scene2d.Stage)39 Texture (com.badlogic.gdx.graphics.Texture)27 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)27 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)24 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)24 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)23 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)23 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)22 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)21 Actor (com.badlogic.gdx.scenes.scene2d.Actor)18 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)18 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)17 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)7 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)6 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)6 Touchpad (com.badlogic.gdx.scenes.scene2d.ui.Touchpad)6 Texto (mx.itesm.another_monkey_paradox.Utils.Texto)6 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5