Skip to content

Commit df80123

Browse files
committed
Add font API's and Linux workaround to GLFW
1 parent 1ad4903 commit df80123

File tree

9 files changed

+387
-39
lines changed

9 files changed

+387
-39
lines changed

bin/libimgui-java64.so

0 Bytes
Binary file not shown.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ext {
88

99
allprojects {
1010
group = 'imgui-java'
11-
version = 'git describe --tags --always'.execute().text.trim().substring(1)
11+
version = '1.90.9'
1212

1313
repositories {
1414
mavenCentral()

imgui-binding/src/generated/java/imgui/ImFontAtlas.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,17 @@ public int addCustomRectFontGlyph(final ImFont imFont, final short id, final int
719719
return _result;
720720
*/
721721

722+
/**
723+
* Id needs to be {@code <} 0x110000 to register a rectangle to map into a specific font.
724+
*/
725+
public ImFontAtlasCustomRect getCustomRectByIndex(final int index) {
726+
return new ImFontAtlasCustomRect(nGetCustomRectByIndex(index));
727+
}
728+
729+
private native long nGetCustomRectByIndex(int index); /*
730+
return (uintptr_t)THIS->GetCustomRectByIndex(index);
731+
*/
732+
722733
// TODO GetCustomRectByIndex
723734

724735
//-------------------------------------------
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
package imgui;
2+
3+
import imgui.binding.ImGuiStructDestroyable;
4+
5+
/**
6+
*
7+
* // See ImFontAtlas::AddCustomRectXXX functions.
8+
* struct ImFontAtlasCustomRect
9+
* {
10+
* unsigned short Width, Height; // Input // Desired rectangle dimension
11+
* unsigned short X, Y; // Output // Packed position in Atlas
12+
* unsigned int GlyphID; // Input // For custom font glyphs only (ID < 0x110000)
13+
* float GlyphAdvanceX; // Input // For custom font glyphs only: glyph xadvance
14+
* ImVec2 GlyphOffset; // Input // For custom font glyphs only: glyph display offset
15+
* ImFont* Font; // Input // For custom font glyphs only: target font
16+
* ImFontAtlasCustomRect() { Width = Height = 0; X = Y = 0xFFFF; GlyphID = 0; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0, 0); Font = NULL; }
17+
* bool IsPacked() const { return X != 0xFFFF; }
18+
};
19+
*/
20+
public final class ImFontAtlasCustomRect extends ImGuiStructDestroyable {
21+
public ImFontAtlasCustomRect() {
22+
super();
23+
}
24+
25+
public ImFontAtlasCustomRect(final long ptr) {
26+
super(ptr);
27+
}
28+
29+
@Override
30+
protected long create() {
31+
return nCreate();
32+
}
33+
34+
/*JNI
35+
#include "_common.h"
36+
#define THIS ((ImFontAtlasCustomRect*)STRUCT_PTR)
37+
*/
38+
39+
private native long nCreate(); /*
40+
return (uintptr_t)(new ImFontAtlasCustomRect());
41+
*/
42+
43+
/**
44+
* Desired rectangle dimension
45+
*/
46+
public short getWidth() {
47+
return nGetWidth();
48+
}
49+
50+
/**
51+
* Desired rectangle dimension
52+
*/
53+
public void setWidth(final short value) {
54+
nSetWidth(value);
55+
}
56+
57+
private native short nGetWidth(); /*
58+
return THIS->Width;
59+
*/
60+
61+
private native void nSetWidth(short value); /*
62+
THIS->Width = value;
63+
*/
64+
65+
/**
66+
* Desired rectangle dimension
67+
*/
68+
public short getHeight() {
69+
return nGetHeight();
70+
}
71+
72+
/**
73+
* Desired rectangle dimension
74+
*/
75+
public void setHeight(final short value) {
76+
nSetHeight(value);
77+
}
78+
79+
private native short nGetHeight(); /*
80+
return THIS->Height;
81+
*/
82+
83+
private native void nSetHeight(short value); /*
84+
THIS->Height = value;
85+
*/
86+
87+
/**
88+
* Packed position in Atlas
89+
*/
90+
public short getX() {
91+
return nGetX();
92+
}
93+
94+
private native short nGetX(); /*
95+
return THIS->X;
96+
*/
97+
98+
/**
99+
* Packed position in Atlas
100+
*/
101+
public short getY() {
102+
return nGetY();
103+
}
104+
105+
private native short nGetY(); /*
106+
return THIS->Y;
107+
*/
108+
109+
/**
110+
* For custom font glyphs only (ID < 0x110000)
111+
*/
112+
public int getGlyphID() {
113+
return nGetGlyphID();
114+
}
115+
116+
/**
117+
* For custom font glyphs only (ID < 0x110000)
118+
*/
119+
public void setGlyphID(final int value) {
120+
nSetGlyphID(value);
121+
}
122+
123+
private native int nGetGlyphID(); /*
124+
return THIS->GlyphID;
125+
*/
126+
127+
private native void nSetGlyphID(int value); /*
128+
THIS->GlyphID = value;
129+
*/
130+
131+
/**
132+
* For custom font glyphs only: glyph xadvance
133+
*/
134+
public float getGlyphAdvanceX() {
135+
return nGetGlyphAdvanceX();
136+
}
137+
138+
/**
139+
* For custom font glyphs only: glyph xadvance
140+
*/
141+
public void setGlyphAdvanceX(final float value) {
142+
nSetGlyphAdvanceX(value);
143+
}
144+
145+
private native float nGetGlyphAdvanceX(); /*
146+
return THIS->GlyphAdvanceX;
147+
*/
148+
149+
private native void nSetGlyphAdvanceX(float value); /*
150+
THIS->GlyphAdvanceX = value;
151+
*/
152+
153+
/**
154+
* For custom font glyphs only: glyph display offset
155+
*/
156+
public ImVec2 getGlyphOffset() {
157+
final ImVec2 dst = new ImVec2();
158+
nGetGlyphOffset(dst);
159+
return dst;
160+
}
161+
162+
/**
163+
* For custom font glyphs only: glyph display offset
164+
*/
165+
public float getGlyphOffsetX() {
166+
return nGetGlyphOffsetX();
167+
}
168+
169+
/**
170+
* For custom font glyphs only: glyph display offset
171+
*/
172+
public float getGlyphOffsetY() {
173+
return nGetGlyphOffsetY();
174+
}
175+
176+
/**
177+
* For custom font glyphs only: glyph display offset
178+
*/
179+
public void getGlyphOffset(final ImVec2 dst) {
180+
nGetGlyphOffset(dst);
181+
}
182+
183+
/**
184+
* For custom font glyphs only: glyph display offset
185+
*/
186+
public void setGlyphOffset(final ImVec2 value) {
187+
nSetGlyphOffset(value.x, value.y);
188+
}
189+
190+
/**
191+
* For custom font glyphs only: glyph display offset
192+
*/
193+
public void setGlyphOffset(final float valueX, final float valueY) {
194+
nSetGlyphOffset(valueX, valueY);
195+
}
196+
197+
private native void nGetGlyphOffset(ImVec2 dst); /*
198+
Jni::ImVec2Cpy(env, THIS->GlyphOffset, dst);
199+
*/
200+
201+
private native float nGetGlyphOffsetX(); /*
202+
return THIS->GlyphOffset.x;
203+
*/
204+
205+
private native float nGetGlyphOffsetY(); /*
206+
return THIS->GlyphOffset.y;
207+
*/
208+
209+
private native void nSetGlyphOffset(float valueX, float valueY); /*MANUAL
210+
ImVec2 value = ImVec2(valueX, valueY);
211+
THIS->GlyphOffset = value;
212+
*/
213+
214+
/**
215+
* For custom font glyphs only: target font
216+
*/
217+
public ImFont getFont() {
218+
return new ImFont(nGetFont());
219+
}
220+
221+
/**
222+
* For custom font glyphs only: target font
223+
*/
224+
public void setFont(final ImFont value) {
225+
nSetFont(value.ptr);
226+
}
227+
228+
private native long nGetFont(); /*
229+
return (uintptr_t)THIS->Font;
230+
*/
231+
232+
private native void nSetFont(long value); /*
233+
THIS->Font = reinterpret_cast<ImFont*>(value);
234+
*/
235+
236+
public boolean isPacked() {
237+
return nIsPacked();
238+
}
239+
240+
private native boolean nIsPacked(); /*
241+
return THIS->IsPacked();
242+
*/
243+
244+
/*JNI
245+
#undef THIS
246+
*/
247+
}

imgui-binding/src/generated/java/imgui/ImGui.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,7 @@ public class ImGui {
3030
private static final String LIB_NAME_DEFAULT = "imgui-java64";
3131
private static final String LIB_TMP_DIR_PREFIX = "imgui-java-natives";
3232

33-
static {
34-
final String libPath = System.getProperty(LIB_PATH_PROP);
35-
final String libName = System.getProperty(LIB_NAME_PROP, LIB_NAME_DEFAULT);
36-
final String fullLibName = resolveFullLibName();
37-
38-
if (libPath != null) {
39-
System.load(Paths.get(libPath).resolve(fullLibName).toAbsolutePath().toString());
40-
} else {
41-
try {
42-
System.loadLibrary(libName);
43-
} catch (Exception | Error e) {
44-
final String extractedLibAbsPath = tryLoadFromClasspath(fullLibName);
45-
if (extractedLibAbsPath != null) {
46-
System.load(extractedLibAbsPath);
47-
} else {
48-
throw e;
49-
}
50-
}
51-
}
33+
public static void onLoadJNI() {
5234

5335
nInitJni();
5436
ImFontAtlas.nInit();

imgui-binding/src/main/java/imgui/ImFontAtlas.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ private ByteBuffer createRgba32Pixels(final int size) {
351351
@BindingMethod
352352
public native int AddCustomRectFontGlyph(ImFont imFont, @ArgValue(callPrefix = "(ImWchar)") short id, int width, int height, float advanceX, @OptArg ImVec2 offset);
353353

354+
/**
355+
* Id needs to be {@code <} 0x110000 to register a rectangle to map into a specific font.
356+
*/
357+
@BindingMethod
358+
public native ImFontAtlasCustomRect GetCustomRectByIndex(int index);
359+
354360
// TODO GetCustomRectByIndex
355361

356362
//-------------------------------------------

0 commit comments

Comments
 (0)