use of com.badlogic.gdx.graphics.g2d.BitmapFont in project gdx-skineditor by cobolfoo.
the class OptionsPane method updateTableFields.
/**
*
*/
private void updateTableFields(final String style) {
ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
String widget = button.getUserObject().toString();
Gdx.app.log("OptionsPane", "Update fields table for widget: " + widget + ", style: " + style);
tableFields.clear();
tableFields.add(new Label("Name", game.skin, "title")).left().width(170);
tableFields.add(new Label("Value", game.skin, "title")).left().width(60).padRight(50);
tableFields.row();
Field[] fields = ClassReflection.getFields(currentStyle.getClass());
for (final Field field : fields) {
try {
// Grey optional
if (game.opt.isFieldOptional(currentStyle.getClass(), field.getName())) {
tableFields.add(new Label(field.getName(), game.skin, "optional")).left();
} else {
tableFields.add(new Label(field.getName(), game.skin, "default")).left();
}
Actor actor;
// field type
String name = field.getType().getSimpleName();
Object obj = field.get(currentStyle);
if (name.equals("Drawable")) {
/**
* Handle Drawable object
*/
Drawable drawable = (Drawable) field.get(currentStyle);
String resourceName = "";
ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
if (drawable != null) {
resourceName = game.skinProject.resolveObjectName(Drawable.class, drawable);
buttonStyle.imageUp = drawable;
} else {
buttonStyle.up = game.skinProject.getDrawable("default-rect");
buttonStyle.checked = game.skinProject.getDrawable("default-rect");
}
actor = new ImageTextButton(resourceName, buttonStyle);
((ImageTextButton) actor).setClip(true);
actor.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showDrawableDialog(field);
}
});
} else if (name.equals("Color")) {
/**
* Handle Color object
*/
Color color = (Color) field.get(currentStyle);
ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
String resourceName = "";
if (color != null) {
resourceName = game.skinProject.resolveObjectName(Color.class, color);
resourceName += " (" + color.toString() + ")";
// Create drawable on the fly
Pixmap pixmap = new Pixmap(18, 18, Pixmap.Format.RGBA8888);
pixmap.setColor(color);
pixmap.fill();
pixmap.setColor(Color.BLACK);
pixmap.drawRectangle(0, 0, 18, 18);
Texture texture = new Texture(pixmap);
buttonStyle.imageUp = new SpriteDrawable(new Sprite(texture));
pixmap.dispose();
} else {
buttonStyle.up = game.skinProject.getDrawable("default-rect");
buttonStyle.checked = game.skinProject.getDrawable("default-rect");
}
actor = new ImageTextButton(resourceName, buttonStyle);
((ImageTextButton) actor).setClip(true);
actor.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showColorPickerDialog(field);
}
});
} else if (name.equals("BitmapFont")) {
/**
* Handle BitmapFont object
*/
BitmapFont font = (BitmapFont) field.get(currentStyle);
String resourceName = "";
ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
if (font != null) {
resourceName = game.skinProject.resolveObjectName(BitmapFont.class, font);
buttonStyle.font = font;
} else {
buttonStyle.up = game.skinProject.getDrawable("default-rect");
buttonStyle.checked = game.skinProject.getDrawable("default-rect");
}
actor = new ImageTextButton(resourceName, buttonStyle);
((ImageTextButton) actor).setClip(true);
actor.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showFontPickerDialog(field);
}
});
} else if (name.equals("float")) {
/**
* Handle Float object
*/
Float value = (Float) field.get(currentStyle);
String resourceName = "";
ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"), game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));
if ((value != null) && (value != 0)) {
resourceName = String.valueOf(value);
} else {
buttonStyle.up = game.skinProject.getDrawable("default-rect");
buttonStyle.checked = game.skinProject.getDrawable("default-rect");
}
actor = new ImageTextButton(resourceName, buttonStyle);
((ImageTextButton) actor).setClip(true);
actor.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
showFloatInputDialog(field);
}
});
} else if (name.equals("ListStyle")) {
/**
* Handle ListStyle object
*/
ListStyle listStyle = (ListStyle) field.get(currentStyle);
actor = new SelectBox<String>(game.skin, "default");
Array<String> items = new Array<String>();
final ObjectMap<String, ListStyle> values = game.skinProject.getAll(ListStyle.class);
Iterator<String> it = values.keys().iterator();
String selection = null;
while (it.hasNext()) {
String key = it.next();
items.add(key);
if (listStyle == values.get(key)) {
selection = key;
}
}
((SelectBox) actor).setItems(items);
if (selection != null) {
((SelectBox) actor).setSelected(selection);
}
actor.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
String selection = (String) ((SelectBox) actor).getSelected();
try {
field.set(currentStyle, values.get(selection));
} catch (Exception e) {
e.printStackTrace();
}
game.screenMain.saveToSkin();
refresh();
game.screenMain.paneOptions.updateSelectedTableFields();
game.screenMain.panePreview.refresh();
}
});
} else if (name.equals("ScrollPaneStyle")) {
/**
* Handle ListStyle object
*/
ScrollPaneStyle scrollStyle = (ScrollPaneStyle) field.get(currentStyle);
actor = new SelectBox<String>(game.skin, "default");
Array<String> items = new Array<String>();
final ObjectMap<String, ScrollPaneStyle> values = game.skinProject.getAll(ScrollPaneStyle.class);
Iterator<String> it = values.keys().iterator();
String selection = null;
while (it.hasNext()) {
String key = it.next();
items.add(key);
if (scrollStyle == values.get(key)) {
selection = key;
}
}
((SelectBox) actor).setItems(items);
if (selection != null) {
((SelectBox) actor).setSelected(selection);
}
actor.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
String selection = (String) ((SelectBox) actor).getSelected();
try {
field.set(currentStyle, values.get(selection));
} catch (Exception e) {
e.printStackTrace();
}
game.screenMain.saveToSkin();
refresh();
game.screenMain.paneOptions.updateSelectedTableFields();
game.screenMain.panePreview.refresh();
}
});
} else {
Gdx.app.log("OptionsPane", "Unknown type: " + name);
actor = new Label("Unknown Type", game.skin);
}
tableFields.add(actor).left().height(32).padRight(24).expandX().fillX();
tableFields.row();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project gdx-skineditor by cobolfoo.
the class FontPickerDialog method updateTable.
/**
*
*/
public void updateTable() {
fonts = game.skinProject.getAll(BitmapFont.class);
tableFonts.clear();
tableFonts.add(new Label("Font Name", game.skin, "title")).left().width(170);
tableFonts.add(new Label("Value", game.skin, "title")).colspan(3).left().width(60).padRight(50).expandX().fillX();
tableFonts.row();
Iterator<String> it = fonts.keys().iterator();
while (it.hasNext()) {
final String key = it.next();
final BitmapFont font = fonts.get(key);
tableFonts.add(key).left();
Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = font;
labelStyle.fontColor = Color.WHITE;
tableFonts.add(new Label("Sample Text", labelStyle)).left();
TextButton buttonSelect = new TextButton("Select", game.skin);
buttonSelect.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
try {
// Since we have reloaded everything we have to get
// field back
game.screenMain.paneOptions.refreshSelection();
field.set(game.screenMain.paneOptions.currentStyle, font);
} catch (Exception e) {
e.printStackTrace();
}
hide();
game.screenMain.panePreview.refresh();
game.screenMain.paneOptions.updateSelectedTableFields();
game.screenMain.saveToSkin();
}
});
TextButton buttonRemove = new TextButton("Remove", game.skin);
buttonRemove.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Dialog dlg = new Dialog("Delete Font", game.skin) {
@Override
protected void result(Object object) {
if ((Boolean) object == false) {
return;
}
if (isFontInUse(font) == true) {
game.showNotice("Error", "Bitmap font already in use!", getStage());
} else {
// Remove files from disk (fnt and png)
FileHandle targetFont = new FileHandle("projects/" + game.screenMain.getcurrentProject() + "/" + key + ".fnt");
FileHandle targetImage = new FileHandle("projects/" + game.screenMain.getcurrentProject() + "/assets/" + key + ".png");
targetFont.delete();
targetImage.delete();
fonts.remove(key);
// update table
updateTable();
game.screenMain.saveToSkin();
}
}
};
dlg.pad(20);
dlg.getContentTable().add("You are sure you want to delete this bitmap font?");
dlg.button("OK", true);
dlg.button("Cancel", false);
dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
dlg.show(getStage());
}
});
if (field != null) {
tableFonts.add(buttonSelect).left();
}
tableFonts.add(buttonRemove).left().expandX();
tableFonts.row();
}
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project commons-gdx by gemserk.
the class RenderLayerSpriteBatchImpl method render.
@Override
public void render() {
camera.getFrustum(frustum);
if (optimizationParameters.updateCamera)
camera.apply(spriteBatch);
RandomAccessMap<Entity, EntityComponents> entityComponents = factory.entityComponents;
if (blending && !spriteBatch.isBlendingEnabled())
spriteBatch.enableBlending();
else if (!blending && spriteBatch.isBlendingEnabled())
spriteBatch.disableBlending();
if (optimizationParameters.beginBatch)
spriteBatch.begin();
for (int i = 0; i < orderedByLayerRenderables.size(); i++) {
Renderable renderable = orderedByLayerRenderables.get(i);
if (!renderable.isVisible())
continue;
EntityComponents components = entityComponents.get(renderable.getEntity());
FrustumCullingComponent frustumCullingComponent = components.frustumCullingComponent;
if (frustumCullingComponent != null) {
Spatial spatial = components.spatialComponent.getSpatial();
entityBounds.set(frustumCullingComponent.bounds);
entityBounds.setX(entityBounds.getX() + spatial.getX());
entityBounds.setY(entityBounds.getY() + spatial.getY());
if (!frustum.overlaps(entityBounds))
continue;
}
SpriteComponent spriteComponent = components.spriteComponent;
if (spriteComponent != null) {
Sprite sprite = spriteComponent.getSprite();
sprite.setColor(spriteComponent.getColor());
sprite.draw(spriteBatch);
}
// don't like it will be asking for components all the time.
TextComponent textComponent = components.textComponent;
if (textComponent != null) {
BitmapFont font = textComponent.font;
if (font.getScaleX() != textComponent.scale) {
font.setScale(textComponent.scale);
}
font.setColor(textComponent.color);
//
SpriteBatchUtils.drawMultilineText(//
spriteBatch, //
font, textComponent.text, textComponent.x, textComponent.y, textComponent.cx, textComponent.cy);
}
ParticleEmitterComponent particleEmitterComponent = components.particleEmitterComponent;
if (particleEmitterComponent != null) {
particleEmitterComponent.particleEmitter.draw(spriteBatch);
}
}
if (optimizationParameters.endBatch)
spriteBatch.end();
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class FreeTypeFontGenerator method generateFont.
/** Generates a new {@link BitmapFont}. The size is expressed in pixels. Throws a GdxRuntimeException if the font could not be
* generated. Using big sizes might cause such an exception.
* @param parameter configures how the font is generated */
public BitmapFont generateFont(FreeTypeFontParameter parameter, FreeTypeBitmapFontData data) {
generateData(parameter, data);
if (data.regions == null && parameter.packer != null) {
data.regions = new Array();
parameter.packer.updateTextureRegions(data.regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps);
}
BitmapFont font = new BitmapFont(data, data.regions, true);
font.setOwnsTexture(parameter.packer == null);
return font;
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class FreeTypeMetricsTest method create.
@Override
public void create() {
spriteBatch = new SpriteBatch();
atlas = new TextureAtlas("data/pack");
smallFont = new BitmapFont();
FreeTypeFontParameter parameter = new FreeTypeFontParameter();
parameter.size = 60;
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf"));
font = generator.generateFont(parameter);
generator.dispose();
renderer = new ShapeRenderer();
renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
}
Aggregations