use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project Eidolons by IDemiurge.
the class EmitterPalette method init.
public void init() {
clear();
setSize(GdxMaster.getWidth() - 300, 256);
// int columns = (int) (getWidth() / 64);
defaults().padLeft(200).top().right().width(GdxMaster.getWidth() - 300);
Map<String, List<File>> presets = new LinkedHashMap<>();
List<File> subfolders = FileManager.getFilesFromDirectory(PathFinder.getSfxPath(), true);
subfolders.forEach(file -> {
if (!file.isDirectory()) {
MapMaster.addToListMap(presets, "main", file);
} else
presets.put(file.getName(), FileManager.getFilesFromDirectory(file.getPath(), false));
});
LabelStyle style = StyleHolder.getSizedLabelStyle(FONT.MAIN, 15);
for (String sub : presets.keySet()) {
HorizontalFlowGroup table = new HorizontalFlowGroup(0);
table.setWidth(getWidth() - 100);
boolean bg = presets.get(sub).size() < 55;
for (File preset : presets.get(sub)) {
// textButton?
ValueContainer label = new ValueContainer(new Label(preset.getName(), style));
NinePatch patch = NinePatchFactory.getTooltip();
patch.scale(0.7f, 0.7f);
if (bg)
label.setBackground(new NinePatchDrawable(patch));
label.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT)) {
// EmitterMaster.
}
EditorManager.setMode(MAP_EDITOR_MOUSE_MODE.EMITTER);
if (selectedLabel != null)
selectedLabel.setColor(1, 1, 1, 1);
if (sub.equals("main"))
selected = preset.getName();
else
selected = StrPathBuilder.build(sub, preset.getName());
selectedLabel = label;
label.setColor(1, 0.3f, 0.8f, 1);
return super.touchDown(event, x, y, pointer, button);
}
});
table.addActor(label);
}
addTab(table, sub);
}
}
use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project skin-composer by raeleus.
the class DialogDrawables method produceAtlas.
/**
* Writes a TextureAtlas based on drawables list. Creates drawables to be
* displayed on screen
* @return
*/
private boolean produceAtlas() {
try {
if (atlas != null) {
atlas.dispose();
atlas = null;
}
if (!main.getAtlasData().atlasCurrent) {
main.getAtlasData().writeAtlas();
main.getAtlasData().atlasCurrent = true;
}
atlas = main.getAtlasData().getAtlas();
for (DrawableData data : main.getAtlasData().getDrawables()) {
Drawable drawable;
if (data.customized) {
drawable = getSkin().getDrawable("custom-drawable-skincomposer-image");
} else if (data.tiled) {
String name = data.file.name();
name = DrawableData.proper(name);
drawable = new TiledDrawable(atlas.findRegion(name));
drawable.setMinWidth(data.minWidth);
drawable.setMinHeight(data.minHeight);
((TiledDrawable) drawable).getColor().set(main.getJsonData().getColorByName(data.tintName).color);
} else if (data.file.name().matches(".*\\.9\\.[a-zA-Z0-9]*$")) {
String name = data.file.name();
name = DrawableData.proper(name);
drawable = new NinePatchDrawable(atlas.createPatch(name));
if (data.tint != null) {
drawable = ((NinePatchDrawable) drawable).tint(data.tint);
} else if (data.tintName != null) {
drawable = ((NinePatchDrawable) drawable).tint(main.getJsonData().getColorByName(data.tintName).color);
}
} else {
String name = data.file.name();
name = DrawableData.proper(name);
drawable = new SpriteDrawable(atlas.createSprite(name));
if (data.tint != null) {
drawable = ((SpriteDrawable) drawable).tint(data.tint);
} else if (data.tintName != null) {
drawable = ((SpriteDrawable) drawable).tint(main.getJsonData().getColorByName(data.tintName).color);
}
}
drawablePairs.put(data, drawable);
}
return true;
} catch (Exception e) {
Gdx.app.error(getClass().getName(), "Error while attempting to generate drawables.", e);
main.getDialogFactory().showDialogError("Atlas Error...", "Error while attempting to generate drawables.\n\nOpen log?");
return false;
}
}
use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project skin-composer by raeleus.
the class DialogDrawables method colorSwatchesDialog.
private void colorSwatchesDialog(DrawableData drawableData) {
DialogColors dialog = new DialogColors(main, (StyleProperty) null, true, (ColorData colorData) -> {
if (colorData != null) {
final DrawableData tintedDrawable = new DrawableData(drawableData.file);
tintedDrawable.tintName = colorData.getName();
// Fix background color for new, tinted drawable
Color temp = Utils.averageEdgeColor(tintedDrawable.file, colorData.color);
if (Utils.brightness(temp) > .5f) {
tintedDrawable.bgColor = Color.BLACK;
} else {
tintedDrawable.bgColor = Color.WHITE;
}
final TextField textField = new TextField(drawableData.name, getSkin());
final TextButton button = new TextButton("OK", getSkin());
button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
button.addListener(main.getHandListener());
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
}
});
textField.addListener(main.getIbeamListener());
Dialog approveDialog = new Dialog("TintedDrawable...", getSkin(), "bg") {
@Override
protected void result(Object object) {
if (object instanceof Boolean && (boolean) object) {
tintedDrawable.name = textField.getText();
main.getAtlasData().getDrawables().add(tintedDrawable);
main.getProjectData().setChangesSaved(false);
}
}
@Override
public boolean remove() {
gatherDrawables();
produceAtlas();
sortBySelectedMode();
getStage().setScrollFocus(scrollPane);
return super.remove();
}
};
approveDialog.addCaptureListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode2) {
if (keycode2 == Input.Keys.ENTER) {
if (!button.isDisabled()) {
tintedDrawable.name = textField.getText();
main.getAtlasData().getDrawables().add(tintedDrawable);
main.getProjectData().setChangesSaved(false);
approveDialog.hide();
}
}
return false;
}
});
approveDialog.getTitleTable().padLeft(5.0f);
approveDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
approveDialog.getButtonTable().padBottom(15.0f);
approveDialog.text("What is the name of the new tinted drawable?");
Drawable drawable = drawablePairs.get(drawableData);
Drawable preview = null;
if (drawable instanceof SpriteDrawable) {
preview = ((SpriteDrawable) drawable).tint(colorData.color);
} else if (drawable instanceof NinePatchDrawable) {
preview = ((NinePatchDrawable) drawable).tint(colorData.color);
}
if (preview != null) {
approveDialog.getContentTable().row();
Table table = new Table();
table.setBackground(preview);
approveDialog.getContentTable().add(table);
}
approveDialog.getContentTable().row();
approveDialog.getContentTable().add(textField).growX();
approveDialog.button(button, true);
approveDialog.button("Cancel", false);
approveDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
approveDialog.key(Input.Keys.ESCAPE, false);
approveDialog.show(getStage());
getStage().setKeyboardFocus(textField);
textField.selectAll();
textField.setFocusTraversal(false);
}
});
dialog.setFillParent(true);
dialog.show(getStage());
dialog.refreshTable();
}
use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project skin-composer by raeleus.
the class DialogDrawables method newTintedDrawable.
/**
* Creates a TintedDrawable based on the provided DrawableData. Prompts
* user for a Color and name.
* @param drawableData
*/
private void newTintedDrawable(DrawableData drawableData) {
Color previousColor = Color.WHITE;
if (drawableData.tint != null) {
previousColor = drawableData.tint;
}
main.getDialogFactory().showDialogColorPicker(previousColor, new DialogColorPicker.ColorListener() {
@Override
public void selected(Color color) {
if (color != null) {
final DrawableData tintedDrawable = new DrawableData(drawableData.file);
tintedDrawable.tint = color;
// Fix background color for new, tinted drawable
Color temp = Utils.averageEdgeColor(tintedDrawable.file, tintedDrawable.tint);
if (Utils.brightness(temp) > .5f) {
tintedDrawable.bgColor = Color.BLACK;
} else {
tintedDrawable.bgColor = Color.WHITE;
}
final TextField textField = new TextField(drawableData.name, getSkin());
final TextButton button = new TextButton("OK", getSkin());
button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText()));
}
});
textField.addListener(main.getIbeamListener());
Dialog dialog = new Dialog("TintedDrawable...", getSkin(), "bg") {
@Override
protected void result(Object object) {
if (object instanceof Boolean && (boolean) object) {
tintedDrawable.name = textField.getText();
main.getAtlasData().getDrawables().add(tintedDrawable);
main.getProjectData().setChangesSaved(false);
}
}
@Override
public boolean remove() {
gatherDrawables();
produceAtlas();
sortBySelectedMode();
getStage().setScrollFocus(scrollPane);
return super.remove();
}
};
dialog.getTitleTable().getCells().first().padLeft(5.0f);
dialog.addCaptureListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode2) {
if (keycode2 == Input.Keys.ENTER) {
if (!button.isDisabled()) {
tintedDrawable.name = textField.getText();
main.getAtlasData().getDrawables().add(tintedDrawable);
main.getProjectData().setChangesSaved(false);
dialog.hide();
}
}
return false;
}
});
dialog.text("What is the name of the new tinted drawable?");
dialog.getContentTable().getCells().first().pad(10.0f);
Drawable drawable = drawablePairs.get(drawableData);
Drawable preview = null;
if (drawable instanceof SpriteDrawable) {
preview = ((SpriteDrawable) drawable).tint(color);
} else if (drawable instanceof NinePatchDrawable) {
preview = ((NinePatchDrawable) drawable).tint(color);
}
if (preview != null) {
dialog.getContentTable().row();
Table table = new Table();
table.setBackground(preview);
dialog.getContentTable().add(table);
}
dialog.getContentTable().row();
dialog.getContentTable().add(textField).growX().pad(10.0f);
dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
dialog.button(button, true);
button.addListener(main.getHandListener());
dialog.button("Cancel", false);
dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
dialog.key(Input.Keys.ESCAPE, false);
dialog.show(getStage());
getStage().setKeyboardFocus(textField);
textField.selectAll();
textField.setFocusTraversal(false);
}
}
});
}
use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project var3dframe by Var3D.
the class VGame method getRectLineDrawable.
// 创建钜形线条Drawable
public Drawable getRectLineDrawable(Color color, Color out, int w, int h) {
Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888);
pixmap.setColor(color);
pixmap.fill();
pixmap.setColor(out);
pixmap.drawRectangle(0, 0, w, h);
Texture colorPoint = new Texture(pixmap);
colorPoint.setFilter(filter, filter);
pixmap.dispose();
NinePatchDrawable nine = new NinePatchDrawable(new NinePatch(colorPoint, 2, 2, 2, 2));
return nine;
}
Aggregations