|
| 1 | +package imgui; |
| 2 | + |
| 3 | +/** |
| 4 | + * Font runtime data and rendering |
| 5 | + * ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32(). |
| 6 | + */ |
| 7 | +public final class ImFont implements ImDestroyable { |
| 8 | + final long ptr; |
| 9 | + |
| 10 | + private ImFontGlyph fallbackGlyph = null; |
| 11 | + |
| 12 | + /** |
| 13 | + * This class will create a native structure. |
| 14 | + * Call {@link #destroy()} method to manually free used memory. |
| 15 | + */ |
| 16 | + public ImFont() { |
| 17 | + ImGui.touch(); |
| 18 | + ptr = nCreate(); |
| 19 | + } |
| 20 | + |
| 21 | + ImFont(final long ptr) { |
| 22 | + this.ptr = ptr; |
| 23 | + } |
| 24 | + |
| 25 | + @Override |
| 26 | + public void destroy() { |
| 27 | + nDestroy(ptr); |
| 28 | + } |
| 29 | + |
| 30 | + /*JNI |
| 31 | + #include <imgui.h> |
| 32 | + #include "jni_common.h" |
| 33 | +
|
| 34 | + jfieldID imFontPtrID; |
| 35 | +
|
| 36 | + #define IM_FONT ((ImFont*)env->GetLongField(object, imFontPtrID)) |
| 37 | + */ |
| 38 | + |
| 39 | + static native void nInit(); /* |
| 40 | + jclass jImFontClass = env->FindClass("imgui/ImFont"); |
| 41 | + imFontPtrID = env->GetFieldID(jImFontClass, "ptr", "J"); |
| 42 | + */ |
| 43 | + |
| 44 | + private native long nCreate(); /* |
| 45 | + ImFont* imFont = new ImFont(); |
| 46 | + return (long)imFont; |
| 47 | + */ |
| 48 | + |
| 49 | + private native void nDestroy(long ptr); /* |
| 50 | + delete (ImFont*)ptr; |
| 51 | + */ |
| 52 | + |
| 53 | + // TODO IndexAdvanceX |
| 54 | + |
| 55 | + /** |
| 56 | + * = FallbackGlyph->AdvanceX |
| 57 | + */ |
| 58 | + public native float getFallbackAdvanceX(); /* |
| 59 | + return IM_FONT->FallbackAdvanceX; |
| 60 | + */ |
| 61 | + |
| 62 | + /** |
| 63 | + * = FallbackGlyph->AdvanceX |
| 64 | + */ |
| 65 | + public native void setFallbackAdvanceX(float fallbackAdvanceX); /* |
| 66 | + IM_FONT->FallbackAdvanceX = fallbackAdvanceX; |
| 67 | + */ |
| 68 | + |
| 69 | + /** |
| 70 | + * Height of characters/line, set during loading (don't change after loading) |
| 71 | + */ |
| 72 | + public native float getFontSize(); /* |
| 73 | + return IM_FONT->FontSize; |
| 74 | + */ |
| 75 | + |
| 76 | + // TODO IndexLookup, Glyphs |
| 77 | + |
| 78 | + /** |
| 79 | + * = FindGlyph(FontFallbackChar) |
| 80 | + */ |
| 81 | + public ImFontGlyph getFallbackGlyph() { |
| 82 | + if (fallbackGlyph == null) { |
| 83 | + fallbackGlyph = new ImFontGlyph(nGetFallbackGlyphPtr()); |
| 84 | + } |
| 85 | + return fallbackGlyph; |
| 86 | + } |
| 87 | + |
| 88 | + private native long nGetFallbackGlyphPtr(); /* |
| 89 | + return (long)IM_FONT->FallbackGlyph; |
| 90 | + */ |
| 91 | + |
| 92 | + /** |
| 93 | + * Offset font rendering by xx pixels |
| 94 | + */ |
| 95 | + public native void getDisplayOffset(ImVec2 dstImVec2); /* |
| 96 | + Jni::ImVec2Cpy(env, &IM_FONT->DisplayOffset, dstImVec2); |
| 97 | + */ |
| 98 | + |
| 99 | + /** |
| 100 | + * Offset font rendering by xx pixels |
| 101 | + */ |
| 102 | + public native void setDisplayOffset(float x, float y); /* |
| 103 | + IM_FONT->DisplayOffset.x = x; |
| 104 | + IM_FONT->DisplayOffset.y = y; |
| 105 | + */ |
| 106 | + |
| 107 | + // TODO ContainerAtlas, ConfigData |
| 108 | + |
| 109 | + /** |
| 110 | + * Number of ImFontConfig involved in creating this font. |
| 111 | + * Bigger than 1 when merging multiple font sources into one ImFont. |
| 112 | + */ |
| 113 | + public native short getConfigDataCount(); /* |
| 114 | + return IM_FONT->ConfigDataCount; |
| 115 | + */ |
| 116 | + |
| 117 | + /** |
| 118 | + * Replacement character if a glyph isn't found. |
| 119 | + */ |
| 120 | + public native short getFallbackChar(); /* |
| 121 | + return IM_FONT->FallbackChar; |
| 122 | + */ |
| 123 | + |
| 124 | + /** |
| 125 | + * Character used for ellipsis rendering. |
| 126 | + */ |
| 127 | + public native short getEllipsisChar(); /* |
| 128 | + return IM_FONT->EllipsisChar; |
| 129 | + */ |
| 130 | + |
| 131 | + /** |
| 132 | + * Character used for ellipsis rendering. |
| 133 | + */ |
| 134 | + public native void setEllipsisChar(short ellipsisChar); /* |
| 135 | + IM_FONT->EllipsisChar = (ImWchar)ellipsisChar; |
| 136 | + */ |
| 137 | + |
| 138 | + /** |
| 139 | + * Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale() |
| 140 | + */ |
| 141 | + public native float getScale(); /* |
| 142 | + return IM_FONT->Scale; |
| 143 | + */ |
| 144 | + |
| 145 | + /** |
| 146 | + * Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale() |
| 147 | + */ |
| 148 | + public native void setScale(float scale); /* |
| 149 | + IM_FONT->Scale = scale; |
| 150 | + */ |
| 151 | + |
| 152 | + /** |
| 153 | + * Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] |
| 154 | + */ |
| 155 | + public native float getAscent(); /* |
| 156 | + return IM_FONT->Ascent; |
| 157 | + */ |
| 158 | + |
| 159 | + /** |
| 160 | + * Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] |
| 161 | + */ |
| 162 | + public native void setAscent(float ascent); /* |
| 163 | + IM_FONT->Ascent = ascent; |
| 164 | + */ |
| 165 | + |
| 166 | + /** |
| 167 | + * Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] |
| 168 | + */ |
| 169 | + public native float getDescent(); /* |
| 170 | + return IM_FONT->Descent; |
| 171 | + */ |
| 172 | + |
| 173 | + /** |
| 174 | + * Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] |
| 175 | + */ |
| 176 | + public native void setDescent(float descent); /* |
| 177 | + IM_FONT->Descent = descent; |
| 178 | + */ |
| 179 | + |
| 180 | + /** |
| 181 | + * Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs) |
| 182 | + */ |
| 183 | + public native int getMetricsTotalSurface(); /* |
| 184 | + return IM_FONT->MetricsTotalSurface; |
| 185 | + */ |
| 186 | + |
| 187 | + /** |
| 188 | + * Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs) |
| 189 | + */ |
| 190 | + public native void setMetricsTotalSurface(int metricsTotalSurface); /* |
| 191 | + IM_FONT->MetricsTotalSurface = metricsTotalSurface; |
| 192 | + */ |
| 193 | + |
| 194 | + public native boolean getDirtyLookupTables(); /* |
| 195 | + return IM_FONT->DirtyLookupTables; |
| 196 | + */ |
| 197 | + |
| 198 | + public native void setDirtyLookupTables(boolean dirtyLookupTables); /* |
| 199 | + IM_FONT->DirtyLookupTables = dirtyLookupTables; |
| 200 | + */ |
| 201 | + |
| 202 | + // TODO methods |
| 203 | +} |
0 commit comments