Search in sources :

Example 1 with Spinner

use of com.ray3k.skincomposer.Spinner 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, "required");
    root.add(label);
    root.row();
    Table table = new Table();
    root.add(table).growX();
    table.defaults().space(5.0f);
    label = new Label("Font Name:", skin);
    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", main.getTooltipManager(), getSkin());
    textField.addListener(toolTip);
    textField.addListener(main.getIbeamListener());
    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 = Gdx.files.local("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", main.getTooltipManager(), getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(main.getHandListener());
    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", main.getTooltipManager(), getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            try {
                Utils.openFileExplorer(Gdx.files.local("preview fonts/"));
            } catch (Exception e) {
            }
        }
    });
    root.row();
    Image image = new Image(skin, "welcome-separator");
    image.setScaling(Scaling.stretch);
    root.add(image).growX().space(15.0f);
    root.row();
    textField = new TextField(previewText, previewStyle);
    textField.setName("previewField");
    textField.setAlignment(Align.center);
    root.add(textField).growX();
    textField.addListener(main.getIbeamListener());
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            previewText = ((TextField) actor).getText();
        }
    });
    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 TTF in Skin JSON", skin);
    checkBox.setName("serializerCheckBox");
    checkBox.setChecked(data.useCustomSerializer);
    table.add(checkBox);
    checkBox.addListener(main.getHandListener());
    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();
        }
    });
    textButton = new TextButton("More Info...", skin);
    table.add(textButton);
    textButton.addListener(main.getHandListener());
    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);
    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(4).spaceBottom(15.0f);
    table.defaults().space(5.0f);
    label = new Label("TTF Path:", skin);
    table.add(label);
    textField = new TextField(data.file == null ? "" : data.file.path(), skin);
    textField.setName("fileField");
    textField.setDisabled(true);
    table.add(textField).growX();
    toolTip = new TextTooltip("Path to TTF font to be distributed with skin", main.getTooltipManager(), getSkin());
    textField.addListener(toolTip);
    textButton = new TextButton("Browse...", skin);
    table.add(textButton);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Runnable runnable = () -> {
                String defaultPath = main.getProjectData().getLastFontPath();
                String[] filterPatterns = null;
                if (!Utils.isMac()) {
                    filterPatterns = new String[] { "*.ttf" };
                }
                File file = main.getDesktopWorker().openDialog("Select TTF file...", defaultPath, filterPatterns, "True Type Font files");
                if (file != null) {
                    FileHandle fileHandle = new FileHandle(file);
                    data.file = fileHandle;
                    updateDisabledFields();
                    ((TextField) DialogFreeTypeFont.this.findActor("fileField")).setText(fileHandle.path());
                    main.getProjectData().setLastFontPath(fileHandle.parent().path() + "/");
                }
            };
            main.getDialogFactory().showDialogLoading(runnable);
        }
    });
    bottom.row();
    label = new Label("Size:", skin);
    bottom.add(label).right();
    Spinner spinner = new Spinner(data.size, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("The size in pixels", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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.setChecked(data.mono);
    bottom.add(button).left();
    toolTip = new TextTooltip("If on, font smoothing is disabled", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    button.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.mono = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Hinting:", skin);
    bottom.add(label).right();
    selectBox = new SelectBox(skin);
    selectBox.setItems("None", "Slight", "Medium", "Full", "AutoSlight", "AutoMedium", "AutoFull");
    selectBox.setSelected(data.hinting);
    bottom.add(selectBox).fillX().left();
    toolTip = new TextTooltip("Strength of hinting", main.getTooltipManager(), getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(main.getHandListener());
    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);
    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)", main.getTooltipManager(), getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            main.getDialogFactory().showDialogColors(new StyleProperty(), (ColorData colorData) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.color = colorData.getName();
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.color = null;
                }
                updateColors();
                updateDisabledFields();
            });
        }
    });
    bottom.row();
    label = new Label("Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.gamma)), 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Glyph gamma. Values > 1 reduce antialiasing.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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);
    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.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Border width in pixels, 0 to disable", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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);
    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", main.getTooltipManager(), getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            main.getDialogFactory().showDialogColors(new StyleProperty(), (ColorData colorData) -> {
                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();
            });
        }
    });
    bottom.row();
    label = new Label("Border Straight:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setChecked(data.borderStraight);
    bottom.add(button).left();
    toolTip = new TextTooltip("On for straight (mitered), off for rounded borders", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    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);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Values < 1 increase the border size.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on X axis in pixels, 0 to disable", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on Y axis in pixels, 0 to disable", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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);
    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.", main.getTooltipManager(), getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            main.getDialogFactory().showDialogColors(new StyleProperty(), (ColorData colorData) -> {
                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();
            });
        }
    });
    label = new Label("Incremental:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    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.", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    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);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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);
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", main.getTooltipManager(), getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(main.getHandListener());
    spinner.getButtonPlus().addListener(main.getHandListener());
    spinner.getTextField().addListener(main.getIbeamListener());
    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("Characters:", skin);
    bottom.add(label).right();
    textField = new TextField(data.characters, skin);
    bottom.add(textField).left().growX();
    toolTip = new TextTooltip("The characters the font should contain. Leave blank for defaults.", main.getTooltipManager(), getSkin());
    textField.addListener(toolTip);
    textField.addListener(main.getIbeamListener());
    textField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextField textField = (TextField) actor;
            data.characters = textField.getText();
            updateDisabledFields();
        }
    });
    label = new Label("Kerning:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setChecked(data.kerning);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether the font should include kerning", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    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.setChecked(data.flip);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to flip the font vertically", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    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.setChecked(data.genMipMaps);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether to generate mip maps for the resulting texture", main.getTooltipManager(), getSkin());
    button.addListener(toolTip);
    button.addListener(main.getHandListener());
    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.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.minFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Minification filter", main.getTooltipManager(), getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(main.getHandListener());
    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.setItems("Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear");
    selectBox.setSelected(data.magFilter);
    bottom.add(selectBox).left();
    toolTip = new TextTooltip("Magnification filter", main.getTooltipManager(), getSkin());
    selectBox.addListener(toolTip);
    selectBox.addListener(main.getHandListener());
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            SelectBox<String> selectBox = (SelectBox) actor;
            data.magFilter = selectBox.getSelected();
            updateDisabledFields();
        }
    });
    buttons.pad(10.0f);
    buttons.defaults().minWidth(75.0f).space(25.0f);
    textButton = new TextButton("OK", skin);
    textButton.setName("okButton");
    textButton.addListener(main.getHandListener());
    button(textButton, true);
    textButton = new TextButton("Cancel", skin);
    textButton.setName("cancelButton");
    textButton.addListener(main.getHandListener());
    button(textButton, false);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Spinner(com.ray3k.skincomposer.Spinner) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Array(com.badlogic.gdx.utils.Array) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) ColorData(com.ray3k.skincomposer.data.ColorData) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) File(java.io.File)

Example 2 with Spinner

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

the class DialogDrawables method tiledDrawableSettingsDialog.

private void tiledDrawableSettingsDialog(DrawableData drawable) {
    DialogColors dialog = new DialogColors(main, (StyleProperty) null, true, (ColorData colorData) -> {
        if (colorData != null) {
            final Spinner minWidthSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            final Spinner minHeightSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            TextField textField = new TextField("", getSkin()) {

                @Override
                public void next(boolean up) {
                    if (up) {
                        getStage().setKeyboardFocus(minHeightSpinner.getTextField());
                        minHeightSpinner.getTextField().selectAll();
                    } else {
                        getStage().setKeyboardFocus(minWidthSpinner.getTextField());
                        minWidthSpinner.getTextField().selectAll();
                    }
                }
            };
            Dialog tileDialog = new Dialog("Tiled Drawable Settings", getSkin(), "bg") {

                @Override
                protected void result(Object object) {
                    super.result(object);
                    if (object instanceof Boolean && (boolean) object == true) {
                        tiledDrawableSettings(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                    }
                    getStage().setScrollFocus(scrollPane);
                }

                @Override
                public Dialog show(Stage stage) {
                    Dialog dialog = super.show(stage);
                    stage.setKeyboardFocus(textField);
                    return dialog;
                }
            };
            tileDialog.getTitleTable().padLeft(5.0f);
            tileDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
            tileDialog.getButtonTable().padBottom(15.0f);
            tileDialog.getContentTable().add(new Label("Please enter a name for the TiledDrawable: ", getSkin()));
            tileDialog.button("OK", true);
            tileDialog.button("Cancel", false).key(Keys.ESCAPE, false);
            TextButton okButton = (TextButton) tileDialog.getButtonTable().getCells().first().getActor();
            okButton.addListener(main.getHandListener());
            tileDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
            tileDialog.getContentTable().row();
            textField.setText(drawable.name);
            textField.selectAll();
            tileDialog.getContentTable().add(textField);
            tileDialog.getContentTable().row();
            Table table = new Table();
            table.defaults().space(10.0f);
            tileDialog.getContentTable().add(table);
            Label label = new Label("MinWidth:", getSkin());
            table.add(label);
            minWidthSpinner.setValue(drawable.minWidth);
            minWidthSpinner.setMinimum(0.0f);
            table.add(minWidthSpinner).minWidth(150.0f);
            minWidthSpinner.setTransversalPrevious(textField);
            minWidthSpinner.setTransversalNext(minHeightSpinner.getTextField());
            table.row();
            label = new Label("MinHeight:", getSkin());
            table.add(label);
            minHeightSpinner.setValue(drawable.minHeight);
            minHeightSpinner.setMinimum(0.0f);
            table.add(minHeightSpinner).minWidth(150.0f);
            minHeightSpinner.setTransversalPrevious(minWidthSpinner.getTextField());
            minHeightSpinner.setTransversalNext(textField);
            textField.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    boolean disable = !DrawableData.validate(textField.getText());
                    if (!disable) {
                        if (!drawable.name.equals(textField.getText())) {
                            for (DrawableData data : main.getAtlasData().getDrawables()) {
                                if (data.name.equals(textField.getText())) {
                                    disable = true;
                                    break;
                                }
                            }
                        }
                    }
                    okButton.setDisabled(disable);
                }
            });
            textField.setTextFieldListener(new TextField.TextFieldListener() {

                @Override
                public void keyTyped(TextField textField, char c) {
                    if (c == '\n') {
                        if (!okButton.isDisabled()) {
                            tiledDrawableSettings(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                            tileDialog.hide();
                        }
                    }
                }
            });
            textField.addListener(main.getIbeamListener());
            tileDialog.show(getStage());
        }
    });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.refreshTable();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Spinner(com.ray3k.skincomposer.Spinner) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 3 with Spinner

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

the class DialogColorPicker method populate.

public void populate() {
    content.clear();
    content.defaults().padLeft(10.0f);
    Image cursor = new Image(skin.getDrawable("color-picker"));
    cursor.setTouchable(Touchable.enabled);
    Image hueKnob = new Image(skin, "color-scale");
    hueKnob.setTouchable(Touchable.enabled);
    Image hueKnob2 = new Image(skin, "color-scale-flipped");
    hueKnob2.setTouchable(Touchable.enabled);
    Image alphaKnob = new Image(skin, "color-scale");
    alphaKnob.setTouchable(Touchable.enabled);
    Image alphaKnob2 = new Image(skin, "color-scale-flipped");
    alphaKnob2.setTouchable(Touchable.enabled);
    Container selectedColorCont = new Container();
    selectedColorCont.setBackground(skin.getDrawable("white"));
    selectedColorCont.setColor(selectedColor);
    Vector3 v = rgbToHsb(selectedColor.r, selectedColor.g, selectedColor.b);
    Spinner greenSpinner, blueSpinner, alphaSpinner, hueSpinner, saturationSpinner, brightnessSpinner;
    hueSpinner = new Spinner(v.x * 359.0f, 1.0, true, Orientation.HORIZONTAL, skin);
    hueSpinner.setMinimum(0.0);
    hueSpinner.setMaximum(359.0);
    hueSpinner.getTextField().addListener(main.getIbeamListener());
    hueSpinner.getButtonMinus().addListener(main.getHandListener());
    hueSpinner.getButtonPlus().addListener(main.getHandListener());
    saturationSpinner = new Spinner(v.y * 100.0f, 1.0, true, Orientation.HORIZONTAL, skin);
    saturationSpinner.setMinimum(0.0);
    saturationSpinner.setMaximum(100.0);
    saturationSpinner.getTextField().addListener(main.getIbeamListener());
    saturationSpinner.getButtonMinus().addListener(main.getHandListener());
    saturationSpinner.getButtonPlus().addListener(main.getHandListener());
    brightnessSpinner = new Spinner(v.z * 100.0f, 1.0, true, Orientation.HORIZONTAL, skin);
    brightnessSpinner.setMinimum(0.0);
    brightnessSpinner.setMaximum(100.0);
    brightnessSpinner.getTextField().addListener(main.getIbeamListener());
    brightnessSpinner.getButtonMinus().addListener(main.getHandListener());
    brightnessSpinner.getButtonPlus().addListener(main.getHandListener());
    redSpinner = new Spinner(selectedColor.r * 255.0f, 1.0, true, Orientation.HORIZONTAL, skin);
    redSpinner.setMinimum(0.0);
    redSpinner.setMaximum(255.0);
    redSpinner.getTextField().addListener(main.getIbeamListener());
    redSpinner.getButtonMinus().addListener(main.getHandListener());
    redSpinner.getButtonPlus().addListener(main.getHandListener());
    greenSpinner = new Spinner(selectedColor.g * 255.0f, 1.0, true, Orientation.HORIZONTAL, skin);
    greenSpinner.setMinimum(0.0);
    greenSpinner.setMaximum(255.0);
    greenSpinner.getTextField().addListener(main.getIbeamListener());
    greenSpinner.getButtonMinus().addListener(main.getHandListener());
    greenSpinner.getButtonPlus().addListener(main.getHandListener());
    blueSpinner = new Spinner(selectedColor.b * 255.0f, 1.0, true, Orientation.HORIZONTAL, skin);
    blueSpinner.setMinimum(0.0);
    blueSpinner.setMaximum(255.0);
    blueSpinner.getTextField().addListener(main.getIbeamListener());
    blueSpinner.getButtonMinus().addListener(main.getHandListener());
    blueSpinner.getButtonPlus().addListener(main.getHandListener());
    alphaSpinner = new Spinner(selectedColor.a * 255.0f, 1.0, true, Orientation.HORIZONTAL, skin);
    alphaSpinner.setMinimum(0.0);
    alphaSpinner.setMaximum(255.0);
    alphaSpinner.getTextField().addListener(main.getIbeamListener());
    alphaSpinner.getButtonMinus().addListener(main.getHandListener());
    alphaSpinner.getButtonPlus().addListener(main.getHandListener());
    final TextField hexField = new TextField(selectedColor.toString(), skin);
    hexField.setMaxLength(8);
    hexField.setTextFieldFilter(new TextField.TextFieldFilter() {

        @Override
        public boolean acceptChar(TextField textField, char c) {
            return c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f';
        }
    });
    hexField.addListener(main.getIbeamListener());
    redSpinner.setTransversalNext(greenSpinner.getTextField());
    greenSpinner.setTransversalNext(blueSpinner.getTextField());
    blueSpinner.setTransversalNext(alphaSpinner.getTextField());
    alphaSpinner.setTransversalNext(hueSpinner.getTextField());
    hueSpinner.setTransversalNext(saturationSpinner.getTextField());
    saturationSpinner.setTransversalNext(brightnessSpinner.getTextField());
    brightnessSpinner.setTransversalNext(redSpinner.getTextField());
    redSpinner.setTransversalPrevious(brightnessSpinner.getTextField());
    greenSpinner.setTransversalPrevious(redSpinner.getTextField());
    blueSpinner.setTransversalPrevious(greenSpinner.getTextField());
    alphaSpinner.setTransversalPrevious(blueSpinner.getTextField());
    hueSpinner.setTransversalPrevious(alphaSpinner.getTextField());
    saturationSpinner.setTransversalPrevious(hueSpinner.getTextField());
    brightnessSpinner.setTransversalPrevious(saturationSpinner.getTextField());
    ChangeListener rgbListener = new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            selectedColor.set((float) redSpinner.getValue() / 255.0f, (float) greenSpinner.getValue() / 255.0f, (float) blueSpinner.getValue() / 255.0f, (float) alphaSpinner.getValue() / 255.0f);
            Vector3 v = rgbToHsb(selectedColor.r, selectedColor.g, selectedColor.b);
            hueSpinner.setValue(v.x * 359.0f);
            saturationSpinner.setValue(v.y * 100.0f);
            brightnessSpinner.setValue(v.z * 100.0f);
            selectedColorCont.setColor(selectedColor);
            Color color = hsbToRgb((float) hueSpinner.getValue(), 1.0f, 1.0f);
            gradientS.setCol2(color);
            gradientS.setCol3(color);
            gradientAlpha.setCol3(color);
            gradientAlpha.setCol4(color);
            color = new Color(color);
            color.a = 0.0f;
            gradientAlpha.setCol1(color);
            gradientAlpha.setCol2(color);
            cursor.setX(v.y * SIZE - cursor.getWidth() / 2.0f);
            cursor.setY(v.z * SIZE - cursor.getHeight() / 2.0f);
            hueKnob.setY(v.x * SIZE - hueKnob.getHeight() / 2.0f);
            hueKnob2.setY(hueKnob.getY());
            hexField.setText(selectedColor.toString());
        }
    };
    redSpinner.addListener(rgbListener);
    greenSpinner.addListener(rgbListener);
    blueSpinner.addListener(rgbListener);
    ChangeListener hsbListener = new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Color color = hsbToRgb((float) hueSpinner.getValue(), (float) saturationSpinner.getValue() / 100.0f, (float) brightnessSpinner.getValue() / 100.0f);
            color.a = (float) alphaSpinner.getValue() / 255.0f;
            redSpinner.setValue(color.r * 255.0f);
            greenSpinner.setValue(color.g * 255.0f);
            blueSpinner.setValue(color.b * 255.0f);
            selectedColor.set(color);
            selectedColorCont.setColor(selectedColor);
            color = hsbToRgb((float) hueSpinner.getValue(), 1.0f, 1.0f);
            gradientS.setCol2(color);
            gradientS.setCol3(color);
            gradientAlpha.setCol3(color);
            gradientAlpha.setCol4(color);
            color = new Color(color);
            color.a = 0.0f;
            gradientAlpha.setCol1(color);
            gradientAlpha.setCol2(color);
            cursor.setX((float) saturationSpinner.getValue() / 100.0f * SIZE - cursor.getWidth() / 2.0f);
            cursor.setY((float) brightnessSpinner.getValue() / 100.0f * SIZE - cursor.getHeight() / 2.0f);
            hueKnob.setY((float) hueSpinner.getValue() / 359.0f * SIZE - hueKnob.getHeight() / 2.0f);
            hueKnob2.setY(hueKnob.getY());
            hexField.setText(selectedColor.toString());
        }
    };
    hueSpinner.addListener(hsbListener);
    saturationSpinner.addListener(hsbListener);
    brightnessSpinner.addListener(hsbListener);
    ChangeListener hexListener = new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            if (hexField.getText().length() == 6 || hexField.getText().length() == 8) {
                Color color = Color.valueOf(hexField.getText());
                redSpinner.setValue(color.r * 255);
                greenSpinner.setValue(color.g * 255);
                blueSpinner.setValue(color.b * 255);
                alphaSpinner.setValue(color.a * 255);
                if (hexField.getText().length() == 6) {
                    selectedColor.set(color.r, color.g, color.b, (float) alphaSpinner.getValue() / 255.0f);
                } else {
                    selectedColor.set(color.r, color.g, color.b, color.a);
                }
                Vector3 v = rgbToHsb(selectedColor.r, selectedColor.g, selectedColor.b);
                hueSpinner.setValue(v.x * 359.0f);
                saturationSpinner.setValue(v.y * 100.0f);
                brightnessSpinner.setValue(v.z * 100.0f);
                selectedColorCont.setColor(selectedColor);
                color = hsbToRgb((float) hueSpinner.getValue(), 1.0f, 1.0f);
                gradientS.setCol2(color);
                gradientS.setCol3(color);
                gradientAlpha.setCol3(color);
                gradientAlpha.setCol4(color);
                color = new Color(color);
                color.a = 0.0f;
                gradientAlpha.setCol1(color);
                gradientAlpha.setCol2(color);
                cursor.setX(v.y * SIZE - cursor.getWidth() / 2.0f);
                cursor.setY(v.z * SIZE - cursor.getHeight() / 2.0f);
                hueKnob.setY(v.x * SIZE - hueKnob.getHeight() / 2.0f);
                hueKnob2.setY(hueKnob.getY());
                alphaKnob.setY(selectedColor.a * SIZE - alphaKnob.getHeight() / 2.0f);
                alphaKnob2.setY(alphaKnob.getY());
            }
        }
    };
    hexField.addListener(hexListener);
    alphaSpinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            selectedColor.set((float) redSpinner.getValue() / 255.0f, (float) greenSpinner.getValue() / 255.0f, (float) blueSpinner.getValue() / 255.0f, (float) alphaSpinner.getValue() / 255.0f);
            selectedColorCont.setColor(selectedColor);
            alphaKnob.setY(selectedColor.a * SIZE - alphaKnob.getHeight() / 2.0f);
            alphaKnob2.setY(alphaKnob.getY());
            hexField.setText(selectedColor.toString());
        }
    });
    Table panel = new Table(skin);
    panel.setBackground("color-box");
    Table t = new Table(skin);
    t.setClip(true);
    t.setBackground(gradientSB);
    t.setTouchable(Touchable.enabled);
    cursor.setPosition(v.y * SIZE - cursor.getWidth() / 2.0f, v.z * SIZE - cursor.getHeight() / 2.0f);
    t.addActor(cursor);
    DragListener dragListener = new DragListener() {

        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            saturationSpinner.setValue(MathUtils.clamp(x / SIZE * 100.0f, 0, 100));
            brightnessSpinner.setValue(MathUtils.clamp(y / SIZE * 100.0f, 0, 100));
            saturationSpinner.fire(new ChangeListener.ChangeEvent());
        }
    };
    dragListener.setTapSquareSize(1.0f);
    t.addListener(dragListener);
    t.addListener(new InputListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            saturationSpinner.setValue(MathUtils.clamp(x / SIZE * 100.0f, 0, 100));
            brightnessSpinner.setValue(MathUtils.clamp(y / SIZE * 100.0f, 0, 100));
            saturationSpinner.fire(new ChangeListener.ChangeEvent());
            return false;
        }
    });
    panel.add(t).size(SIZE, SIZE);
    content.add(panel);
    panel = new Table(skin);
    panel.setBackground("color-box");
    t = new Table(skin);
    t.setTouchable(Touchable.enabled);
    t.setClip(true);
    for (GradientDrawable gradient : hueGradient) {
        Container container = new Container();
        container.background(gradient);
        t.add(container).growX().height(50.0f);
        t.row();
    }
    t.addActor(hueKnob);
    t.addActor(hueKnob2);
    hueKnob.setY(v.x * SIZE - hueKnob.getHeight() / 2.0f);
    hueKnob2.setX(30.0f - hueKnob2.getWidth());
    hueKnob2.setY(v.x * SIZE - hueKnob2.getHeight() / 2.0f);
    dragListener = new DragListener() {

        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            hueSpinner.setValue(MathUtils.clamp(y / SIZE * 359.0f, 0.0f, 359.0f));
            hueSpinner.fire(new ChangeListener.ChangeEvent());
        }
    };
    dragListener.setTapSquareSize(1.0f);
    t.addListener(dragListener);
    t.addListener(new InputListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            hueSpinner.setValue(MathUtils.clamp(y / SIZE * 359.0f, 0.0f, 359.0f));
            hueSpinner.fire(new ChangeListener.ChangeEvent());
            return false;
        }
    });
    panel.add(t).minWidth(30.0f).height(SIZE);
    content.add(panel);
    panel = new Table(skin);
    panel.setBackground("color-box");
    t = new Table();
    t.setTouchable(Touchable.enabled);
    t.setBackground(alphaStack);
    t.setClip(true);
    t.addActor(alphaKnob);
    t.addActor(alphaKnob2);
    alphaKnob.setY(selectedColor.a * SIZE - alphaKnob.getHeight() / 2.0f);
    alphaKnob2.setX(30.0f - alphaKnob2.getWidth());
    alphaKnob2.setY(selectedColor.a * SIZE - alphaKnob2.getHeight() / 2.0f);
    dragListener = new DragListener() {

        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            alphaSpinner.setValue(MathUtils.clamp(y / SIZE * 255.0f, 0.0f, 255.0f));
            alphaSpinner.fire(new ChangeListener.ChangeEvent());
        }
    };
    dragListener.setTapSquareSize(1.0f);
    t.addListener(dragListener);
    t.addListener(new InputListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            alphaSpinner.setValue(MathUtils.clamp(y / SIZE * 255.0f, 0.0f, 255.0f));
            alphaSpinner.fire(new ChangeListener.ChangeEvent());
            return false;
        }
    });
    panel.add(t).minWidth(30.0f).height(SIZE);
    content.add(panel);
    t = new Table();
    t.defaults().pad(10.0f);
    Table table = new Table(skin);
    Label label = new Label("new", skin);
    label.setAlignment(Align.center);
    table.add(label).growX();
    table.row();
    Container bg = new Container();
    bg.setBackground(checker);
    Stack stack = new Stack(bg, selectedColorCont);
    panel = new Table(skin);
    panel.setBackground("color-box");
    panel.add(stack).grow();
    table.add(panel).grow();
    if (previousColor != null) {
        Container cont = new Container();
        cont.setBackground(skin.getDrawable("white"));
        cont.setColor(previousColor);
        bg = new Container();
        bg.setBackground(checker);
        stack = new Stack(bg, cont);
        panel.row();
        panel.add(stack).grow();
        table.row();
        label = new Label("current", skin);
        label.setAlignment(Align.center);
        table.add(label).growX();
        t.add(table).minWidth(80.0f).minHeight(150.0f);
    } else {
        t.add(table).minWidth(80.0f).minHeight(100.0f);
    }
    table = new Table();
    table.setName("confirmTable");
    table.defaults().space(10.0f).minWidth(80.0f);
    TextButton textButton = new TextButton("OK", skin);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            if (listener != null) {
                listener.handle(new ColorListener.ColorEvent(selectedColor));
            }
            hide();
        }
    });
    table.add(textButton);
    textButton = new TextButton("Cancel", skin);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            if (listener != null) {
                listener.handle(new ColorListener.ColorEvent(null));
            }
            hide();
        }
    });
    table.add(textButton);
    t.add(table);
    table.row();
    table = new Table();
    ((Table) t.findActor("confirmTable")).add(table).colspan(2);
    table.defaults().space(10.0f);
    label = new Label("#", skin, "required");
    table.add(label);
    table.add(hexField).width(75.0f);
    t.row();
    table = new Table();
    label = new Label("R", skin, "required");
    table.add(label);
    table.add(redSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);
    table = new Table();
    label = new Label("H", skin, "required");
    table.add(label);
    table.add(hueSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);
    t.row();
    table = new Table();
    label = new Label("G", skin, "required");
    table.add(label);
    table.add(greenSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);
    table = new Table();
    label = new Label("S", skin, "required");
    table.add(label);
    table.add(saturationSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);
    t.row();
    table = new Table();
    label = new Label("B", skin, "required");
    table.add(label);
    table.add(blueSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);
    table = new Table();
    label = new Label("B", skin, "required");
    table.add(label);
    table.add(brightnessSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);
    t.row();
    table = new Table();
    label = new Label("A", skin, "required");
    table.add(label);
    t.add(table);
    table.add(alphaSpinner).padLeft(10.0f).minWidth(90.0f);
    content.add(t).growY();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Spinner(com.ray3k.skincomposer.Spinner) Color(com.badlogic.gdx.graphics.Color) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Vector3(com.badlogic.gdx.math.Vector3) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) GradientDrawable(com.ray3k.skincomposer.GradientDrawable) Stack(com.badlogic.gdx.scenes.scene2d.ui.Stack) Container(com.badlogic.gdx.scenes.scene2d.ui.Container) DragListener(com.badlogic.gdx.scenes.scene2d.utils.DragListener) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 4 with Spinner

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

the class DialogDrawables method tiledDrawableDialog.

private void tiledDrawableDialog(DrawableData drawable) {
    DialogColors dialog = new DialogColors(main, (StyleProperty) null, true, (ColorData colorData) -> {
        if (colorData != null) {
            final Spinner minWidthSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            final Spinner minHeightSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            TextField textField = new TextField("", getSkin()) {

                @Override
                public void next(boolean up) {
                    if (up) {
                        getStage().setKeyboardFocus(minHeightSpinner.getTextField());
                        minHeightSpinner.getTextField().selectAll();
                    } else {
                        getStage().setKeyboardFocus(minWidthSpinner.getTextField());
                        minWidthSpinner.getTextField().selectAll();
                    }
                }
            };
            Dialog tileDialog = new Dialog("New Tiled Drawable", getSkin(), "bg") {

                @Override
                protected void result(Object object) {
                    super.result(object);
                    if (object instanceof Boolean && (boolean) object == true) {
                        tiledDrawable(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                    }
                    getStage().setScrollFocus(scrollPane);
                }

                @Override
                public Dialog show(Stage stage) {
                    Dialog dialog = super.show(stage);
                    stage.setKeyboardFocus(textField);
                    return dialog;
                }
            };
            tileDialog.getTitleTable().padLeft(5.0f);
            tileDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
            tileDialog.getButtonTable().padBottom(15.0f);
            tileDialog.getContentTable().add(new Label("Please enter a name for the TiledDrawable: ", getSkin()));
            tileDialog.button("OK", true);
            tileDialog.button("Cancel", false).key(Keys.ESCAPE, false);
            TextButton okButton = (TextButton) tileDialog.getButtonTable().getCells().first().getActor();
            okButton.setDisabled(true);
            okButton.addListener(main.getHandListener());
            tileDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
            tileDialog.getContentTable().row();
            textField.setText(drawable.name);
            textField.selectAll();
            tileDialog.getContentTable().add(textField);
            Vector2 dimensions = Utils.imageDimensions(drawable.file);
            tileDialog.getContentTable().row();
            Table table = new Table();
            table.defaults().space(10.0f);
            tileDialog.getContentTable().add(table);
            Label label = new Label("MinWidth:", getSkin());
            table.add(label);
            minWidthSpinner.setValue(dimensions.x);
            minWidthSpinner.setMinimum(0.0f);
            table.add(minWidthSpinner).minWidth(150.0f);
            minWidthSpinner.setTransversalPrevious(textField);
            minWidthSpinner.setTransversalNext(minHeightSpinner.getTextField());
            table.row();
            label = new Label("MinHeight:", getSkin());
            table.add(label);
            minHeightSpinner.setValue(dimensions.y);
            minHeightSpinner.setMinimum(0.0f);
            table.add(minHeightSpinner).minWidth(150.0f);
            minHeightSpinner.setTransversalPrevious(minWidthSpinner.getTextField());
            minHeightSpinner.setTransversalNext(textField);
            textField.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    boolean disable = !DrawableData.validate(textField.getText());
                    if (!disable) {
                        for (DrawableData data : main.getAtlasData().getDrawables()) {
                            if (data.name.equals(textField.getText())) {
                                disable = true;
                                break;
                            }
                        }
                    }
                    okButton.setDisabled(disable);
                }
            });
            textField.setTextFieldListener(new TextField.TextFieldListener() {

                @Override
                public void keyTyped(TextField textField, char c) {
                    if (c == '\n') {
                        if (!okButton.isDisabled()) {
                            tiledDrawable(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                            tileDialog.hide();
                        }
                    }
                }
            });
            textField.addListener(main.getIbeamListener());
            tileDialog.show(getStage());
        }
    });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.refreshTable();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Spinner(com.ray3k.skincomposer.Spinner) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) Vector2(com.badlogic.gdx.math.Vector2) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 5 with Spinner

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

the class DialogSettings method populate.

public void populate() {
    Table t = getContentTable();
    getButtonTable().padBottom(15.0f);
    Label label = new Label("Settings", main.getSkin(), "title");
    t.add(label).colspan(2);
    t.row();
    TextButton textButton = new TextButton("Open temp/log directory", main.getSkin());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            try {
                Utils.openFileExplorer(Gdx.files.local("temp/"));
            } catch (Exception e) {
                Gdx.app.error(getClass().getName(), "Error opening temp folder", e);
                main.getDialogFactory().showDialogError("Folder Error...", "Error opening temp folder.\n\nOpen log?");
            }
        }
    });
    textButton.addListener(main.getHandListener());
    t.add(textButton).colspan(2).padTop(15.0f);
    t.row();
    textButton = new TextButton("Open preferences directory", main.getSkin());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            try {
                Utils.openFileExplorer(Gdx.files.external(".prefs/"));
            } catch (Exception e) {
                Gdx.app.error(getClass().getName(), "Error opening preferences folder", e);
                main.getDialogFactory().showDialogError("Folder Error...", "Error opening preferences folder.\n\nOpen log?");
            }
        }
    });
    textButton.addListener(main.getHandListener());
    t.add(textButton).colspan(2);
    if (main.getProjectData().areChangesSaved() && main.getProjectData().getSaveFile().exists()) {
        t.row();
        textButton = new TextButton("Open project/import directory", main.getSkin());
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                try {
                    Utils.openFileExplorer(main.getProjectData().getSaveFile().sibling(main.getProjectData().getSaveFile().nameWithoutExtension() + "_data"));
                } catch (Exception e) {
                    Gdx.app.error(getClass().getName(), "Error opening project folder", e);
                    main.getDialogFactory().showDialogError("Folder Error...", "Error opening project folder\n\nOpen log?");
                }
            }
        });
        textButton.addListener(main.getHandListener());
        t.add(textButton).colspan(2);
    }
    t.row();
    textButton = new TextButton("Open texture packer settings file", main.getSkin());
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            try {
                Utils.openFileExplorer(Gdx.files.local("texturepacker/defaults.json"));
            } catch (Exception e) {
                Gdx.app.error(getClass().getName(), "Error opening defaults.json", e);
                main.getDialogFactory().showDialogError("File Error...", "Error opening defaults.json\n\nOpen log?");
            }
        }
    });
    textButton.addListener(main.getHandListener());
    t.add(textButton).colspan(2);
    t.row();
    label = new Label("Max Number of Undos: ", main.getSkin());
    t.add(label).right().padTop(10.0f);
    Spinner spinner3 = new Spinner(main.getProjectData().getMaxUndos(), 1.0, true, Orientation.HORIZONTAL, getSkin());
    spinner3.setMinimum(1.0);
    spinner3.setMaximum(100.0);
    spinner3.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            maxUndos = (int) spinner3.getValue();
        }
    });
    spinner3.addListener(new FocusListener() {

        @Override
        public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
            maxUndos = (int) spinner3.getValue();
        }
    });
    spinner3.getTextField().addListener(main.getIbeamListener());
    spinner3.getButtonMinus().addListener(main.getHandListener());
    spinner3.getButtonPlus().addListener(main.getHandListener());
    t.add(spinner3).minWidth(150.0f).left().padTop(10.0f);
    t.row();
    final ImageTextButton checkBox = new ImageTextButton("Keep resources relative?", getSkin(), "checkbox");
    checkBox.setChecked(resourcesRelative);
    checkBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            resourcesRelative = checkBox.isChecked();
        }
    });
    t.add(checkBox).padTop(10.0f).colspan(2);
    t.row();
    final ImageTextButton welcomeCheckBox = new ImageTextButton("Show welcome screen?", getSkin(), "checkbox");
    welcomeCheckBox.setChecked(allowingWelcome);
    welcomeCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            allowingWelcome = welcomeCheckBox.isChecked();
        }
    });
    t.add(welcomeCheckBox).padTop(10.0f).colspan(2);
    t.row();
    label = new Label("Exported JSON Format:", getSkin());
    t.add(label).right().padTop(10.0f);
    final SelectBox<ExportFormat> exportFormatSelectBox = new SelectBox(getSkin());
    exportFormatSelectBox.setItems(ExportFormat.MINIMAL, ExportFormat.JAVASCRIPT, ExportFormat.JSON);
    exportFormatSelectBox.setSelected(exportFormat);
    exportFormatSelectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            exportFormat = exportFormatSelectBox.getSelected();
        }
    });
    t.add(exportFormatSelectBox).left().padTop(10.0f);
    ;
    button("OK", true);
    button("Cancel", false);
    getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
    getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
    key(Keys.ESCAPE, false);
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Spinner(com.ray3k.skincomposer.Spinner) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) FocusListener(com.badlogic.gdx.scenes.scene2d.utils.FocusListener)

Aggregations

Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)5 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)5 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)5 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)5 Spinner (com.ray3k.skincomposer.Spinner)5 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)4 ColorData (com.ray3k.skincomposer.data.ColorData)3 Stage (com.badlogic.gdx.scenes.scene2d.Stage)2 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)2 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)2 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)2 DrawableData (com.ray3k.skincomposer.data.DrawableData)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Color (com.badlogic.gdx.graphics.Color)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Vector3 (com.badlogic.gdx.math.Vector3)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)1