GithubHelp home page GithubHelp logo

crykn / freetype-skin Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 73 KB

A Java library that makes it possible to specify TTF fronts right in the LibGDX skin file.

License: MIT License

Java 100.00%

freetype-skin's Introduction

LibGDX freetype skin

This library extends LibGDX asset management with FreeTypeSkin and FreeTypeSkinLoader classes, which allow you to specify TTF fronts right in the uiskin.json file. You don't need to pack bitmap fonts manually and specify them via skin parameter. Just drop some .ttf into your assets folder, set parameters and done.

Dependencies

To use freetype-skin in your project just add the jipack repo and the freetype-skin dependency

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.acanthite:freetype-skin:0.3'
}

Simple usage

You will need to load your uiskin.json via FreeTypeSkin and pass it to where you needed a Skin, just like you would do this with standard Skin.

{
  BitmapFont: {
    default: {
      file: myfont.ttf,
      size: 14
      // other font properties (see the parameters section)
    }
    small: {
      file: myfont.ttf,
      size: 10
      // other font properties ...
    }
  }
  // other styles ...
}

Then load it and use it:

Skin skin = new FreeTypeSkin(Gdx.files.internal("assets/uiskin.json"));
Window window = new Window("Some Title", skin);

Note: the skin variable is defined as Skin and has assigned a FreeTypeSkin. That is, FreeTypeSkin is subclass of Skin, and you can freely pass it where Skin is required. It will work just as you expect.

Using with AssetManager

If you want to use it with AssetManager you need to replace the default asset loader for Skin.class. The rest is done as usual:

AssetManager manager = new AssetManager();

// replace the builtin skin loader with FreeTypeSkinLoader
manager.setLoader(Skin.class, new FreeTypeSkinLoader(manager.getFileHandleResolver()));

// queue skin loading
manager.load(Skin.class, "assets/uiskin.json");
manager.finishLoading();

// and use it
Skin skin = manager.get("assets/uiskin.json", Skin.class);
Window window = new Window("Some Title", skin);

Font (FreeType) parameters

To define bitmap fonts in a skin file, you must specify TTF font via file and font size via size properties. This is the required min minimum.

Other than that, you can specify any other property from FreeTypeFontParameter class, except the packer and the incremental.

Any omitted property will simply default to its value as specified in FreeTypeFontParameter, except the characters which has some more advanced set than the default one.

Here is an example with some advanced properties:

{
  Color: {
    black: { a: 1, b: 0, g: 0, r: 0 },
    white: { a: 1, b: 1, g: 1, r: 1 },
    skyBlue: { a: 1, b: 0.922, g: 0.808, r: 0.529 }
  }, 
  BitmapFont: {
    title: {
      // these are required
      file: myfont.ttf,
      size: 36,

      // these are optional
      color: skyBlue,
      borderColor: black,
      borderWidth: 2,
      shadowColor: black,
      shadowOffsetX: 3,
      shadowOffsetY: 3,
    }
  }
}

Vis UI Support?

Yes! It works out of the box. As it was said earlier, FreeTypeSkin is a Skin. You can use it in any place where Skin is needed.

FileHandle skinFile = Gdx.files.internal("assets/uiskin.json");
VisUI.load(new FreeTypeSkin(skinFile));

freetype-skin's People

Contributors

acanthite1855 avatar crykn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.