use of com.badlogic.gdx.graphics.g2d.NinePatch in project gdx-skineditor by cobolfoo.
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;
drawable = optional(name, TiledDrawable.class);
if (drawable != null)
return drawable;
// 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) {
}
// 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);
}
}
add(name, drawable, Drawable.class);
return drawable;
}
use of com.badlogic.gdx.graphics.g2d.NinePatch in project libgdx by libgdx.
the class TableTest method create.
@Override
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
TextureRegion region = new TextureRegion(texture);
NinePatch patch = skin.getPatch("default-round");
Label label = new Label("This is some text.", skin);
root = new Table() {
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
}
};
stage.addActor(root);
// root.setTransform(true);
Table table = new Table();
table.setTransform(true);
table.setPosition(100, 100);
table.setOrigin(0, 0);
table.setRotation(45);
table.setScaleY(2);
table.add(label);
table.add(new TextButton("Text Button", skin));
table.pack();
// table.debug();
table.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("click!");
}
});
// root.addActor(table);
TextButton button = new TextButton("Text Button", skin);
Table table2 = new Table();
// table2.debug()
table2.add(button);
table2.setTransform(true);
table2.setScaleX(1.5f);
table2.setOrigin(table2.getPrefWidth() / 2, table2.getPrefHeight() / 2);
// Test colspan with expandX.
// root.setPosition(10, 10);
root.debug();
root.setFillParent(true);
root.add(new Label("meow meow meow meow meow meow meow meow meow meow meow meow", skin)).colspan(3).expandX();
root.add(new TextButton("Text Button", skin));
root.row();
root.add(new TextButton("Text Button", skin));
root.add(new TextButton("Toggle Button", skin.get("toggle", TextButtonStyle.class)));
root.add(new CheckBox("meow meow meow meow meow meow meow meow", skin));
// root.pack();
// root.add(new Button(new Image(region), skin));
// root.add(new LabelButton("Toggley", skin.getStyle("toggle", LabelButtonStyle.class)));
}
use of com.badlogic.gdx.graphics.g2d.NinePatch in project libgdx by libgdx.
the class NinePatchDrawable method tint.
/** Creates a new drawable that renders the same as this drawable tinted the specified color. */
public NinePatchDrawable tint(Color tint) {
NinePatchDrawable drawable = new NinePatchDrawable(this);
drawable.setPatch(new NinePatch(drawable.getPatch(), tint));
return drawable;
}
use of com.badlogic.gdx.graphics.g2d.NinePatch in project libgdx by libgdx.
the class NinePatchTest method newDegenerateNinePatch.
// Make a degenerate NinePatch
static NinePatch newDegenerateNinePatch() {
final int patchSize = 8;
final int pixmapSize = patchSize * 3;
TextureRegion tr = newPatchPix(patchSize, pixmapSize);
return new NinePatch(tr);
}
use of com.badlogic.gdx.graphics.g2d.NinePatch in project libgdx by libgdx.
the class NinePatchTest method newMidlessPatch.
// Make a ninepatch with no middle band, just top three and bottom three.
static NinePatch newMidlessPatch() {
final int patchSize = 8;
final int fullPatchHeight = patchSize * 2;
final int fullPatchWidth = patchSize * 3;
final int pixmapDim = MathUtils.nextPowerOfTwo(Math.max(fullPatchWidth, fullPatchHeight));
Pixmap testPatch = new Pixmap(pixmapDim, pixmapDim, Pixmap.Format.RGBA8888);
testPatch.setColor(1, 1, 1, 0);
testPatch.fill();
for (int x = 0; x < fullPatchWidth; x += patchSize) {
for (int y = 0; y < fullPatchHeight; y += patchSize) {
testPatch.setColor(x / (float) fullPatchWidth, y / (float) fullPatchHeight, 1.0f, 1.0f);
testPatch.fillRectangle(x, y, patchSize, patchSize);
}
}
return new NinePatch(new TextureRegion(new Texture(testPatch), fullPatchWidth, fullPatchHeight), patchSize, patchSize, patchSize, patchSize);
}
Aggregations