Search in sources :

Example 1 with LeadingTruncateLabel

use of com.ray3k.skincomposer.LeadingTruncateLabel in project skin-composer by raeleus.

the class DialogFreeTypeFont method populate.

private void populate() {
    root.pad(15.0f);
    Label label = new Label(mode == Mode.NEW ? "Create a new FreeType Font placeholder." : "Edit FreeType Font placeholder.", skin, "black");
    root.add(label);
    root.row();
    Table table = new Table();
    root.add(table).growX();
    table.defaults().space(5.0f);
    label = new Label("Font Name:", skin);
    label.setName("name-label");
    table.add(label);
    TextField textField = new TextField(data.name, skin);
    textField.setName("fontName");
    table.add(textField);
    TextTooltip toolTip = new TextTooltip("The name used in skin JSON", tooltipManager, getSkin());
    textField.addListener(toolTip);
    textField.addListener(ibeamListener);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextField textField = (TextField) actor;
            data.name = textField.getText();
            updateDisabledFields();
        }
    });
    label = new Label("Preview TTF:", skin);
    table.add(label).spaceLeft(15.0f);
    SelectBox<String> selectBox = new SelectBox(skin);
    selectBox.setName("previewSelectBox");
    Array<String> previewFontNames = new Array<>();
    FileHandle previewFontsPath = Main.appFolder.child("preview fonts");
    if (previewFontsPath.exists()) {
        Array<FileHandle> files = new Array<>(previewFontsPath.list("ttf"));
        for (FileHandle file : files) {
            previewFontNames.add(file.nameWithoutExtension());
        }
    }
    selectBox.setItems(previewFontNames);
    selectBox.setSelected(data.previewTTF);
    table.add(selectBox);
    toolTip = new TextTooltip("The TTF font for preview use in Skin Composer only", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.previewTTF = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    TextButton textButton = new TextButton("Open Preview Folder", skin);
    table.add(textButton);
    toolTip = new TextTooltip("Add new preview fonts here", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            try {
                Utils.openFileExplorer(Main.appFolder.child("preview fonts/"));
            } catch (IOException e) {
                Gdx.app.error(getClass().getName(), "Error while selecting preview font.", e);
            }
        }
    });
    root.row();
    Image image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    final var previewTable = new Table();
    previewTable.setBackground(getSkin().getDrawable("white"));
    root.add(previewTable).growX();
    textField = new TextField(previewText, previewStyle);
    textField.setName("previewField");
    textField.setAlignment(Align.center);
    previewTable.add(textField).growX();
    textField.addListener(ibeamListener);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            previewText = ((TextField) actor).getText();
        }
    });
    root.row();
    var imageButton = new ImageButton(getSkin(), "color");
    root.add(imageButton).expandX().right();
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            dialogFactory.showDialogColorPicker(previewBGcolor, new DialogColorPicker.ColorListener() {

                @Override
                public void selected(Color color) {
                    if (color != null) {
                        previewBGcolor.set(color);
                        previewTable.setColor(color);
                        automaticBgColor = false;
                    }
                }
            });
        }
    });
    toolTip = new TextTooltip("Background color for preview text.", tooltipManager, getSkin());
    imageButton.addListener(toolTip);
    root.row();
    image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    table = new Table();
    root.add(table);
    table.defaults().space(5.0f);
    CheckBox checkBox = new CheckBox("Use custom serializer and integrate FreeType in Skin JSON", skin);
    checkBox.setName("serializerCheckBox");
    checkBox.setChecked(data.useCustomSerializer);
    table.add(checkBox);
    checkBox.addListener(handListener);
    checkBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            CheckBox checkBox = (CheckBox) actor;
            ScrollPane scrollPane = findActor("scrollPane");
            SelectBox selectBox = findActor("previewSelectBox");
            if (checkBox.isChecked()) {
                scrollPane.addAction(Actions.sequence(Actions.fadeIn(.25f), Actions.touchable(Touchable.enabled)));
                selectBox.addAction(Actions.sequence(Actions.alpha(.25f, .25f), Actions.touchable(Touchable.disabled)));
            } else {
                scrollPane.addAction(Actions.sequence(Actions.alpha(.25f, .25f), Actions.touchable(Touchable.disabled)));
                selectBox.addAction(Actions.sequence(Actions.fadeIn(.25f), Actions.touchable(Touchable.enabled)));
            }
            data.useCustomSerializer = checkBox.isChecked();
            updateDisabledFields();
            if (automaticBgColor) {
                var color = jsonData.getColorByName(data.name);
                previewBGcolor.set(Utils.blackOrWhiteBgColor(color == null ? Color.WHITE : color.color));
                previewTable.setColor(previewBGcolor);
            }
        }
    });
    textButton = new TextButton("More Info...", skin);
    table.add(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            showMoreInfoDialog();
        }
    });
    root.row();
    Table bottom = new Table();
    ScrollPane scrollPane = new ScrollPane(bottom, skin);
    scrollPane.setName("scrollPane");
    scrollPane.setFadeScrollBars(false);
    scrollPane.setFlickScroll(false);
    root.add(scrollPane).padTop(10.0f).grow();
    if (!data.useCustomSerializer) {
        scrollPane.setColor(1, 1, 1, .25f);
        scrollPane.setTouchable(Touchable.disabled);
    } else {
        selectBox.setColor(1, 1, 1, .25f);
        selectBox.setTouchable(Touchable.disabled);
    }
    bottom.defaults().space(5.0f);
    table = new Table();
    bottom.add(table).growX().colspan(5).spaceBottom(15.0f);
    table.defaults().space(5.0f);
    label = new Label("Font Path:", skin);
    label.setName("source-label");
    table.add(label).right();
    var ltLabel = new LeadingTruncateLabel(data.file == null ? "" : data.file.path(), skin, "field");
    ltLabel.setName("fileField");
    ltLabel.setEllipsis(true);
    table.add(ltLabel).growX().minWidth(0).prefWidth(0);
    ltLabel.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            var ltLabel = findActor("fileField");
            ltLabel.fire(new ChangeListener.ChangeEvent());
        }
    });
    textButton = new TextButton("Browse...", skin);
    table.add(textButton).fillX();
    toolTip = new TextTooltip("Path to font to be distributed with skin", tooltipManager, getSkin());
    ltLabel.addListener(toolTip);
    textButton.addListener(toolTip);
    ltLabel.addListener(handListener);
    textButton.addListener(handListener);
    var changeListener = new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Runnable runnable = () -> {
                String defaultPath = projectData.getLastFontPath();
                String[] filterPatterns = null;
                if (!Utils.isMac()) {
                    filterPatterns = new String[] { "*.ttf", "*.otf" };
                }
                File file = desktopWorker.openDialog("Select Font file...", defaultPath, filterPatterns, "Font Files (*.TTF;*.OTF)");
                if (file != null) {
                    Gdx.app.postRunnable(() -> {
                        FileHandle fileHandle = new FileHandle(file);
                        loadTTF(fileHandle);
                    });
                }
            };
            dialogFactory.showDialogLoading(runnable);
        }
    };
    textButton.addListener(changeListener);
    ltLabel.addListener(changeListener);
    table.row();
    label = new Label("Characters:", skin);
    table.add(label).right();
    textField = new TextField(data.characters, skin);
    textField.setName("characters");
    table.add(textField).growX();
    toolTip = new TextTooltip("The characters the font should contain. Leave blank for defaults.", tooltipManager, getSkin());
    textField.addListener(toolTip);
    textField.addListener(ibeamListener);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextField textField = (TextField) actor;
            data.characters = textField.getText();
            data.characters = !data.characters.equals("") && !data.characters.contains("\u0000") ? "\u0000" + data.characters : data.characters;
            updateDisabledFields();
            var selectBox = (SelectBox<String>) findActor("character-select-box");
            selectBox.setSelected("custom");
        }
    });
    selectBox = new SelectBox<String>(skin);
    selectBox.setName("character-select-box");
    selectBox.setItems("default", "0-9", "a-zA-Z", "a-zA-Z0-9", "custom", "Load from file (UTF-8)...");
    table.add(selectBox);
    if (!data.characters.equals("")) {
        selectBox.setSelected("custom");
    }
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var selectBox = (SelectBox<String>) findActor("character-select-box");
            var textField = (TextField) findActor("characters");
            switch(selectBox.getSelected()) {
                case "default":
                    textField.setText("");
                    textField.setMessageText("");
                    data.characters = "";
                    break;
                case "0-9":
                    textField.setText("0123456789");
                    textField.setMessageText("");
                    data.characters = textField.getText();
                    break;
                case "a-zA-Z":
                    textField.setText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
                    textField.setMessageText("");
                    data.characters = textField.getText();
                    break;
                case "a-zA-Z0-9":
                    textField.setText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
                    textField.setMessageText("");
                    data.characters = textField.getText();
                    break;
                case "Load from file (UTF-8)...":
                    textField.setText("");
                    textField.setMessageText("Characters loaded from text file...");
                    data.characters = "";
                    showCharacterDialog();
                    break;
            }
            data.characters = !data.characters.equals("") && !data.characters.contains("\u0000") ? "\u0000" + data.characters : data.characters;
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Size:", skin);
    bottom.add(label).right();
    Spinner spinner = new Spinner(data.size, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("size");
    spinner.setMinimum(5);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("The size in pixels", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.size = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Mono:", skin);
    bottom.add(label).right();
    Button button = new Button(skin, "switch");
    button.setName("mono");
    button.setChecked(data.mono);
    bottom.add(button).left();
    toolTip = new TextTooltip("If on, font smoothing is disabled", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.mono = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.add().growX();
    bottom.row();
    label = new Label("Hinting:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox<>(skin);
    selectBox.setName("hinting");
    selectBox.setItems("None", "Slight", "Medium", "Full", "AutoSlight", "AutoMedium", "AutoFull");
    selectBox.setSelected(data.hinting);
    bottom.add(selectBox).fillX().left();
    toolTip = new TextTooltip("Strength of hinting", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.hinting = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    label = new Label("Color:", skin);
    label.setName("color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.color, skin);
    textButton.setName("colorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Foreground color (Required)", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.color = colorData.getName();
                    if (automaticBgColor) {
                        previewBGcolor.set(Utils.blackOrWhiteBgColor(colorData.color));
                        previewCursor.getSprite().setColor(colorData.color);
                        previewSelection.getSprite().setColor(previewBGcolor == Color.BLACK ? Color.LIGHT_GRAY : Color.DARK_GRAY);
                        previewTable.setColor(previewBGcolor);
                    }
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.color = null;
                }
                updateColors();
                updateDisabledFields();
            }, null);
        }
    });
    if (data.color != null) {
        textButton.setUserObject(jsonData.getColorByName(data.color));
    }
    bottom.row();
    label = new Label("Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.gamma)), .1, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("gamma");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Glyph gamma. Values > 1 reduce antialiasing.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.gamma = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Render Count:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.renderCount, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("renderCount");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Number of times to render the glyph. Useful with a shadow or border, so it doesn't show through the glyph.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.renderCount = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Border Width:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.borderWidth, 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("borderWidth");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Border width in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.borderWidth = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Border Color:", skin);
    label.setName("border-color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.borderColor, skin);
    textButton.setName("borderColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Border color; Required if borderWidth > 0", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.borderColor = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.borderColor = null;
                }
                updateColors();
                updateDisabledFields();
            }, null);
        }
    });
    if (data.borderColor != null) {
        textButton.setUserObject(jsonData.getColorByName(data.borderColor));
    }
    bottom.row();
    label = new Label("Border Straight:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("borderStraight");
    button.setChecked(data.borderStraight);
    bottom.add(button).left();
    toolTip = new TextTooltip("On for straight (mitered), off for rounded borders", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.borderStraight = button.isChecked();
            updateDisabledFields();
        }
    });
    label = new Label("Border Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.borderGamma)), 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("borderGamma");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Values < 1 increase the border size.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.borderGamma = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Shadow Offset X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("shadowOffsetX");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on X axis in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetX = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Shadow Offset Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("shadowOffsetY");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on Y axis in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetY = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Shadow Color:", skin);
    label.setName("shadow-color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.shadowColor, skin);
    textButton.setName("shadowColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Shadow color; required if shadowOffset > 0.", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.shadowColor = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.shadowColor = null;
                }
                updateColors();
                updateDisabledFields();
            }, null);
        }
    });
    if (data.shadowColor != null) {
        textButton.setUserObject(jsonData.getColorByName(data.shadowColor));
    }
    label = new Label("Incremental:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("incremental");
    button.setChecked(data.incremental);
    bottom.add(button).left();
    toolTip = new TextTooltip("When true, glyphs are rendered on the fly to the \n" + "font's glyph page textures as they are needed.", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.incremental = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Space X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("spaceX");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.spaceX = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Space Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("spaceY");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.spaceY = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Kerning:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("kerning");
    button.setChecked(data.kerning);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether the font should include kerning", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.kerning = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Flip:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("flip");
    button.setChecked(data.flip);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to flip the font vertically", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.flip = button.isChecked();
            updateDisabledFields();
        }
    });
    label = new Label("GenMipMaps:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("genMipMaps");
    button.setChecked(data.genMipMaps);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to generate mip maps for the resulting texture", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.genMipMaps = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Min Filter:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox<>(skin);
    selectBox.setName("minFilter");
    selectBox.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.minFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Minification filter", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.minFilter = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    label = new Label("Mag Filter:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox<>(skin);
    selectBox.setName("magFilter");
    selectBox.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.magFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Magnification filter", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.magFilter = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    bottom.row();
    bottom.add().growY();
    buttons.pad(10.0f);
    buttons.defaults().minWidth(75.0f).space(25.0f);
    textButton = new TextButton("Generate Font", skin);
    textButton.setName("okButton");
    textButton.addListener(handListener);
    button(textButton, ButtonType.GENERATE);
    textButton = new TextButton("Save Settings", skin);
    textButton.setName("saveButton");
    textButton.addListener(handListener);
    getButtonTable().add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            result(ButtonType.SAVE_SETTINGS);
        }
    });
    textButton = new TextButton("Load Settings", skin);
    textButton.setName("loadButton");
    textButton.addListener(handListener);
    getButtonTable().add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            result(ButtonType.LOAD_SETTINGS);
        }
    });
    textButton = new TextButton("Cancel", skin);
    textButton.setName("cancelButton");
    textButton.addListener(handListener);
    button(textButton, ButtonType.CANCEL);
}
Also used : TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) FileHandle(com.badlogic.gdx.files.FileHandle) MathUtils(com.badlogic.gdx.math.MathUtils) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) DecimalFormatSymbols(java.text.DecimalFormatSymbols) Utils(com.ray3k.skincomposer.utils.Utils) Spinner(com.ray3k.stripe.Spinner) Gdx(com.badlogic.gdx.Gdx) Touchable(com.badlogic.gdx.scenes.scene2d.Touchable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) com.ray3k.skincomposer.data(com.ray3k.skincomposer.data) BigDecimal(java.math.BigDecimal) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) com.badlogic.gdx.utils(com.badlogic.gdx.utils) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) Locale(java.util.Locale) Actions(com.badlogic.gdx.scenes.scene2d.actions.Actions) TextFieldStyle(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) FilesDroppedListener(com.ray3k.skincomposer.FilesDroppedListener) Group(com.badlogic.gdx.scenes.scene2d.Group) Color(com.badlogic.gdx.graphics.Color) Actor(com.badlogic.gdx.scenes.scene2d.Actor) File(java.io.File) Keys(com.badlogic.gdx.Input.Keys) Main(com.ray3k.skincomposer.Main) FileHandle(com.badlogic.gdx.files.FileHandle) Spinner(com.ray3k.stripe.Spinner) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Color(com.badlogic.gdx.graphics.Color) IOException(java.io.IOException) File(java.io.File)

Example 2 with LeadingTruncateLabel

use of com.ray3k.skincomposer.LeadingTruncateLabel in project skin-composer by raeleus.

the class DialogBitmapFont method loadTTFsource.

private void loadTTFsource(FileHandle file) {
    data.file = file;
    LeadingTruncateLabel ltLabel = DialogBitmapFont.this.findActor("sourceFileField");
    ltLabel.setText(data.file.path());
    projectData.setLastFontPath(data.file.parent().path() + "/");
    if (target == null) {
        var name = data.file.nameWithoutExtension();
        target = data.file.sibling(name + ".fnt");
        var counter = 1;
        while (target.exists()) {
            target = target.sibling(name + "(" + counter + ").fnt");
            counter++;
        }
        ltLabel = DialogBitmapFont.this.findActor("targetFileField");
        ltLabel.setText(this.target.path());
    }
    updatePreviewAndOK();
}
Also used : LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel)

Example 3 with LeadingTruncateLabel

use of com.ray3k.skincomposer.LeadingTruncateLabel in project skin-composer by raeleus.

the class DialogBitmapFont method populate.

private void populate() {
    root.pad(15.0f);
    Label label = new Label("Create a new Bitmap Font.", skin, "black");
    root.add(label);
    root.row();
    Image image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    previewTable = new Table();
    previewTable.setBackground(getSkin().getDrawable("white"));
    previewTable.setColor(Color.BLACK);
    root.add(previewTable).growX();
    var textField = new TextField(previewText, previewStyle);
    textField.setName("previewField");
    textField.setAlignment(Align.center);
    previewTable.add(textField).growX();
    textField.addListener(ibeamListener);
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            previewText = ((TextField) actor).getText();
        }
    });
    root.row();
    var imageButton = new ImageButton(getSkin(), "color");
    root.add(imageButton).expandX().right();
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            dialogFactory.showDialogColorPicker(previewBGcolor, new DialogColorPicker.ColorListener() {

                @Override
                public void selected(Color color) {
                    if (color != null) {
                        automaticBgColor = false;
                        previewBGcolor.set(color);
                        previewTable.setColor(color);
                    }
                }
            });
        }
    });
    var toolTip = new TextTooltip("Background color for preview text.", tooltipManager, getSkin());
    imageButton.addListener(toolTip);
    root.row();
    image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    Table bottom = new Table();
    ScrollPane scrollPane = new ScrollPane(bottom, skin);
    scrollPane.setName("scrollPane");
    scrollPane.setFadeScrollBars(false);
    scrollPane.setFlickScroll(false);
    root.add(scrollPane).padTop(10.0f).growX();
    bottom.defaults().space(5.0f);
    var table = new Table();
    bottom.add(table).growX().colspan(5).spaceBottom(15.0f);
    table.defaults().space(5.0f);
    label = new Label("Source Font Path:", skin);
    label.setName("source-label");
    table.add(label).right();
    var ltLabel = new LeadingTruncateLabel(data.file == null ? "" : data.file.path(), skin, "field");
    ltLabel.setName("sourceFileField");
    ltLabel.setEllipsis(true);
    table.add(ltLabel).growX().minWidth(0).prefWidth(0);
    ltLabel.addListener(handListener);
    ltLabel.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            event.getListenerActor().fire(new ChangeListener.ChangeEvent());
        }
    });
    var textButton = new TextButton("Browse...", skin);
    table.add(textButton).fillX();
    toolTip = new TextTooltip("Path to source Font file to be read", tooltipManager, getSkin());
    ltLabel.addListener(toolTip);
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    var sourceChangeListener = new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Runnable runnable = () -> {
                String defaultPath = projectData.getLastFontPath();
                String[] filterPatterns = null;
                if (!Utils.isMac()) {
                    filterPatterns = new String[] { "*.ttf", "*.otf" };
                }
                File file = desktopWorker.openDialog("Select Font file...", defaultPath, filterPatterns, "Font Files (*.TTF;*.OTF)");
                if (file != null) {
                    Gdx.app.postRunnable(() -> {
                        loadTTFsource(new FileHandle(file));
                    });
                }
            };
            dialogFactory.showDialogLoading(runnable);
        }
    };
    ltLabel.addListener(sourceChangeListener);
    textButton.addListener(sourceChangeListener);
    table.row();
    table.defaults().space(5.0f);
    label = new Label("Target FNT Path:", skin);
    label.setName("target-label");
    label.setEllipsis(true);
    table.add(label).right();
    ltLabel = new LeadingTruncateLabel(target == null ? "" : data.file.path(), skin, "field");
    ltLabel.setName("targetFileField");
    ltLabel.setEllipsis(true);
    table.add(ltLabel).growX().minWidth(0).prefWidth(0);
    ltLabel.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            event.getListenerActor().fire(new ChangeListener.ChangeEvent());
        }
    });
    textButton = new TextButton("Browse...", skin);
    table.add(textButton).fillX();
    toolTip = new TextTooltip("Path to target FNT file to be saved", tooltipManager, getSkin());
    ltLabel.addListener(toolTip);
    textButton.addListener(toolTip);
    ltLabel.addListener(handListener);
    textButton.addListener(handListener);
    var targetChangeListener = new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Runnable runnable = () -> {
                String defaultPath = projectData.getLastFontPath();
                String[] filterPatterns = null;
                if (!Utils.isMac()) {
                    filterPatterns = new String[] { "*.fnt" };
                }
                File file = desktopWorker.saveDialog("Select FNT file...", defaultPath, filterPatterns, "Bitmap Font files");
                if (file != null) {
                    Gdx.app.postRunnable(() -> {
                        target = new FileHandle(file);
                        if (!target.extension().equalsIgnoreCase("fnt")) {
                            target = target.sibling(target.name() + ".fnt");
                        }
                        var leadingTruncateLabel = (LeadingTruncateLabel) DialogBitmapFont.this.findActor("targetFileField");
                        leadingTruncateLabel.setText(target.path());
                        projectData.setLastFontPath(target.parent().path() + "/");
                        updatePreviewAndOK();
                    });
                }
            };
            dialogFactory.showDialogLoading(runnable);
        }
    };
    ltLabel.addListener(targetChangeListener);
    textButton.addListener(targetChangeListener);
    table.row();
    table.defaults().space(5.0f);
    label = new Label("Characters:", skin);
    table.add(label).right();
    final var charactersTextField = new TextField(data.characters, skin);
    charactersTextField.setName("characters");
    table.add(charactersTextField).growX();
    charactersTextField.addListener(ibeamListener);
    toolTip = new TextTooltip("The characters the font should contain. Leave blank for defaults.", tooltipManager, getSkin());
    charactersTextField.addListener(toolTip);
    var characterSelectBox = new SelectBox<String>(skin);
    characterSelectBox.setName("characterSelectBox");
    characterSelectBox.setItems("default", "0-9", "a-zA-Z", "a-zA-Z0-9", "custom", "Load from file (UTF-8)...");
    table.add(characterSelectBox).fillX();
    characterSelectBox.addListener(handListener);
    characterSelectBox.getList().addListener(handListener);
    toolTip = new TextTooltip("Character preset list", tooltipManager, getSkin());
    characterSelectBox.addListener(toolTip);
    characterSelectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            switch(characterSelectBox.getSelected()) {
                case "default":
                    charactersTextField.setText("");
                    charactersTextField.setMessageText("");
                    data.characters = "";
                    break;
                case "0-9":
                    charactersTextField.setText("0123456789");
                    charactersTextField.setMessageText("");
                    data.characters = charactersTextField.getText();
                    break;
                case "a-zA-Z":
                    charactersTextField.setText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
                    charactersTextField.setMessageText("");
                    data.characters = charactersTextField.getText();
                    break;
                case "a-zA-Z0-9":
                    charactersTextField.setText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
                    charactersTextField.setMessageText("");
                    data.characters = charactersTextField.getText();
                    break;
                case "Load from file (UTF-8)...":
                    charactersTextField.setText("");
                    charactersTextField.setMessageText("Characters loaded from text file...");
                    data.characters = "";
                    showCharacterDialog();
                    break;
            }
            data.characters = !data.characters.equals("") && !data.characters.contains("\u0000") ? "\u0000" + data.characters : data.characters;
            updatePreviewAndOK();
        }
    });
    charactersTextField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            data.characters = charactersTextField.getText();
            data.characters = !data.characters.equals("") && !data.characters.contains("\u0000") ? "\u0000" + data.characters : data.characters;
            updatePreviewAndOK();
            if ("".equals(charactersTextField.getText())) {
                characterSelectBox.setSelected("default");
            } else {
                characterSelectBox.setSelected("custom");
            }
        }
    });
    bottom.row();
    label = new Label("Size:", skin);
    bottom.add(label).right();
    Spinner spinner = new Spinner(data.size, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("size");
    spinner.setMinimum(5);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("The size in pixels", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.size = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Mono:", skin);
    bottom.add(label).right();
    Button button = new Button(skin, "switch");
    button.setName("mono");
    button.setChecked(data.mono);
    bottom.add(button).left();
    toolTip = new TextTooltip("If on, font smoothing is disabled", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.mono = button.isChecked();
            updatePreviewAndOK();
        }
    });
    bottom.add().growX();
    bottom.row();
    label = new Label("Hinting:", skin);
    bottom.add(label).right();
    var selectBox = new SelectBox<String>(skin);
    selectBox.setName("hinting");
    selectBox.setItems("None", "Slight", "Medium", "Full", "AutoSlight", "AutoMedium", "AutoFull");
    selectBox.setSelected(data.hinting);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Strength of hinting", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.hinting = selectBox.getSelected();
            updatePreviewAndOK();
        }
    });
    label = new Label("Color:", skin);
    label.setName("color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.color, skin);
    textButton.setName("colorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Foreground color (Required)", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.color = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.color = null;
                }
                updateColors();
                updatePreviewAndOK();
            }, null);
        }
    });
    bottom.row();
    label = new Label("Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.gamma)), .1, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("gamma");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Glyph gamma. Values > 1 reduce antialiasing.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.gamma = (float) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Render Count:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.renderCount, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("renderCount");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Number of times to render the glyph. Useful with a shadow or border, so it doesn't show through the glyph.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.renderCount = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Border Width:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.borderWidth, 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("borderWidth");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Border width in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.borderWidth = (float) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Border Color:", skin);
    label.setName("border-color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.borderColor, skin);
    textButton.setName("borderColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Border color; Required if borderWidth > 0", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.borderColor = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.borderColor = null;
                }
                updateColors();
                updatePreviewAndOK();
            }, null);
        }
    });
    bottom.row();
    label = new Label("Border Straight:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("borderStraight");
    button.setChecked(data.borderStraight);
    bottom.add(button).left();
    toolTip = new TextTooltip("On for straight (mitered), off for rounded borders", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.borderStraight = button.isChecked();
            updatePreviewAndOK();
        }
    });
    label = new Label("Border Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.borderGamma)), 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("borderGamma");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Values < 1 increase the border size.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.borderGamma = (float) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Shadow Offset X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("shadowOffsetX");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on X axis in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetX = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Shadow Offset Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("shadowOffsetY");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on Y axis in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetY = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Shadow Color:", skin);
    label.setName("shadow-color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.shadowColor, skin);
    textButton.setName("shadowColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Shadow color; required if shadowOffset > 0.", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.shadowColor = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.shadowColor = null;
                }
                updateColors();
                updatePreviewAndOK();
            }, null);
        }
    });
    label = new Label("Incremental:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("incremental");
    button.setChecked(data.incremental);
    bottom.add(button).left();
    toolTip = new TextTooltip("When true, glyphs are rendered on the fly to the \n" + "font's glyph page textures as they are needed.", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.incremental = button.isChecked();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Space X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("spaceX");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.spaceX = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    label = new Label("Space Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("spaceY");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    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) {
            Spinner spinner = (Spinner) actor;
            data.spaceY = (int) spinner.getValue();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Kerning:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("kerning");
    button.setChecked(data.kerning);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether the font should include kerning", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.kerning = button.isChecked();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Flip:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("flip");
    button.setChecked(data.flip);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to flip the font vertically", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.flip = button.isChecked();
            updatePreviewAndOK();
        }
    });
    label = new Label("GenMipMaps:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("genMipMaps");
    button.setChecked(data.genMipMaps);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to generate mip maps for the resulting texture", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.genMipMaps = button.isChecked();
            updatePreviewAndOK();
        }
    });
    bottom.row();
    label = new Label("Min Filter:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox<>(skin);
    selectBox.setName("minFilter");
    selectBox.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.minFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Minification filter", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.minFilter = selectBox.getSelected();
            updatePreviewAndOK();
        }
    });
    label = new Label("Mag Filter:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox<>(skin);
    selectBox.setName("magFilter");
    selectBox.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.magFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Magnification filter", tooltipManager, getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.magFilter = selectBox.getSelected();
            updatePreviewAndOK();
        }
    });
    buttons.pad(10.0f);
    buttons.defaults().minWidth(75.0f).space(25.0f);
    textButton = new TextButton("Generate Font", skin);
    textButton.setName("okButton");
    textButton.addListener(handListener);
    button(textButton, ButtonType.GENERATE);
    textButton = new TextButton("Save Settings", skin);
    textButton.setName("saveButton");
    textButton.addListener(handListener);
    getButtonTable().add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            result(ButtonType.SAVE_SETTINGS);
        }
    });
    textButton = new TextButton("Load Settings", skin);
    textButton.setName("loadButton");
    textButton.addListener(handListener);
    getButtonTable().add(textButton);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            result(ButtonType.LOAD_SETTINGS);
        }
    });
    textButton = new TextButton("Cancel", skin);
    textButton.setName("cancelButton");
    textButton.addListener(handListener);
    button(textButton, ButtonType.CANCEL);
    updateLabelHighlight(null);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) MathUtils(com.badlogic.gdx.math.MathUtils) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) DecimalFormatSymbols(java.text.DecimalFormatSymbols) Utils(com.ray3k.skincomposer.utils.Utils) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) Spinner(com.ray3k.stripe.Spinner) Gdx(com.badlogic.gdx.Gdx) BigDecimal(java.math.BigDecimal) com.badlogic.gdx.utils(com.badlogic.gdx.utils) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) Locale(java.util.Locale) TextFieldStyle(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) DecimalFormat(java.text.DecimalFormat) ColorData(com.ray3k.skincomposer.data.ColorData) FilesDroppedListener(com.ray3k.skincomposer.FilesDroppedListener) Group(com.badlogic.gdx.scenes.scene2d.Group) Color(com.badlogic.gdx.graphics.Color) Actor(com.badlogic.gdx.scenes.scene2d.Actor) com.badlogic.gdx.scenes.scene2d.utils(com.badlogic.gdx.scenes.scene2d.utils) File(java.io.File) Keys(com.badlogic.gdx.Input.Keys) Main(com.ray3k.skincomposer.Main) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) FileHandle(com.badlogic.gdx.files.FileHandle) Spinner(com.ray3k.stripe.Spinner) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) LeadingTruncateLabel(com.ray3k.skincomposer.LeadingTruncateLabel) Actor(com.badlogic.gdx.scenes.scene2d.Actor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Color(com.badlogic.gdx.graphics.Color) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) File(java.io.File)

Aggregations

LeadingTruncateLabel (com.ray3k.skincomposer.LeadingTruncateLabel)3 Gdx (com.badlogic.gdx.Gdx)2 Keys (com.badlogic.gdx.Input.Keys)2 FileHandle (com.badlogic.gdx.files.FileHandle)2 Color (com.badlogic.gdx.graphics.Color)2 MathUtils (com.badlogic.gdx.math.MathUtils)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 Group (com.badlogic.gdx.scenes.scene2d.Group)2 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)2 com.badlogic.gdx.scenes.scene2d.ui (com.badlogic.gdx.scenes.scene2d.ui)2 TextFieldStyle (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle)2 com.badlogic.gdx.utils (com.badlogic.gdx.utils)2 FilesDroppedListener (com.ray3k.skincomposer.FilesDroppedListener)2 Main (com.ray3k.skincomposer.Main)2 Utils (com.ray3k.skincomposer.utils.Utils)2 Spinner (com.ray3k.stripe.Spinner)2 File (java.io.File)2 BigDecimal (java.math.BigDecimal)2 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2