2022-02-04 17:44:02 +00:00
|
|
|
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-29 04:50:02 +00:00
|
|
|
/**
|
2022-01-31 12:40:01 +00:00
|
|
|
* Create and shutdown of ImGui and font activations.
|
2022-01-29 04:50:02 +00:00
|
|
|
*/
|
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
|
|
|
ImFontConfig fontConfig = new ImFontConfig();
|
2022-02-01 13:53:02 +00:00
|
|
|
ImFontGlyphRangesBuilder fontBuilder = new ImFontGlyphRangesBuilder();
|
|
|
|
addRangeUnicodePlane0(fontBuilder);
|
|
|
|
final short[] glyphRanges = fontBuilder.buildRanges();
|
2022-02-11 01:46:44 +00:00
|
|
|
io.getFonts().addFontFromMemoryTTF(Gdx.files.internal("font/code2000.ttf").readBytes(), 24, fontConfig, glyphRanges);
|
|
|
|
fontConfig.setMergeMode(true);
|
|
|
|
// note: just for 3 sub chars for SUBHEX, but still missing 2 chars from T12 alt1 clock
|
|
|
|
io.getFonts().addFontFromMemoryTTF(Gdx.files.internal("font/free-sans.ttf").readBytes(), 24, 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) {
|
2022-02-11 01:46:44 +00:00
|
|
|
for (int c=0x0001;c<=0xFFEF;c++) {
|
2022-02-01 13:53:02 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|