Search in sources :

Example 31 with InputEvent

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

the class TouchPadListeners method touchPadDeadZoneListener.

public static EventListener touchPadDeadZoneListener(final DialogSceneComposerEvents events, SimActor simActor) {
    var simTouchPad = (DialogSceneComposerModel.SimTouchPad) 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);
            table.defaults().right().spaceRight(5);
            var label = new Label("Dead Zone:", skin, "scene-label-colored");
            table.add(label);
            var spinner = new Spinner(0, 1, true, Spinner.Orientation.RIGHT_STACK, skin, "scene");
            spinner.setValue(simTouchPad.deadZone);
            table.add(spinner);
            spinner.getTextField().addListener(ibeamListener);
            spinner.getButtonMinus().addListener(handListener);
            spinner.getButtonPlus().addListener(handListener);
            spinner.addListener(new TextTooltip("The dead zone that does not react to user input.", tooltipManager, skin, "scene"));
            spinner.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.touchPadDeadZone(spinner.getValueAsInt());
                }
            });
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : StyleSelectorPopTable(com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable) 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)

Example 32 with InputEvent

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

the class VerticalGroupListeners method verticalGroupColumnAlignmentListener.

public static EventListener verticalGroupColumnAlignmentListener(final DialogSceneComposerEvents events, final SimActor simActor) {
    var popTableClickListener = new PopTableClickListener(skin) {

        {
            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 simVerticalGroup = (DialogSceneComposerModel.SimVerticalGroup) simActor;
            var popTable = getPopTable();
            popTable.clearChildren();
            var table = new Table();
            popTable.add(table);
            var label = new Label("Alignment:", skin, "scene-label-colored");
            table.add(label).colspan(3);
            table.row();
            table.defaults().space(10).left().uniformX();
            var buttonGroup = new ButtonGroup<ImageTextButton>();
            var imageTextButton = new ImageTextButton("Top-Left", skin, "scene-checkbox-colored");
            var topLeft = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the top left.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.topLeft);
                }
            });
            buttonGroup.add(imageTextButton);
            imageTextButton = new ImageTextButton("Top", skin, "scene-checkbox-colored");
            var top = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the top center.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.top);
                }
            });
            buttonGroup.add(imageTextButton);
            imageTextButton = new ImageTextButton("Top-Right", skin, "scene-checkbox-colored");
            var topRight = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the top right.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.topRight);
                }
            });
            buttonGroup.add(imageTextButton);
            table.row();
            imageTextButton = new ImageTextButton("Left", skin, "scene-checkbox-colored");
            var left = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the middle left.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.left);
                }
            });
            buttonGroup.add(imageTextButton);
            imageTextButton = new ImageTextButton("Center", skin, "scene-checkbox-colored");
            var center = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the center.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.center);
                }
            });
            buttonGroup.add(imageTextButton);
            imageTextButton = new ImageTextButton("Right", skin, "scene-checkbox-colored");
            var right = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the middle right.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.right);
                }
            });
            buttonGroup.add(imageTextButton);
            table.row();
            imageTextButton = new ImageTextButton("Bottom-Left", skin, "scene-checkbox-colored");
            var bottomLeft = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the bottom left.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.bottomLeft);
                }
            });
            buttonGroup.add(imageTextButton);
            imageTextButton = new ImageTextButton("Bottom", skin, "scene-checkbox-colored");
            var bottom = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the bottom center.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.bottom);
                }
            });
            buttonGroup.add(imageTextButton);
            imageTextButton = new ImageTextButton("Bottom-Right", skin, "scene-checkbox-colored");
            var bottomRight = imageTextButton;
            imageTextButton.setProgrammaticChangeEvents(false);
            table.add(imageTextButton);
            imageTextButton.addListener(handListener);
            imageTextButton.addListener(new TextTooltip("Align the widgets to the bottom right.", tooltipManager, skin, "scene"));
            imageTextButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    events.verticalGroupColumnAlignment(Align.bottomRight);
                }
            });
            buttonGroup.add(imageTextButton);
            switch(simVerticalGroup.alignment) {
                case Align.topLeft:
                    topLeft.setChecked(true);
                    break;
                case Align.top:
                    top.setChecked(true);
                    break;
                case Align.topRight:
                    topRight.setChecked(true);
                    break;
                case Align.right:
                    right.setChecked(true);
                    break;
                case Align.bottomRight:
                    bottomRight.setChecked(true);
                    break;
                case Align.bottom:
                    bottom.setChecked(true);
                    break;
                case Align.bottomLeft:
                    bottomLeft.setChecked(true);
                    break;
                case Align.left:
                    left.setChecked(true);
                    break;
                case Align.center:
                    center.setChecked(true);
                    break;
            }
        }
    };
    popTableClickListener.update();
    return popTableClickListener;
}
Also used : PopTable(com.ray3k.stripe.PopTable) 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)

Example 33 with InputEvent

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

the class Core method create.

@Override
public void create() {
    properties = new ObjectMap<>();
    try {
        PropertiesUtils.load(properties, Gdx.files.internal("values.properties").reader());
    } catch (IOException e) {
        Gdx.app.error(getClass().getName(), "Error reading installer properties file.", e);
    }
    installationPath = Gdx.files.absolute(System.getenv("ProgramFiles") + "\\" + Core.properties.get("product-name"));
    installationCreateDesktopIcon = true;
    installationCreateStartIcon = true;
    skin = new Skin(Gdx.files.internal("ui/skin-composer-installer-ui.json"));
    stage = new Stage(new ScreenViewport(), new PolygonSpriteBatch());
    Gdx.input.setInputProcessor(stage);
    root = new Table();
    root.setFillParent(true);
    root.setTouchable(Touchable.enabled);
    root.setName("root");
    stage.addActor(root);
    MenuTable menuTable = new MenuTable(skin, stage);
    root.add(menuTable).grow();
    stage.addListener(new DragListener() {

        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            if (event.getTarget() == root) {
                desktopWorker.dragWindow(windowStartX + (int) x - dragStartX, windowStartY + dragStartY - (int) y);
                windowStartX = desktopWorker.getWindowX();
                windowStartY = desktopWorker.getWindowY();
            }
        }

        @Override
        public void dragStart(InputEvent event, float x, float y, int pointer) {
            dragStartX = (int) x;
            dragStartY = (int) y;
            windowStartX = desktopWorker.getWindowX();
            windowStartY = desktopWorker.getWindowY();
        }
    });
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) IOException(java.io.IOException) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) PolygonSpriteBatch(com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch) DragListener(com.badlogic.gdx.scenes.scene2d.utils.DragListener) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 34 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent 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 35 with InputEvent

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

the class EditWidget method addSimListener.

private void addSimListener() {
    addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (simActor != null) {
                dialog.simActor = simActor;
                dialog.populateProperties();
                dialog.model.updatePreview();
                dialog.populatePath();
                var label = new FadeLabel(simActor.toString(), skin, "scene-edit-tip");
                stage.addActor(label);
                label.setPosition(Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY());
            }
        }
    });
    addListener(handListener);
}
Also used : InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)358 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)183 Actor (com.badlogic.gdx.scenes.scene2d.Actor)174 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)144 PopTableClickListener (com.ray3k.stripe.PopTableClickListener)110 SimActor (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor)109 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)86 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)53 Stage (com.badlogic.gdx.scenes.scene2d.Stage)49 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)47 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)45 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)35 Texture (com.badlogic.gdx.graphics.Texture)34 Spinner (com.ray3k.stripe.Spinner)32 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)31 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)29 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)26 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)25 StyleSelectorPopTable (com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable)25 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)22