Search in sources :

Example 6 with ColorData

use of com.ray3k.skincomposer.data.ColorData 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 7 with ColorData

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

the class DialogColors method result.

@Override
protected void result(Object object) {
    if (styleProperty != null) {
        if (object instanceof ColorData) {
            main.getProjectData().setChangesSaved(false);
            ColorData color = (ColorData) object;
            ColorUndoable undoable = new ColorUndoable(main.getRootTable(), main.getJsonData(), styleProperty, styleProperty.value, color.getName());
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof Boolean) {
            if ((boolean) object) {
                main.getProjectData().setChangesSaved(false);
                ColorUndoable undoable = new ColorUndoable(main.getRootTable(), main.getJsonData(), styleProperty, styleProperty.value, null);
                main.getUndoableManager().addUndoable(undoable, true);
            } else {
                boolean hasColor = false;
                for (ColorData color : main.getJsonData().getColors()) {
                    if (color.getName().equals(styleProperty.value)) {
                        hasColor = true;
                        break;
                    }
                }
                if (!hasColor) {
                    main.getProjectData().setChangesSaved(false);
                    styleProperty.value = null;
                    main.getRootTable().setStatusBarMessage("Deleted color for \"" + styleProperty.name + "\"");
                    main.getRootTable().refreshStyleProperties(true);
                }
            }
        }
    } else if (customProperty != null) {
        if (object instanceof ColorData) {
            main.getProjectData().setChangesSaved(false);
            ColorData color = (ColorData) object;
            CustomColorUndoable undoable = new UndoableManager.CustomColorUndoable(main, customProperty, color.getName());
            main.getUndoableManager().addUndoable(undoable, true);
        } else if (object instanceof Boolean) {
            if ((boolean) object) {
                main.getProjectData().setChangesSaved(false);
                CustomColorUndoable undoable = new UndoableManager.CustomColorUndoable(main, customProperty, null);
                main.getUndoableManager().addUndoable(undoable, true);
                main.getRootTable().setStatusBarMessage("Emptied color for \"" + customProperty.getName() + "\"");
                main.getRootTable().refreshStyleProperties(true);
            } else {
                boolean hasColor = false;
                for (ColorData color : main.getJsonData().getColors()) {
                    if (color.getName().equals(customProperty.getValue())) {
                        hasColor = true;
                        break;
                    }
                }
                if (!hasColor) {
                    main.getProjectData().setChangesSaved(false);
                    customProperty.setValue(null);
                    main.getRootTable().setStatusBarMessage("Deleted color for \"" + customProperty.getName() + "\"");
                    main.getRootTable().refreshStyleProperties(true);
                }
            }
        }
    }
    if (listener != null) {
        if (object instanceof ColorData) {
            listener.handle((ColorData) object);
        } else {
            listener.handle(null);
        }
    }
}
Also used : ColorData(com.ray3k.skincomposer.data.ColorData) CustomColorUndoable(com.ray3k.skincomposer.UndoableManager.CustomColorUndoable) UndoableManager(com.ray3k.skincomposer.UndoableManager) CustomColorUndoable(com.ray3k.skincomposer.UndoableManager.CustomColorUndoable) ColorUndoable(com.ray3k.skincomposer.UndoableManager.ColorUndoable) CustomColorUndoable(com.ray3k.skincomposer.UndoableManager.CustomColorUndoable)

Example 8 with ColorData

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

the class DialogColors method renameColor.

private void renameColor(ColorData color, String newName) {
    // style properties
    for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
        for (StyleData data : datas) {
            for (StyleProperty property : data.properties.values()) {
                if (property != null && property.type.equals(Color.class) && property.value != null && property.value.equals(color.getName())) {
                    property.value = newName;
                }
            }
        }
    }
    // tinted drawables
    for (DrawableData drawableData : main.getAtlasData().getDrawables()) {
        if (drawableData.tintName != null && drawableData.tintName.equals(color.getName())) {
            drawableData.tintName = newName;
        }
    }
    try {
        color.setName(newName);
    } catch (ColorData.NameFormatException ex) {
        Gdx.app.error(getClass().getName(), "Error trying to rename a color.", ex);
        main.getDialogFactory().showDialogError("Name Error...", "Error while naming a color.\\nPlease ensure name is formatted appropriately:\\nNo spaces, don't start with a number, - and _ acceptable.\n\nOpen log?");
    }
    main.getUndoableManager().clearUndoables();
    main.getRootTable().refreshStyleProperties(true);
    main.getRootTable().refreshPreview();
    main.getProjectData().setChangesSaved(false);
    refreshTable();
}
Also used : StyleProperty(com.ray3k.skincomposer.data.StyleProperty) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) Color(com.badlogic.gdx.graphics.Color) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 9 with ColorData

use of com.ray3k.skincomposer.data.ColorData 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 10 with ColorData

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

the class DialogColors method showColorPicker.

private void showColorPicker() {
    main.getDialogFactory().showDialogColorPicker(new DialogColorPicker.ColorListener() {

        @Override
        public void selected(Color color) {
            if (color != null) {
                final TextField field = new TextField("RGBA_" + (int) (color.r * 255) + "_" + (int) (color.g * 255) + "_" + (int) (color.b * 255) + "_" + (int) (color.a * 255), getSkin());
                final Dialog dialog = new Dialog("Color name...", getSkin(), "bg") {

                    @Override
                    protected void result(Object object) {
                        if ((Boolean) object == true) {
                            newColor(field.getText(), color);
                        }
                    }
                };
                dialog.getTitleTable().padLeft(5.0f);
                dialog.button("Ok", true).button("Cancel", false).key(Keys.ESCAPE, false);
                final TextButton button = (TextButton) dialog.getButtonTable().getCells().first().getActor();
                button.addListener(main.getHandListener());
                dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
                dialog.getButtonTable().pad(15.0f);
                field.setTextFieldListener(new TextField.TextFieldListener() {

                    @Override
                    public void keyTyped(TextField textField, char c) {
                        if (c == '\n') {
                            if (!button.isDisabled()) {
                                String name = field.getText();
                                if (newColor(name, color)) {
                                    dialog.hide();
                                }
                            }
                            main.getStage().setKeyboardFocus(textField);
                        }
                    }
                });
                field.addListener(main.getIbeamListener());
                dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
                dialog.text("Please enter a name for the new color: ");
                dialog.getContentTable().row();
                dialog.getContentTable().add(field).growX();
                dialog.getContentTable().row();
                dialog.text("Preview:");
                dialog.getContentTable().row();
                Table table = new Table(getSkin());
                table.setBackground("white");
                table.setColor(color);
                dialog.getContentTable().add(table).minSize(50.0f);
                button.setDisabled(!ColorData.validate(field.getText()));
                field.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        boolean disable = !ColorData.validate(field.getText());
                        if (!disable) {
                            for (ColorData data : main.getJsonData().getColors()) {
                                if (data.getName().equals(field.getText())) {
                                    disable = true;
                                    break;
                                }
                            }
                        }
                        button.setDisabled(disable);
                    }
                });
                dialog.show(getStage());
                getStage().setKeyboardFocus(field);
                field.selectAll();
                field.setFocusTraversal(false);
            }
        }
    });
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Color(com.badlogic.gdx.graphics.Color) ColorData(com.ray3k.skincomposer.data.ColorData) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Aggregations

ColorData (com.ray3k.skincomposer.data.ColorData)15 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)11 Actor (com.badlogic.gdx.scenes.scene2d.Actor)10 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)10 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)10 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)10 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)8 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)7 DrawableData (com.ray3k.skincomposer.data.DrawableData)7 Color (com.badlogic.gdx.graphics.Color)6 StyleData (com.ray3k.skincomposer.data.StyleData)5 Stage (com.badlogic.gdx.scenes.scene2d.Stage)4 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)4 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)4 TextTooltip (com.badlogic.gdx.scenes.scene2d.ui.TextTooltip)4 Array (com.badlogic.gdx.utils.Array)4 StyleProperty (com.ray3k.skincomposer.data.StyleProperty)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)3 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)3