use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project libgdx by libgdx.
the class Skin method getDrawable.
/** Returns a registered drawable. If no drawable is found but a region, ninepatch, or sprite exists with the name, then the
* appropriate drawable is created and stored in the skin. */
public Drawable getDrawable(String name) {
Drawable drawable = optional(name, Drawable.class);
if (drawable != null)
return drawable;
// Use texture or texture region. If it has splits, use ninepatch. If it has rotation or whitespace stripping, use sprite.
try {
TextureRegion textureRegion = getRegion(name);
if (textureRegion instanceof AtlasRegion) {
AtlasRegion region = (AtlasRegion) textureRegion;
if (region.splits != null)
drawable = new NinePatchDrawable(getPatch(name));
else if (region.rotate || region.packedWidth != region.originalWidth || region.packedHeight != region.originalHeight)
drawable = new SpriteDrawable(getSprite(name));
}
if (drawable == null)
drawable = new TextureRegionDrawable(textureRegion);
} catch (GdxRuntimeException ignored) {
}
// Check for explicit registration of ninepatch, sprite, or tiled drawable.
if (drawable == null) {
NinePatch patch = optional(name, NinePatch.class);
if (patch != null)
drawable = new NinePatchDrawable(patch);
else {
Sprite sprite = optional(name, Sprite.class);
if (sprite != null)
drawable = new SpriteDrawable(sprite);
else
throw new GdxRuntimeException("No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: " + name);
}
}
if (drawable instanceof BaseDrawable)
((BaseDrawable) drawable).setName(name);
add(name, drawable, Drawable.class);
return drawable;
}
use of com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable in project skin-composer by raeleus.
the class RootTable method produceAtlas.
/**
* Writes a TextureAtlas based on drawables list. Creates drawables to be
* displayed on screen
* @return
*/
public boolean produceAtlas() {
try {
if (atlas != null) {
atlas.dispose();
atlas = null;
}
if (!main.getProjectData().getAtlasData().atlasCurrent) {
main.getProjectData().getAtlasData().writeAtlas();
main.getProjectData().getAtlasData().atlasCurrent = true;
}
atlas = main.getProjectData().getAtlasData().getAtlas();
for (DrawableData data : main.getProjectData().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.getProjectData().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.getProjectData().getJsonData().getColorByName(data.tintName).color);
}
}
drawablePairs.put(data.name, 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 Eidolons by IDemiurge.
the class PlaceTooltip method updateAct.
@Override
public void updateAct(float delta) {
clearChildren();
TextureRegion r = TextureCache.getOrCreateR(place.getImagePath());
ValueContainer container = new ValueContainer(r, place.getName());
float size = GdxMaster.adjustSize(128);
if (size < r.getRegionHeight() && size < r.getRegionWidth())
container.overrideImageSize(size, size);
add(container);
setBackground(new NinePatchDrawable(NinePatchFactory.getTooltip()));
// return ;
if (place.getRoutes().isEmpty()) {
return;
}
row();
TablePanel<ValueContainer> routesInfo = new TablePanel<>();
routesInfo.defaults().space(5);
add(routesInfo);
routesInfo.addListener(new ClickListener() {
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
if (toActor == routesInfo)
return;
if (toActor == null) {
if (getWidth() >= x)
return;
if (getWidth() >= y)
return;
}
if (GdxMaster.getAncestors(toActor).contains(routesInfo))
return;
if (!checkActorExitRemoves(toActor))
return;
super.exit(event, x, y, pointer, toActor);
GuiEventManager.trigger(MapEvent.ROUTES_PANEL_HOVER_OFF);
}
});
int i = 0;
for (Route sub : place.getRoutes()) {
// reverse pic pos
TextureRegion tex = TextureCache.getOrCreateR(sub.getImagePath());
ValueContainer routeInfo = new ValueContainer(tex, sub.getName(), sub.getLength() + " leagues");
routeInfo.setBackground(new NinePatchDrawable(NinePatchFactory.getTooltip()));
routesInfo.add(routeInfo).left().padLeft(5).uniform(true, false);
routeInfo.setUserObject(sub);
routeInfo.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
// getTapCount()
GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, sub);
return super.touchDown(event, x, y, pointer, button);
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
super.exit(event, x, y, pointer, toActor);
GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, null);
}
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
super.enter(event, x, y, pointer, fromActor);
GuiEventManager.trigger(MapEvent.ROUTE_HOVERED, sub);
}
});
if (i % 2 == 1)
routesInfo.row();
i++;
}
}
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;
}
}
Aggregations