Search in sources :

Example 1 with Spinner

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

the class Dialog9Patch method populate.

private void populate() {
    var root = getContentTable();
    root.clear();
    root.pad(10);
    var horizontalGroup = new HorizontalGroup();
    horizontalGroup.space(5.0f);
    horizontalGroup.wrap();
    horizontalGroup.wrapSpace(5.0f);
    horizontalGroup.center();
    root.add(horizontalGroup).growX();
    var textButton = new TextButton("Load Image", getSkin());
    horizontalGroup.addActor(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            showLoadImageDialog();
        }
    });
    textButton = new TextButton("Reset", getSkin());
    textButton.setName("reset-button");
    horizontalGroup.addActor(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinnerItem = (Spinner) findActor("spinner-padding-left");
            spinnerItem.setValue(ninePatchLeftOriginal);
            widget.setPaddingLeft(ninePatchLeftOriginal);
            ninePatchLeft = ninePatchLeftOriginal;
            spinnerItem = (Spinner) findActor("spinner-padding-right");
            spinnerItem.setValue(ninePatchRightOriginal);
            widget.setPaddingRight(ninePatchRightOriginal);
            ninePatchRight = ninePatchRightOriginal;
            spinnerItem = (Spinner) findActor("spinner-padding-bottom");
            spinnerItem.setValue(ninePatchBottomOriginal);
            widget.setPaddingBottom(ninePatchBottomOriginal);
            ninePatchBottom = ninePatchBottomOriginal;
            spinnerItem = (Spinner) findActor("spinner-padding-top");
            spinnerItem.setValue(ninePatchTopOriginal);
            widget.setPaddingTop(ninePatchTopOriginal);
            ninePatchTop = ninePatchTopOriginal;
            spinnerItem = (Spinner) findActor("spinner-content-left");
            spinnerItem.setValue(ninePatchContentLeftOriginal);
            widget.setContentLeft(ninePatchContentLeftOriginal);
            ninePatchContentLeft = ninePatchContentLeftOriginal;
            spinnerItem = (Spinner) findActor("spinner-content-right");
            spinnerItem.setValue(ninePatchContentRightOriginal);
            widget.setContentRight(ninePatchContentRightOriginal);
            ninePatchContentRight = ninePatchContentRightOriginal;
            spinnerItem = (Spinner) findActor("spinner-content-bottom");
            spinnerItem.setValue(ninePatchContentBottomOriginal);
            widget.setContentBottom(ninePatchContentBottomOriginal);
            ninePatchContentBottom = ninePatchContentBottomOriginal;
            spinnerItem = (Spinner) findActor("spinner-content-top");
            spinnerItem.setValue(ninePatchContentTopOriginal);
            widget.setContentTop(ninePatchContentTopOriginal);
            ninePatchContentTop = ninePatchContentTopOriginal;
            updatePreviewSplits();
        }
    });
    textButton = new TextButton("Auto Patches", getSkin());
    textButton.setName("auto-button");
    horizontalGroup.addActor(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            autoPatches();
        }
    });
    textButton = new TextButton("Load Patches From File", getSkin());
    textButton.setName("load-patches-button");
    horizontalGroup.addActor(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            showLoadPatchesDialog();
        }
    });
    textButton = new TextButton("Batch Apply to File(s)", getSkin());
    textButton.setName("batch-button");
    horizontalGroup.addActor(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            showBatchApplyDialog();
        }
    });
    root.row();
    var image = new Image(getSkin(), "welcome-separator");
    root.add(image).growX().space(15.0f);
    image.setScaling(Scaling.stretch);
    var top = new Table();
    top.setTouchable(Touchable.enabled);
    var bottom = new Table();
    bottom.setBackground(getSkin().getDrawable("white"));
    bottom.setTouchable(Touchable.enabled);
    root.row();
    var splitPane = new SplitPane(top, bottom, true, getSkin());
    splitPane.setName("split");
    root.add(splitPane).grow();
    splitPane.addListener(verticalResizeListener);
    var table = new Table();
    top.add(table).growX();
    var spinner = new Spinner(0, 1, true, Spinner.Orientation.HORIZONTAL, getSkin());
    spinner.setName("spinner-padding-left");
    spinner.setValue(ninePatchLeft);
    spinner.setMinimum(0);
    table.add(spinner).expandX().left().padLeft(50.0f);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinner = (Spinner) actor;
            ninePatchLeft = spinner.getValueAsInt();
            widget.setPaddingLeft(spinner.getValueAsInt());
            widget.getPaddingButton().setChecked(false);
            var otherSpinner = (Spinner) findActor("spinner-padding-right");
            otherSpinner.setMaximum(widget.getRegionWidth() - spinner.getValueAsInt());
            updatePreviewSplits();
        }
    });
    var label = new Label("STRETCH REGION", getSkin());
    table.add(label);
    spinner = new Spinner(0, 1, true, Spinner.Orientation.HORIZONTAL_FLIPPED, getSkin(), "horizontal-reversed");
    spinner.setName("spinner-padding-right");
    spinner.setValue(ninePatchRight);
    spinner.setMinimum(0);
    table.add(spinner).expandX().right().padRight(50.0f);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinner = (Spinner) actor;
            ninePatchRight = spinner.getValueAsInt();
            widget.setPaddingRight(spinner.getValueAsInt());
            widget.getPaddingButton().setChecked(false);
            var otherSpinner = (Spinner) findActor("spinner-padding-left");
            otherSpinner.setMaximum(widget.getRegionWidth() - spinner.getValueAsInt());
            updatePreviewSplits();
        }
    });
    top.row();
    table = new Table();
    top.add(table).grow();
    var subTable = new Table();
    table.add(subTable).growY();
    spinner = new Spinner(0, 1, true, Spinner.Orientation.VERTICAL_FLIPPED, getSkin(), "vertical-reversed");
    spinner.setName("spinner-padding-top");
    spinner.setValue(ninePatchTop);
    spinner.setMinimum(0);
    subTable.add(spinner).expandY().top();
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinner = (Spinner) actor;
            ninePatchTop = spinner.getValueAsInt();
            widget.setPaddingTop(spinner.getValueAsInt());
            widget.getPaddingButton().setChecked(false);
            var otherSpinner = (Spinner) findActor("spinner-padding-bottom");
            otherSpinner.setMaximum(widget.getRegionHeight() - spinner.getValueAsInt());
            updatePreviewSplits();
        }
    });
    subTable.row();
    var group = new Table();
    group.setTransform(true);
    subTable.add(group).size(0).minHeight(100.0f);
    label = new Label("STRETCH REGION", getSkin());
    group.add(label);
    group.setOriginY(50.0f);
    group.rotateBy(90.0f);
    subTable.row();
    spinner = new Spinner(0, 1, true, Spinner.Orientation.VERTICAL, getSkin(), "vertical");
    spinner.setName("spinner-padding-bottom");
    spinner.setValue(ninePatchBottom);
    spinner.setMinimum(0);
    subTable.add(spinner).expandY().bottom();
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinner = (Spinner) actor;
            ninePatchBottom = spinner.getValueAsInt();
            widget.setPaddingBottom(spinner.getValueAsInt());
            widget.getPaddingButton().setChecked(false);
            var otherSpinner = (Spinner) findActor("spinner-padding-top");
            otherSpinner.setMaximum(widget.getRegionHeight() - spinner.getValueAsInt());
            updatePreviewSplits();
        }
    });
    var ninePatchWidget = new NinePatchWidget(getSkin());
    ninePatchWidget.setName("ninePatchWidget");
    ninePatchWidget.setTouchable(Touchable.enabled);
    table.add(ninePatchWidget).grow().pad(5.0f);
    ninePatchWidget.getPaddingButton().addListener(handListener);
    ninePatchWidget.addListener((NinePatchWidget.HandleType handle, int value) -> {
        switch(handle) {
            case PADDING_LEFT:
                var spinnerItem = (Spinner) findActor("spinner-padding-left");
                spinnerItem.setValue(value);
                ninePatchLeft = value;
                var otherSpinner = (Spinner) findActor("spinner-padding-right");
                otherSpinner.setMaximum(ninePatchWidget.getRegionWidth() - value);
                break;
            case PADDING_RIGHT:
                spinnerItem = (Spinner) findActor("spinner-padding-right");
                spinnerItem.setValue(value);
                ninePatchRight = value;
                otherSpinner = (Spinner) findActor("spinner-padding-left");
                otherSpinner.setMaximum(ninePatchWidget.getRegionWidth() - value);
                break;
            case PADDING_BOTTOM:
                spinnerItem = (Spinner) findActor("spinner-padding-bottom");
                spinnerItem.setValue(value);
                ninePatchBottom = value;
                otherSpinner = (Spinner) findActor("spinner-padding-top");
                otherSpinner.setMaximum(ninePatchWidget.getRegionHeight() - value);
                break;
            case PADDING_TOP:
                spinnerItem = (Spinner) findActor("spinner-padding-top");
                spinnerItem.setValue(value);
                ninePatchTop = value;
                otherSpinner = (Spinner) findActor("spinner-padding-bottom");
                otherSpinner.setMaximum(ninePatchWidget.getRegionHeight() - value);
                break;
            case CONTENT_LEFT:
                spinnerItem = (Spinner) findActor("spinner-content-left");
                spinnerItem.setValue(value);
                ninePatchContentLeft = value;
                otherSpinner = (Spinner) findActor("spinner-content-right");
                otherSpinner.setMaximum(ninePatchWidget.getRegionWidth() - value);
                break;
            case CONTENT_RIGHT:
                spinnerItem = (Spinner) findActor("spinner-content-right");
                spinnerItem.setValue(value);
                ninePatchContentRight = value;
                otherSpinner = (Spinner) findActor("spinner-content-left");
                otherSpinner.setMaximum(ninePatchWidget.getRegionWidth() - value);
                break;
            case CONTENT_BOTTOM:
                spinnerItem = (Spinner) findActor("spinner-content-bottom");
                spinnerItem.setValue(value);
                ninePatchContentBottom = value;
                otherSpinner = (Spinner) findActor("spinner-content-top");
                otherSpinner.setMaximum(ninePatchWidget.getRegionHeight() - value);
                break;
            case CONTENT_TOP:
                spinnerItem = (Spinner) findActor("spinner-content-top");
                spinnerItem.setValue(value);
                ninePatchContentTop = value;
                otherSpinner = (Spinner) findActor("spinner-content-bottom");
                otherSpinner.setMaximum(ninePatchWidget.getRegionHeight() - value);
                break;
        }
        updatePreviewSplits();
    });
    var inputListener = new InputListener() {

        @Override
        public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            getStage().setScrollFocus(ninePatchWidget);
        }

        @Override
        public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY) {
            var slider = (Slider) findActor("top-zoom");
            slider.setValue(slider.getValue() - amountY * 3);
            return true;
        }
    };
    ninePatchWidget.addCaptureListener(inputListener);
    subTable = new Table();
    table.add(subTable).growY();
    spinner = new Spinner(0, 1, true, Spinner.Orientation.VERTICAL_FLIPPED, getSkin(), "vertical-reversed");
    spinner.setName("spinner-content-top");
    spinner.setValue(ninePatchContentTop);
    spinner.setMinimum(0);
    subTable.add(spinner).expandY().top();
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinner = (Spinner) actor;
            ninePatchContentTop = spinner.getValueAsInt();
            widget.setContentTop(spinner.getValueAsInt());
            widget.getPaddingButton().setChecked(true);
            var otherSpinner = (Spinner) findActor("spinner-content-bottom");
            otherSpinner.setMaximum(widget.getRegionHeight() - spinner.getValueAsInt());
            updatePreviewSplits();
        }
    });
    subTable.row();
    group = new Table();
    group.setTransform(true);
    subTable.add(group).size(0).minHeight(100.0f);
    label = new Label("CONTENT", getSkin());
    group.add(label);
    group.setOriginY(50.0f);
    group.rotateBy(-90);
    subTable.row();
    spinner = new Spinner(0, 1, true, Spinner.Orientation.VERTICAL, getSkin(), "vertical");
    spinner.setName("spinner-content-bottom");
    spinner.setValue(ninePatchContentBottom);
    spinner.setMinimum(0);
    subTable.add(spinner).expandY().bottom();
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinner = (Spinner) actor;
            ninePatchContentBottom = spinner.getValueAsInt();
            widget.setContentBottom(spinner.getValueAsInt());
            widget.getPaddingButton().setChecked(true);
            var otherSpinner = (Spinner) findActor("spinner-content-top");
            otherSpinner.setMaximum(widget.getRegionHeight() - spinner.getValueAsInt());
            updatePreviewSplits();
        }
    });
    top.row().padBottom(15.0f);
    table = new Table();
    top.add(table).growX();
    spinner = new Spinner(0, 1, true, Spinner.Orientation.HORIZONTAL, getSkin());
    spinner.setName("spinner-content-left");
    spinner.setValue(ninePatchContentLeft);
    spinner.setMinimum(0);
    table.add(spinner).expandX().left().padLeft(50.0f);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinner = (Spinner) actor;
            ninePatchContentLeft = spinner.getValueAsInt();
            widget.setContentLeft(spinner.getValueAsInt());
            widget.getPaddingButton().setChecked(true);
            var otherSpinner = (Spinner) findActor("spinner-content-right");
            otherSpinner.setMaximum(widget.getRegionWidth() - spinner.getValueAsInt());
            updatePreviewSplits();
        }
    });
    label = new Label("CONTENT", getSkin());
    table.add(label);
    spinner = new Spinner(0, 1, true, Spinner.Orientation.HORIZONTAL_FLIPPED, getSkin(), "horizontal-reversed");
    spinner.setName("spinner-content-right");
    spinner.setValue(ninePatchContentRight);
    spinner.setMinimum(0);
    table.add(spinner).expandX().right().padRight(50.0f);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            var spinner = (Spinner) actor;
            ninePatchContentRight = spinner.getValueAsInt();
            widget.setContentRight(spinner.getValueAsInt());
            widget.getPaddingButton().setChecked(true);
            var otherSpinner = (Spinner) findActor("spinner-content-left");
            otherSpinner.setMaximum(widget.getRegionWidth() - spinner.getValueAsInt());
            updatePreviewSplits();
        }
    });
    top.row();
    table = new Table();
    table.pad(5);
    top.add(table).growX();
    table.defaults().space(5);
    var imageButton = new ImageButton(getSkin(), "grid-light");
    imageButton.setName("grid-light");
    imageButton.setProgrammaticChangeEvents(false);
    table.add(imageButton);
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            if (((ImageButton) actor).isChecked()) {
                widget.setGridType(NinePatchWidget.GridType.LIGHT);
            } else {
                widget.setGridType(NinePatchWidget.GridType.NONE);
            }
            ((ImageButton) findActor("grid-dark")).setChecked(false);
        }
    });
    imageButton = new ImageButton(getSkin(), "grid-dark");
    imageButton.setName("grid-dark");
    imageButton.setProgrammaticChangeEvents(false);
    table.add(imageButton);
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var widget = (NinePatchWidget) findActor("ninePatchWidget");
            if (((ImageButton) actor).isChecked()) {
                widget.setGridType(NinePatchWidget.GridType.DARK);
            } else {
                widget.setGridType(NinePatchWidget.GridType.NONE);
            }
            ((ImageButton) findActor("grid-light")).setChecked(false);
        }
    });
    imageButton = new ImageButton(getSkin(), "resize");
    table.add(imageButton).expandX().right();
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            zoomAndRecenter();
        }
    });
    var slider = new Slider(1, 50, 1, false, getSkin(), "zoom-horizontal");
    slider.setName("top-zoom");
    table.add(slider);
    slider.addListener(handListener);
    slider.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var slider = (Slider) findActor("top-zoom");
            ninePatchWidget.setZoom((int) slider.getValue());
        }
    });
    label = new Label("Preview", getSkin(), "title");
    bottom.add(label);
    bottom.row();
    var resizer = new ResizeWidget(null, getSkin());
    resizer.setTouchable(Touchable.enabled);
    resizer.setName("resizer");
    table = new Table();
    resizer.setActor(table);
    if (previewZoomed == null) {
        resizer.setMinWidth(100);
        resizer.setMinHeight(100);
    } else {
        resizer.setMinWidth(previewZoomed.getTotalWidth());
        resizer.setMinHeight(previewZoomed.getTotalHeight());
        table.setBackground(new NinePatchDrawable(previewZoomed));
    }
    resizer.setResizingFromCenter(true);
    resizer.getBottomLeftHandle().addListener(neResizeListener);
    resizer.getBottomRightHandle().addListener(nwResizeListener);
    resizer.getTopLeftHandle().addListener(nwResizeListener);
    resizer.getTopRightHandle().addListener(neResizeListener);
    resizer.getBottomHandle().addListener(verticalResizeListener);
    resizer.getTopHandle().addListener(verticalResizeListener);
    resizer.getLeftHandle().addListener(horizontalResizeListener);
    resizer.getRightHandle().addListener(horizontalResizeListener);
    resizer.addListener(new InputListener() {

        @Override
        public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
            getStage().setScrollFocus(resizer);
        }

        @Override
        public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY) {
            var slider = (Slider) findActor("bottom-zoom");
            slider.setValue(slider.getValue() - amountY * 5);
            return true;
        }
    });
    var scrollPane = new ScrollPane(resizer, getSkin());
    scrollPane.setName("scroll");
    scrollPane.setFlickScroll(false);
    scrollPane.setFadeScrollBars(false);
    bottom.add(scrollPane).grow();
    bottom.row();
    table = new Table();
    table.padLeft(5);
    table.padRight(5);
    bottom.add(table).growX();
    table.defaults().space(5);
    label = new Label("Content:", getSkin());
    table.add(label);
    var selectBox = new SelectBox<String>(getSkin());
    selectBox.setName("contentSelectBox");
    table.add(selectBox);
    selectBox.setItems("None", "Text", "Color", "Drawable");
    selectBox.addListener(handListener);
    selectBox.getList().addListener(handListener);
    selectBox.getList().addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            selectBox.fire(new ChangeListener.ChangeEvent());
        }
    });
    selectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            switch(selectBox.getSelected()) {
                case "None":
                    updatePreviewContentActor(null);
                    break;
                case "Text":
                    dialogFactory.showInputDialog("Text Content", "Enter the text to be displayed inside of the preview:", "Lorem Ipsum", new DialogFactory.InputDialogListener() {

                        @Override
                        public void confirmed(String text) {
                            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                                if (colorData == null) {
                                    selectBox.setSelected("None");
                                } else {
                                    var label = new Label(text, getSkin(), "white");
                                    label.setAlignment(Align.center);
                                    label.setColor(colorData.color);
                                    label.setUserObject("Text");
                                    updatePreviewContentActor(label);
                                }
                            }, null);
                        }

                        @Override
                        public void cancelled() {
                            selectBox.setSelected("None");
                        }
                    });
                    break;
                case "Color":
                    dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                        if (colorData == null) {
                            selectBox.setSelected("None");
                        } else {
                            var image = new Image(getSkin(), "white");
                            image.setScaling(Scaling.stretch);
                            image.setColor(colorData.color);
                            image.setUserObject("Color");
                            updatePreviewContentActor(image);
                        }
                    }, null);
                    break;
                case "Drawable":
                    var dialog = dialogFactory.showDialogDrawables(true, new DialogDrawables.DialogDrawablesListener() {

                        @Override
                        public void confirmed(DrawableData drawable, DialogDrawables dialog) {
                            var image = new Image(drawablePairs.get(drawable));
                            image.setScaling(Scaling.none);
                            image.setUserObject("Drawable");
                            updatePreviewContentActor(image);
                        }

                        @Override
                        public void emptied(DialogDrawables dialog) {
                            selectBox.setSelected("None");
                        }

                        @Override
                        public void cancelled(DialogDrawables dialog) {
                            selectBox.setSelected("None");
                        }
                    }, null);
                    dialog.setShowing9patchButton(false);
                    break;
            }
        }
    });
    imageButton = new ImageButton(getSkin(), "color");
    table.add(imageButton);
    imageButton.addListener(handListener);
    imageButton.addListener(new ChangeListener() {

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

                @Override
                public void selected(Color color) {
                    if (color != null) {
                        previewBGcolor.set(color);
                        bottom.setColor(color);
                    }
                }
            });
        }
    });
    var toolTip = new TextTooltip("Background color for preview pane.", tooltipManager, getSkin());
    imageButton.addListener(toolTip);
    slider = new Slider(1.0f, 100.0f, 1.0f, false, getSkin(), "zoom-horizontal");
    slider.setName("bottom-zoom");
    slider.setValue(1.0f);
    table.add(slider).expandX().right();
    slider.addListener(handListener);
    slider.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            var slider = (Slider) findActor("bottom-zoom");
            var zoom = slider.getValue();
            if (previewZoomed != null) {
                previewZoomed.setLeftWidth(preview.getLeftWidth() * zoom);
                previewZoomed.setRightWidth(preview.getRightWidth() * zoom);
                previewZoomed.setTopHeight(preview.getTopHeight() * zoom);
                previewZoomed.setBottomHeight(preview.getBottomHeight() * zoom);
                if (preview.getPadLeft() != -1) {
                    previewZoomed.setPadLeft(preview.getPadLeft() * zoom);
                }
                if (preview.getPadRight() != -1) {
                    previewZoomed.setPadRight(preview.getPadRight() * zoom);
                }
                if (preview.getPadTop() != -1) {
                    previewZoomed.setPadTop(preview.getPadTop() * zoom);
                }
                if (preview.getPadBottom() != -1) {
                    previewZoomed.setPadBottom(preview.getPadBottom() * zoom);
                }
                var table = new Table();
                resizer.setActor(table);
                resizer.setMinWidth(previewZoomed.getTotalWidth() + previewZoomed.getPadLeft() + preview.getPadRight());
                resizer.setMinHeight(previewZoomed.getTotalHeight() + previewZoomed.getPadTop() + preview.getPadBottom());
                table.setBackground(new NinePatchDrawable(previewZoomed));
                updatePreviewContentActor(previewContentActor);
                if (previewContentActor != null) {
                    var selectBox = (SelectBox<String>) findActor("contentSelectBox");
                    var listeners = new Array<EventListener>(selectBox.getListeners());
                    for (var listener : listeners) {
                        if (listener instanceof ChangeListener) {
                            selectBox.removeListener(listener);
                        }
                    }
                    selectBox.setSelected((String) previewContentActor.getUserObject());
                    for (var listener : listeners) {
                        if (listener instanceof ChangeListener) {
                            selectBox.addListener(listener);
                        }
                    }
                }
            }
        }
    });
    getButtonTable().clearChildren();
    getButtonTable().pad(10);
    getButtonTable().defaults().space(10).minWidth(100);
    textButton = new TextButton("Save", getSkin());
    textButton.setName("save-button");
    getButtonTable().add(textButton);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            dialogFactory.showDialogLoading(() -> {
                String defaultPath = loadedFile.path();
                if (!defaultPath.toLowerCase(Locale.ROOT).endsWith(".9.png")) {
                    defaultPath = loadedFile.sibling(loadedFile.nameWithoutExtension() + ".9.png").path();
                }
                String[] filterPatterns = { "*.9.png" };
                File file = desktopWorker.saveDialog("Save nine patch file as...", defaultPath, filterPatterns, "Nine Patch files");
                if (file != null) {
                    Gdx.app.postRunnable(() -> {
                        FileHandle fileHandle = new FileHandle(file);
                        if (fileHandle.extension() == null || !fileHandle.name().toLowerCase(Locale.ROOT).endsWith(".9.png")) {
                            fileHandle = fileHandle.sibling(fileHandle.nameWithoutExtension() + ".9.png");
                        }
                        saveNinePatch(fileHandle);
                        projectData.setLastDrawablePath(fileHandle.parent().path() + "/");
                        hide();
                        for (var listener : listeners) {
                            listener.fileSaved(fileHandle);
                        }
                    });
                }
            });
        }
    });
    textButton = new TextButton("Cancel", getSkin());
    button(textButton, false);
    textButton.addListener(handListener);
    key(Keys.ESCAPE, false);
    updateDisabled();
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) MathUtils(com.badlogic.gdx.math.MathUtils) Array(com.badlogic.gdx.utils.Array) Scaling(com.badlogic.gdx.utils.Scaling) Utils(com.ray3k.skincomposer.utils.Utils) Spinner(com.ray3k.stripe.Spinner) Gdx(com.badlogic.gdx.Gdx) Texture(com.badlogic.gdx.graphics.Texture) ResizeWidget(com.ray3k.stripe.ResizeWidget) Locale(java.util.Locale) NinePatchWidget(com.ray3k.skincomposer.NinePatchWidget) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PixmapIO(com.badlogic.gdx.graphics.PixmapIO) com.badlogic.gdx.scenes.scene2d(com.badlogic.gdx.scenes.scene2d) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) DrawableData(com.ray3k.skincomposer.data.DrawableData) com.badlogic.gdx.scenes.scene2d.ui(com.badlogic.gdx.scenes.scene2d.ui) Pixmap(com.badlogic.gdx.graphics.Pixmap) FilesDroppedListener(com.ray3k.skincomposer.FilesDroppedListener) Align(com.badlogic.gdx.utils.Align) Color(com.badlogic.gdx.graphics.Color) com.badlogic.gdx.scenes.scene2d.utils(com.badlogic.gdx.scenes.scene2d.utils) File(java.io.File) Keys(com.badlogic.gdx.Input.Keys) ResizeFourArrowListener(com.ray3k.skincomposer.ResizeFourArrowListener) Main(com.ray3k.skincomposer.Main) ObjectMap(com.badlogic.gdx.utils.ObjectMap) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) Spinner(com.ray3k.stripe.Spinner) FileHandle(com.badlogic.gdx.files.FileHandle) DrawableData(com.ray3k.skincomposer.data.DrawableData) Color(com.badlogic.gdx.graphics.Color) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) NinePatchWidget(com.ray3k.skincomposer.NinePatchWidget) ResizeWidget(com.ray3k.stripe.ResizeWidget) File(java.io.File)

Example 2 with Spinner

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

the class Dialog9Patch method loadImage.

private void loadImage(FileHandle fileHandle) {
    loadedFile = fileHandle;
    ninePatchLeft = 0;
    ninePatchRight = 0;
    ninePatchTop = 0;
    ninePatchBottom = 0;
    ninePatchContentLeft = 0;
    ninePatchContentRight = 0;
    ninePatchContentTop = 0;
    ninePatchContentBottom = 0;
    var pixmap = new Pixmap(fileHandle);
    if (fileHandle.nameWithoutExtension().endsWith(".9") && pixmap.getWidth() >= 3 && pixmap.getHeight() >= 3) {
        var cropped = new Pixmap(pixmap.getWidth() - 2, pixmap.getHeight() - 2, Pixmap.Format.RGBA8888);
        cropped.setBlending(Pixmap.Blending.None);
        cropped.drawPixmap(pixmap, 0, 0, 1, 1, pixmap.getWidth() - 2, pixmap.getHeight() - 2);
        for (int x = 1; x < pixmap.getWidth() - 2; x++) {
            var color = new Color(pixmap.getPixel(x, pixmap.getHeight() - 1));
            if (color.a > 0) {
                if (color.r != 0 || color.g != 0 || color.b != 0) {
                    break;
                }
                ninePatchContentLeft = x - 1;
                break;
            }
        }
        for (int x = pixmap.getWidth() - 2; x > 0; x--) {
            var color = new Color(pixmap.getPixel(x, pixmap.getHeight() - 1));
            if (color.a > 0) {
                if (color.r != 0 || color.g != 0 || color.b != 0) {
                    break;
                }
                ninePatchContentRight = cropped.getWidth() - x;
                break;
            }
        }
        for (int y = 1; y < pixmap.getHeight() - 2; y++) {
            var color = new Color(pixmap.getPixel(0, y));
            if (color.a > 0) {
                if (color.r != 0 || color.g != 0 || color.b != 0) {
                    break;
                }
                ninePatchTop = y - 1;
                break;
            }
        }
        for (int y = pixmap.getHeight() - 2; y > 0; y--) {
            var color = new Color(pixmap.getPixel(0, y));
            if (color.a > 0) {
                if (color.r != 0 || color.g != 0 || color.b != 0) {
                    break;
                }
                ninePatchBottom = cropped.getHeight() - y;
                break;
            }
        }
        for (int x = 1; x < pixmap.getWidth() - 2; x++) {
            var color = new Color(pixmap.getPixel(x, 0));
            if (color.a > 0) {
                if (color.r != 0 || color.g != 0 || color.b != 0) {
                    break;
                }
                ninePatchLeft = x - 1;
                break;
            }
        }
        for (int x = pixmap.getWidth() - 2; x > 0; x--) {
            var color = new Color(pixmap.getPixel(x, 0));
            if (color.a > 0) {
                if (color.r != 0 || color.g != 0 || color.b != 0) {
                    break;
                }
                ninePatchRight = cropped.getWidth() - x;
                break;
            }
        }
        for (int y = 1; y < pixmap.getHeight() - 2; y++) {
            var color = new Color(pixmap.getPixel(pixmap.getWidth() - 1, y));
            if (color.a > 0) {
                if (color.r != 0 || color.g != 0 || color.b != 0) {
                    break;
                }
                ninePatchContentTop = y - 1;
                break;
            }
        }
        for (int y = pixmap.getHeight() - 2; y > 0; y--) {
            var color = new Color(pixmap.getPixel(pixmap.getWidth() - 1, y));
            if (color.a > 0) {
                if (color.r != 0 || color.g != 0 || color.b != 0) {
                    break;
                }
                ninePatchContentBottom = cropped.getHeight() - y;
                break;
            }
        }
        pixmap.dispose();
        pixmap = cropped;
    }
    ninePatchLeftOriginal = ninePatchLeft;
    ninePatchRightOriginal = ninePatchRight;
    ninePatchBottomOriginal = ninePatchBottom;
    ninePatchTopOriginal = ninePatchTop;
    ninePatchContentLeftOriginal = ninePatchContentLeft;
    ninePatchContentRightOriginal = ninePatchContentRight;
    ninePatchContentBottomOriginal = ninePatchContentBottom;
    ninePatchContentTopOriginal = ninePatchContentTop;
    var texture = new Texture(pixmap);
    preview = new NinePatch(texture, ninePatchLeft, ninePatchRight, ninePatchTop, ninePatchBottom);
    preview.setPadding(ninePatchContentLeft, ninePatchContentRight, ninePatchContentTop, ninePatchContentBottom);
    previewZoomed = new NinePatch(preview);
    pixmap.dispose();
    populate();
    updateDisabled();
    updatePreviewContentActor(previewContentActor);
    if (previewContentActor != null) {
        var selectBox = (SelectBox<String>) findActor("contentSelectBox");
        var listeners = new Array<EventListener>(selectBox.getListeners());
        for (var listener : listeners) {
            if (listener instanceof ChangeListener) {
                selectBox.removeListener(listener);
            }
        }
        selectBox.setSelected((String) previewContentActor.getUserObject());
        for (var listener : listeners) {
            if (listener instanceof ChangeListener) {
                selectBox.addListener(listener);
            }
        }
    }
    var ninePatchWidget = (NinePatchWidget) findActor("ninePatchWidget");
    var existingDrawable = ninePatchWidget.getDrawable();
    if (existingDrawable != null) {
        ((TextureRegionDrawable) existingDrawable).getRegion().getTexture().dispose();
    }
    var region = new TextureRegion(texture);
    ninePatchWidget.setDrawable(new TextureRegionDrawable(region));
    ninePatchWidget.setRegionWidth(region.getRegionWidth());
    ninePatchWidget.setRegionHeight(region.getRegionHeight());
    ninePatchWidget.setPaddingLeft(ninePatchLeft);
    ninePatchWidget.setPaddingRight(ninePatchRight);
    ninePatchWidget.setPaddingBottom(ninePatchBottom);
    ninePatchWidget.setPaddingTop(ninePatchTop);
    ninePatchWidget.setContentLeft(ninePatchContentLeft);
    ninePatchWidget.setContentRight(ninePatchContentRight);
    ninePatchWidget.setContentBottom(ninePatchContentBottom);
    ninePatchWidget.setContentTop(ninePatchContentTop);
    zoomAndRecenter();
    var spinner = (Spinner) findActor("spinner-padding-left");
    spinner.setMaximum(region.getRegionWidth() - ninePatchRight);
    spinner = (Spinner) findActor("spinner-padding-right");
    spinner.setMaximum(region.getRegionWidth() - ninePatchLeft);
    spinner = (Spinner) findActor("spinner-padding-bottom");
    spinner.setMaximum(region.getRegionWidth() - ninePatchTop);
    spinner = (Spinner) findActor("spinner-padding-top");
    spinner.setMaximum(region.getRegionWidth() - ninePatchBottom);
    spinner = (Spinner) findActor("spinner-content-left");
    spinner.setMaximum(region.getRegionWidth() - ninePatchContentRight);
    spinner = (Spinner) findActor("spinner-content-right");
    spinner.setMaximum(region.getRegionWidth() - ninePatchContentLeft);
    spinner = (Spinner) findActor("spinner-content-bottom");
    spinner.setMaximum(region.getRegionWidth() - ninePatchContentTop);
    spinner = (Spinner) findActor("spinner-content-top");
    spinner.setMaximum(region.getRegionWidth() - ninePatchContentBottom);
    projectData.setLastDrawablePath(fileHandle.parent().path() + "/");
}
Also used : Spinner(com.ray3k.stripe.Spinner) Color(com.badlogic.gdx.graphics.Color) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) Texture(com.badlogic.gdx.graphics.Texture) Array(com.badlogic.gdx.utils.Array) NinePatchWidget(com.ray3k.skincomposer.NinePatchWidget) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 3 with Spinner

use of com.ray3k.stripe.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, "black");
    root.add(label);
    root.row();
    Table table = new Table();
    root.add(table).growX();
    table.defaults().space(5.0f);
    label = new Label("Font Name:", skin);
    label.setName("name-label");
    table.add(label);
    TextField textField = new TextField(data.name, skin);
    textField.setName("fontName");
    table.add(textField);
    TextTooltip toolTip = new TextTooltip("The name used in skin JSON", tooltipManager, getSkin());
    textField.addListener(toolTip);
    textField.addListener(ibeamListener);
    textField.addListener(new ChangeListener() {

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

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

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

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

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

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

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

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

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

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

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

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

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.size = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Mono:", skin);
    bottom.add(label).right();
    Button button = new Button(skin, "switch");
    button.setName("mono");
    button.setChecked(data.mono);
    bottom.add(button).left();
    toolTip = new TextTooltip("If on, font smoothing is disabled", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

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

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

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            TextButton textButton = (TextButton) actor;
            dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
                if (colorData != null) {
                    textButton.setText(colorData.getName());
                    textButton.setUserObject(colorData);
                    data.color = colorData.getName();
                    if (automaticBgColor) {
                        previewBGcolor.set(Utils.blackOrWhiteBgColor(colorData.color));
                        previewCursor.getSprite().setColor(colorData.color);
                        previewSelection.getSprite().setColor(previewBGcolor == Color.BLACK ? Color.LIGHT_GRAY : Color.DARK_GRAY);
                        previewTable.setColor(previewBGcolor);
                    }
                } else {
                    textButton.setText("");
                    textButton.setUserObject(null);
                    data.color = null;
                }
                updateColors();
                updateDisabledFields();
            }, null);
        }
    });
    if (data.color != null) {
        textButton.setUserObject(jsonData.getColorByName(data.color));
    }
    bottom.row();
    label = new Label("Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.gamma)), .1, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("gamma");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Glyph gamma. Values > 1 reduce antialiasing.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.gamma = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Render Count:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.renderCount, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("renderCount");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Number of times to render the glyph. Useful with a shadow or border, so it doesn't show through the glyph.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.renderCount = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Border Width:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.borderWidth, 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("borderWidth");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Border width in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.borderWidth = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Border Color:", skin);
    label.setName("border-color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.borderColor, skin);
    textButton.setName("borderColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Border color; Required if borderWidth > 0", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

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

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.borderStraight = button.isChecked();
            updateDisabledFields();
        }
    });
    label = new Label("Border Gamma:", skin);
    bottom.add(label).right();
    spinner = new Spinner(Double.parseDouble(df.format(data.borderGamma)), 1.0, false, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("borderGamma");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Values < 1 increase the border size.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.borderGamma = (float) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Shadow Offset X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("shadowOffsetX");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on X axis in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetX = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Shadow Offset Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.shadowOffsetY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("shadowOffsetY");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Offset of text shadow on Y axis in pixels, 0 to disable", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.shadowOffsetY = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Shadow Color:", skin);
    label.setName("shadow-color-label");
    bottom.add(label).right();
    textButton = new TextButton(data.shadowColor, skin);
    textButton.setName("shadowColorTextButton");
    image = new Image(skin, "icon-colorwheel-over");
    textButton.add(image).space(10.0f);
    bottom.add(textButton).left();
    toolTip = new TextTooltip("Shadow color; required if shadowOffset > 0.", tooltipManager, getSkin());
    textButton.addListener(toolTip);
    textButton.addListener(handListener);
    textButton.addListener(new ChangeListener() {

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

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Button button = (Button) actor;
            data.incremental = button.isChecked();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Space X:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceX, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("spaceX");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.spaceX = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    label = new Label("Space Y:", skin);
    bottom.add(label).right();
    spinner = new Spinner(data.spaceY, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
    spinner.setName("spaceY");
    bottom.add(spinner).left().minWidth(100.0f);
    toolTip = new TextTooltip("Pixels to add to glyph spacing. Can be negative.", tooltipManager, getSkin());
    spinner.addListener(toolTip);
    spinner.getButtonMinus().addListener(handListener);
    spinner.getButtonPlus().addListener(handListener);
    spinner.getTextField().addListener(ibeamListener);
    spinner.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Spinner spinner = (Spinner) actor;
            data.spaceY = (int) spinner.getValue();
            updateDisabledFields();
        }
    });
    bottom.row();
    label = new Label("Kerning:", skin);
    bottom.add(label).right();
    button = new Button(skin, "switch");
    button.setName("kerning");
    button.setChecked(data.kerning);
    bottom.add(button).left();
    toolTip = new TextTooltip("Whether the font should include kerning", tooltipManager, getSkin());
    button.addListener(toolTip);
    button.addListener(handListener);
    button.addListener(new ChangeListener() {

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

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

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

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

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

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

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

Example 4 with Spinner

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

the class DialogImageFont method loadPixmap.

private void loadPixmap(FileHandle fileHandle, boolean setDefaults) throws InvalidFontImageException {
    var fontPixmap = new Pixmap(fileHandle);
    var tempColor = new Color();
    bitmapCharacters = new Array<>();
    var yBreaks = new IntArray();
    var characterList = settings.characters;
    var gapSize = settings.gap;
    var findGapSize = false;
    if (setDefaults) {
        gapSize = 0;
        findGapSize = true;
    }
    var averageWidth = 0;
    boolean failure;
    do {
        failure = false;
        bitmapCharacters.clear();
        yBreaks.clear();
        var lookingForBreak = false;
        // find vertical breaks for separate rows
        for (int y = 0; y < fontPixmap.getHeight(); y++) {
            var foundLine = false;
            for (int x = 0; x < fontPixmap.getWidth(); x++) {
                tempColor.set(fontPixmap.getPixel(x, y));
                if (tempColor.a > 0) {
                    foundLine = true;
                    break;
                }
            }
            if (!lookingForBreak) {
                if (foundLine) {
                    yBreaks.add(y);
                    lookingForBreak = true;
                }
            } else {
                if (!foundLine) {
                    yBreaks.add(y);
                    lookingForBreak = false;
                }
            }
        }
        if (yBreaks.size < 2) {
            throw new InvalidFontImageException();
        }
        for (int i = 1; i + 1 < yBreaks.size; i += 2) {
            if (yBreaks.get(i + 1) - yBreaks.get(i) < gapSize) {
                yBreaks.removeIndex(i + 1);
                yBreaks.removeIndex(i);
                i -= 2;
            }
        }
        int nameCounter = 0;
        // find characters for each row
        for (int i = 0; i < yBreaks.size && !failure; i += 2) {
            BitmapCharacter bitmapCharacter = null;
            lookingForBreak = false;
            var gapCounter = 0;
            for (int x = 0; x < fontPixmap.getWidth(); x++) {
                var foundCharacter = false;
                for (int y = yBreaks.get(i); y < yBreaks.get(i + 1); y++) {
                    tempColor.set(fontPixmap.getPixel(x, y));
                    if (tempColor.a > 0) {
                        foundCharacter = true;
                        break;
                    }
                }
                if (!lookingForBreak) {
                    if (foundCharacter) {
                        if (nameCounter >= characterList.length()) {
                            failure = true;
                            break;
                        }
                        bitmapCharacter = new BitmapCharacter();
                        bitmapCharacter.character = characterList.charAt(nameCounter);
                        bitmapCharacter.name = Integer.toString(nameCounter) + " " + bitmapCharacter.character + " " + (int) bitmapCharacter.character;
                        bitmapCharacter.name = sanitizeFileName(bitmapCharacter.name);
                        bitmapCharacter.x = x;
                        bitmapCharacter.y = yBreaks.get(i);
                        bitmapCharacter.height = yBreaks.get(i + 1) - bitmapCharacter.y;
                        lookingForBreak = true;
                    }
                } else {
                    if (!foundCharacter) {
                        gapCounter++;
                        if (gapCounter == 1) {
                            bitmapCharacter.width = x - bitmapCharacter.x;
                        }
                        if (gapCounter > gapSize) {
                            lookingForBreak = false;
                            averageWidth += bitmapCharacter.width;
                            bitmapCharacters.add(bitmapCharacter);
                            nameCounter++;
                            gapCounter = 0;
                        }
                    } else {
                        gapCounter = 0;
                    }
                }
            }
            if (!failure && lookingForBreak) {
                bitmapCharacter.width = fontPixmap.getWidth() - 1 - bitmapCharacter.x;
                averageWidth += bitmapCharacter.width;
                bitmapCharacters.add(bitmapCharacter);
                nameCounter++;
            }
        }
        if (bitmapCharacters.size == 0) {
            failure = true;
        }
    } while (findGapSize && failure && ++gapSize <= AUTO_GAP_LIMIT);
    if (bitmapCharacters.size > 0) {
        averageWidth /= bitmapCharacters.size;
    } else {
        averageWidth = 1;
    }
    // find crop y and crop height
    for (var character : bitmapCharacters) {
        for (int y = character.y; y < character.y + character.height; y++) {
            var lineEmpty = true;
            for (int x = character.x; x < character.x + character.width; x++) {
                tempColor.set(fontPixmap.getPixel(x, y));
                if (tempColor.a > 0) {
                    lineEmpty = false;
                    break;
                }
            }
            if (!lineEmpty) {
                character.cropY = y - 1;
                break;
            }
        }
    }
    for (var character : bitmapCharacters) {
        for (int y = character.cropY + character.height; y >= character.cropY; y--) {
            var lineEmpty = true;
            for (int x = character.x; x < character.x + character.width; x++) {
                tempColor.set(fontPixmap.getPixel(x, y));
                if (tempColor.a > 0) {
                    lineEmpty = false;
                    break;
                }
            }
            if (!lineEmpty) {
                character.cropHeight = y - character.cropY + 1;
                character.yoffset = character.cropY - character.y;
                character.baseline = y - character.cropY;
                break;
            }
        }
    }
    // find baseline
    var baseline = 0;
    for (var character : bitmapCharacters) {
        if (!BASELINE_EXCLUSION.contains(character.character)) {
            if (character.baseline > baseline) {
                baseline = character.baseline;
            }
        }
    }
    // write characters to temporary PNGs
    Main.appFolder.child("imagefont/characters").emptyDirectory();
    for (var character : bitmapCharacters) {
        var pixmap = new Pixmap(character.width, character.cropHeight, Pixmap.Format.RGBA8888);
        pixmap.setBlending(Pixmap.Blending.None);
        pixmap.drawPixmap(fontPixmap, 0, 0, character.x, character.cropY, character.width, character.cropHeight);
        PixmapIO.writePNG(Main.appFolder.child("imagefont/characters/" + character.name + ".png"), pixmap);
        pixmap.dispose();
    }
    // calculate auto kerning pairs
    if (settings.kerningPairsActivated) {
        var pairs = settings.kerningPairs.trim().split(" ");
        pairs = Stream.of(pairs).filter((t) -> {
            return t.length() == 2;
        }).toArray(String[]::new);
        var charFolder = Main.appFolder.child("imagefont/characters");
        var pixmaps = new Array<Pixmap>();
        var testColor = new Color();
        kerningPairValues.clear();
        for (var pair : pairs) {
            pixmaps.clear();
            // find images for each character
            var fileHandles = charFolder.list((File dir, String name1) -> name1.matches(".* (" + (int) pair.charAt(0) + "|" + (int) pair.charAt(1) + ").png"));
            // create pixmaps
            if (fileHandles.length == 1 && pair.charAt(0) == pair.charAt(1) || fileHandles.length == 2)
                for (var imageFileHandle : fileHandles) {
                    var testPixmap = new Pixmap(imageFileHandle);
                    pixmaps.add(testPixmap);
                }
            else {
                continue;
            }
            Pixmap compilationPixmap;
            if (fileHandles.length == 1) {
                compilationPixmap = new Pixmap(pixmaps.get(0).getWidth() + pixmaps.get(0).getWidth(), pixmaps.get(0).getHeight(), Pixmap.Format.RGBA8888);
            } else {
                compilationPixmap = new Pixmap(pixmaps.get(0).getWidth() + pixmaps.get(1).getWidth(), pixmaps.get(0).getHeight(), Pixmap.Format.RGBA8888);
            }
            // convert each pixmap to 50% transparency on every opaque character
            for (int i = 0; i < pixmaps.size; i++) {
                var testPixmap = pixmaps.get(i);
                var temp = new Pixmap(testPixmap.getWidth(), testPixmap.getHeight(), Pixmap.Format.RGBA8888);
                for (int y = 0; y < testPixmap.getHeight(); y++) {
                    for (int x = 0; x < testPixmap.getWidth(); x++) {
                        testColor.set(testPixmap.getPixel(x, y));
                        if (testColor.a > 0) {
                            testColor.set(1, 1, 1, .5f);
                            temp.setColor(testColor);
                            temp.drawPixel(x, y);
                        }
                    }
                }
                testPixmap.dispose();
                pixmaps.set(i, temp);
            }
            var testX = pixmaps.get(0).getWidth();
            float alpha = 0.0f;
            while (testX >= 0.0f && alpha < .6f) {
                // overlap pixmaps and test transparency, 100% means fail
                compilationPixmap.setColor(Color.CLEAR);
                compilationPixmap.fill();
                if (fileHandles.length == 1) {
                    compilationPixmap.drawPixmap(pixmaps.get(0), 0, 0);
                    compilationPixmap.drawPixmap(pixmaps.get(0), testX, 0);
                } else {
                    compilationPixmap.drawPixmap(pixmaps.get(0), 0, 0);
                    compilationPixmap.drawPixmap(pixmaps.get(1), testX, 0);
                }
                for (int y = 0; y < compilationPixmap.getHeight(); y++) {
                    for (int x = 0; x < compilationPixmap.getWidth(); x++) {
                        testColor.set(compilationPixmap.getPixel(x, y));
                        if (testColor.a > alpha) {
                            alpha = testColor.a;
                        }
                    }
                }
                testX--;
            }
            testX -= pixmaps.get(0).getWidth() - settings.kerningPairsOffset;
            // reset
            for (var testPixmap : pixmaps) {
                testPixmap.dispose();
            }
            compilationPixmap.dispose();
            kerningPairValues.add(new KerningPair(pair.charAt(0), pair.charAt(1), testX));
        }
    }
    // set defaults for fields
    if (setDefaults) {
        ((Spinner) findActor("gap")).setValue(gapSize);
        settings.gap = gapSize;
        int height = 0;
        for (var character : bitmapCharacters) {
            if (character.cropHeight > height) {
                height = character.cropHeight;
            }
        }
        ((Spinner) findActor("leading")).setValue(height);
        settings.leading = height;
        if (baseline == 0) {
            baseline = settings.leading;
        }
        ((Spinner) findActor("baseline")).setValue(baseline);
        settings.baseline = baseline;
        ((Spinner) findActor("space width")).setValue(MathUtils.round(averageWidth * .28f));
        settings.spaceWidth = MathUtils.round(averageWidth * .28f);
    }
    fontPixmap.dispose();
}
Also used : Spinner(com.ray3k.stripe.Spinner) Color(com.badlogic.gdx.graphics.Color) File(java.io.File) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 5 with Spinner

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

the class HorizontalGroupListeners method horizontalGroupPaddingSpacingListener.

public static EventListener horizontalGroupPaddingSpacingListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simHorizontalGroup = (DialogSceneComposerModel.SimHorizontalGroup) simActor;
    var popTableClickListener = new PopTableClickListener(skin) {

        {
            getPopTable().key(Keys.ENTER, popTable::hide);
            getPopTable().key(Keys.NUMPAD_ENTER, popTable::hide);
            getPopTable().key(Keys.ESCAPE, popTable::hide);
        }

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            update();
        }

        public void update() {
            var popTable = getPopTable();
            popTable.clearChildren();
            var table = new Table();
            popTable.add(table);
            var label = new Label("Padding:", skin, "scene-label-colored");
            table.add(label).colspan(2);
            table.row();
            table.defaults().right().spaceRight(5);
            label = new Label("Left:", skin, "scene-label-colored");
            table.add(label);
            var spinner = new Spinner(0, 1, true, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            spinner.setValue(simHorizontalGroup.padLeft);
            table.add(spinner);
            spinner.getTextField().addListener(ibeamListener);
            spinner.getButtonMinus().addListener(handListener);
            spinner.getButtonPlus().addListener(handListener);
            spinner.addListener(new TextTooltip("The padding to the left of the widgets.", tooltipManager, skin, "scene"));
            spinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.horizontalGroupPadLeft(((Spinner) actor).getValueAsInt());
                }
            });
            table.row();
            label = new Label("Right:", skin, "scene-label-colored");
            table.add(label);
            spinner = new Spinner(0, 1, true, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            spinner.setValue(simHorizontalGroup.padRight);
            spinner.setName("padding-right");
            table.add(spinner);
            spinner.getTextField().addListener(ibeamListener);
            spinner.getButtonMinus().addListener(handListener);
            spinner.getButtonPlus().addListener(handListener);
            spinner.addListener(new TextTooltip("The padding to the right of the widgets.", tooltipManager, skin, "scene"));
            spinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.horizontalGroupPadRight(((Spinner) actor).getValueAsInt());
                }
            });
            table.row();
            label = new Label("Top:", skin, "scene-label-colored");
            table.add(label);
            spinner = new Spinner(0, 1, true, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            spinner.setValue(simHorizontalGroup.padTop);
            spinner.setName("padding-top");
            table.add(spinner);
            spinner.getTextField().addListener(ibeamListener);
            spinner.getButtonMinus().addListener(handListener);
            spinner.getButtonPlus().addListener(handListener);
            spinner.addListener(new TextTooltip("The padding to the top of the widgets.", tooltipManager, skin, "scene"));
            spinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.horizontalGroupPadTop(((Spinner) actor).getValueAsInt());
                }
            });
            table.row();
            label = new Label("Bottom:", skin, "scene-label-colored");
            table.add(label);
            spinner = new Spinner(0, 1, true, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            spinner.setValue(simHorizontalGroup.padBottom);
            spinner.setName("padding-bottom");
            table.add(spinner);
            spinner.getTextField().addListener(ibeamListener);
            spinner.getButtonMinus().addListener(handListener);
            spinner.getButtonPlus().addListener(handListener);
            spinner.addListener(new TextTooltip("The padding to the bottom of the widgets.", tooltipManager, skin, "scene"));
            spinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.horizontalGroupPadBottom(((Spinner) actor).getValueAsInt());
                }
            });
            var image = new Image(skin, "scene-menu-divider");
            popTable.add(image).space(10).growY();
            table = new Table();
            popTable.add(table);
            table.defaults().right().spaceRight(5);
            label = new Label("Spacing:", skin, "scene-label-colored");
            table.add(label);
            spinner = new Spinner(0, 1, true, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            spinner.setValue(simHorizontalGroup.space);
            spinner.setName("spacing-left");
            table.add(spinner);
            spinner.getTextField().addListener(ibeamListener);
            spinner.getButtonMinus().addListener(handListener);
            spinner.getButtonPlus().addListener(handListener);
            spinner.addListener(new TextTooltip("The spacing between the widgets.", tooltipManager, skin, "scene"));
            spinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.horizontalGroupSpace(((Spinner) actor).getValueAsInt());
                }
            });
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : PopTable(com.ray3k.stripe.PopTable) Spinner(com.ray3k.stripe.Spinner) PopTableClickListener(com.ray3k.stripe.PopTableClickListener) Actor(com.badlogic.gdx.scenes.scene2d.Actor) SimActor(com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Aggregations

Spinner (com.ray3k.stripe.Spinner)43 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)34 Actor (com.badlogic.gdx.scenes.scene2d.Actor)29 PopTableClickListener (com.ray3k.stripe.PopTableClickListener)29 SimActor (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor)28 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)27 StyleSelectorPopTable (com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable)12 Color (com.badlogic.gdx.graphics.Color)11 PopTable (com.ray3k.stripe.PopTable)11 Keys (com.badlogic.gdx.Input.Keys)8 com.badlogic.gdx.scenes.scene2d.ui (com.badlogic.gdx.scenes.scene2d.ui)8 Main (com.ray3k.skincomposer.Main)8 Gdx (com.badlogic.gdx.Gdx)6 File (java.io.File)6 FileHandle (com.badlogic.gdx.files.FileHandle)5 MathUtils (com.badlogic.gdx.math.MathUtils)5 FilesDroppedListener (com.ray3k.skincomposer.FilesDroppedListener)5 Utils (com.ray3k.skincomposer.utils.Utils)5 Input (com.badlogic.gdx.Input)4 Pixmap (com.badlogic.gdx.graphics.Pixmap)4