Search in sources :

Example 51 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project Entitas-Java by Rubentxu.

the class SplashState method initialize.

@Override
public void initialize() {
    // Input
    Camera camera = engine.getManager(BaseSceneManager.class).getDefaultCamera();
    Batch batch = engine.getManager(BaseSceneManager.class).getBatch();
    BitmapFont font = engine.getManager(BaseGUIManager.class).getDefaultFont();
    systems.add(new DelaySystem(context.core)).add(new RendererSystem(context.core, engine.sr, camera, batch, font));
    Texture texture = assetsManager.getTexture(splash);
    context.core.createEntity().addTextureView("Pong", new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()), new Vector2(), 0, Pong.SCREEN_HEIGHT, Pong.SCREEN_WIDTH).addDelay(3);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Batch(com.badlogic.gdx.graphics.g2d.Batch) Vector2(com.badlogic.gdx.math.Vector2) BaseSceneManager(com.ilargia.games.entitas.egdx.base.managers.BaseSceneManager) BaseGUIManager(com.ilargia.games.entitas.egdx.base.managers.BaseGUIManager) RendererSystem(com.ilargia.games.entitas.systems.RendererSystem) Camera(com.badlogic.gdx.graphics.Camera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) DelaySystem(com.ilargia.games.entitas.systems.DelaySystem)

Example 52 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project Entitas-Java by Rubentxu.

the class Examples method create.

@Override
public void create() {
    engine = new ExamplesEngine();
    entitas = new Entitas();
    preferencesManager.LOG_LEVEL = LogManager.LOG_DEBUG;
    AssetManager assetsManager = new AssetManager(new TestFileHandleResolver());
    engine.addManager(new AssetsManagerGDX(assetsManager, preferencesManager));
    engine.addManager(new PhysicsManagerGDX(new Vector2(0, -9.8f)));
    engine.addManager(new GUIManagerGDX(new ScreenViewport(), new BitmapFont(), engine));
    engine.addManager(new SceneManagerGDX(engine, entitas));
    engine.addManager(new LogManagerGDX(preferencesManager));
    engine.addManager(new InputManagerGDX(entitas, engine));
    engine.addManager(preferencesManager);
    game = new ExamplesGame(engine, new EventBusGDX(new MBassador()));
    game.init();
    game.pushState(new PlatformExampleState(engine, entitas));
}
Also used : AssetManager(com.badlogic.gdx.assets.AssetManager) TestFileHandleResolver(com.examples.games.util.TestFileHandleResolver) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) MBassador(net.engio.mbassy.bus.MBassador) EventBusGDX(ilargia.egdx.impl.EventBusGDX) PlatformExampleState(com.examples.games.states.PlatformExampleState) Vector2(com.badlogic.gdx.math.Vector2) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Entitas(ilargia.egdx.logicbricks.gen.Entitas)

Example 53 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project gdx-skineditor by cobolfoo.

the class Skin method getJsonLoader.

protected Json getJsonLoader(final FileHandle skinFile) {
    final Skin skin = this;
    final Json json = new Json() {

        public <T> T readValue(Class<T> type, Class elementType, JsonValue jsonData) {
            // actual value by name.
            if (jsonData.isString() && !ClassReflection.isAssignableFrom(CharSequence.class, type))
                return get(jsonData.asString(), type);
            return super.readValue(type, elementType, jsonData);
        }
    };
    json.setTypeName(null);
    json.setUsePrototypes(false);
    json.setSerializer(Skin.class, new ReadOnlySerializer<Skin>() {

        public Skin read(Json json, JsonValue typeToValueMap, Class ignored) {
            for (JsonValue valueMap = typeToValueMap.child; valueMap != null; valueMap = valueMap.next) {
                try {
                    readNamedObjects(json, ClassReflection.forName(valueMap.name()), valueMap);
                } catch (ReflectionException ex) {
                    throw new SerializationException(ex);
                }
            }
            return skin;
        }

        private void readNamedObjects(Json json, Class type, JsonValue valueMap) {
            for (JsonValue valueEntry = valueMap.child; valueEntry != null; valueEntry = valueEntry.next) {
                Object object = json.readValue(type, valueEntry);
                if (object == null)
                    continue;
                try {
                    add(valueEntry.name(), object, type);
                } catch (Exception ex) {
                    throw new SerializationException("Error reading " + ClassReflection.getSimpleName(type) + ": " + valueEntry.name(), ex);
                }
            }
        }
    });
    json.setSerializer(BitmapFont.class, new ReadOnlySerializer<BitmapFont>() {

        public BitmapFont read(Json json, JsonValue jsonData, Class type) {
            String path = json.readValue("file", String.class, jsonData);
            int scaledSize = json.readValue("scaledSize", int.class, -1, jsonData);
            Boolean flip = json.readValue("flip", Boolean.class, false, jsonData);
            FileHandle fontFile = skinFile.parent().child(path);
            if (!fontFile.exists())
                fontFile = Gdx.files.internal(path);
            if (!fontFile.exists())
                throw new SerializationException("Font file not found: " + fontFile);
            // Use a region with the same name as the font, else use
            // a PNG file in the same directory as the FNT file.
            String regionName = fontFile.nameWithoutExtension();
            try {
                BitmapFont font;
                TextureRegion region = skin.optional(regionName, TextureRegion.class);
                if (region != null)
                    font = new BitmapFont(fontFile, region, flip);
                else {
                    FileHandle imageFile = fontFile.parent().child(regionName + ".png");
                    if (imageFile.exists())
                        font = new BitmapFont(fontFile, imageFile, flip);
                    else
                        font = new BitmapFont(fontFile, flip);
                }
                // the font to.
                if (scaledSize != -1)
                    font.setScale(scaledSize / font.getCapHeight());
                return font;
            } catch (RuntimeException ex) {
                throw new SerializationException("Error loading bitmap font: " + fontFile, ex);
            }
        }
    });
    json.setSerializer(Color.class, new ReadOnlySerializer<Color>() {

        public Color read(Json json, JsonValue jsonData, Class type) {
            if (jsonData.isString())
                return get(jsonData.asString(), Color.class);
            String hex = json.readValue("hex", String.class, (String) null, jsonData);
            if (hex != null)
                return Color.valueOf(hex);
            float r = json.readValue("r", float.class, 0f, jsonData);
            float g = json.readValue("g", float.class, 0f, jsonData);
            float b = json.readValue("b", float.class, 0f, jsonData);
            float a = json.readValue("a", float.class, 1f, jsonData);
            return new Color(r, g, b, a);
        }
    });
    json.setSerializer(TintedDrawable.class, new ReadOnlySerializer() {

        public Object read(Json json, JsonValue jsonData, Class type) {
            String name = json.readValue("name", String.class, jsonData);
            Color color = json.readValue("color", Color.class, jsonData);
            TintedDrawable td = new TintedDrawable();
            td.name = name;
            td.color = color;
            td.drawable = newDrawable(name, color);
            return td;
        //				return newDrawable(name, color);
        }
    });
    return json;
}
Also used : ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException) SerializationException(com.badlogic.gdx.utils.SerializationException) FileHandle(com.badlogic.gdx.files.FileHandle) Color(com.badlogic.gdx.graphics.Color) JsonValue(com.badlogic.gdx.utils.JsonValue) Json(com.badlogic.gdx.utils.Json) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) SerializationException(com.badlogic.gdx.utils.SerializationException) ReflectionException(com.badlogic.gdx.utils.reflect.ReflectionException) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ReadOnlySerializer(com.badlogic.gdx.utils.Json.ReadOnlySerializer) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 54 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project gdx-skineditor by cobolfoo.

the class FontPickerDialog method isFontInUse.

/**
	 * Is font is already in use somewhere else?
	 */
public boolean isFontInUse(BitmapFont font) {
    try {
        // Check if it is already in use somewhere!
        for (String widget : SkinEditorGame.widgets) {
            String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
            Class<?> style = Class.forName(widgetStyle);
            ObjectMap<String, ?> styles = game.skinProject.getAll(style);
            Iterator<String> it = styles.keys().iterator();
            while (it.hasNext()) {
                Object item = styles.get((String) it.next());
                Field[] fields = ClassReflection.getFields(item.getClass());
                for (Field field : fields) {
                    if (field.getType() == BitmapFont.class) {
                        BitmapFont f = (BitmapFont) field.get(item);
                        if (font.equals(f)) {
                            return true;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : Field(com.badlogic.gdx.utils.reflect.Field) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 55 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project gdx-skineditor by cobolfoo.

the class NewFontDialog method refreshFontPreview.

/**
	 * 
	 */
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();
        String newFontName = generateProperFontName(fontName);
        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());
    }
}
Also used : UnicodeFont(com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont) FileHandle(com.badlogic.gdx.files.FileHandle) Font(java.awt.Font) UnicodeFont(com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ColorEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ColorEffect) ShadowEffect(com.badlogic.gdx.tools.hiero.unicodefont.effects.ShadowEffect) BMFontUtil(com.badlogic.gdx.tools.hiero.BMFontUtil) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) File(java.io.File)

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