Example usage for com.badlogic.gdx.tools.hiero.unicodefont.effects ColorEffect setColor

List of usage examples for com.badlogic.gdx.tools.hiero.unicodefont.effects ColorEffect setColor

Introduction

In this page you can find the example usage for com.badlogic.gdx.tools.hiero.unicodefont.effects ColorEffect setColor.

Prototype

public void setColor(Color color) 

Source Link

Usage

From source file:org.shadebob.skineditor.NewFontDialog.java

License:Apache License

/**
 * //from  w  w w  . j  ava 2s  .  c o  m
 */
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();

        // Generate a temporary name for your font (Do not end with a number, it will be removed in the atlas)
        String newFontName = "font_" + fontName.toLowerCase().replace(" ", "_") + "_" + selectSize.getSelected()
                + "pt";
        if (checkBold.isChecked() == true) {
            newFontName += "_bold";
        }

        if (checkItalic.isChecked() == true) {
            newFontName += "_italic";
        }

        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());
    }
}