gdxapp4d/main-gdxapp/src/main/love/distributedrebirth/gdxapp/ImGuiSetup.java

68 lines
2.3 KiB
Java
Raw Normal View History

package love.distributedrebirth.gdxapp;
2022-01-28 11:00:59 +00:00
import com.badlogic.gdx.Gdx;
import imgui.ImFontConfig;
import imgui.ImFontGlyphRangesBuilder;
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.gl3.ImGuiImplGl3;
import imgui.glfw.ImGuiImplGlfw;
2022-02-04 13:39:25 +00:00
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
2022-01-28 11:00:59 +00:00
/**
2022-01-31 12:40:01 +00:00
* Create and shutdown of ImGui and font activations.
*/
2022-02-04 13:39:25 +00:00
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
2022-01-28 11:00:59 +00:00
public class ImGuiSetup {
public static final ImGuiImplGlfw imGuiImp = new ImGuiImplGlfw();
public static final ImGuiImplGl3 imGuiGlImp = new ImGuiImplGl3();
public static void init() {
long windowHandle = -1;
try {
Object window = Gdx.graphics.getClass().getMethod("getWindow").invoke(Gdx.graphics);
windowHandle = (Long)window.getClass().getMethod("getWindowHandle").invoke(window);
} catch (Exception e) {
throw new RuntimeException(e);
}
ImGui.createContext();
initFonts(ImGui.getIO());
imGuiImp.init(windowHandle, true);
2022-02-03 22:16:07 +00:00
imGuiGlImp.init("#version 140");
2022-01-28 11:00:59 +00:00
ImGui.init();
ImGui.styleColorsLight();
}
private static void initFonts(final ImGuiIO io) {
2022-01-31 23:26:21 +00:00
io.getFonts().addFontDefault();
ImFontConfig fontConfig = new ImFontConfig();
fontConfig.setMergeMode(true);
2022-02-01 13:53:02 +00:00
ImFontGlyphRangesBuilder fontBuilder = new ImFontGlyphRangesBuilder();
addRangeUnicodePlane0(fontBuilder);
final short[] glyphRanges = fontBuilder.buildRanges();
2022-01-28 11:00:59 +00:00
io.getFonts().addFontFromMemoryTTF(Gdx.files.internal("font/NotoSansCJKjp-Medium.otf").readBytes(), 14, fontConfig, glyphRanges);
io.getFonts().addFontFromMemoryTTF(Gdx.files.internal("font/FreeSans.ttf").readBytes(), 14, fontConfig, glyphRanges);
2022-02-04 22:57:52 +00:00
io.getFonts().addFontFromMemoryTTF(Gdx.files.internal("font/roboto-bold.ttf").readBytes(), 14, fontConfig, glyphRanges);
2022-02-09 11:43:57 +00:00
io.getFonts().addFontFromMemoryTTF(Gdx.files.internal("font/arslan-wessam.ttf").readBytes(), 14, fontConfig, glyphRanges);
2022-01-28 11:00:59 +00:00
fontConfig.destroy();
}
2022-02-01 13:53:02 +00:00
private static void addRangeUnicodePlane0(ImFontGlyphRangesBuilder fontBuilder) {
for (int c=0x0100;c<=0xFFEF;c++) {
StringBuilder buf = new StringBuilder();
buf.append(""+(char)c);
fontBuilder.addText(buf.toString());
}
}
2022-01-28 11:00:59 +00:00
public static void dispose() {
imGuiImp.dispose();
imGuiGlImp.dispose();
ImGui.destroyContext();
}
}