use of com.badlogic.gdx.tools.hiero.unicodefont.effects.ShadowEffect 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