diff --git a/Font.go b/Font.go index 4eac79f..577a357 100644 --- a/Font.go +++ b/Font.go @@ -7,6 +7,9 @@ import "C" // Font describes one loaded font in an atlas. type Font uintptr +// FontGlyph represents a single font glyph from a font atlas. +type FontGlyph uintptr + // DefaultFont can be used to refer to the default font of the current font atlas without // having the actual font reference. const DefaultFont Font = 0 @@ -43,3 +46,77 @@ func CalcTextSize(text string, hideTextAfterDoubleHash bool, wrapWidth float32) func (font Font) handle() C.IggFont { return C.IggFont(font) } + +// FontSize returns the height of the given font. +func (font Font) FontSize() float32 { + return float32(C.iggFontFontSize(font.handle())) +} + +// FindGlyph returns the FontGlyph corresponding to the given rune. +func (font Font) FindGlyph(ch rune) FontGlyph { + return FontGlyph(C.iggFindGlyph(font.handle(), C.int(ch))) +} + +func (glyph FontGlyph) handle() C.IggFontGlyph { + return C.IggFontGlyph(glyph) +} + +// Colored returns whether the glyph is colored. +func (glyph FontGlyph) Colored() bool { + return C.iggFontGlyphColored(glyph.handle()) != 0 +} + +// Visible indicates whether the glyph is visible; it will be false for a space character, for example. +func (glyph FontGlyph) Visible() bool { + return C.iggFontGlyphVisible(glyph.handle()) != 0 +} + +// Codepoint returns the codepoint associated with the glyph. +func (glyph FontGlyph) Codepoint() int { + return int(C.iggFontGlyphCodepoint(glyph.handle())) +} + +// AdvanceX returns the horizontal difference to the next character after the glyph is drawn. +func (glyph FontGlyph) AdvanceX() float32 { + return float32(C.iggFontGlyphAdvanceX(glyph.handle())) +} + +// X0 returns the lower x coordinate of the glyph. +func (glyph FontGlyph) X0() float32 { + return float32(C.iggFontGlyphX0(glyph.handle())) +} + +// Y0 returns the lower y coordinate of the glyph. +func (glyph FontGlyph) Y0() float32 { + return float32(C.iggFontGlyphY0(glyph.handle())) +} + +// X1 returns the upper x coordinate of the glyph. +func (glyph FontGlyph) X1() float32 { + return float32(C.iggFontGlyphX1(glyph.handle())) +} + +// Y1 returns the upper y coordinate of the glyph. +func (glyph FontGlyph) Y1() float32 { + return float32(C.iggFontGlyphY1(glyph.handle())) +} + +// U0 returns the u texture coordinate associated with the X0() vertex of the glyph. +func (glyph FontGlyph) U0() float32 { + return float32(C.iggFontGlyphU0(glyph.handle())) +} + +// V0 returns the v texture coordinate associated with the Y0() vertex of the glyph. +func (glyph FontGlyph) V0() float32 { + return float32(C.iggFontGlyphV0(glyph.handle())) +} + +// U1 returns the u texture coordinate associated with the X1() vertex of the glyph. +func (glyph FontGlyph) U1() float32 { + return float32(C.iggFontGlyphU1(glyph.handle())) +} + +// V1 returns the v texture coordinate associated with the Y1() vertex of the glyph. +func (glyph FontGlyph) V1() float32 { + return float32(C.iggFontGlyphV1(glyph.handle())) +} diff --git a/FontAtlas.go b/FontAtlas.go index fcec789..dfc43d9 100644 --- a/FontAtlas.go +++ b/FontAtlas.go @@ -163,6 +163,11 @@ func (atlas FontAtlas) SetTextureID(id TextureID) { C.iggFontAtlasSetTextureID(atlas.handle(), id.handle()) } +// TextureID returns the renderer-specific texture identifier for the font atlas. +func (atlas FontAtlas) TextureID() TextureID { + return TextureID(C.iggFontAtlasGetTextureID(atlas.handle())) +} + // Build pixels data. This is called automatically for you by the TextureData*** functions. func (atlas FontAtlas) Build() bool { return C.iggFontAtlasBuild(atlas.handle()) != 0 diff --git a/State.go b/State.go index eaa449e..8fcdd99 100644 --- a/State.go +++ b/State.go @@ -169,6 +169,11 @@ func IsWindowHovered() bool { return IsWindowHoveredV(HoveredFlagsNone) } +// KeyIndex returns the key index corresponding to an imgui key. +func KeyIndex(key int) int { + return int(C.iggGetKeyIndex(C.int(key))) +} + // IsKeyDown returns true if the corresponding key is currently being held down. func IsKeyDown(key int) bool { return C.iggIsKeyDown(C.int(key)) != 0 diff --git a/wrapper/Font.cpp b/wrapper/Font.cpp index df66e3d..e40f546 100644 --- a/wrapper/Font.cpp +++ b/wrapper/Font.cpp @@ -22,3 +22,87 @@ void iggCalcTextSize(const char *text, int length, IggBool hide_text_after_doubl { exportValue(*value, ImGui::CalcTextSize(text, text + length, hide_text_after_double_hash, wrap_width)); } + +float iggFontFontSize(IggFont handle) +{ + ImFont *font = reinterpret_cast(handle); + return font->FontSize; +} + +IggFontGlyph iggFindGlyph(IggFont handle, int ch) +{ + ImFont *font = reinterpret_cast(handle); + return (IggFontGlyph)font->FindGlyph(ch); +} + +int iggFontGlyphColored(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->Colored; +} + +int iggFontGlyphVisible(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->Visible; +} + +int iggFontGlyphCodepoint(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->Codepoint; +} + +float iggFontGlyphAdvanceX(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->AdvanceX; +} + +float iggFontGlyphX0(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->X0; +} + +float iggFontGlyphY0(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->Y0; +} + +float iggFontGlyphX1(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->X1; +} + +float iggFontGlyphY1(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->Y1; +} + +float iggFontGlyphU0(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->U0; +} + +float iggFontGlyphV0(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->V0; +} + +float iggFontGlyphU1(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->U1; +} + +float iggFontGlyphV1(IggFontGlyph handle) +{ + ImFontGlyph *glyph = reinterpret_cast(handle); + return glyph->V1; +} diff --git a/wrapper/Font.h b/wrapper/Font.h index 6611d4c..d165e3d 100644 --- a/wrapper/Font.h +++ b/wrapper/Font.h @@ -10,6 +10,20 @@ extern void iggPushFont(IggFont handle); extern void iggPopFont(void); extern void iggCalcTextSize(const char *text, int length, IggBool hide_text_after_double_hash, float wrap_width, IggVec2 *value); extern float iggGetFontSize(); +extern float iggFontFontSize(IggFont handle); +extern IggFontGlyph iggFindGlyph(IggFont font, int ch); +extern int iggFontGlyphColored(IggFontGlyph glyph); +extern int iggFontGlyphVisible(IggFontGlyph glyph); +extern int iggFontGlyphCodepoint(IggFontGlyph glyph); +extern float iggFontGlyphAdvanceX(IggFontGlyph glyph); +extern float iggFontGlyphX0(IggFontGlyph glyph); +extern float iggFontGlyphY0(IggFontGlyph glyph); +extern float iggFontGlyphX1(IggFontGlyph glyph); +extern float iggFontGlyphY1(IggFontGlyph glyph); +extern float iggFontGlyphU0(IggFontGlyph glyph); +extern float iggFontGlyphV0(IggFontGlyph glyph); +extern float iggFontGlyphU1(IggFontGlyph glyph); +extern float iggFontGlyphV1(IggFontGlyph glyph); #ifdef __cplusplus } diff --git a/wrapper/FontAtlas.cpp b/wrapper/FontAtlas.cpp index 7f17381..dd37888 100644 --- a/wrapper/FontAtlas.cpp +++ b/wrapper/FontAtlas.cpp @@ -106,6 +106,12 @@ void iggFontAtlasSetTextureID(IggFontAtlas handle, IggTextureID id) fontAtlas->SetTexID(reinterpret_cast(id)); } +IggTextureID iggFontAtlasGetTextureID(IggFontAtlas handle) +{ + ImFontAtlas *fontAtlas = reinterpret_cast(handle); + return IggTextureID(fontAtlas->TexID); +} + IggBool iggFontAtlasBuild(IggFontAtlas handle) { ImFontAtlas *fontAtlas = reinterpret_cast(handle); diff --git a/wrapper/FontAtlas.h b/wrapper/FontAtlas.h index 5eec373..90e3f8b 100644 --- a/wrapper/FontAtlas.h +++ b/wrapper/FontAtlas.h @@ -28,6 +28,7 @@ extern void iggFontAtlasGetTexDataAsAlpha8(IggFontAtlas handle, unsigned char ** extern void iggFontAtlasGetTexDataAsRGBA32(IggFontAtlas handle, unsigned char **pixels, int *width, int *height, int *bytesPerPixel); extern void iggFontAtlasSetTextureID(IggFontAtlas handle, IggTextureID id); +extern IggTextureID iggFontAtlasGetTextureID(IggFontAtlas handle); extern IggBool iggFontAtlasBuild(IggFontAtlas handle); extern unsigned int iggFontAtlasGetFontBuilderFlags(IggFontAtlas handle); diff --git a/wrapper/State.cpp b/wrapper/State.cpp index cdc5e14..edd3b33 100644 --- a/wrapper/State.cpp +++ b/wrapper/State.cpp @@ -83,6 +83,11 @@ IggBool iggIsWindowHovered(int flags) return ImGui::IsWindowHovered(flags) ? 1 : 0; } +int iggGetKeyIndex(int key) +{ + return ImGui::GetKeyIndex(key); +} + IggBool iggIsKeyDown(int key) { return ImGui::IsKeyDown(key); diff --git a/wrapper/State.h b/wrapper/State.h index e41c71b..d3d79ba 100644 --- a/wrapper/State.h +++ b/wrapper/State.h @@ -27,6 +27,7 @@ extern IggBool iggIsWindowCollapsed(); extern IggBool iggIsWindowFocused(int flags); extern IggBool iggIsWindowHovered(int flags); +extern int iggGetKeyIndex(int key); extern IggBool iggIsKeyDown(int key); extern IggBool iggIsKeyPressed(int key, IggBool repeat); extern IggBool iggIsKeyReleased(int key); diff --git a/wrapper/Types.h b/wrapper/Types.h index 60d4efc..1e6f822 100644 --- a/wrapper/Types.h +++ b/wrapper/Types.h @@ -18,6 +18,7 @@ typedef void *IggDrawList; typedef void *IggFontAtlas; typedef void *IggFontConfig; typedef void *IggFont; +typedef void *IggFontGlyph; typedef void *IggGlyphRanges; typedef void *IggGuiStyle; typedef void *IggInputTextCallbackData;