Search in sources :

Example 1 with BitmapFontCache

use of com.badlogic.gdx.graphics.g2d.BitmapFontCache in project libgdx by libgdx.

the class BitmapFontTest method render.

@Override
public void render() {
    // red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1;
    int viewHeight = Gdx.graphics.getHeight();
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    // Test wrapping or truncation with the font directly.
    if (!true) {
        // BitmapFont font = label.getStyle().font;
        BitmapFont font = this.font;
        font.getRegion().getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
        font.getData().setScale(2f);
        renderer.begin(ShapeRenderer.ShapeType.Line);
        renderer.setColor(0, 1, 0, 1);
        float w = Gdx.input.getX();
        // w = 855;
        renderer.rect(10, 10, w, 500);
        renderer.end();
        spriteBatch.begin();
        String text = "your new";
        text = "How quickly [RED]daft jumping zebras vex.";
        // text = "Another font wrap is-sue, this time with    multiple whitespace characters.";
        text = "test with AGWlWi      AGWlWi issue";
        if (true) {
            // Test wrap.
            layout.setText(font, text, 0, text.length(), font.getColor(), w, Align.center, true, null);
        } else {
            // Test truncation.
            layout.setText(font, text, 0, text.length(), font.getColor(), w, Align.center, false, "...");
        }
        float meowy = (500 / 2 + layout.height / 2 + 5);
        font.draw(spriteBatch, layout, 10, 10 + meowy);
        spriteBatch.end();
        renderer.begin(ShapeRenderer.ShapeType.Line);
        renderer.setColor(0, 1, 0, 1);
        for (int i = 0, n = layout.runs.size; i < n; i++) {
            GlyphRun r = layout.runs.get(i);
            renderer.rect(10 + r.x, 10 + meowy + r.y, r.width, -font.getLineHeight());
        }
        renderer.end();
        font.getData().setScale(1f);
        return;
    }
    // Test wrapping with label.
    if (false) {
        label.debug();
        label.getStyle().font = font;
        label.setStyle(label.getStyle());
        label.setText("How quickly [RED]daft[] jumping zebras vex.");
        label.setWrap(true);
        //			label.setEllipsis(true);
        label.setAlignment(Align.center, Align.right);
        label.setWidth(Gdx.input.getX() - label.getX());
        label.setHeight(label.getPrefHeight());
    } else {
        // Test various font features.
        spriteBatch.begin();
        String text = "Sphinx of black quartz, judge my vow.";
        font.setColor(Color.RED);
        float x = 100, y = 20;
        float alignmentWidth;
        if (false) {
            alignmentWidth = 0;
            font.draw(spriteBatch, text, x, viewHeight - y, alignmentWidth, Align.right, false);
        }
        if (true) {
            alignmentWidth = 280;
            font.draw(spriteBatch, text, x, viewHeight - y, alignmentWidth, Align.right, true);
        }
        font.draw(spriteBatch, "[", 50, 60, 100, Align.left, true);
        font.getData().markupEnabled = true;
        font.draw(spriteBatch, "[", 100, 60, 100, Align.left, true);
        font.getData().markupEnabled = false;
        // 'R' and 'p' are in different pages
        String txt2 = "this font uses " + multiPageFont.getRegions().size + " texture pages: RpRpRpRpRpNM";
        spriteBatch.renderCalls = 0;
        // regular draw function
        multiPageFont.setColor(Color.BLUE);
        multiPageFont.draw(spriteBatch, txt2, 10, 100);
        // expert usage.. drawing with bitmap font cache
        BitmapFontCache cache = multiPageFont.getCache();
        cache.clear();
        cache.setColor(Color.BLACK);
        cache.setText(txt2, 10, 50);
        cache.setColors(Color.PINK, 3, 6);
        cache.setColors(Color.ORANGE, 9, 12);
        cache.setColors(Color.GREEN, 16, txt2.length());
        cache.draw(spriteBatch, 5, txt2.length() - 5);
        cache.clear();
        cache.setColor(Color.BLACK);
        float textX = 10;
        textX += cache.setText("[black] ", textX, 150).width;
        multiPageFont.getData().markupEnabled = true;
        textX += cache.addText("[[[PINK]pink[]] ", textX, 150).width;
        textX += cache.addText("[PERU][[peru] ", textX, 150).width;
        cache.setColor(Color.GREEN);
        textX += cache.addText("green ", textX, 150).width;
        textX += cache.addText("[#A52A2A]br[#A52A2ADF]ow[#A52A2ABF]n f[#A52A2A9F]ad[#A52A2A7F]in[#A52A2A5F]g o[#A52A2A3F]ut ", textX, 150).width;
        multiPageFont.getData().markupEnabled = false;
        cache.draw(spriteBatch);
        // tinting
        cache.tint(new Color(1f, 1f, 1f, 0.3f));
        cache.translate(0f, 40f);
        cache.draw(spriteBatch);
        spriteBatch.end();
        // System.out.println(spriteBatch.renderCalls);
        renderer.begin(ShapeType.Line);
        renderer.setColor(Color.BLACK);
        renderer.rect(x, viewHeight - y - 200, alignmentWidth, 200);
        renderer.end();
    }
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();
}
Also used : GlyphRun(com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun) Color(com.badlogic.gdx.graphics.Color) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache)

Example 2 with BitmapFontCache

use of com.badlogic.gdx.graphics.g2d.BitmapFontCache in project libgdx by libgdx.

the class IntegerBitmapFontTest method create.

public void create() {
    TextureAtlas textureAtlas = new TextureAtlas("data/pack");
    font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), textureAtlas.findRegion("verdana39"), false);
    singleLineCache = new BitmapFontCache(font, true);
    multiLineCache = new BitmapFontCache(font, true);
    singleLineCacheNonInteger = new BitmapFontCache(font, false);
    multiLineCacheNonInteger = new BitmapFontCache(font, false);
    batch = new SpriteBatch();
    fillCaches();
}
Also used : TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache)

Example 3 with BitmapFontCache

use of com.badlogic.gdx.graphics.g2d.BitmapFontCache in project Alkahest-Coffee by AlkahestDev.

the class CoffeeServer method render.

@Override
public void render() {
    for (BitmapFontCache bmfc : fonts) {
        bmfc.clear();
    }
    switch(svState) {
        case LOADING:
            if (Gdx.input.getInputProcessor() != loadingMenu) {
                loadingMenu.setInputProcessor();
            }
            if (loadingMenu.doneLoading()) {
                svState = ServerState.SERVERCONFIG;
                askConfig = createServerForm();
                serverInfo.init();
                serverRunningMenu.init();
            }
            loadingMenu.update();
            loadingMenu.draw(batch, shapeRenderer);
            break;
        case SERVERCONFIG:
            if (Gdx.input.getInputProcessor() != askConfig) {
                askConfig.setInputProcessor();
            }
            askConfig.update();
            askConfig.draw(batch, shapeRenderer);
            break;
        case GAMELOBBY:
            if (Gdx.input.getInputProcessor() != serverInfo) {
                serverInfo.setInputProcessor();
            }
            serverInfo.update(sv, redTeamMembers.size(), bluTeamMembers.size(), sv.getMaxPlayers());
            serverInfo.draw(batch, shapeRenderer);
            break;
        case RUNNINGGAME:
            if (Gdx.input.getInputProcessor() != serverRunningMenu) {
                serverRunningMenu.setInputProcessor();
                instance = new ServerGameInstance(sv.getPlayers());
                instance.setWorldMap(new WorldMap(MenuTools.mGTR("pixmapTest.png", manager), MenuTools.mGTR("pixmapVisual.png", manager)));
            //instance.world.setCollisionBoxes(Gdx.files.internal("pixmapTest.png"));
            }
            instance.update(sv);
            serverRunningMenu.updateMenuInfo(sv);
            serverRunningMenu.update();
            serverRunningMenu.draw(batch, shapeRenderer);
            break;
    }
}
Also used : WorldMap(me.dumfing.multiplayerTools.WorldMap) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache)

Example 4 with BitmapFontCache

use of com.badlogic.gdx.graphics.g2d.BitmapFontCache in project Alkahest-Coffee by AlkahestDev.

the class MainGame method create.

@Override
public void create() {
    Gdx.graphics.setCursor(Gdx.graphics.newCursor(new Pixmap(Gdx.files.internal("mouseCursorTemp.png")), 0, 0));
    assetManager = new AssetManager();
    queueLoading();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.translate(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    camera.update();
    //viewport = new FitViewport(1920, 1080, camera);
    fontCaches = new Array<BitmapFontCache>();
    BitmapFont dagger20 = new BitmapFont(Gdx.files.internal("fonts/dagger20.fnt"));
    BitmapFont dagger30 = new BitmapFont(Gdx.files.internal("fonts/dagger30.fnt"));
    BitmapFont dagger40 = new BitmapFont(Gdx.files.internal("fonts/dagger40.fnt"));
    BitmapFont dagger50 = new BitmapFont(Gdx.files.internal("fonts/dagger50.fnt"));
    dagger20.getData().markupEnabled = true;
    dagger30.getData().markupEnabled = true;
    dagger40.getData().markupEnabled = true;
    dagger50.getData().markupEnabled = true;
    fontCaches.add(new BitmapFontCache(dagger20));
    fontCaches.add(new BitmapFontCache(dagger30));
    fontCaches.add(new BitmapFontCache(dagger40));
    fontCaches.add(new BitmapFontCache(dagger50));
    shapeRenderer = new ShapeRenderer();
    gameMain = new MainMenu(fontCaches, assetManager, camera);
    loadingMenu = new LoadingMenu(fontCaches, assetManager, camera);
    connectingMenu = new ConnectingMenu(fontCaches, assetManager, camera);
    serverBrowser = new ServerBrowser(fontCaches, assetManager, camera);
    settingsMenu = new SettingsMenu(fontCaches, assetManager, camera);
    pickingInfoMenu = new ClientPickingInfoMenu(fontCaches, assetManager, camera);
    lobbyMenu = new ClientLobbyMenu(fontCaches, assetManager, camera);
    // loadingmenu is the only one that is setup before anything else is loaded, background frames are loaded and added to it here
    setupLoadingMenu();
    scW = Gdx.graphics.getWidth();
    scH = Gdx.graphics.getHeight();
    //System.out.println(new Pixmap(Gdx.files.internal("pixmapTest.png")).getPixel(0,0)>>8);//since gimp doesn't do alpha in a friendly way, I'll bitshift right 8 bits to ignore alpha
    state = GameState.State.LOADINGGAME;
    batch = new SpriteBatch();
    client = new MultiplayerClient();
    clientSoldier = new PlayerSoldier(new Rectangle(0, 0, 1, 2), 0, "");
    client.startClient();
    shapeRenderer.setProjectionMatrix(camera.combined);
    batch.setProjectionMatrix(camera.combined);
    menu = new UniversalClientMenu(fontCaches, assetManager, camera);
    Gdx.input.setInputProcessor(this);
}
Also used : MultiplayerClient(me.dumfing.multiplayerTools.MultiplayerClient) AssetManager(com.badlogic.gdx.assets.AssetManager) Rectangle(com.badlogic.gdx.math.Rectangle) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 5 with BitmapFontCache

use of com.badlogic.gdx.graphics.g2d.BitmapFontCache in project Alkahest-Coffee by AlkahestDev.

the class MainGame method render.

@Override
public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    for (BitmapFontCache bmfc : fontCaches) {
        // clear bitmap font cache because it doesn't clear itself upon drawing (grumble grumble)
        bmfc.clear();
    }
    if (state == GameState.State.PLAYINGGAME) {
        if (!zoomedIn) {
            System.out.println("CameraZoom " + camera.zoom);
            System.out.println("zoomin");
            zoomCamera(0.025f);
            zoomedIn = true;
        }
    } else {
        if (zoomedIn) {
            camera.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0);
            zoomCamera(1);
            //camera.update();
            //shapeRenderer.setProjectionMatrix(camera.combined);
            //batch.setProjectionMatrix(camera.combined);
            zoomedIn = false;
        }
    }
    switch(state) {
        case // we shouldn't ever be going back to LOADINGGAME
        LOADINGGAME:
            //LOADINGGAME just needs to call assetManager.update(), then assign the values
            loadingMenu.update();
            loadingMenu.draw(batch, shapeRenderer);
            if (loadingMenu.doneLoading()) {
                // returns true if done loading
                //assets are assigned to variables here
                assignValues();
                gameMain.init();
                serverBrowser.init();
                settingsMenu.init();
                connectingMenu.init();
                pickingInfoMenu.init(client);
                lobbyMenu.init(client);
                menu.init();
                createWorlds();
                client.pingServers();
            }
            break;
        case MAINMENU:
            if (Gdx.input.getInputProcessor() != gameMain) {
                gameMain.setInputProcessor();
            }
            /*
				if(Gdx.input.getInputProcessor() != menu ){
					menu.setInputProcessor();
				}
				menu.update();
				menu.standardDraw(batch,shapeRenderer);*/
            gameMain.update();
            gameMain.standardDraw(batch, shapeRenderer);
            break;
        case MAINMENUSETTINGS:
            if (Gdx.input.getInputProcessor() != settingsMenu) {
                settingsMenu.setInputProcessor();
            }
            settingsMenu.update();
            settingsMenu.standardDraw(batch, shapeRenderer);
            break;
        case SERVERBROWSER:
            if (Gdx.input.getInputProcessor() != serverBrowser) {
                serverBrowser.setInputProcessor();
                System.out.println("RUN!");
            }
            serverBrowser.update();
            serverBrowser.draw(batch, shapeRenderer);
            break;
        case STARTSERVER:
            break;
        case CONNECTINGTOSERVER:
            connectingMenu.update();
            connectingMenu.standardDraw(batch, shapeRenderer);
            break;
        case GAMELOBBY:
            if (Gdx.input.getInputProcessor() != lobbyMenu) {
                lobbyMenu.setInputProcessor();
            }
            lobbyMenu.update(client);
            lobbyMenu.draw(batch, shapeRenderer);
            break;
        case PICKINGINFO:
            if (Gdx.input.getInputProcessor() != pickingInfoMenu) {
                pickingInfoMenu.setInputProcessor();
            }
            pickingInfoMenu.updateTeamNumbers(client.getRedTeam(), client.getBlueTeam(), client.getrLimit(), client.getbLimit());
            pickingInfoMenu.update();
            pickingInfoMenu.standardDraw(batch, shapeRenderer);
            break;
        case PLAYINGGAME:
            //camera.setToOrtho(true,900,450);
            if (Gdx.input.getInputProcessor() != gameInstance) {
                gameInstance = new ClientGameInstance(client, client.getPlayers(), camera);
                gameInstance.pickWorld(DEBUGWORLD);
                Gdx.input.setInputProcessor(gameInstance);
            }
            gameInstance.update();
            shapeRenderer.setColor(Color.BLUE);
            PlayerSoldier clientSoldierTemp = gameInstance.getPlayer(client.getConnectionID());
            //System.out.println("before "+clientSoldierTemp.getX());
            float deltaX = camera.position.x - clientSoldierTemp.getX();
            float deltaY = camera.position.y - clientSoldierTemp.getY();
            if (deltaX < -3) {
                //camera.position.x = clientSoldierTemp.getX()-5;
                if (Math.abs(deltaX) < 6) {
                    camera.position.x = clientSoldierTemp.getX() - 3;
                } else {
                    camera.position.x += Math.abs(deltaX) / 5f;
                }
            } else if (deltaX > 3) {
                //camera.position.x = clientSoldierTemp.getX()+5;//-=Math.abs(deltaX)/5f;
                if (Math.abs(deltaX) < 6) {
                    camera.position.x = clientSoldierTemp.getX() + 3;
                } else {
                    camera.position.x -= Math.abs(deltaX / 5f);
                }
            }
            if (deltaY < -3f) {
                //Math.min(Math.abs(deltaY)/5f,Math.abs(deltaY));
                camera.position.y += Math.abs(deltaY) / 5f;
            } else if (deltaY > 3f) {
                //Math.min(Math.abs(deltaY)/5f,Math.abs(deltaY));
                camera.position.y -= Math.abs(deltaY) / 5f;
            }
            //camera.position.x = clientSoldierTemp.getX();
            //System.out.println("camera update");
            //System.out.println(camera.position.x-clientSoldierTemp.getX()+" "+deltaX);
            camera.update();
            shapeRenderer.setProjectionMatrix(camera.combined);
            batch.setProjectionMatrix(camera.combined);
            gameInstance.draw(batch, shapeRenderer);
            //System.out.println("after "+clientSoldierTemp.getX());
            break;
        case ROUNDOVER:
            break;
        case QUIT:
            Gdx.app.exit();
            break;
    }
}
Also used : PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache)

Aggregations

BitmapFontCache (com.badlogic.gdx.graphics.g2d.BitmapFontCache)6 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 AssetManager (com.badlogic.gdx.assets.AssetManager)2 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)2 PlayerSoldier (me.dumfing.multiplayerTools.PlayerSoldier)2 Color (com.badlogic.gdx.graphics.Color)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 GlyphRun (com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Rectangle (com.badlogic.gdx.math.Rectangle)1 LoadingMenu (me.dumfing.menus.LoadingMenu)1 ServerInfoMenu (me.dumfing.menus.ServerInfoMenu)1 ServerRunningGameMenu (me.dumfing.menus.ServerRunningGameMenu)1 MultiplayerClient (me.dumfing.multiplayerTools.MultiplayerClient)1 WorldMap (me.dumfing.multiplayerTools.WorldMap)1