Example usage for com.badlogic.gdx.graphics.g2d BitmapFont getRegion

List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont getRegion

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d BitmapFont getRegion.

Prototype


public TextureRegion getRegion() 

Source Link

Document

Returns the first texture region.

Usage

From source file:CB_UI_Base.GL_UI.Fonts.java

License:Open Source License

private static BitmapFont loadFontFromFile(FreeTypeFontGenerator generator, int scale) {
    String fs = Global.fs;/*  w  ww.  j  a va  2s  . c  o  m*/
    String fontPath = "";
    // fonts-Verzeichnis "lokal" im cachebox/skins/small oder ..normal oder christmas

    if (cfg.SkinFolder.type() == FileType.Absolute) {
        String FolderPath = cfg.SkinFolder.path();
        String path = FolderPath.replace("/", fs) + fs + "fnts";
        if (FileIO.DirectoryExists(path)) {
            // fonts-Verzeichnis "lokal" im cachebox/skins/small oder ..normal oder christmas
            fontPath = path + fs + String.valueOf(scale) + ".fnt";
        } else {
            // fonts-Verzeichnis "global" im cachebox/skins
            path = FolderPath.replace("/", fs) + fs + ".." + fs + "fnts";
            fontPath = path + fs + String.valueOf(scale) + ".fnt";
        }

    }

    // Wenn der font nicht vorberechnet ist, dann wird er generiert
    if (FileIO.FileExists(fontPath)) {
        Log.debug(log, "load font for scale " + scale + " from " + fontPath);
        // automatic load of png does not work on Android, so
        // return new BitmapFont(Gdx.files.absolute(fontPath),false);
        Texture tex = new Texture(Gdx.files.absolute(fontPath.replace(".fnt", ".png")));
        tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        TextureRegion region = new TextureRegion(tex);
        BitmapFont ret = new BitmapFont(Gdx.files.absolute(fontPath), region, false);
        return ret;
    } else {
        Log.debug(log, "generate font for scale " + scale);
        FreeTypeFontParameter parameter = new FreeTypeFontParameter();
        parameter.size = scale;
        parameter.characters = DEFAULT_CHARACTER;
        BitmapFont ret = generator.generateFont(parameter);
        TextureRegion region = ret.getRegion();
        Texture tex = region.getTexture();
        tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        return ret;
    }
}

From source file:CB_UI_Base.graphics.GL_Fonts.java

License:Open Source License

private BitmapFont generateFont(FileHandle file, int textSize) {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(file);

    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = textSize;/*w  ww. ja v  a2  s  . c  om*/
    parameter.characters = Fonts.DEFAULT_CHARACTER;
    BitmapFont ret = generator.generateFont(parameter);

    TextureRegion region = ret.getRegion();
    Texture tex = region.getTexture();
    tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    generator.dispose();

    return ret;
}

From source file:com.laex.cg2d.render.impl.ScreenManagerImpl.java

License:Open Source License

@Override
public void drawText(String text, float x, float y) {
    BitmapFont font = new BitmapFont();
    spriteBatch.begin();//from   www  . ja  v  a2  s .  c  om
    font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    font.setScale(0.1f);
    font.draw(spriteBatch, text, x, y);
    spriteBatch.end();
}

From source file:com.sawan.mathattack.utils.UtilsAssets.java

License:Open Source License

/**
 * Load a font. Input file path without format type. Works only with ".png"
 * and ".fnt". (Leave filter null if no filter needed).
 * <p>/*from w w  w . j  a v  a2 s.  c  o  m*/
 * 
 * EXAMPLE:</br> User input for file: "data/font" </br> Auto fill will
 * perform "font.png" and "font.fnt" for user.
 *
 * @param file the file
 * @param flip the flip
 * @param filter the filter
 * @return the bitmap font
 */
public static BitmapFont loadFont(String file, boolean flip, Filter filter) {
    BitmapFont f = new BitmapFont(Gdx.files.internal(file + ".fnt"), Gdx.files.internal(file + ".png"), flip);
    if (filter != null)
        addFilter(f.getRegion().getTexture(), filter);
    return f;
}

From source file:it.alcacoop.backgammon.actors.Board.java

License:Open Source License

public Board() {

    jp = new JSONProperties(Gdx.files.internal("data/" + GnuBackgammon.Instance.getResName() + "/pos.json"));
    _board = new int[2][25];

    moves = new Stack<Move>();
    playedMoves = new Stack<Move>();
    availableMoves = new AvailableMoves(this);
    checkers = new Checker[2][15]; // [0]=WHITE [1]=BLACK

    board = new BoardImage(0, 0);

    TextureRegion r1 = GnuBackgammon.atlas.findRegion("boardbg");
    boardbg = new Image(r1);
    boardbg.setX(0);/*from  w  w w.jav  a2  s .  co  m*/
    boardbg.setY(0);
    addActor(boardbg);

    pos = new Vector2[25];
    for (int i = 0; i < 24; i++) {
        pos[i] = new Vector2();
        pos[i].x = board.getX() + GnuBackgammon.Instance.jp.asFloat("pos" + i, 0)
                + GnuBackgammon.Instance.jp.asFloat("pos", 0) / 2;
        if (i < 12)
            pos[i].y = board.getY() + GnuBackgammon.Instance.jp.asFloat("down", 0);
        else
            pos[i].y = board.getY() + GnuBackgammon.Instance.jp.asFloat("up", 0);
    }
    pos[24] = new Vector2(); // HITTED
    pos[24].x = board.getX() + GnuBackgammon.Instance.jp.asFloat("pos24", 0)
            + GnuBackgammon.Instance.jp.asFloat("pos", 0);
    pos[24].y = board.getY();

    for (int i = 0; i < 15; i++) {
        checkers[0][i] = new Checker(this, 0); // BLACK
        checkers[1][i] = new Checker(this, 1); // WHITE
    }

    points = new Points(this);
    addActor(points);
    addActor(board);

    for (int i = 0; i < 15; i++) {
        addActor(checkers[0][i]);
        addActor(checkers[1][i]);
    }

    dices = new Dices(this);
    addActor(dices);

    thinking = new Label("... Thinking ...", GnuBackgammon.skin);
    thinking.setX(getX() + (boardbg.getWidth() - thinking.getWidth()) / 2);
    thinking.setY(getY() + (boardbg.getHeight() - thinking.getHeight()) / 2);
    thinking.addAction(Actions.forever(Actions.sequence(Actions.alpha(0.7f, 0.4f), Actions.alpha(1, 0.5f))));
    thinking.setVisible(false);
    addActor(thinking);

    waiting = new Label("... Wait ...", GnuBackgammon.skin);
    waiting.setX(getX() + (boardbg.getWidth() - waiting.getWidth()) / 2);
    waiting.setY(getY() + (boardbg.getHeight() - waiting.getHeight()) / 2);
    waiting.addAction(Actions.forever(Actions.sequence(Actions.alpha(0.7f, 0.4f), Actions.alpha(1, 0.5f))));
    waiting.setVisible(false);
    addActor(waiting);

    larrow = new Image(GnuBackgammon.atlas.findRegion("larrow"));
    rarrow = new Image(GnuBackgammon.atlas.findRegion("rarrow"));
    larrow.setVisible(false);
    rarrow.setVisible(false);
    addActor(larrow);
    addActor(rarrow);

    TextButtonStyle ts = GnuBackgammon.skin.get("button", TextButtonStyle.class);
    rollBtn = new TextButton("Roll", ts);
    rollBtn.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Board.this.rollBtn.remove();
            Board.this.doubleBtn.remove();
            if (MatchState.matchType < 2)
                if (!GnuBackgammon.Instance.optionPrefs.getString("DICESG", "MER-TWS").equals("Manual")) {
                    Board.this.rollDices();
                } else {
                    UIDialog.getDicesDialog(false);
                }
            else
                GnuBackgammon.fsm.processEvent(Events.ROLL_DICE, null);
        }
    });
    rollBtn.setWidth(boardbg.getWidth() / 5);
    rollBtn.setHeight(boardbg.getHeight() / 9);
    rollBtn.setX(board.getX() + GnuBackgammon.Instance.jp.asFloat("dice0", 0) - rollBtn.getWidth() / 2);
    rollBtn.setY(board.getY() + boardbg.getHeight() / 2 - rollBtn.getHeight() / 2);

    doubleBtn = new TextButton("Double", ts);
    doubleBtn.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Board.this.doubleBtn.remove();
            if (GnuBackgammon.fsm instanceof GameFSM)
                GnuBackgammon.fsm.state(GameFSM.States.DIALOG_HANDLER);
            else if (GnuBackgammon.fsm instanceof GServiceFSM)
                GnuBackgammon.fsm.state(GServiceFSM.States.DIALOG_HANDLER);
            GnuBackgammon.fsm.processEvent(Events.DOUBLE_REQUEST, null);
        }
    });
    doubleBtn.setWidth(boardbg.getWidth() / 5);
    doubleBtn.setHeight(boardbg.getHeight() / 9);
    doubleBtn.setX(board.getX() + jp.asFloat("dice1", 0) - doubleBtn.getWidth() / 2);
    doubleBtn.setY(board.getY() + boardbg.getHeight() / 2 - doubleBtn.getHeight() / 2);

    doublingCube = new DoublingCube(this);
    addActor(doublingCube);

    ns = new Label[24];
    BitmapFont f = GnuBackgammon.skin.getFont("alternate-font");
    f.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
    LabelStyle stl = new LabelStyle(f, Color.WHITE);
    for (int i = 0; i < 24; i++)
        ns[i] = new Label((i + 1) + "", stl);
}

From source file:it.alcacoop.backgammon.GnuBackgammon.java

License:Open Source License

public void initAssets() {
    Gdx.graphics.setContinuousRendering(false);
    Gdx.graphics.requestRendering();/*w  w w. ja v a2 s. c  o m*/

    atlas = new TextureAtlas(Gdx.files.internal("data/" + resname[ss] + "/pack.atlas"));

    fibsPlayersPool = new Pool<Player>(50) {
        @Override
        protected Player newObject() {
            return new Player();
        }
    };

    snd = new SoundManager();
    rec = new MatchRecorder();

    fibs = new FibsNetHandler();

    commandDispatcher = new CommandDispatcherImpl();

    fname = nativeFunctions.getDataDir() + "/data/match.";

    GnuBackgammon.Instance.jp = new JSONProperties(
            Gdx.files.internal("data/" + GnuBackgammon.Instance.getResName() + "/pos.json"));
    skin = new Skin(Gdx.files.internal("data/" + resname[ss] + "/myskin.json"));
    font = new BitmapFont(Gdx.files.internal("data/" + resname[ss] + "/checker.fnt"), false);
    TextureRegion r = font.getRegion();
    r.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    BitmapFont f = skin.getFont("default-font");
    f.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);

    GnuBackgammon.atlas.addRegion("board", atlas.findRegion("B1"));
    GnuBackgammon.atlas.addRegion("boardbg", atlas.findRegion("B1-BG"));
    GnuBackgammon.atlas.addRegion("cb", atlas.findRegion("CS1-B"));
    GnuBackgammon.atlas.addRegion("cw", atlas.findRegion("CS1-W"));
    GnuBackgammon.atlas.addRegion("ch", atlas.findRegion("CS1-H"));

    board = new Board();

    gameFSM = new GameFSM(board);
    simulationFSM = new SimulationFSM(board);
    menuFSM = new MenuFSM(board);
    fibsFSM = new FIBSFSM(board);
    gserviceFSM = new GServiceFSM(board);
    oldGserviceFSM = new OldGServiceFSM(board);

    fsm = simulationFSM;

    gameScreen = new GameScreen();
    matchOptionsScreen = new MatchOptionsScreen();
    menuScreen = new MainMenuScreen();
    twoplayersScreen = new TwoPlayersScreen();
    optionsScreen = new OptionsScreen();
    welcomeScreen = new WelcomeScreen();
    appearanceScreen = new AppearanceScreen();
    fibsScreen = new FibsScreen();
    generalStatsScreen = new GeneralStatsScreen();
    diceStatsScreen = new DiceStatsScreen();

    nativeFunctions.injectBGInstance();
}