Search in sources :

Example 11 with BitmapFontData

use of com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData in project skin-composer by raeleus.

the class DialogFonts method refreshTable.

public void refreshTable() {
    fontsTable.clear();
    fontsTable.defaults().growX().pad(5.0f);
    if (fonts.size == 0 && freeTypeFonts.size == 0) {
        fontsTable.add(new Label("No fonts have been set!", getSkin()));
    } else {
        if (fonts.size > 0) {
            Label label = new Label("Bitmap Fonts", getSkin(), "required");
            label.setAlignment(Align.center);
            fontsTable.add(label);
            fontsTable.row();
        }
        for (FontData font : fonts) {
            Button button = new Button(getSkin(), "color-base");
            Label label = new Label(font.getName(), getSkin());
            label.setTouchable(Touchable.disabled);
            button.add(label).left();
            button.addListener(main.getHandListener());
            Button renameButton = new Button(getSkin(), "settings-small");
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameDialog(font);
                    event.setBubbles(false);
                }
            });
            renameButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(renameButton).padLeft(15.0f);
            TextTooltip toolTip = new TextTooltip("Rename Font", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            LabelStyle style = new LabelStyle();
            style.font = fontMap.get(font);
            style.fontColor = Color.WHITE;
            label = new Label("Lorem Ipsum", style);
            label.setAlignment(Align.center);
            label.setTouchable(Touchable.disabled);
            Table bg = new Table(getSkin());
            bg.setBackground("white");
            BitmapFontData bf = new BitmapFontData(font.file, false);
            if (bf.imagePaths.length > 0) {
                FileHandle file = new FileHandle(bf.imagePaths[0]);
                if (!file.exists()) {
                    file = bf.fontFile.sibling(bf.fontFile.nameWithoutExtension() + ".png");
                }
                if (Utils.brightness(Utils.averageEdgeColor(file)) < .5f) {
                    bg.setColor(Color.WHITE);
                } else {
                    bg.setColor(Color.BLACK);
                }
            }
            bg.add(label).pad(5.0f).grow();
            button.add(bg).padLeft(15).growX();
            Button closeButton = new Button(getSkin(), "delete-small");
            final FontData deleteFont = font;
            closeButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    fonts.removeValue(deleteFont, true);
                    main.getProjectData().setChangesSaved(false);
                    BitmapFontData bitmapFontData = new BitmapFontData(deleteFont.file, false);
                    for (String path : bitmapFontData.imagePaths) {
                        FileHandle imagefile = new FileHandle(path);
                        drawables.removeValue(new DrawableData(imagefile), false);
                    }
                    for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
                        for (StyleData data : datas) {
                            for (StyleProperty property : data.properties.values()) {
                                if (property != null && property.type.equals(BitmapFont.class) && property.value != null && property.value.equals(deleteFont.getName())) {
                                    property.value = null;
                                }
                            }
                        }
                    }
                    main.getUndoableManager().clearUndoables();
                    main.getRootTable().refreshStyleProperties(true);
                    main.getRootTable().refreshPreview();
                    event.setBubbles(false);
                    refreshTable();
                }
            });
            closeButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(closeButton).padLeft(5.0f).right();
            toolTip = new TextTooltip("Delete Font", main.getTooltipManager(), getSkin());
            closeButton.addListener(toolTip);
            if (styleProperty == null && customProperty == null) {
                button.setTouchable(Touchable.childrenOnly);
            } else {
                final FontData fontResult = font;
                button.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        result(fontResult);
                        hide();
                    }
                });
            }
            fontsTable.add(button);
            fontsTable.row();
        }
        if (freeTypeFonts.size > 0) {
            Label label = new Label("FreeType Fonts", getSkin(), "required");
            label.setAlignment(Align.center);
            fontsTable.add(label).spaceTop(20.0f);
            fontsTable.row();
        }
        for (FreeTypeFontData font : freeTypeFonts) {
            Button button = new Button(getSkin(), "color-base");
            Label label = new Label(font.name, getSkin());
            label.setTouchable(Touchable.disabled);
            button.add(label).left();
            button.addListener(main.getHandListener());
            Button renameButton = new Button(getSkin(), "settings-small");
            renameButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    freeTypeSettingsDialog(font);
                    event.setBubbles(false);
                }
            });
            renameButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(renameButton).padLeft(15.0f);
            TextTooltip toolTip = new TextTooltip("Rename Font", main.getTooltipManager(), getSkin());
            renameButton.addListener(toolTip);
            LabelStyle style = new LabelStyle();
            style.font = font.bitmapFont;
            style.fontColor = Color.WHITE;
            label = new Label("Lorem Ipsum", style);
            label.setAlignment(Align.center);
            label.setTouchable(Touchable.disabled);
            Table bg = new Table(getSkin());
            bg.setBackground("white");
            bg.add(label).pad(5.0f).grow();
            button.add(bg).padLeft(15).growX();
            Button closeButton = new Button(getSkin(), "delete-small");
            final FreeTypeFontData deleteFont = font;
            closeButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    freeTypeFonts.removeValue(deleteFont, true);
                    main.getProjectData().setChangesSaved(false);
                    for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
                        for (StyleData data : datas) {
                            for (StyleProperty property : data.properties.values()) {
                                if (property != null && property.type.equals(BitmapFont.class) && property.value != null && property.value.equals(deleteFont.name)) {
                                    property.value = null;
                                }
                            }
                        }
                    }
                    main.getUndoableManager().clearUndoables();
                    main.getRootTable().refreshStyleProperties(true);
                    main.getRootTable().refreshPreview();
                    event.setBubbles(false);
                    refreshTable();
                }
            });
            closeButton.addListener(new InputListener() {

                @Override
                public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                    event.setBubbles(false);
                    return true;
                }
            });
            button.add(closeButton).padLeft(5.0f).right();
            toolTip = new TextTooltip("Delete Font", main.getTooltipManager(), getSkin());
            closeButton.addListener(toolTip);
            if (styleProperty == null && customProperty == null) {
                button.setTouchable(Touchable.childrenOnly);
            } else {
                final FreeTypeFontData fontResult = font;
                button.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                        result(fontResult);
                        hide();
                    }
                });
            }
            fontsTable.add(button);
            fontsTable.row();
        }
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) FileHandle(com.badlogic.gdx.files.FileHandle) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) Array(com.badlogic.gdx.utils.Array) StyleProperty(com.ray3k.skincomposer.data.StyleProperty) DrawableData(com.ray3k.skincomposer.data.DrawableData) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) StyleData(com.ray3k.skincomposer.data.StyleData)

Example 12 with BitmapFontData

use of com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData in project skin-composer by raeleus.

the class DialogFonts method addFont.

private boolean addFont(String name, FileHandle file) {
    if (FontData.validate(name)) {
        try {
            main.getProjectData().setChangesSaved(false);
            FontData font = new FontData(name, file);
            // remove any existing FontData that shares the same name.
            if (fonts.contains(font, false)) {
                FontData deleteFont = fonts.get(fonts.indexOf(font, false));
                BitmapFontData deleteFontData = new BitmapFontData(deleteFont.file, false);
                for (String path : deleteFontData.imagePaths) {
                    FileHandle imagefile = new FileHandle(path);
                    drawables.removeValue(new DrawableData(imagefile), false);
                }
                fonts.removeValue(font, false);
            }
            BitmapFontData bitmapFontData = new BitmapFontData(file, false);
            for (String path : bitmapFontData.imagePaths) {
                DrawableData drawable = new DrawableData(new FileHandle(path));
                drawable.visible = false;
                if (!drawables.contains(drawable, false)) {
                    main.getAtlasData().atlasCurrent = false;
                    drawables.add(drawable);
                }
            }
            produceAtlas();
            fonts.add(font);
            Array<TextureRegion> regions = new Array<>();
            for (String path : bitmapFontData.imagePaths) {
                FileHandle imageFile = new FileHandle(path);
                regions.add(atlas.findRegion(imageFile.nameWithoutExtension()));
            }
            fontMap.put(font, new BitmapFont(bitmapFontData, regions, true));
            sortBySelectedMode();
            refreshTable();
        } catch (Exception e) {
            Gdx.app.error(getClass().getName(), "Error creating font from file", e);
            main.getDialogFactory().showDialogError("Font Error...", "Error creating font from file. Check file paths.\n\nOpen log?");
        }
        return true;
    } else {
        return false;
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) DrawableData(com.ray3k.skincomposer.data.DrawableData) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) FileHandle(com.badlogic.gdx.files.FileHandle) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 13 with BitmapFontData

use of com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData in project commons-gdx by gemserk.

the class BitmapFontUtils method spacing.

public static void spacing(BitmapFont bitmapFont, CharSequence charSequence, int spacing) {
    BitmapFontData data = bitmapFont.getData();
    for (int c = 0; c < charSequence.length(); c++) {
        char charAt = charSequence.charAt(c);
        Glyph g = data.getGlyph(charAt);
        if (g == null)
            continue;
        g.xoffset += (spacing - g.xadvance) / 2;
        g.xadvance = spacing;
    }
}
Also used : BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) Glyph(com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)

Aggregations

BitmapFontData (com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData)13 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 Array (com.badlogic.gdx.utils.Array)5 FontData (com.ray3k.skincomposer.data.FontData)4 FreeTypeFontData (com.ray3k.skincomposer.data.FreeTypeFontData)4 Color (com.badlogic.gdx.graphics.Color)2 GlyphRun (com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)2 LabelStyle (com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 DrawableData (com.ray3k.skincomposer.data.DrawableData)2 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Glyph (com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)1 PixmapPacker (com.badlogic.gdx.graphics.g2d.PixmapPacker)1