use of com.badlogic.gdx.graphics.g2d.BitmapFont in project Entitas-Java by Rubentxu.
the class SplashState method initialize.
@Override
public void initialize() {
// Input
Camera camera = engine.getManager(BaseSceneManager.class).getDefaultCamera();
Batch batch = engine.getManager(BaseSceneManager.class).getBatch();
BitmapFont font = engine.getManager(BaseGUIManager.class).getDefaultFont();
systems.add(new DelaySystem(context.core)).add(new RendererSystem(context.core, engine.sr, camera, batch, font));
Texture texture = assetsManager.getTexture(splash);
context.core.createEntity().addTextureView("Pong", new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()), new Vector2(), 0, Pong.SCREEN_HEIGHT, Pong.SCREEN_WIDTH).addDelay(3);
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project Entitas-Java by Rubentxu.
the class Examples method create.
@Override
public void create() {
engine = new ExamplesEngine();
entitas = new Entitas();
preferencesManager.LOG_LEVEL = LogManager.LOG_DEBUG;
AssetManager assetsManager = new AssetManager(new TestFileHandleResolver());
engine.addManager(new AssetsManagerGDX(assetsManager, preferencesManager));
engine.addManager(new PhysicsManagerGDX(new Vector2(0, -9.8f)));
engine.addManager(new GUIManagerGDX(new ScreenViewport(), new BitmapFont(), engine));
engine.addManager(new SceneManagerGDX(engine, entitas));
engine.addManager(new LogManagerGDX(preferencesManager));
engine.addManager(new InputManagerGDX(entitas, engine));
engine.addManager(preferencesManager);
game = new ExamplesGame(engine, new EventBusGDX(new MBassador()));
game.init();
game.pushState(new PlatformExampleState(engine, entitas));
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project gdx-skineditor by cobolfoo.
the class Skin method getJsonLoader.
protected Json getJsonLoader(final FileHandle skinFile) {
final Skin skin = this;
final Json json = new Json() {
public <T> T readValue(Class<T> type, Class elementType, JsonValue jsonData) {
// actual value by name.
if (jsonData.isString() && !ClassReflection.isAssignableFrom(CharSequence.class, type))
return get(jsonData.asString(), type);
return super.readValue(type, elementType, jsonData);
}
};
json.setTypeName(null);
json.setUsePrototypes(false);
json.setSerializer(Skin.class, new ReadOnlySerializer<Skin>() {
public Skin read(Json json, JsonValue typeToValueMap, Class ignored) {
for (JsonValue valueMap = typeToValueMap.child; valueMap != null; valueMap = valueMap.next) {
try {
readNamedObjects(json, ClassReflection.forName(valueMap.name()), valueMap);
} catch (ReflectionException ex) {
throw new SerializationException(ex);
}
}
return skin;
}
private void readNamedObjects(Json json, Class type, JsonValue valueMap) {
for (JsonValue valueEntry = valueMap.child; valueEntry != null; valueEntry = valueEntry.next) {
Object object = json.readValue(type, valueEntry);
if (object == null)
continue;
try {
add(valueEntry.name(), object, type);
} catch (Exception ex) {
throw new SerializationException("Error reading " + ClassReflection.getSimpleName(type) + ": " + valueEntry.name(), ex);
}
}
}
});
json.setSerializer(BitmapFont.class, new ReadOnlySerializer<BitmapFont>() {
public BitmapFont read(Json json, JsonValue jsonData, Class type) {
String path = json.readValue("file", String.class, jsonData);
int scaledSize = json.readValue("scaledSize", int.class, -1, jsonData);
Boolean flip = json.readValue("flip", Boolean.class, false, jsonData);
FileHandle fontFile = skinFile.parent().child(path);
if (!fontFile.exists())
fontFile = Gdx.files.internal(path);
if (!fontFile.exists())
throw new SerializationException("Font file not found: " + fontFile);
// Use a region with the same name as the font, else use
// a PNG file in the same directory as the FNT file.
String regionName = fontFile.nameWithoutExtension();
try {
BitmapFont font;
TextureRegion region = skin.optional(regionName, TextureRegion.class);
if (region != null)
font = new BitmapFont(fontFile, region, flip);
else {
FileHandle imageFile = fontFile.parent().child(regionName + ".png");
if (imageFile.exists())
font = new BitmapFont(fontFile, imageFile, flip);
else
font = new BitmapFont(fontFile, flip);
}
// the font to.
if (scaledSize != -1)
font.setScale(scaledSize / font.getCapHeight());
return font;
} catch (RuntimeException ex) {
throw new SerializationException("Error loading bitmap font: " + fontFile, ex);
}
}
});
json.setSerializer(Color.class, new ReadOnlySerializer<Color>() {
public Color read(Json json, JsonValue jsonData, Class type) {
if (jsonData.isString())
return get(jsonData.asString(), Color.class);
String hex = json.readValue("hex", String.class, (String) null, jsonData);
if (hex != null)
return Color.valueOf(hex);
float r = json.readValue("r", float.class, 0f, jsonData);
float g = json.readValue("g", float.class, 0f, jsonData);
float b = json.readValue("b", float.class, 0f, jsonData);
float a = json.readValue("a", float.class, 1f, jsonData);
return new Color(r, g, b, a);
}
});
json.setSerializer(TintedDrawable.class, new ReadOnlySerializer() {
public Object read(Json json, JsonValue jsonData, Class type) {
String name = json.readValue("name", String.class, jsonData);
Color color = json.readValue("color", Color.class, jsonData);
TintedDrawable td = new TintedDrawable();
td.name = name;
td.color = color;
td.drawable = newDrawable(name, color);
return td;
// return newDrawable(name, color);
}
});
return json;
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project gdx-skineditor by cobolfoo.
the class FontPickerDialog method isFontInUse.
/**
* Is font is already in use somewhere else?
*/
public boolean isFontInUse(BitmapFont font) {
try {
// Check if it is already in use somewhere!
for (String widget : SkinEditorGame.widgets) {
String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
Class<?> style = Class.forName(widgetStyle);
ObjectMap<String, ?> styles = game.skinProject.getAll(style);
Iterator<String> it = styles.keys().iterator();
while (it.hasNext()) {
Object item = styles.get((String) it.next());
Field[] fields = ClassReflection.getFields(item.getClass());
for (Field field : fields) {
if (field.getType() == BitmapFont.class) {
BitmapFont f = (BitmapFont) field.get(item);
if (font.equals(f)) {
return true;
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project gdx-skineditor by cobolfoo.
the class NewFontDialog method refreshFontPreview.
/**
*
*/
public void refreshFontPreview() {
try {
String fontName = selectFonts.getSelected();
Gdx.app.log("FontPickerDialog", "Refreshing preview for font: " + fontName);
File fontPath = game.fm.fonts.get(selectFonts.getSelected());
Gdx.app.log("FontPickerDialog", "Loading font from file:" + fontPath);
Font font = Font.createFont(Font.TRUETYPE_FONT, fontPath);
UnicodeFont unicodeFont = new UnicodeFont(font, Integer.valueOf(selectSize.getSelected()), checkBold.isChecked(), checkItalic.isChecked());
if (checkShadow.isChecked() == true) {
ColorEffect colorEffect = new ColorEffect();
colorEffect.setColor(java.awt.Color.BLACK);
unicodeFont.getEffects().add(colorEffect);
ShadowEffect shadow = new ShadowEffect();
shadow.setOpacity(1.0f);
shadow.setXDistance(1);
shadow.setYDistance(1);
shadow.setColor(java.awt.Color.WHITE);
unicodeFont.getEffects().add(shadow);
} else {
ColorEffect colorEffect = new ColorEffect();
colorEffect.setColor(java.awt.Color.WHITE);
unicodeFont.getEffects().add(colorEffect);
}
unicodeFont.addAsciiGlyphs();
String newFontName = generateProperFontName(fontName);
textFontName.setText(newFontName);
// Create bitmap font
BMFontUtil bfu = new BMFontUtil(unicodeFont);
FileHandle handle = new FileHandle(System.getProperty("java.io.tmpdir")).child(newFontName);
FileHandle handleFont = new FileHandle(handle.file().getAbsolutePath() + ".fnt");
bfu.save(handle.file());
FileHandle handleImage = new FileHandle(System.getProperty("java.io.tmpdir")).child(newFontName + ".png");
TextField.TextFieldStyle textStyle = new TextField.TextFieldStyle();
textStyle.cursor = game.skin.getDrawable("cursor");
textStyle.selection = game.skin.getDrawable("selection");
textStyle.background = game.skin.getDrawable("textfield");
textStyle.fontColor = Color.YELLOW;
textStyle.font = new BitmapFont(handleFont, handleImage, false);
textFontPreview.setStyle(textStyle);
// Have to do this to force clipping of font
textFontPreview.setText(textFontPreview.getText());
} catch (Exception e) {
e.printStackTrace();
textFontPreview.getStyle().font = game.skin.getFont("default-font");
// Have to do this to force clipping of font
textFontPreview.setText(textFontPreview.getText());
}
}
Aggregations