use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.
the class DialogFactory method showDrawableSettingsDialog.
public void showDrawableSettingsDialog(Skin skin, Stage stage, DrawableData drawable, DrawableSettingsListener listener) {
var dialog = new Dialog("Drawable Settings", skin, "bg") {
@Override
protected void result(Object object) {
if (listener != null) {
if ((Boolean) object) {
drawable.minWidth = ((Spinner) findActor("minWidth")).getValueAsInt();
drawable.minHeight = ((Spinner) findActor("minHeight")).getValueAsInt();
listener.result(true);
} else {
listener.result(false);
}
}
}
};
dialog.getTitleTable().pad(5);
dialog.getContentTable().pad(5);
dialog.getButtonTable().pad(5);
var root = dialog.getContentTable();
root.defaults().space(3);
var label = new Label("Set values to -1 to disable.", skin);
root.add(label).colspan(2);
root.row();
label = new Label("minWidth:", skin);
root.add(label);
var spinner = new Spinner(drawable.minWidth, 1, true, Spinner.Orientation.HORIZONTAL, skin);
spinner.setMinimum(-1);
spinner.setName("minWidth");
root.add(spinner).width(100);
spinner.getButtonMinus().addListener(handListener);
spinner.getButtonPlus().addListener(handListener);
spinner.getTextField().addListener(ibeamListener);
root.row();
label = new Label("minHeight:", skin);
root.add(label);
spinner = new Spinner(drawable.minHeight, 1, true, Spinner.Orientation.HORIZONTAL, skin);
spinner.setMinimum(-1);
spinner.setName("minHeight");
root.add(spinner).width(100);
spinner.getButtonMinus().addListener(handListener);
spinner.getButtonPlus().addListener(handListener);
spinner.getTextField().addListener(ibeamListener);
var textButton = new TextButton("OK", skin);
dialog.button(textButton, true);
dialog.getButtonTable().add(textButton).uniform();
textButton.addListener(handListener);
textButton = new TextButton("Cancel", skin);
dialog.button(textButton, false);
textButton.addListener(handListener);
dialog.show(stage);
}
use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.
the class DialogFreeTypeFont method loadSettings.
private void loadSettings(FileHandle fileHandle) {
var fontSettings = json.fromJson(FontSettings.class, fileHandle.readString("utf-8"));
((TextField) findActor("characters")).setText(fontSettings.characters);
data.characters = fontSettings.characters;
((Spinner) findActor("size")).setValue(fontSettings.size);
data.size = fontSettings.size;
((Button) findActor("mono")).setChecked(fontSettings.mono);
data.mono = fontSettings.mono;
((SelectBox<String>) findActor("hinting")).setSelected(fontSettings.hinting);
data.hinting = fontSettings.hinting;
if (fontSettings.color != null) {
var color = jsonData.getColorByName(fontSettings.color);
if (color == null) {
try {
color = new ColorData(fontSettings.color, new Color(fontSettings.colorValue));
jsonData.getColors().add(color);
} catch (ColorData.NameFormatException ex) {
Gdx.app.error(getClass().getName(), "Error creating color.", ex);
}
}
((TextButton) findActor("colorTextButton")).setUserObject(color);
data.color = fontSettings.color;
}
((Spinner) findActor("gamma")).setValue(new BigDecimal(df.format(fontSettings.gamma)));
data.gamma = fontSettings.gamma;
((Spinner) findActor("renderCount")).setValue(fontSettings.renderCount);
data.renderCount = fontSettings.renderCount;
((Spinner) findActor("borderWidth")).setValue(fontSettings.borderWidth);
data.borderWidth = fontSettings.borderWidth;
if (fontSettings.borderColor != null) {
var color = jsonData.getColorByName(fontSettings.borderColor);
if (color == null) {
try {
color = new ColorData(fontSettings.borderColor, new Color(fontSettings.borderColorValue));
} catch (ColorData.NameFormatException ex) {
Gdx.app.error(getClass().getName(), "Error creating color.", ex);
}
jsonData.getColors().add(color);
}
((TextButton) findActor("borderColorTextButton")).setUserObject(color);
data.borderColor = fontSettings.borderColor;
}
((Button) findActor("borderStraight")).setChecked(fontSettings.borderStraight);
data.borderStraight = fontSettings.borderStraight;
((Spinner) findActor("borderGamma")).setValue(new BigDecimal(df.format(fontSettings.borderGamma)));
data.borderGamma = fontSettings.borderGamma;
((Spinner) findActor("shadowOffsetX")).setValue(fontSettings.shadowOffsetX);
data.shadowOffsetX = fontSettings.shadowOffsetX;
((Spinner) findActor("shadowOffsetY")).setValue(fontSettings.shadowOffsetY);
data.shadowOffsetY = fontSettings.shadowOffsetY;
if (fontSettings.shadowColor != null) {
var color = jsonData.getColorByName(fontSettings.shadowColor);
if (color == null) {
try {
color = new ColorData(fontSettings.shadowColor, new Color(fontSettings.shadowColorValue));
} catch (ColorData.NameFormatException ex) {
Gdx.app.error(getClass().getName(), "Error creating color.", ex);
}
jsonData.getColors().add(color);
}
((TextButton) findActor("shadowColorTextButton")).setUserObject(color);
data.shadowColor = fontSettings.shadowColor;
}
((Button) findActor("incremental")).setChecked(fontSettings.incremental);
data.incremental = fontSettings.incremental;
((Spinner) findActor("spaceX")).setValue(fontSettings.spaceX);
data.spaceX = fontSettings.spaceX;
((Spinner) findActor("spaceY")).setValue(fontSettings.spaceY);
data.spaceY = fontSettings.spaceY;
((Button) findActor("kerning")).setChecked(fontSettings.kerning);
data.kerning = fontSettings.kerning;
((Button) findActor("flip")).setChecked(fontSettings.flip);
data.flip = fontSettings.flip;
((Button) findActor("genMipMaps")).setChecked(fontSettings.genMipMaps);
data.genMipMaps = fontSettings.genMipMaps;
((SelectBox<String>) findActor("minFilter")).setSelected(fontSettings.minFilter);
data.minFilter = fontSettings.minFilter;
((SelectBox<String>) findActor("magFilter")).setSelected(fontSettings.magFilter);
data.magFilter = fontSettings.magFilter;
updateColors();
updateDisabledFields();
}
use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.
the class DialogColorPicker method populate.
public void populate() {
content.clear();
content.defaults().padLeft(10.0f);
Image cursor = new Image(skin.getDrawable("color-picker"));
cursor.setTouchable(Touchable.enabled);
Image hueKnob = new Image(skin, "color-scale");
hueKnob.setTouchable(Touchable.enabled);
Image hueKnob2 = new Image(skin, "color-scale-flipped");
hueKnob2.setTouchable(Touchable.enabled);
Image alphaKnob = new Image(skin, "color-scale");
alphaKnob.setTouchable(Touchable.enabled);
Image alphaKnob2 = new Image(skin, "color-scale-flipped");
alphaKnob2.setTouchable(Touchable.enabled);
Container selectedColorCont = new Container();
selectedColorCont.setBackground(skin.getDrawable("white"));
selectedColorCont.setColor(selectedColor);
Vector3 v = rgbToHsb(selectedColor.r, selectedColor.g, selectedColor.b);
Spinner greenSpinner, blueSpinner, alphaSpinner, hueSpinner, saturationSpinner, brightnessSpinner;
hueSpinner = new Spinner(v.x * 359.0f, 1.0, true, Orientation.HORIZONTAL, skin);
hueSpinner.setMinimum(0.0);
hueSpinner.setMaximum(359.0);
hueSpinner.getTextField().addListener(ibeamListener);
hueSpinner.getButtonMinus().addListener(handListener);
hueSpinner.getButtonPlus().addListener(handListener);
saturationSpinner = new Spinner(v.y * 100.0f, 1.0, true, Orientation.HORIZONTAL, skin);
saturationSpinner.setMinimum(0.0);
saturationSpinner.setMaximum(100.0);
saturationSpinner.getTextField().addListener(ibeamListener);
saturationSpinner.getButtonMinus().addListener(handListener);
saturationSpinner.getButtonPlus().addListener(handListener);
brightnessSpinner = new Spinner(v.z * 100.0f, 1.0, true, Orientation.HORIZONTAL, skin);
brightnessSpinner.setMinimum(0.0);
brightnessSpinner.setMaximum(100.0);
brightnessSpinner.getTextField().addListener(ibeamListener);
brightnessSpinner.getButtonMinus().addListener(handListener);
brightnessSpinner.getButtonPlus().addListener(handListener);
redSpinner = new Spinner(Math.floor(selectedColor.r * 255.0f), 1.0, true, Orientation.HORIZONTAL, skin);
redSpinner.setMinimum(0.0);
redSpinner.setMaximum(255.0);
redSpinner.getTextField().addListener(ibeamListener);
redSpinner.getButtonMinus().addListener(handListener);
redSpinner.getButtonPlus().addListener(handListener);
greenSpinner = new Spinner(Math.floor(selectedColor.g * 255.0f), 1.0, true, Orientation.HORIZONTAL, skin);
greenSpinner.setMinimum(0.0);
greenSpinner.setMaximum(255.0);
greenSpinner.getTextField().addListener(ibeamListener);
greenSpinner.getButtonMinus().addListener(handListener);
greenSpinner.getButtonPlus().addListener(handListener);
blueSpinner = new Spinner(Math.floor(selectedColor.b * 255.0f), 1.0, true, Orientation.HORIZONTAL, skin);
blueSpinner.setMinimum(0.0);
blueSpinner.setMaximum(255.0);
blueSpinner.getTextField().addListener(ibeamListener);
blueSpinner.getButtonMinus().addListener(handListener);
blueSpinner.getButtonPlus().addListener(handListener);
alphaSpinner = new Spinner(Math.floor(selectedColor.a * 255.0f), 1.0, true, Orientation.HORIZONTAL, skin);
alphaSpinner.setMinimum(0.0);
alphaSpinner.setMaximum(255.0);
alphaSpinner.getTextField().addListener(ibeamListener);
alphaSpinner.getButtonMinus().addListener(handListener);
alphaSpinner.getButtonPlus().addListener(handListener);
final TextField hexField = new TextField(selectedColor.toString(), skin);
hexField.setMaxLength(8);
hexField.setTextFieldFilter(new TextField.TextFieldFilter() {
@Override
public boolean acceptChar(TextField textField, char c) {
return c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f';
}
});
hexField.addListener(ibeamListener);
redSpinner.setTransversalNext(greenSpinner.getTextField());
greenSpinner.setTransversalNext(blueSpinner.getTextField());
blueSpinner.setTransversalNext(alphaSpinner.getTextField());
alphaSpinner.setTransversalNext(hueSpinner.getTextField());
hueSpinner.setTransversalNext(saturationSpinner.getTextField());
saturationSpinner.setTransversalNext(brightnessSpinner.getTextField());
brightnessSpinner.setTransversalNext(redSpinner.getTextField());
redSpinner.setTransversalPrevious(brightnessSpinner.getTextField());
greenSpinner.setTransversalPrevious(redSpinner.getTextField());
blueSpinner.setTransversalPrevious(greenSpinner.getTextField());
alphaSpinner.setTransversalPrevious(blueSpinner.getTextField());
hueSpinner.setTransversalPrevious(alphaSpinner.getTextField());
saturationSpinner.setTransversalPrevious(hueSpinner.getTextField());
brightnessSpinner.setTransversalPrevious(saturationSpinner.getTextField());
ChangeListener rgbListener = new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
selectedColor.set((float) redSpinner.getValue() / 255.0f, (float) greenSpinner.getValue() / 255.0f, (float) blueSpinner.getValue() / 255.0f, (float) alphaSpinner.getValue() / 255.0f);
Vector3 v = rgbToHsb(selectedColor.r, selectedColor.g, selectedColor.b);
hueSpinner.setValue(v.x * 359.0f);
saturationSpinner.setValue(v.y * 100.0f);
brightnessSpinner.setValue(v.z * 100.0f);
selectedColorCont.setColor(selectedColor);
Color color = hsbToRgb((float) hueSpinner.getValue(), 1.0f, 1.0f);
gradientS.setCol2(color);
gradientS.setCol3(color);
gradientAlpha.setCol3(color);
gradientAlpha.setCol4(color);
color = new Color(color);
color.a = 0.0f;
gradientAlpha.setCol1(color);
gradientAlpha.setCol2(color);
cursor.setX(v.y * SIZE - cursor.getWidth() / 2.0f);
cursor.setY(v.z * SIZE - cursor.getHeight() / 2.0f);
hueKnob.setY(v.x * SIZE - hueKnob.getHeight() / 2.0f);
hueKnob2.setY(hueKnob.getY());
hexField.setText(selectedColor.toString());
}
};
redSpinner.addListener(rgbListener);
greenSpinner.addListener(rgbListener);
blueSpinner.addListener(rgbListener);
ChangeListener hsbListener = new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
Color color = hsbToRgb((float) hueSpinner.getValue(), (float) saturationSpinner.getValue() / 100.0f, (float) brightnessSpinner.getValue() / 100.0f);
color.a = (float) alphaSpinner.getValue() / 255.0f;
redSpinner.setValue(color.r * 255.0f);
greenSpinner.setValue(color.g * 255.0f);
blueSpinner.setValue(color.b * 255.0f);
selectedColor.set(color);
selectedColorCont.setColor(selectedColor);
color = hsbToRgb((float) hueSpinner.getValue(), 1.0f, 1.0f);
gradientS.setCol2(color);
gradientS.setCol3(color);
gradientAlpha.setCol3(color);
gradientAlpha.setCol4(color);
color = new Color(color);
color.a = 0.0f;
gradientAlpha.setCol1(color);
gradientAlpha.setCol2(color);
cursor.setX((float) saturationSpinner.getValue() / 100.0f * SIZE - cursor.getWidth() / 2.0f);
cursor.setY((float) brightnessSpinner.getValue() / 100.0f * SIZE - cursor.getHeight() / 2.0f);
hueKnob.setY((float) hueSpinner.getValue() / 359.0f * SIZE - hueKnob.getHeight() / 2.0f);
hueKnob2.setY(hueKnob.getY());
hexField.setText(selectedColor.toString());
}
};
hueSpinner.addListener(hsbListener);
saturationSpinner.addListener(hsbListener);
brightnessSpinner.addListener(hsbListener);
ChangeListener hexListener = new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
if (hexField.getText().length() == 6 || hexField.getText().length() == 8) {
Color color = Color.valueOf(hexField.getText());
redSpinner.setValue(color.r * 255);
greenSpinner.setValue(color.g * 255);
blueSpinner.setValue(color.b * 255);
alphaSpinner.setValue(color.a * 255);
if (hexField.getText().length() == 6) {
selectedColor.set(color.r, color.g, color.b, (float) alphaSpinner.getValue() / 255.0f);
} else {
selectedColor.set(color.r, color.g, color.b, color.a);
}
Vector3 v = rgbToHsb(selectedColor.r, selectedColor.g, selectedColor.b);
hueSpinner.setValue(v.x * 359.0f);
saturationSpinner.setValue(v.y * 100.0f);
brightnessSpinner.setValue(v.z * 100.0f);
selectedColorCont.setColor(selectedColor);
color = hsbToRgb((float) hueSpinner.getValue(), 1.0f, 1.0f);
gradientS.setCol2(color);
gradientS.setCol3(color);
gradientAlpha.setCol3(color);
gradientAlpha.setCol4(color);
color = new Color(color);
color.a = 0.0f;
gradientAlpha.setCol1(color);
gradientAlpha.setCol2(color);
cursor.setX(v.y * SIZE - cursor.getWidth() / 2.0f);
cursor.setY(v.z * SIZE - cursor.getHeight() / 2.0f);
hueKnob.setY(v.x * SIZE - hueKnob.getHeight() / 2.0f);
hueKnob2.setY(hueKnob.getY());
alphaKnob.setY(selectedColor.a * SIZE - alphaKnob.getHeight() / 2.0f);
alphaKnob2.setY(alphaKnob.getY());
}
}
};
hexField.addListener(hexListener);
alphaSpinner.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
selectedColor.set((float) redSpinner.getValue() / 255.0f, (float) greenSpinner.getValue() / 255.0f, (float) blueSpinner.getValue() / 255.0f, (float) alphaSpinner.getValue() / 255.0f);
selectedColorCont.setColor(selectedColor);
alphaKnob.setY(selectedColor.a * SIZE - alphaKnob.getHeight() / 2.0f);
alphaKnob2.setY(alphaKnob.getY());
hexField.setText(selectedColor.toString());
}
});
Table panel = new Table(skin);
panel.setBackground("color-box");
Table t = new Table(skin);
t.setClip(true);
t.setBackground(gradientSB);
t.setTouchable(Touchable.enabled);
cursor.setPosition(v.y * SIZE - cursor.getWidth() / 2.0f, v.z * SIZE - cursor.getHeight() / 2.0f);
t.addActor(cursor);
DragListener dragListener = new DragListener() {
@Override
public void drag(InputEvent event, float x, float y, int pointer) {
saturationSpinner.setValue(MathUtils.clamp(x / SIZE * 100.0f, 0, 100));
brightnessSpinner.setValue(MathUtils.clamp(y / SIZE * 100.0f, 0, 100));
saturationSpinner.fire(new ChangeListener.ChangeEvent());
}
};
dragListener.setTapSquareSize(1.0f);
t.addListener(dragListener);
t.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
saturationSpinner.setValue(MathUtils.clamp(x / SIZE * 100.0f, 0, 100));
brightnessSpinner.setValue(MathUtils.clamp(y / SIZE * 100.0f, 0, 100));
saturationSpinner.fire(new ChangeListener.ChangeEvent());
return false;
}
});
panel.add(t).size(SIZE, SIZE);
content.add(panel);
panel = new Table(skin);
panel.setBackground("color-box");
t = new Table(skin);
t.setTouchable(Touchable.enabled);
t.setClip(true);
for (GradientDrawable gradient : hueGradient) {
Container container = new Container();
container.background(gradient);
t.add(container).growX().height(50.0f);
t.row();
}
t.addActor(hueKnob);
t.addActor(hueKnob2);
hueKnob.setY(v.x * SIZE - hueKnob.getHeight() / 2.0f);
hueKnob2.setX(30.0f - hueKnob2.getWidth());
hueKnob2.setY(v.x * SIZE - hueKnob2.getHeight() / 2.0f);
dragListener = new DragListener() {
@Override
public void drag(InputEvent event, float x, float y, int pointer) {
hueSpinner.setValue(MathUtils.clamp(y / SIZE * 359.0f, 0.0f, 359.0f));
hueSpinner.fire(new ChangeListener.ChangeEvent());
}
};
dragListener.setTapSquareSize(1.0f);
t.addListener(dragListener);
t.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
hueSpinner.setValue(MathUtils.clamp(y / SIZE * 359.0f, 0.0f, 359.0f));
hueSpinner.fire(new ChangeListener.ChangeEvent());
return false;
}
});
panel.add(t).minWidth(30.0f).height(SIZE);
content.add(panel);
panel = new Table(skin);
panel.setBackground("color-box");
t = new Table();
t.setTouchable(Touchable.enabled);
t.setBackground(alphaStack);
t.setClip(true);
t.addActor(alphaKnob);
t.addActor(alphaKnob2);
alphaKnob.setY(selectedColor.a * SIZE - alphaKnob.getHeight() / 2.0f);
alphaKnob2.setX(30.0f - alphaKnob2.getWidth());
alphaKnob2.setY(selectedColor.a * SIZE - alphaKnob2.getHeight() / 2.0f);
dragListener = new DragListener() {
@Override
public void drag(InputEvent event, float x, float y, int pointer) {
alphaSpinner.setValue(MathUtils.clamp(y / SIZE * 255.0f, 0.0f, 255.0f));
alphaSpinner.fire(new ChangeListener.ChangeEvent());
}
};
dragListener.setTapSquareSize(1.0f);
t.addListener(dragListener);
t.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
alphaSpinner.setValue(MathUtils.clamp(y / SIZE * 255.0f, 0.0f, 255.0f));
alphaSpinner.fire(new ChangeListener.ChangeEvent());
return false;
}
});
panel.add(t).minWidth(30.0f).height(SIZE);
content.add(panel);
t = new Table();
t.defaults().pad(10.0f);
Table table = new Table(skin);
Label label = new Label("new", skin);
label.setAlignment(Align.center);
table.add(label).growX();
table.row();
Container bg = new Container();
bg.setBackground(checker);
Stack stack = new Stack(bg, selectedColorCont);
panel = new Table(skin);
panel.setBackground("color-box");
panel.add(stack).grow();
table.add(panel).grow();
if (previousColor != null) {
Container cont = new Container();
cont.setBackground(skin.getDrawable("white"));
cont.setColor(previousColor);
bg = new Container();
bg.setBackground(checker);
stack = new Stack(bg, cont);
panel.row();
panel.add(stack).grow();
table.row();
label = new Label("current", skin);
label.setAlignment(Align.center);
table.add(label).growX();
t.add(table).minWidth(80.0f).minHeight(150.0f);
} else {
t.add(table).minWidth(80.0f).minHeight(100.0f);
}
table = new Table();
table.setName("confirmTable");
table.defaults().space(10.0f).minWidth(80.0f);
TextButton textButton = new TextButton("OK", skin);
textButton.addListener(handListener);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
if (listener != null) {
listener.handle(new ColorListener.ColorEvent(selectedColor));
}
hide();
}
});
table.add(textButton);
textButton = new TextButton("Cancel", skin);
textButton.addListener(handListener);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
if (listener != null) {
listener.handle(new ColorListener.ColorEvent(null));
}
hide();
}
});
table.add(textButton);
t.add(table);
table.row();
table = new Table();
((Table) t.findActor("confirmTable")).add(table).colspan(2);
table.defaults().space(10.0f);
label = new Label("#", skin, "black");
table.add(label);
table.add(hexField).width(75.0f);
t.row();
table = new Table();
label = new Label("R", skin, "black");
table.add(label);
table.add(redSpinner).padLeft(10.0f).minWidth(90.0f);
t.add(table);
table = new Table();
label = new Label("H", skin, "black");
table.add(label);
table.add(hueSpinner).padLeft(10.0f).minWidth(90.0f);
t.add(table);
t.row();
table = new Table();
label = new Label("G", skin, "black");
table.add(label);
table.add(greenSpinner).padLeft(10.0f).minWidth(90.0f);
t.add(table);
table = new Table();
label = new Label("S", skin, "black");
table.add(label);
table.add(saturationSpinner).padLeft(10.0f).minWidth(90.0f);
t.add(table);
t.row();
table = new Table();
label = new Label("B", skin, "black");
table.add(label);
table.add(blueSpinner).padLeft(10.0f).minWidth(90.0f);
t.add(table);
table = new Table();
label = new Label("B", skin, "black");
table.add(label);
table.add(brightnessSpinner).padLeft(10.0f).minWidth(90.0f);
t.add(table);
t.row();
table = new Table();
label = new Label("A", skin, "black");
table.add(label);
t.add(table);
table.add(alphaSpinner).padLeft(10.0f).minWidth(90.0f);
content.add(t).growY();
}
use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.
the class DialogImageFont method showKerningDialog.
private void showKerningDialog() {
Dialog dialog = new Dialog("Auto Kerning Pairs", skin) {
@Override
protected void result(Object object) {
var textButton = (TextButton) DialogImageFont.this.findActor("kerning button");
var fileHandle = Gdx.files.absolute(((TextField) DialogImageFont.this.findActor("imagepath")).getText());
if ((Boolean) object) {
textButton.setText("Kerning Pairs: ON");
settings.kerningPairsActivated = true;
try {
loadPixmap(fileHandle, false);
preview(true);
} catch (InvalidFontImageException e) {
Gdx.app.error(getClass().getName(), "Error processing font source image: " + fileHandle, e);
dialogFactory.showDialogError("Error creating font from image...", "Error creating font from image.\nPlease ensure that the image has 100% transparent pixels\nto break the different characters.\nOpen log?");
refreshTable();
}
} else {
textButton.setText("Kerning Pairs: OFF");
settings.kerningPairsActivated = false;
try {
loadPixmap(fileHandle, false);
preview(true);
} catch (InvalidFontImageException e) {
Gdx.app.error(getClass().getName(), "Error processing font source image: " + fileHandle, e);
dialogFactory.showDialogError("Error creating font from image...", "Error creating font from image.\nPlease ensure that the image has 100% transparent pixels\nto break the different characters.\nOpen log?");
refreshTable();
}
}
}
};
dialog.getTitleTable().padLeft(10.0f);
var table = dialog.getContentTable();
table.pad(10.0f);
var label = new Label("Kerning Pairs", skin);
table.add(label).right();
var textField = new TextField(settings.kerningPairs, skin);
textField.setName("pairs");
table.add(textField).growX();
textField.addListener(ibeamListener);
textField.addListener(new TextTooltip("Space separated list of kerning pairs to optimize spacing", tooltipManager, skin));
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
settings.kerningPairs = textField.getText();
}
});
var textButton = new TextButton("Reset", skin);
table.add(textButton);
textButton.addListener(handListener);
textButton.addListener(new TextTooltip("Reset kerning pairs to defaults", tooltipManager, skin));
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
((TextField) dialog.findActor("pairs")).setText(KERNING_DEFAULTS);
settings.kerningPairs = KERNING_DEFAULTS;
}
});
table.row();
label = new Label("Offset", skin);
table.add(label).right();
var spinner = new Spinner(settings.kerningPairsOffset, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
table.add(spinner).left();
spinner.getButtonMinus().addListener(handListener);
spinner.getTextField().addListener(ibeamListener);
spinner.getButtonPlus().addListener(handListener);
spinner.addListener(new TextTooltip("Offset to add to each kerning pair", tooltipManager, skin));
spinner.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
settings.kerningPairsOffset = spinner.getValueAsInt();
}
});
dialog.key(Keys.ESCAPE, false).key(Keys.ENTER, true).key(Keys.NUMPAD_ENTER, true);
textButton = new TextButton("Turn ON Kern Pairs", skin);
dialog.button(textButton, true);
textButton.addListener(handListener);
textButton = new TextButton("Turn OFF Kern Pairs", skin);
dialog.button(textButton, false);
textButton.addListener(handListener);
dialog.getButtonTable().pad(10.0f);
dialog.show(getStage());
getStage().setKeyboardFocus(((TextField) dialog.findActor("pairs")));
}
use of com.ray3k.stripe.Spinner in project skin-composer by raeleus.
the class DialogImageFont method refreshTable.
private void refreshTable() {
previewStyle = new TextFieldStyle(skin.get(TextFieldStyle.class));
fadables = new Array<>();
root.clearChildren();
var scrollTable = new Table();
scrollTable.defaults().space(10.0f);
var scrollPane = new ScrollPane(scrollTable, skin);
scrollPane.setName("scroll");
scrollPane.setFlickScroll(false);
scrollPane.setFadeScrollBars(false);
root.add(scrollPane).growY().growX();
var label = new Label("Settings", skin, "title-no-line");
scrollTable.add(label);
scrollTable.row();
var content = new Table();
content.defaults().space(10.0f).spaceBottom(15.0f);
scrollTable.add(content).minWidth(500).growX();
// characters and copy to clipboard
label = new Label("Characters", skin);
content.add(label).right().right();
float width = label.getWidth();
var table = new Table();
table.defaults().space(10.0f);
content.add(table).growX().colspan(3);
var textField = new TextField(settings.characters, skin);
textField.setName("characters");
table.add(textField).growX();
textField.addListener(new TextTooltip("Characters to be included in font", tooltipManager, skin));
textField.addListener(ibeamListener);
textField.setTextFieldFilter((TextField textField1, char c) -> textField1.getText().indexOf(c) == -1);
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
settings.characters = ((TextField) actor).getText();
((SelectBox) findActor("characters select")).setSelected("custom");
}
});
var selectBox = new SelectBox<String>(skin);
selectBox.setItems("0-9", "a-zA-Z", "a-zA-Z0-9", "a-zA-Z0-9!-?*", "custom", "Load from file (UTF-8)...");
switch(settings.characters) {
case NUMBERS:
selectBox.setSelectedIndex(0);
break;
case ALPHA:
selectBox.setSelectedIndex(1);
break;
case ALPHA_NUMERIC:
selectBox.setSelectedIndex(2);
break;
case ALL:
selectBox.setSelectedIndex(3);
break;
default:
selectBox.setSelectedIndex(4);
break;
}
selectBox.setName("characters select");
table.add(selectBox);
selectBox.addListener(new TextTooltip("Character Presets", tooltipManager, skin));
selectBox.addListener(handListener);
selectBox.getList().addListener(handListener);
selectBox.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
var textField = (TextField) findActor("characters");
switch(selectBox.getSelectedIndex()) {
case 0:
textField.setText(NUMBERS);
textField.setMessageText("");
settings.characters = NUMBERS;
break;
case 1:
textField.setText(ALPHA);
textField.setMessageText("");
settings.characters = ALPHA;
break;
case 2:
textField.setText(ALPHA_NUMERIC);
textField.setMessageText("");
settings.characters = ALPHA_NUMERIC;
break;
case 3:
textField.setText(ALL);
textField.setMessageText("");
settings.characters = ALL;
break;
case 4:
textField.setText(textField.getText());
textField.setMessageText("");
settings.characters = ((TextField) findActor("characters")).getText();
break;
case 5:
textField.setText("");
textField.setMessageText("Characters loaded from text file...");
settings.characters = "";
showCharacterDialog();
break;
}
}
});
var textButton = new TextButton("Copy", skin);
table.add(textButton);
textButton.addListener(new TextTooltip("Copy characters to clipboard", tooltipManager, skin));
textButton.addListener(handListener);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
var text = settings.characters;
var append = " ";
for (int i = text.length() - 1; i > 0; i--) {
text = text.substring(0, i) + append + text.substring(i);
}
Gdx.app.getClipboard().setContents(text);
}
});
content.add().width(width);
// source file
content.row();
label = new Label("Image File", skin);
label.setName("image-label");
content.add(label).right();
width = label.getWidth();
table = new Table();
table.defaults().space(10.0f);
content.add(table).growX().colspan(3);
textField = new TextField("", skin);
textField.setName("imagepath");
textField.setDisabled(true);
table.add(textField).growX();
textField.addListener(new TextTooltip("Path to source image", tooltipManager, skin));
textField.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
sourceFileBrowse();
}
});
textField.addListener(handListener);
textButton = new TextButton("Browse", skin);
table.add(textButton);
textButton.addListener(handListener);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
sourceFileBrowse();
}
});
textButton.addListener(handListener);
content.add().width(width);
// target file
content.row();
label = new Label("Save File", skin);
content.add(label).right();
fadables.add(label);
width = label.getWidth();
table = new Table();
table.defaults().space(10.0f);
content.add(table).growX().colspan(3);
fadables.add(table);
textField = new TextField("", skin);
textField.setName("targetpath");
textField.setDisabled(true);
table.add(textField).growX();
textField.addListener(new TextTooltip("Path to save file", tooltipManager, skin));
textField.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
saveFileBrowse();
}
});
textField.addListener(handListener);
textButton = new TextButton("Browse", skin);
table.add(textButton);
textButton.addListener(handListener);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
saveFileBrowse();
}
});
content.add().width(width);
// gap size
content.row();
label = new Label("Gap Detection Size", skin);
content.add(label).right();
fadables.add(label);
width = label.getWidth();
var spinner = new Spinner(settings.gap, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
spinner.setName("gap");
spinner.setMinimum(0);
content.add(spinner).left().minWidth(100.0f);
fadables.add(spinner);
spinner.addListener(new TextTooltip("Minimum distance between opaque pixels to split characters", tooltipManager, skin));
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) {
settings.gap = ((Spinner) actor).getValueAsInt();
var fileHandle = Gdx.files.absolute(((TextField) findActor("imagepath")).getText());
try {
loadPixmap(fileHandle, false);
preview(true);
} catch (InvalidFontImageException e) {
Gdx.app.error(getClass().getName(), "Error processing font source image: " + fileHandle, e);
dialogFactory.showDialogError("Error creating font from image...", "Error creating font from image.\nPlease ensure that the image has 100% transparent pixels\nto break the different characters.\nOpen log?");
refreshTable();
}
}
});
textButton = new TextButton(settings.kerningPairsActivated ? "Kerning Pairs: ON" : "Kerning Pairs: OFF", skin);
textButton.setName("kerning button");
content.add(textButton).colspan(2).expandX().padLeft(10.0f).padRight(10.0f).minWidth(200.0f).left();
fadables.add(textButton);
textButton.addListener(new TextTooltip("Adjust auto kerning settings", tooltipManager, skin));
textButton.addListener(handListener);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
showKerningDialog();
}
});
content.add().width(width);
// kerning
content.row();
label = new Label("Kerning", skin);
content.add(label).right();
fadables.add(label);
width = label.getWidth();
spinner = new Spinner(settings.kerning, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
spinner.setName("kerning");
content.add(spinner).left().minWidth(100.0f);
fadables.add(spinner);
spinner.addListener(new TextTooltip("The horizontal spacing between characters", tooltipManager, skin));
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) {
settings.kerning = ((Spinner) actor).getValueAsInt();
preview(false);
}
});
// leading
label = new Label("Line Height", skin);
content.add(label).right();
fadables.add(label);
spinner = new Spinner(settings.leading, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
spinner.setName("leading");
content.add(spinner).expandX().left().minWidth(100.0f);
fadables.add(spinner);
spinner.addListener(new TextTooltip("The vertical spacing between each line", tooltipManager, skin));
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) {
settings.leading = ((Spinner) actor).getValueAsInt();
preview(false);
}
});
content.add().width(width);
// baseline
content.row();
label = new Label("Baseline", skin);
content.add(label).right();
fadables.add(label);
width = label.getWidth();
spinner = new Spinner(settings.baseline, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
spinner.setName("baseline");
content.add(spinner).expandX().left().minWidth(100.0f).colspan(3);
fadables.add(spinner);
spinner.addListener(new TextTooltip("The distance to the line that the text rests on.", tooltipManager, skin));
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) {
settings.baseline = ((Spinner) actor).getValueAsInt();
preview(false);
}
});
content.add().width(width);
// space width
content.row();
label = new Label("Space Width", skin);
content.add(label).right();
fadables.add(label);
width = label.getWidth();
spinner = new Spinner(settings.spaceWidth, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
spinner.setName("space width");
spinner.setMinimum(0);
content.add(spinner).left().minWidth(100.0f);
fadables.add(spinner);
spinner.addListener(new TextTooltip("Set the width of a single space", tooltipManager, skin));
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) {
settings.spaceWidth = ((Spinner) actor).getValueAsInt();
preview(false);
}
});
// tab space count
label = new Label("Tab Space Count", skin);
content.add(label).right();
fadables.add(label);
spinner = new Spinner(settings.tabSpace, 1.0, true, Spinner.Orientation.HORIZONTAL, skin);
spinner.setName("tab space count");
spinner.setMinimum(0);
content.add(spinner).expandX().left().minWidth(100.0f);
fadables.add(spinner);
spinner.addListener(new TextTooltip("The number of space characters to make a tab", tooltipManager, skin));
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) {
settings.tabSpace = ((Spinner) actor).getValueAsInt();
preview(false);
}
});
content.add().width(width);
for (var fadable : fadables) {
fadable.setColor(1.0f, 1.0f, 1.0f, .25f);
fadable.setTouchable(Touchable.disabled);
}
// preview text
scrollTable.row();
var image = new Image(skin, "pressed");
scrollTable.add(image).growX();
scrollTable.row();
label = new Label("Preview", skin, "title-no-line");
scrollTable.add(label);
scrollTable.row();
var textArea = new TextArea(settings.preview, previewStyle);
textArea.setName("preview");
scrollTable.add(textArea).grow().minHeight(100.0f);
textArea.addListener(ibeamListener);
textArea.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
settings.preview = ((TextArea) actor).getText();
}
});
scrollTable.row();
table = new Table();
table.defaults().space(10.0f);
scrollTable.add(table).growX();
textButton = new TextButton("View Characters", skin);
textButton.setName("view characters");
textButton.setDisabled(true);
table.add(textButton);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
try {
Utils.openFileExplorer(Main.appFolder.child("imagefont/characters/"));
} catch (IOException e) {
Gdx.app.error(getClass().getName(), "Error opening characters folder", e);
dialogFactory.showDialogError("Folder Error...", "Error opening characters folder.\n\nOpen log?");
}
}
});
textButton.addListener(handListener);
textButton = new TextButton("Reset Text", skin);
table.add(textButton).expandX().right();
textButton.addListener(new TextTooltip("Reset preview text to default", tooltipManager, skin));
textButton.addListener(handListener);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
var textArea = (TextArea) findActor("preview");
textArea.setText(SAMPLE_TEXT);
}
});
var imageButton = new ImageButton(skin, "color");
table.add(imageButton);
imageButton.addListener(new TextTooltip("Change preview color", tooltipManager, skin));
imageButton.addListener(handListener);
imageButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
if (colorData != null) {
var textArea = (TextArea) findActor("preview");
previewStyle.fontColor = colorData.color;
settings.previewColor = colorData.color;
}
}, null);
}
});
imageButton = new ImageButton(skin, "color-bg");
table.add(imageButton);
imageButton.addListener(new TextTooltip("Change background color", tooltipManager, skin));
imageButton.addListener(handListener);
imageButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
if (colorData != null) {
var textArea = (TextArea) findActor("preview");
previewStyle.background = ((NinePatchDrawable) previewStyle.background).tint(colorData.color);
previewStyle.focusedBackground = ((NinePatchDrawable) previewStyle.focusedBackground).tint(colorData.color);
settings.previewBackgroundColor = colorData.color;
}
}, null);
}
});
}
Aggregations