Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #187 from mmp/glyph-mr
Browse files Browse the repository at this point in the history
Add support for FontGlyph
  • Loading branch information
dertseha authored Sep 22, 2022
2 parents b0a0a7f + d44eb5d commit d55c0f4
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 0 deletions.
77 changes: 77 additions & 0 deletions Font.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
}
5 changes: 5 additions & 0 deletions FontAtlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions State.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 84 additions & 0 deletions wrapper/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImFont *>(handle);
return font->FontSize;
}

IggFontGlyph iggFindGlyph(IggFont handle, int ch)
{
ImFont *font = reinterpret_cast<ImFont *>(handle);
return (IggFontGlyph)font->FindGlyph(ch);
}

int iggFontGlyphColored(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->Colored;
}

int iggFontGlyphVisible(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->Visible;
}

int iggFontGlyphCodepoint(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->Codepoint;
}

float iggFontGlyphAdvanceX(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->AdvanceX;
}

float iggFontGlyphX0(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->X0;
}

float iggFontGlyphY0(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->Y0;
}

float iggFontGlyphX1(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->X1;
}

float iggFontGlyphY1(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->Y1;
}

float iggFontGlyphU0(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->U0;
}

float iggFontGlyphV0(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->V0;
}

float iggFontGlyphU1(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->U1;
}

float iggFontGlyphV1(IggFontGlyph handle)
{
ImFontGlyph *glyph = reinterpret_cast<ImFontGlyph *>(handle);
return glyph->V1;
}
14 changes: 14 additions & 0 deletions wrapper/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions wrapper/FontAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ void iggFontAtlasSetTextureID(IggFontAtlas handle, IggTextureID id)
fontAtlas->SetTexID(reinterpret_cast<ImTextureID>(id));
}

IggTextureID iggFontAtlasGetTextureID(IggFontAtlas handle)
{
ImFontAtlas *fontAtlas = reinterpret_cast<ImFontAtlas *>(handle);
return IggTextureID(fontAtlas->TexID);
}

IggBool iggFontAtlasBuild(IggFontAtlas handle)
{
ImFontAtlas *fontAtlas = reinterpret_cast<ImFontAtlas *>(handle);
Expand Down
1 change: 1 addition & 0 deletions wrapper/FontAtlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions wrapper/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions wrapper/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions wrapper/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d55c0f4

Please sign in to comment.