Search in sources :

Example 66 with BitmapFont

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

the class SelectBox method draw.

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();
    Drawable background;
    if (disabled && style.backgroundDisabled != null)
        background = style.backgroundDisabled;
    else if (selectBoxList.hasParent() && style.backgroundOpen != null)
        background = style.backgroundOpen;
    else if (clickListener.isOver() && style.backgroundOver != null)
        background = style.backgroundOver;
    else if (style.background != null)
        background = style.background;
    else
        background = null;
    final BitmapFont font = style.font;
    final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : style.fontColor;
    Color color = getColor();
    float x = getX();
    float y = getY();
    float width = getWidth();
    float height = getHeight();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    if (background != null)
        background.draw(batch, x, y, width, height);
    T selected = selection.first();
    if (selected != null) {
        String string = toString(selected);
        if (background != null) {
            width -= background.getLeftWidth() + background.getRightWidth();
            height -= background.getBottomHeight() + background.getTopHeight();
            x += background.getLeftWidth();
            y += (int) (height / 2 + background.getBottomHeight() + font.getData().capHeight / 2);
        } else {
            y += (int) (height / 2 + font.getData().capHeight / 2);
        }
        font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
        layout.setText(font, string, 0, string.length(), font.getColor(), width, Align.left, false, "...");
        font.draw(batch, layout, x, y);
    }
}
Also used : Color(com.badlogic.gdx.graphics.Color) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 67 with BitmapFont

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

the class Lwjgl3DebugStarter method main.

public static void main(String[] argv) throws NoSuchFieldException, SecurityException, ClassNotFoundException {
    GdxTest test = new GdxTest() {

        float r = 0;

        SpriteBatch batch;

        BitmapFont font;

        FPSLogger fps = new FPSLogger();

        Texture texture;

        @Override
        public void create() {
            BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR);
            texture = new Texture("data/badlogic.jpg");
            batch = new SpriteBatch();
            font = new BitmapFont();
            Gdx.input.setInputProcessor(new InputAdapter() {

                @Override
                public boolean keyDown(int keycode) {
                    System.out.println("Key down: " + Keys.toString(keycode));
                    return false;
                }

                @Override
                public boolean keyUp(int keycode) {
                    System.out.println("Key up: " + Keys.toString(keycode));
                    return false;
                }

                @Override
                public boolean keyTyped(char character) {
                    System.out.println("Key typed: '" + character + "', " + (int) character);
                    if (character == 'f') {
                        Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
                    //							DisplayMode[] modes = Gdx.graphics.getDisplayModes();
                    //							for(DisplayMode mode: modes) {
                    //								if(mode.width == 1920 && mode.height == 1080) {
                    //									Gdx.graphics.setFullscreenMode(mode);
                    //									break;
                    //								}
                    //							}
                    }
                    if (character == 'w') {
                        Gdx.graphics.setWindowedMode(MathUtils.random(400, 800), MathUtils.random(400, 800));
                    }
                    if (character == 'e') {
                        throw new GdxRuntimeException("derp");
                    }
                    if (character == 'c') {
                        Gdx.input.setCursorCatched(!Gdx.input.isCursorCatched());
                    }
                    Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();
                    if (character == 'v') {
                        window.setVisible(false);
                    }
                    if (character == 's') {
                        window.setVisible(true);
                    }
                    if (character == 'q') {
                        window.closeWindow();
                    }
                    if (character == 'i') {
                        window.iconifyWindow();
                    }
                    if (character == 'm') {
                        window.maximizeWindow();
                    }
                    if (character == 'r') {
                        window.restoreWindow();
                    }
                    if (character == 'u') {
                        Gdx.net.openURI("https://google.com");
                    }
                    return false;
                }
            });
        }

        long start = System.nanoTime();

        @Override
        public void render() {
            Gdx.gl.glClearColor(1, 0, 0, 1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            HdpiUtils.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            batch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            batch.begin();
            font.draw(batch, Gdx.graphics.getWidth() + "x" + Gdx.graphics.getHeight() + ", " + Gdx.graphics.getBackBufferWidth() + "x" + Gdx.graphics.getBackBufferHeight() + ", " + Gdx.input.getX() + ", " + Gdx.input.getY() + ", " + Gdx.input.getDeltaX() + ", " + Gdx.input.getDeltaY(), 0, 20);
            batch.draw(texture, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY());
            batch.end();
            fps.log();
        }

        @Override
        public void resize(int width, int height) {
            Gdx.app.log("Test", "Resized " + width + "x" + height);
        }

        @Override
        public void resume() {
            Gdx.app.log("Test", "resuming");
        }

        @Override
        public void pause() {
            Gdx.app.log("Test", "pausing");
        }

        @Override
        public void dispose() {
            Gdx.app.log("Test", "disposing");
        }
    };
    Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
    config.setWindowedMode(640, 480);
    config.setWindowListener(new Lwjgl3WindowListener() {

        @Override
        public void iconified(boolean isIconified) {
            Gdx.app.log("Window", "iconified: " + (isIconified ? "true" : "false"));
        }

        @Override
        public void maximized(boolean isMaximized) {
            Gdx.app.log("Window", "maximized: " + (isMaximized ? "true" : "false"));
        }

        @Override
        public void focusLost() {
            Gdx.app.log("Window", "focus lost");
        }

        @Override
        public void focusGained() {
            Gdx.app.log("Window", "focus gained");
        }

        @Override
        public boolean closeRequested() {
            Gdx.app.log("Window", "closing");
            return false;
        }

        @Override
        public void filesDropped(String[] files) {
            for (String file : files) {
                Gdx.app.log("Window", "File dropped: " + file);
            }
        }

        @Override
        public void refreshRequested() {
            Gdx.app.log("Window", "refreshRequested");
        }
    });
    for (DisplayMode mode : Lwjgl3ApplicationConfiguration.getDisplayModes()) {
        System.out.println(mode.width + "x" + mode.height);
    }
    System.setProperty("java.awt.headless", "true");
    new Lwjgl3Application(test, config);
}
Also used : InputAdapter(com.badlogic.gdx.InputAdapter) Lwjgl3Application(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application) GdxTest(com.badlogic.gdx.tests.utils.GdxTest) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) BufferedImage(java.awt.image.BufferedImage) Lwjgl3ApplicationConfiguration(com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration) FPSLogger(com.badlogic.gdx.graphics.FPSLogger) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) DisplayMode(com.badlogic.gdx.Graphics.DisplayMode) Lwjgl3Window(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window) Lwjgl3WindowListener(com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 68 with BitmapFont

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

the class MatrixTest method create.

@Override
public void create() {
    font = new BitmapFont();
    batch = new SpriteBatch();
    Matrix4 m1 = new Matrix4();
    Matrix4 m2 = new Matrix4();
    float[] a1 = new float[16];
    float[] a2 = new float[16];
    float[] a3 = new float[16];
    Matrix.setIdentityM(a1, 0);
    Matrix.setIdentityM(a2, 0);
    Matrix.setIdentityM(a3, 0);
    long startTime = System.nanoTime();
    int ops = 0;
    while (System.nanoTime() - startTime < 5000000000l) {
        Matrix.multiplyMM(a1, 0, a2, 0, a3, 0);
        ops++;
    }
    results = "Matrix ops: " + ops + "\n";
    // warm up
    startTime = System.nanoTime();
    ops = 0;
    while (System.nanoTime() - startTime < 2000000000l) {
        m1.mul(m2);
        ops++;
    }
    startTime = System.nanoTime();
    ops = 0;
    while (System.nanoTime() - startTime < 5000000000l) {
        m1.mul(m2);
        ops++;
    }
    results += "Matrix4 ops: " + ops + "\n";
}
Also used : BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 69 with BitmapFont

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

the class BitmapFontDistanceFieldTest method create.

@Override
public void create() {
    camera = new OrthographicCamera();
    spriteBatch = new SpriteBatch();
    descriptionFont = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true);
    descriptionFont.setColor(Color.RED);
    regularTexture = new Texture(Gdx.files.internal("data/verdana39.png"), true);
    regularFont = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), new TextureRegion(regularTexture), true);
    regularFont.setColor(COLOR);
    distanceFieldTexture = new Texture(Gdx.files.internal("data/verdana39distancefield.png"), true);
    distanceFieldFont = new BitmapFont(Gdx.files.internal("data/verdana39distancefield.fnt"), new TextureRegion(distanceFieldTexture), true);
    distanceFieldFont.setColor(COLOR);
    distanceFieldShader = new DistanceFieldShader();
    // Useful when debugging this test
    ShaderProgram.pedantic = false;
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture)

Example 70 with BitmapFont

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

the class BitmapFontTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    // font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false);
    font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false);
    // font = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf")).generateFont(new FreeTypeFontParameter());
    font.getData().markupEnabled = true;
    font.getData().breakChars = new char[] { '-' };
    multiPageFont = new BitmapFont(Gdx.files.internal("data/multipagefont.fnt"));
    // Add user defined color
    Colors.put("PERU", Color.valueOf("CD853F"));
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
    stage = new Stage(new ScreenViewport());
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    BitmapFont labelFont = skin.get("default-font", BitmapFont.class);
    labelFont.getData().markupEnabled = true;
    // Notice that the last [] has been deliberately added to test the effect of excessive pop operations.
    // They are silently ignored, as expected.
    label = new Label("<<[BLUE]M[RED]u[YELLOW]l[GREEN]t[OLIVE]ic[]o[]l[]o[]r[]*[MAROON]Label[][] [Unknown Color]>>", skin);
    label.setPosition(100, 200);
    stage.addActor(label);
    Window window = new Window("[RED]Multicolor[GREEN] Title", skin);
    window.setPosition(400, 300);
    window.pack();
    stage.addActor(window);
    layout = new GlyphLayout();
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Aggregations

BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)104 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)64 Texture (com.badlogic.gdx.graphics.Texture)31 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)21 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)16 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)13 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)12 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)11 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)10 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)10 AssetManager (com.badlogic.gdx.assets.AssetManager)9 Color (com.badlogic.gdx.graphics.Color)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 InputAdapter (com.badlogic.gdx.InputAdapter)7 Actor (com.badlogic.gdx.scenes.scene2d.Actor)7 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 Pixmap (com.badlogic.gdx.graphics.Pixmap)6 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)6