Search in sources :

Example 1 with ApplicationAdapter

use of com.badlogic.gdx.ApplicationAdapter in project libgdx by libgdx.

the class OisTest method main.

public static void main(String[] args) throws Exception {
    DesktopControllersBuild.main(null);
    new SharedLibraryLoader("libs/gdx-controllers-desktop-natives.jar").load("gdx-controllers-desktop");
    ApplicationAdapter app = new ApplicationAdapter() {

        Ois ois;

        public void create() {
            ois = new Ois(OisControllers.getWindowHandle());
            if (ois.getJoysticks().size() > 0) {
                ois.getJoysticks().get(0).setListener(new OisListener() {

                    @Override
                    public void xSliderMoved(OisJoystick joystick, int slider, boolean value) {
                        System.out.println("xSliderMoved: " + slider + ", " + value);
                    }

                    @Override
                    public void ySliderMoved(OisJoystick joystick, int slider, boolean value) {
                        System.out.println("ySliderMoved: " + slider + ", " + value);
                    }

                    @Override
                    public void povMoved(OisJoystick joystick, int pov, OisPov value) {
                        System.out.println("povMoved: " + pov + ", " + value);
                    }

                    @Override
                    public void buttonReleased(OisJoystick joystick, int button) {
                        System.out.println("buttonReleased: " + button);
                    }

                    @Override
                    public void buttonPressed(OisJoystick joystick, int button) {
                        System.out.println("buttonPressed: " + button);
                    }

                    @Override
                    public void axisMoved(OisJoystick joystick, int axis, float value) {
                        System.out.println("axisMoved: " + axis + ", " + value);
                    }
                });
            }
        }

        public void render() {
            ois.update();
        }
    };
// new LwjglApplication(app);
// new LwjglFrame(app, "Controllers", 200, 200, false);
}
Also used : SharedLibraryLoader(com.badlogic.gdx.utils.SharedLibraryLoader) OisPov(com.badlogic.gdx.controllers.desktop.ois.OisJoystick.OisPov) ApplicationAdapter(com.badlogic.gdx.ApplicationAdapter)

Example 2 with ApplicationAdapter

use of com.badlogic.gdx.ApplicationAdapter in project bdx by GoranM.

the class DesktopLauncher method main.

public static void main(String[] arg) {
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.title = "FontWriter";
    config.width = 666;
    config.height = 444;
    final ArrayList<String[]> files = new ArrayList<>();
    for (String a : arg) files.add(a.split("---"));
    new LwjglApplication(new ApplicationAdapter() {

        public void create() {
            for (String[] commands : files) {
                boolean properlyCreated = false;
                int resX = 256;
                int resY = 256;
                while (!properlyCreated) {
                    // Supply the full path
                    String inputFontPath = commands[0];
                    FileHandle outputFolder = Gdx.files.absolute(commands[1]);
                    String fileName = outputFolder.nameWithoutExtension();
                    outputFolder = outputFolder.parent();
                    int fontSize = Integer.valueOf(commands[2]);
                    int shadowOffsetX = Integer.valueOf(commands[3]);
                    int shadowOffsetY = Integer.valueOf(commands[4]);
                    Color shadowColor = new Color(Float.valueOf(commands[5]), Float.valueOf(commands[6]), Float.valueOf(commands[7]), Float.valueOf(commands[8]));
                    int outlineThickness = Integer.valueOf(commands[9]);
                    Color outlineColor = new Color(Float.valueOf(commands[10]), Float.valueOf(commands[11]), Float.valueOf(commands[12]), Float.valueOf(commands[13]));
                    boolean outlineRounded = Boolean.valueOf(commands[14]);
                    BitmapFontWriter.FontInfo fontInfo = new BitmapFontWriter.FontInfo();
                    fontInfo.padding = new BitmapFontWriter.Padding(1, 1, 1, 1);
                    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.absolute(inputFontPath));
                    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
                    parameter.color = new Color(Float.valueOf(commands[15]), Float.valueOf(commands[16]), Float.valueOf(commands[17]), Float.valueOf(commands[18]));
                    parameter.borderColor = outlineColor;
                    parameter.borderWidth = outlineThickness;
                    parameter.borderStraight = !outlineRounded;
                    parameter.shadowOffsetX = shadowOffsetX;
                    parameter.shadowOffsetY = shadowOffsetY;
                    parameter.shadowColor = shadowColor;
                    parameter.size = fontSize;
                    parameter.packer = new PixmapPacker(resX, resY, Pixmap.Format.RGBA8888, 2, false, new PixmapPacker.SkylineStrategy());
                    FreeTypeFontGenerator.FreeTypeBitmapFontData data = generator.generateData(parameter);
                    // Writes the .fnt file, I guess
                    BitmapFontWriter.writeFont(data, new String[] { fileName + ".png" }, outputFolder.child(fileName + ".fnt"), fontInfo, resX, resY);
                    BitmapFontWriter.writePixmaps(parameter.packer.getPages(), outputFolder, fileName);
                    generator.dispose();
                    FileHandle path = outputFolder.child(fileName + ".png");
                    if (path.exists())
                        properlyCreated = true;
                    else {
                        // BitmapFontWriter generated multiple bitmaps; can't use them.
                        // We re-run with higher source texture res so they should fit
                        resX *= 2;
                        // on a single texture, continuously as necessary.
                        resY *= 2;
                        for (FileHandle f : outputFolder.list()) {
                            if (f.nameWithoutExtension().contains(fileName + "_") && f.extension().equals("png"))
                                f.delete();
                        }
                    }
                }
            }
            Gdx.app.exit();
        }
    }, config);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Color(com.badlogic.gdx.graphics.Color) ArrayList(java.util.ArrayList) LwjglApplicationConfiguration(com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration) BitmapFontWriter(com.badlogic.gdx.tools.bmfont.BitmapFontWriter) FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) LwjglApplication(com.badlogic.gdx.backends.lwjgl.LwjglApplication) PixmapPacker(com.badlogic.gdx.graphics.g2d.PixmapPacker) ApplicationAdapter(com.badlogic.gdx.ApplicationAdapter)

Aggregations

ApplicationAdapter (com.badlogic.gdx.ApplicationAdapter)2 LwjglApplication (com.badlogic.gdx.backends.lwjgl.LwjglApplication)1 LwjglApplicationConfiguration (com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration)1 OisPov (com.badlogic.gdx.controllers.desktop.ois.OisJoystick.OisPov)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Color (com.badlogic.gdx.graphics.Color)1 PixmapPacker (com.badlogic.gdx.graphics.g2d.PixmapPacker)1 FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)1 BitmapFontWriter (com.badlogic.gdx.tools.bmfont.BitmapFontWriter)1 SharedLibraryLoader (com.badlogic.gdx.utils.SharedLibraryLoader)1 ArrayList (java.util.ArrayList)1