public int AddCustomRectFontGlyph(ImFontPtr font, ushort id, int width, int height, float advance_x, Vector2 offset) { ImFont *native_font = font.NativePtr; int ret = ImGuiNative.ImFontAtlas_AddCustomRectFontGlyph(NativePtr, native_font, id, width, height, advance_x, offset); return(ret); }
public void AddText(ImFontPtr font, float font_size, Vector2 pos, uint col, ReadOnlySpan <char> text_begin) { var native_text_begin = default(byte *); var native_text_end = default(byte *); var byte_count = 0; var native_font = font.NativePtr; var wrap_width = 0.0f; var cpu_fine_clip_rect = default(Vector4 *); if (!text_begin.IsEmpty) { byte_count = Util.CalcSizeInUtf8(text_begin, 0, text_begin.Length); if (byte_count > Util.StackAllocationSizeLimit) { native_text_begin = Util.Allocate(byte_count + 1); } else { var buffer = stackalloc byte[byte_count + 1]; native_text_begin = buffer; } var offset = Util.GetUtf8(text_begin, native_text_begin, byte_count); native_text_end = &native_text_begin[offset]; *native_text_end = 0; } else { var buffer = stackalloc byte[1]; native_text_begin = buffer; } ImGuiNative.ImDrawList_AddTextFontPtr(this.NativePtr, native_font, font_size, pos, col, native_text_begin, native_text_end, wrap_width, cpu_fine_clip_rect); if (byte_count > Util.StackAllocationSizeLimit) { Util.Free(native_text_begin); } //var native_font = font.NativePtr; //var text_begin_byteCount = Encoding.UTF8.GetByteCount(text_begin); //var native_text_begin = stackalloc byte[text_begin_byteCount + 1]; //fixed (char* text_begin_ptr = text_begin) //{ // var native_text_begin_offset = Encoding.UTF8.GetBytes(text_begin_ptr, text_begin.Length, native_text_begin, text_begin_byteCount); // native_text_begin[native_text_begin_offset] = 0; //} //byte* native_text_end = null; //var wrap_width = 0.0f; //Vector4* cpu_fine_clip_rect = null; //ImGuiNative.ImDrawList_AddTextFontPtr(this.NativePtr, native_font, font_size, pos, col, native_text_begin, native_text_end, wrap_width, cpu_fine_clip_rect); }
public void AddText(ImFontPtr font, float font_size, Vector2 pos, uint col, string text_begin, float wrap_width, Vector4 clip_rect) { ImFont *native_font = font.NativePtr; int text_begin_byteCount = Encoding.UTF8.GetByteCount(text_begin); byte * native_text_begin = stackalloc byte[text_begin_byteCount + 1]; fixed(char *text_begin_ptr = text_begin) { int native_text_begin_offset = Encoding.UTF8.GetBytes(text_begin_ptr, text_begin.Length, native_text_begin, text_begin_byteCount); native_text_begin[native_text_begin_offset] = 0; } byte * native_text_end = null; Vector4 *cpu_fine_clip_rect = &clip_rect; ImGuiNative.ImDrawList_AddTextFontPtr(NativePtr, native_font, font_size, pos, col, native_text_begin, native_text_end, wrap_width, cpu_fine_clip_rect); }
/// <summary> /// Constructs a new ImGuiController. /// </summary> public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, int width, int height) { _gd = gd; _windowWidth = width; _windowHeight = height; IntPtr context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); var io = ImGui.GetIO(); ImVector ranges; unsafe { var rangesBuilder = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()); rangesBuilder.AddRanges(io.Fonts.GetGlyphRangesJapanese()); rangesBuilder.AddRanges(io.Fonts.GetGlyphRangesChineseFull()); ushort[] extraCharsRange = { 0x25A0, 0x25FF, // geometric shapes, 0x2000, 0x206F, // general punctuation 0xFF00, 0xFFEF, // halfwidth and fullwidth forms 0x2600, 0x26FF, // misc symbols 0x2190, 0x21FF, // arrows 0 }; fixed(ushort *extraCharsRangePtr = extraCharsRange) { rangesBuilder.AddRanges((IntPtr)extraCharsRangePtr); rangesBuilder.BuildRanges(out ranges); } } ImFontPtr font = io.Fonts.AddFontFromFileTTF("../../../NotoSansCJKjp-Medium.otf", 24.0f, null, ranges.Data); CreateDeviceResources(gd, outputDescription); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); ImGui.NewFrame(); _frameBegun = true; }