/// <summary> /// Creates a texture and loads the font data from ImGui. Should be called when the <see cref="GraphicsDevice" /> is initialized but before any rendering is done /// </summary> public unsafe void RebuildFontAtlas(ImGuiOptions options) { // Get font texture from ImGui var io = ImGui.GetIO(); if (options._includeDefaultFont) DefaultFontPtr = io.Fonts.AddFontDefault(); foreach (var font in options._fonts) io.Fonts.AddFontFromFileTTF(font.Item1, font.Item2); io.Fonts.GetTexDataAsRGBA32(out byte* pixelData, out int width, out int height, out int bytesPerPixel); // Copy the data to a managed array var pixels = new byte[width * height * bytesPerPixel]; Marshal.Copy(new IntPtr(pixelData), pixels, 0, pixels.Length); // Create and register the texture as an XNA texture var tex2d = new Texture2D(Core.GraphicsDevice, width, height, false, SurfaceFormat.Color); tex2d.SetData(pixels); // Should a texture already have been built previously, unbind it first so it can be deallocated if (_fontTextureId.HasValue) UnbindTexture(_fontTextureId.Value); // Bind the new texture to an ImGui-friendly id _fontTextureId = BindTexture(tex2d); // Let ImGui know where to find the texture io.Fonts.SetTexID(_fontTextureId.Value); io.Fonts.ClearTexData(); // Clears CPU side texture data }
/// <summary> /// Initializes a new instance of the <see cref="Builder"/> class. /// </summary> /// <param name="fontPtr">Corresponding ImFontPtr.</param> /// <param name="fdt">FDT file to base on.</param> /// <param name="text">Text.</param> public Builder(ImFontPtr fontPtr, FdtReader fdt, string text) { this.fontPtr = fontPtr; this.fdt = fdt; this.text = text; this.size = fdt.FontHeader.LineHeight; }
private void InitFonts() { var fontSizePixels = PT_TO_PX * 12.5f; // Standard fonts unsafe { var stdConfig = ImGuiNative.ImFontConfig_ImFontConfig(); io.Fonts.AddFontFromFileTTF("Content/Fonts/OpenSans/OpenSans-SemiBold.ttf", fontSizePixels, stdConfig); ImGuiNative.ImFontConfig_destroy(stdConfig); } // Monospaced fonts unsafe { var stdConfig = ImGuiNative.ImFontConfig_ImFontConfig(); MonospacedFont = io.Fonts.AddFontFromFileTTF("Content/Fonts/IBMPlexMono/IBMPlexMono-SemiBold.ttf", fontSizePixels, stdConfig).NativePtr; ImGuiNative.ImFontConfig_destroy(stdConfig); } io.Fonts.Build(); io.Fonts.GetTexDataAsRGBA32(out IntPtr pixels, out var width, out var height, out var bpp); defaultFontTexture = Texture.LoadFromPtr(pixels, width, height, bpp, "texture_diffuse"); io.Fonts.SetTexID((IntPtr)defaultFontTexture.Id); io.Fonts.ClearTexData(); }
public void Init() { context.imguiContext = ImGui.CreateContext(); ImGui.SetCurrentContext(context.imguiContext); var io = ImGui.GetIO(); io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset; fontTexture = new Texture2D(); context.renderTargets["imgui_font"] = fontTexture; ImFontPtr font = io.Fonts.AddFontFromFileTTF("c:\\Windows\\Fonts\\SIMHEI.ttf", 14, null, io.Fonts.GetGlyphRangesChineseFull()); io.Fonts.GetTexDataAsRGBA32(out byte *pixels, out int width, out int height, out int bytesPerPixel); io.Fonts.TexID = context.GetStringId("imgui_font"); fontTexture.width = width; fontTexture.height = height; fontTexture.mipLevels = 1; fontTexture.format = Format.R8G8B8A8_UNorm; imguiMesh = context.GetMesh("imgui_mesh"); GPUUpload gpuUpload = new GPUUpload(); gpuUpload.texture2D = fontTexture; gpuUpload.format = Format.R8G8B8A8_UNorm; gpuUpload.textureData = new byte[width * height * bytesPerPixel]; new Span <byte>(pixels, gpuUpload.textureData.Length).CopyTo(gpuUpload.textureData); context.uploadQueue.Enqueue(gpuUpload); }
/// <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 fonts = ImGui.GetIO().Fonts; ImGui.StyleColorsLight(); float scale = 1.5f; ImGui.GetStyle().ScaleAllSizes(scale); int fontSize = (int)(13f * scale); // always round down // First font loaded will become the default font: // Seems that to load specific glyphs I need to pass them in via a ImFontConfig with an IntPtr, which is not something // I've figured out yet, so I'm just leaving these at the default glyph set. ImGui.GetIO().Fonts.AddFontFromFileTTF("EditorFonts\\SourceCodePro-Regular.ttf", fontSize); SemiBoldFont = ImGui.GetIO().Fonts.AddFontFromFileTTF("EditorFonts\\SourceCodePro-SemiBold.ttf", fontSize); BoldFont = ImGui.GetIO().Fonts.AddFontFromFileTTF("EditorFonts\\SourceCodePro-Bold.ttf", fontSize); CreateDeviceResources(gd, outputDescription); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); ImGui.NewFrame(); _frameBegun = true; }
private unsafe void AddFont(string fileName, ref ImFontPtr fontPtr) { string fontFile = fileName; string fontPath = Path.Combine(dllPath, fontFile); ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig(); fontConfig.MergeMode = true; fontConfig.PixelSnapH = false; var gameRangeHandle = GCHandle.Alloc(new ushort[] { 0xE016, 0xf739, 0 }, GCHandleType.Pinned); var gameRangeHandle2 = GCHandle.Alloc(new ushort[] { 0x2013, 0x303D, 0 }, GCHandleType.Pinned); fontPtr = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPath, config.FontSize); ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPath, config.FontSize, fontConfig, gameRangeHandle.AddrOfPinnedObject()); ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPath, config.FontSize, fontConfig, gameRangeHandle2.AddrOfPinnedObject()); fontConfig.Destroy(); gameRangeHandle.Free(); gameRangeHandle2.Free(); }
/// <summary> /// Load the style from a file. /// </summary> /// <param name="themeName">Theme name.</param> public static void LoadFromFile(string themeName) { //Load INI. FileIniDataParser parser = new FileIniDataParser(); IniData ini = parser.ReadFile("Res/Themes/" + themeName + ".ini"); //Get style. var style = ImGui.GetStyle(); //Colors. var names = Enum.GetNames(typeof(ImGuiCol)); for (int i = 0; i < names.Length - 1; i++) { style.Colors[i] = ParseVec(ini["Colors"][names[i]]); } //Main. style.WindowPadding = ParseVec2(ini["Main"]["WindowPadding"]); style.FramePadding = ParseVec2(ini["Main"]["FramePadding"]); style.ItemSpacing = ParseVec2(ini["Main"]["ItemSpacing"]); style.ItemInnerSpacing = ParseVec2(ini["Main"]["ItemInnerSpacing"]); style.TouchExtraPadding = ParseVec2(ini["Main"]["TouchExtraPadding"]); style.IndentSpacing = float.Parse(ini["Main"]["IndentSpacing"]); style.ScrollbarSize = float.Parse(ini["Main"]["ScrollbarSize"]); style.GrabMinSize = float.Parse(ini["Main"]["GrabMinSize"]); //Borders. style.WindowBorderSize = float.Parse(ini["Borders"]["WindowBorderSize"]); style.ChildBorderSize = float.Parse(ini["Borders"]["ChildBorderSize"]); style.PopupBorderSize = float.Parse(ini["Borders"]["PopupBorderSize"]); style.FrameBorderSize = float.Parse(ini["Borders"]["FrameBorderSize"]); style.TabBorderSize = float.Parse(ini["Borders"]["TabBorderSize"]); //Rounding. style.WindowRounding = float.Parse(ini["Rounding"]["WindowRounding"]); style.ChildRounding = float.Parse(ini["Rounding"]["ChildRounding"]); style.FrameRounding = float.Parse(ini["Rounding"]["FrameRounding"]); style.PopupRounding = float.Parse(ini["Rounding"]["PopupRounding"]); style.ScrollbarRounding = float.Parse(ini["Rounding"]["ScrollbarRounding"]); style.GrabRounding = float.Parse(ini["Rounding"]["GrabRounding"]); style.TabRounding = float.Parse(ini["Rounding"]["TabRounding"]); //Alignment. style.WindowTitleAlign = ParseVec2(ini["Alignment"]["WindowTitleAlign"]); style.WindowMenuButtonPosition = (ImGuiDir)Enum.Parse(typeof(ImGuiDir), ini["Alignment"]["WindowMenuButtonPosition"]); style.ColorButtonPosition = (ImGuiDir)Enum.Parse(typeof(ImGuiDir), ini["Alignment"]["ColorButtonPosition"]); style.ButtonTextAlign = ParseVec2(ini["Alignment"]["ButtonTextAlign"]); style.SelectableTextAlign = ParseVec2(ini["Alignment"]["SelectableTextAlign"]); //Safe area padding. style.DisplaySafeAreaPadding = ParseVec2(ini["Safe Area Padding"]["SafeAreaPadding"]); //Font. Font = FontRaw = ini["Font"]["Name"]; FontSize = FontSizeRaw = float.Parse(ini["Font"]["Size"]); FontPtr = ImGui.GetIO().Fonts.AddFontFromFileTTF("Res/Fonts/" + Font + ".ttf", FontSize); FontRebuildNeeded = true; }
private unsafe void SetupFonts() { this.fontBuildSignal.Reset(); ImGui.GetIO().Fonts.Clear(); ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig(); fontConfig.MergeMode = true; fontConfig.PixelSnapH = true; var fontPathJp = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "NotoSansCJKjp-Medium.otf"); var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned); DefaultFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathJp, 17.0f, null, japaneseRangeHandle.AddrOfPinnedObject()); var fontPathGame = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "gamesym.ttf"); var gameRangeHandle = GCHandle.Alloc(new ushort[] { 0xE020, 0xE0DB, 0 }, GCHandleType.Pinned); ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathGame, 17.0f, fontConfig, gameRangeHandle.AddrOfPinnedObject()); var fontPathIcon = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "FontAwesome5FreeSolid.otf"); var iconRangeHandle = GCHandle.Alloc(new ushort[] { 0xE000, 0xF8FF, 0 }, GCHandleType.Pinned); IconFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathIcon, 17.0f, null, iconRangeHandle.AddrOfPinnedObject()); Log.Verbose("[FONT] Invoke OnBuildFonts"); this.OnBuildFonts?.Invoke(); Log.Verbose("[FONT] OnBuildFonts OK!"); for (var i = 0; i < ImGui.GetIO().Fonts.Fonts.Size; i++) { Log.Verbose("{0} - {1}", i, ImGui.GetIO().Fonts.Fonts[i].GetDebugName()); } ImGui.GetIO().Fonts.Build(); Log.Verbose("[FONT] Fonts built!"); this.fontBuildSignal.Set(); fontConfig.Destroy(); japaneseRangeHandle.Free(); gameRangeHandle.Free(); iconRangeHandle.Free(); }
public static void Load(ResourceManager resourceManager) { var openSansRegular = @"Resources\Fonts\OpenSans\OpenSans-Regular.ttf"; Regular32 = resourceManager.LoadFont(openSansRegular, 32); Regular24 = resourceManager.LoadFont(openSansRegular, 24); Regular16 = resourceManager.LoadFont(openSansRegular, 16); }
public unsafe ImGuiHelper(Game game) { this.game = game; game.Keyboard.KeyDown += Keyboard_KeyDown; game.Keyboard.KeyUp += Keyboard_KeyUp; game.Keyboard.TextInput += Keyboard_TextInput; context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); SetKeyMappings(); var io = ImGui.GetIO(); //IniFilename? io.WantSaveIniSettings = false; Default = io.Fonts.AddFontDefault(); using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.Roboto-Medium.ttf")) { var ttf = new byte[stream.Length]; stream.Read(ttf, 0, ttf.Length); ttfPtr = Marshal.AllocHGlobal(ttf.Length); Marshal.Copy(ttf, 0, ttfPtr, ttf.Length); Noto = io.Fonts.AddFontFromMemoryTTF(ttfPtr, ttf.Length, 15); } using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.checkerboard.png")) { checkerboard = LibreLancer.ImageLib.Generic.FromStream(stream); CheckerboardId = RegisterTexture(checkerboard); } ImGuiExt.BuildFontAtlas((IntPtr)io.Fonts.NativePtr); byte *fontBytes; int fontWidth, fontHeight; io.Fonts.GetTexDataAsAlpha8(out fontBytes, out fontWidth, out fontHeight); io.Fonts.TexUvWhitePixel = new Vector2(10, 10); fontTexture = new Texture2D(fontWidth, fontHeight, false, SurfaceFormat.R8); var bytes = new byte[fontWidth * fontHeight]; Marshal.Copy((IntPtr)fontBytes, bytes, 0, fontWidth * fontHeight); fontTexture.SetData(bytes); fontTexture.SetFiltering(TextureFiltering.Linear); io.Fonts.SetTexID((IntPtr)FONT_TEXTURE_ID); io.Fonts.ClearTexData(); textShader = new Shader(vertex_source, text_fragment_source); colorShader = new Shader(vertex_source, color_fragment_source); dot = new Texture2D(1, 1, false, SurfaceFormat.Color); var c = new Color4b[] { Color4b.White }; dot.SetData(c); Theme.Apply(); //Required for clipboard function on non-Windows platforms utf8buf = Marshal.AllocHGlobal(8192); instance = this; setTextDel = SetClipboardText; getTextDel = GetClipboardText; io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(getTextDel); io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(setTextDel); }
private void InitializeFonts() { var fonts = IO.Fonts; RobotoMedium = LoadEmbeddedFont("Roboto-Medium.ttf", 16f); ProggyClean = fonts.AddFontDefault(); RebuildFontAtlas(_game.RenderContext); }
private void AddRobotoFonts() { var fontPath = Path.Join( Path.GetDirectoryName(typeof(DebugUiSystem).Assembly.Location), "DebugUI/Roboto-Medium.ttf" ); _smallFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPath, 10); _normalFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPath, 12); }
public unsafe void SetupFonts() { var ioFonts = ImGui.GetIO().Fonts; ImGui.GetIO().Fonts.Clear(); ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig(); fontConfig.PixelSnapH = true; var fontDataText = AppUtil.GetEmbeddedResourceBytes("NotoSansCJKjp-Regular.otf"); var fontDataIcons = AppUtil.GetEmbeddedResourceBytes("FontAwesome5FreeSolid.otf"); var fontDataTextPtr = Marshal.AllocHGlobal(fontDataText.Length); Marshal.Copy(fontDataText, 0, fontDataTextPtr, fontDataText.Length); var fontDataIconsPtr = Marshal.AllocHGlobal(fontDataIcons.Length); Marshal.Copy(fontDataIcons, 0, fontDataIconsPtr, fontDataIcons.Length); var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned); const float FONT_SIZE = 20.0f; TextFont = ioFonts.AddFontFromMemoryTTF(fontDataTextPtr, fontDataText.Length, FONT_SIZE, null, japaneseRangeHandle.AddrOfPinnedObject()); var iconRangeHandle = GCHandle.Alloc( new ushort[] { 0xE000, 0xF8FF, 0, }, GCHandleType.Pinned); IconFont = ioFonts.AddFontFromMemoryTTF(fontDataIconsPtr, fontDataIcons.Length, FONT_SIZE, fontConfig, iconRangeHandle.AddrOfPinnedObject()); ioFonts.Build(); if (Math.Abs(FONT_GAMMA - 1.0f) >= 0.001) { // Gamma correction (stbtt/FreeType would output in linear space whereas most real world usages will apply 1.4 or 1.8 gamma; Windows/XIV prebaked uses 1.4) ioFonts.GetTexDataAsRGBA32(out byte *texPixels, out var texWidth, out var texHeight); for (int i = 3, j = texWidth * texHeight * 4; i < j; i += 4) { texPixels[i] = (byte)(Math.Pow(texPixels[i] / 255.0f, 1.0f / FONT_GAMMA) * 255.0f); } } fontConfig.Destroy(); japaneseRangeHandle.Free(); iconRangeHandle.Free(); }
public ImGuiUserInterface(ICamera camera, uint width, uint height) { this.camera = camera; this.width = width; this.height = height; IntPtr context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); ImGuiIOPtr io = ImGui.GetIO(); io.Fonts.AddFontDefault(); io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset; io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard; io.MouseDrawCursor = true; ImGui.StyleColorsClassic(); ImGui.GetStyle().FrameBorderSize = 1; ImGui.GetStyle().FrameRounding = 2; defaultFont = io.Fonts.AddFontFromFileTTF("./Fonts/OpenSans/font.ttf", 16); io.Fonts.Build(); io.KeyMap[(int)ImGuiKey.Tab] = (int)Key.Tab; io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)Key.Left; io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Key.Right; io.KeyMap[(int)ImGuiKey.UpArrow] = (int)Key.Up; io.KeyMap[(int)ImGuiKey.DownArrow] = (int)Key.Down; io.KeyMap[(int)ImGuiKey.PageUp] = (int)Key.PageUp; io.KeyMap[(int)ImGuiKey.PageDown] = (int)Key.PageDown; io.KeyMap[(int)ImGuiKey.Home] = (int)Key.Home; io.KeyMap[(int)ImGuiKey.End] = (int)Key.End; io.KeyMap[(int)ImGuiKey.Delete] = (int)Key.Delete; io.KeyMap[(int)ImGuiKey.Backspace] = (int)Key.BackSpace; io.KeyMap[(int)ImGuiKey.Enter] = (int)Key.Enter; io.KeyMap[(int)ImGuiKey.Escape] = (int)Key.Escape; io.KeyMap[(int)ImGuiKey.Space] = (int)Key.Space; io.KeyMap[(int)ImGuiKey.A] = (int)Key.A; io.KeyMap[(int)ImGuiKey.C] = (int)Key.C; io.KeyMap[(int)ImGuiKey.V] = (int)Key.V; io.KeyMap[(int)ImGuiKey.X] = (int)Key.X; io.KeyMap[(int)ImGuiKey.Y] = (int)Key.Y; io.KeyMap[(int)ImGuiKey.Z] = (int)Key.Z; vendor = $"Vendor: {GL.GetString(StringName.Vendor)}"; renderer = $"Renderer: {GL.GetString(StringName.Renderer)}"; version = $"Version: {GL.GetString(StringName.Version)}"; glsl = $"GLSL version: {GL.GetString(StringName.ShadingLanguageVersion)}"; CreateShaderProgram(); CreateVertexArray(); CreateTexture(); }
public ImGuiFontSetter(ImFontPtr pointer) { if (!pointer.IsNull()) { ImGui.PushFont(pointer); } else { _disposed = true; } }
/// <summary> /// Constructs a new ImGuiController. /// </summary> public ImGuiController(int width, int height) { _windowWidth = width; _windowHeight = height; var context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); var io = ImGui.GetIO(); io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; //Load the main font file unsafe { var nativeConfig = ImGuiNative.ImFontConfig_ImFontConfig(); //Add a higher horizontal/vertical sample rate for global scaling. (*nativeConfig).OversampleH = 8; (*nativeConfig).OversampleV = 8; (*nativeConfig).RasterizerMultiply = 1f; (*nativeConfig).GlyphOffset = new System.Numerics.Vector2(0); io.Fonts.AddFontFromFileTTF("Lib/Font.ttf", 16, nativeConfig); } //Merge icon fonts. Important that this goes after the main target font being used so it can be merged. ImFontConfig config = new ImFontConfig { MergeMode = 1, PixelSnapH = 1, }; char min = Convert.ToChar(57344); char max = Convert.ToChar(63743); AddFontFromFileTTF("Lib/OpenFontIcons.ttf", 16, config, new[] { min, max, (char)0 }); //Store the default font for monospaced UI (ie hex viewer) DefaultFont = io.Fonts.AddFontDefault(); io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset; CreateDeviceResources(); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); ImGui.NewFrame(); _frameBegun = true; }
public CFontProvider(ImFontAtlasPtr fontAtlasPtr, Action fontAddedCallback) { m_managedFontAtlas = fontAtlasPtr; // Add our default font in different sizes to provide best quality with different scaling ImFontPtr defaultSmall = fontAtlasPtr.AddFontFromFileTTF(DEFAULT_FONT_PATH, 15.0f); ImFontPtr defaultMedium = fontAtlasPtr.AddFontFromFileTTF(DEFAULT_FONT_PATH, 30.0f); ImFontPtr defaultBig = fontAtlasPtr.AddFontFromFileTTF(DEFAULT_FONT_PATH, 60.0f); m_defaultFont.Add(defaultSmall); m_defaultFont.Add(defaultMedium); m_defaultFont.Add(defaultBig); m_fontAddedCallback = fontAddedCallback; }
public SandboxChart(ImFontPtr font) { chartSize = new Vector2(300, 300); KKLayoutParameters layoutParams = new KKLayoutParameters() { Height = chartSize.Y - (2 * padding), Width = chartSize.X - (2 * padding), LengthFactor = 1, DisconnectedMultiplier = 2, ExchangeVertices = true }; layout = new GraphShape.Algorithms.Layout.KKLayoutAlgorithm <ItemNode, Edge <ItemNode>, BidirectionalGraph <ItemNode, Edge <ItemNode> > >(sbgraph, parameters: layoutParams); layout.Compute(); }
private unsafe void SetupFonts() { ImGui.GetIO().Fonts.Clear(); ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig(); fontConfig.MergeMode = true; fontConfig.PixelSnapH = true; var fontPathJp = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "NotoSansCJKjp-Medium.otf"); var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned); DefaultFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathJp, 17.0f, null, japaneseRangeHandle.AddrOfPinnedObject()); var fontPathGame = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "gamesym.ttf"); var gameRangeHandle = GCHandle.Alloc(new ushort[] { 0xE020, 0xE0DB, 0 }, GCHandleType.Pinned); ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathGame, 17.0f, fontConfig, gameRangeHandle.AddrOfPinnedObject()); var fontPathIcon = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "FontAwesome5FreeSolid.otf"); var iconRangeHandle = GCHandle.Alloc(new ushort[] { 0xE000, 0xF8FF, 0 }, GCHandleType.Pinned); IconFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathIcon, 17.0f, null, iconRangeHandle.AddrOfPinnedObject()); this.OnBuildFonts?.Invoke(); ImGui.GetIO().Fonts.Build(); fontConfig.Destroy(); japaneseRangeHandle.Free(); gameRangeHandle.Free(); iconRangeHandle.Free(); }
protected override void Initialize() { // TODO: Add your initialization logic here imGuiRenderer = new ImGuiRenderer(this, platform, platformFunctions); if (platform == Platform.Android) { AndroidCopyToDisk("OpenSans-Regular.ttf"); } font = ImGui.GetIO().Fonts.AddFontFromFileTTF( PlatformContentPath("OpenSans-Regular.ttf"), 24 * platformFunctions.ScreenDensity()); imGuiRenderer.RebuildFontAtlas(); base.Initialize(); }
void Loading() { bLoading = true; System.Threading.ThreadPool.QueueUserWorkItem((e) => { var io = ImGui.GetIO(); ImFontPtr font = io.Fonts.AddFontFromFileTTF( "Assets/fonts/AlibabaPH-Regular.otf", 16f, null, io.Fonts.GetGlyphRangesChineseFull()); mainthreadAction.Enqueue(() => { var oldfont = io.Fonts; io.SetFontDefault(font); bLoading = false; }); }); }
/// <summary> /// Creates a texture and loads the font data from ImGui. /// Should be called when the <see cref="Microsoft.Xna.Framework.Graphics.GraphicsDevice" /> /// is initialized but before any rendering is done /// </summary> public unsafe void RebuildFontAtlas() { // Get font texture from ImGui var io = ImGui.GetIO(); if (Options != null) { if (Options.LoadDefaultFont) { DefaultFontPtr = io.Fonts.AddFontDefault(); } foreach (var font in Options.Fonts) { font.Context = io.Fonts.AddFontFromFileTTF(font.Path, font.Size); } } io.Fonts.GetTexDataAsRGBA32(out var pixelData, out var width, out var height, out var bytesPerPixel); // Copy the data to a managed array var pixels = new byte[width * height * bytesPerPixel]; Marshal.Copy(new IntPtr(pixelData), pixels, 0, pixels.Length); // Create and register the texture as an XNA texture var tex2D = new Texture2D(GraphicsDevice, width, height, false, SurfaceFormat.Color); tex2D.SetData(pixels); // Should a texture already have been build previously, unbind it first so it can be deallocated if (FontTextureId.HasValue) { UnbindTexture(FontTextureId.Value); } // Bind the new texture to an ImGui-friendly id FontTextureId = BindTexture(tex2D); // Let ImGui know where to find the texture io.Fonts.SetTexID(FontTextureId.Value); io.Fonts.ClearTexData(); // Clears CPU side texture data }
public static unsafe ImFontPtr AddFont(DynamicFontData fontData, int fontSize) { ImFontPtr rv = null; Godot.File fi = new File(); var err = fi.Open(fontData.FontPath, File.ModeFlags.Read); byte[] buf = fi.GetBuffer((int)fi.GetLen()); fi.Close(); // can't add a name, ImFontConfig seems unusable // let ImGui manage this memory IntPtr p = Marshal.AllocHGlobal(buf.Length); Marshal.Copy(buf, 0, p, buf.Length); rv = ImGui.GetIO().Fonts.AddFontFromMemoryTTF(p, buf.Length, (float)fontSize); return(rv); }
public void LoadFont(string fontFamily, string fontFilePath, float[] sizesToLoad) { if (File.Exists(fontFilePath)) { SHashedName fontFamilyName = new SHashedName(fontFamily); if (m_fontCollections.ContainsKey(fontFamilyName)) { // If the font is already know only load sizes we don't already loaded List <ImFontPtr> fonts = m_fontCollections[fontFamilyName]; foreach (float sizeToLoad in sizesToLoad) { if (!fonts.Any(ptr => Math.Abs(ptr.FontSize - sizeToLoad) < 0.001f)) { ImFontPtr fontPtr = m_managedFontAtlas.AddFontFromFileTTF(fontFilePath, sizeToLoad); fonts.Add(fontPtr); } } fonts.Sort((lftFont, rghFont) => lftFont.FontSize.CompareTo(rghFont.FontSize)); } else { List <ImFontPtr> fontList = new List <ImFontPtr>(); foreach (float sizeToLoad in sizesToLoad) { ImFontPtr fontPtr = m_managedFontAtlas.AddFontFromFileTTF(fontFilePath, sizeToLoad); fontList.Add(fontPtr); } fontList.Sort((lftFont, rghFont) => lftFont.FontSize.CompareTo(rghFont.FontSize)); m_fontCollections.Add(fontFamilyName, fontList); } m_fontAddedCallback(); } else { throw new FileNotFoundException("Font does not exists requested path was: " + fontFilePath); } }
private void DrawSplash(rgatSettings.PathRecord[] recentBins, rgatSettings.PathRecord[] recentTraces) { ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, Vector2.Zero); ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, Vector2.Zero); ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, Vector2.Zero); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero); ImGui.PushStyleVar(ImGuiStyleVar.ItemInnerSpacing, Vector2.Zero); float regionHeight = ImGui.GetContentRegionAvail().Y; float regionWidth = ImGui.GetContentRegionAvail().X; float buttonBlockWidth = Math.Min(400f, regionWidth / 2.1f); float headerHeight = ImGui.GetWindowSize().Y / 3; float blockHeight = (regionHeight * 0.95f) - headerHeight; float blockStart = headerHeight + 40f; ImFontPtr titleFont = Controller.rgatLargeFont ?? Controller._originalFont !.Value; ImGui.PushFont(titleFont); Vector2 titleSize = ImGui.CalcTextSize("rgat"); ImGui.SetCursorScreenPos(new Vector2((ImGui.GetWindowContentRegionMax().X / 2) - (titleSize.X / 2), (ImGui.GetWindowContentRegionMax().Y / 5) - (titleSize.Y / 2))); ImGui.Text("rgat"); ImGui.PopFont(); //ImGui.PushStyleColor(ImGuiCol.ChildBg, 0xff0000ff); //ImGui.PushStyleColor(ImGuiCol.ChildBg, new WritableRgbaFloat(0, 0, 0, 255).ToUint()); bool boxBorders = false; //ImGui.PushStyleColor(ImGuiCol.HeaderHovered, 0x45ffffff); _splashHeaderHover = ImGui.GetMousePos().Y < (ImGui.GetWindowSize().Y / 3f); //ImGui.PopStyleColor(); //Run group float voidspace = Math.Max(0, (regionWidth - (2 * buttonBlockWidth)) / 3); float runGrpX = voidspace; float iconTableYSep = 18; float iconTitleYSep = 10; ImGuiTableFlags tblflags = ImGuiTableFlags.NoHostExtendX; if (boxBorders) { tblflags |= ImGuiTableFlags.Borders; } ImGui.SetCursorPos(new Vector2(runGrpX, blockStart)); ImGui.PushStyleColor(ImGuiCol.ChildBg, Themes.GetThemeColourUINT(Themes.eThemeColour.WindowBackground)); if (ImGui.BeginChild("##RunGroup", new Vector2(buttonBlockWidth, blockHeight), boxBorders)) { ImGui.PushFont(Controller.SplashLargeFont ?? Controller._originalFont !.Value); float captionHeight = ImGui.CalcTextSize("Load Binary").Y; if (ImGui.BeginTable("##LoadBinBtnBox", 3, tblflags)) { Vector2 LargeIconSize = Controller.LargeIconSize; float iconColumnWidth = 200; float paddingX = (buttonBlockWidth - iconColumnWidth) / 2; ImGui.TableSetupColumn("##BBSPadL", ImGuiTableColumnFlags.WidthFixed, paddingX); ImGui.TableSetupColumn("##LoadBinBtnIcn", ImGuiTableColumnFlags.WidthFixed, iconColumnWidth); ImGui.TableSetupColumn("##BBSPadR", ImGuiTableColumnFlags.WidthFixed, paddingX); ImGui.TableNextRow(); ImGui.TableSetColumnIndex(1); Vector2 selectableSize = new Vector2(iconColumnWidth, captionHeight + LargeIconSize.Y + iconTitleYSep + 12); if (ImGui.Selectable("##Load Binary", false, ImGuiSelectableFlags.None, selectableSize)) { ToggleLoadExeWindow(); } Controller.PushUnicodeFont(); Widgets.SmallWidgets.MouseoverText("Load an executable or DLL for examination. It will not be executed at this stage."); ImGui.PopFont(); ImGui.SetCursorPosY(ImGui.GetCursorPosY() - ImGui.GetItemRectSize().Y); ImGuiUtils.DrawHorizCenteredText("Load Binary"); ImGui.SetCursorPosX(ImGui.GetCursorPosX() + (iconColumnWidth / 2) - (LargeIconSize.X / 2)); ImGui.SetCursorPosY(ImGui.GetCursorPosY() + iconTitleYSep); Controller.PushBigIconFont(); ImGui.Text($"{ImGuiController.FA_ICON_SAMPLE}"); //If you change this be sure to update ImGuiController.BuildFonts ImGui.PopFont(); ImGui.EndTable(); } ImGui.PopFont(); ImGui.SetCursorPosY(ImGui.GetCursorPosY() + iconTableYSep); Vector2 tableSz = new Vector2(buttonBlockWidth, ImGui.GetContentRegionAvail().Y - 25); ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(0, 2)); if (ImGui.BeginTable("#RecentBinTableList", 1, ImGuiTableFlags.ScrollY, tableSz)) { ImGui.Indent(5); ImGui.TableSetupColumn("Recent Binaries" + $"{(rgatState.ConnectedToRemote ? " (Remote Files)" : "")}"); ImGui.TableSetupScrollFreeze(0, 1); ImGui.TableHeadersRow(); if (recentBins?.Length > 0) { int bincount = Math.Min(GlobalConfig.Settings.UI.MaxStoredRecentPaths, recentBins.Length); for (var bini = 0; bini < bincount; bini++) { var entry = recentBins[bini]; ImGui.TableNextRow(); if (ImGui.TableNextColumn()) { if (DrawRecentPathEntry(entry, menu: false)) { if (File.Exists(entry.Path) || rgatState.ConnectedToRemote) { if (!LoadSelectedBinary(entry.Path, rgatState.ConnectedToRemote) && !_badPaths.Contains(entry.Path)) { _badPaths.Add(entry.Path); } } else if (!_missingPaths.Contains(entry.Path) && rgatState.ConnectedToRemote is false) { _scheduleMissingPathCheck = true; _missingPaths.Add(entry.Path); } } } } } ImGui.EndTable(); } ImGui.PopStyleVar(); ImGui.EndChild(); } ImGui.SetCursorPosY(blockStart); ImGui.SetCursorPosX(runGrpX + buttonBlockWidth + voidspace); if (ImGui.BeginChild("##LoadGroup", new Vector2(buttonBlockWidth, blockHeight), boxBorders)) { ImGui.PushFont(Controller.SplashLargeFont ?? Controller._originalFont !.Value); float captionHeight = ImGui.CalcTextSize("Load Trace").Y; if (ImGui.BeginTable("##LoadBtnBox", 3, tblflags)) { Vector2 LargeIconSize = Controller.LargeIconSize; float iconColumnWidth = 200; float paddingX = (buttonBlockWidth - iconColumnWidth) / 2; ImGui.TableSetupColumn("##LBSPadL", ImGuiTableColumnFlags.WidthFixed, paddingX); ImGui.TableSetupColumn("##LoadBtnIcn", ImGuiTableColumnFlags.WidthFixed, iconColumnWidth); ImGui.TableSetupColumn("##LBSPadR", ImGuiTableColumnFlags.WidthFixed, paddingX); ImGui.TableNextRow(); ImGui.TableSetColumnIndex(1); Vector2 selectableSize = new Vector2(iconColumnWidth, captionHeight + LargeIconSize.Y + iconTitleYSep + 12); if (ImGui.Selectable("##Load Trace", false, ImGuiSelectableFlags.None, selectableSize)) { ToggleLoadTraceWindow(); } Controller.PushUnicodeFont(); Widgets.SmallWidgets.MouseoverText("Load a previously generated trace"); ImGui.PopFont(); ImGui.SetCursorPosY(ImGui.GetCursorPosY() - ImGui.GetItemRectSize().Y); ImGuiUtils.DrawHorizCenteredText("Load Trace"); ImGui.SetCursorPosX(ImGui.GetCursorPosX() + (iconColumnWidth / 2) - (LargeIconSize.X / 2) + 8); //shift a bit to the right to balance it ImGui.SetCursorPosY(ImGui.GetCursorPosY() + iconTitleYSep); Controller.PushBigIconFont(); ImGui.Text($"{ImGuiController.FA_ICON_LOADFILE}");//If you change this be sure to update ImGuiController.BuildFonts ImGui.PopFont(); ImGui.EndTable(); } ImGui.PopFont(); ImGui.SetCursorPosY(ImGui.GetCursorPosY() + iconTableYSep); Vector2 tableSz = new Vector2(buttonBlockWidth, ImGui.GetContentRegionAvail().Y - 25); ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(0, 2)); if (ImGui.BeginTable("#RecentTraceTableList", 1, ImGuiTableFlags.ScrollY, tableSz)) { ImGui.Indent(5); ImGui.TableSetupColumn("Recent Traces"); ImGui.TableSetupScrollFreeze(0, 1); ImGui.TableHeadersRow(); if (recentTraces?.Length > 0) { int traceCount = Math.Min(GlobalConfig.Settings.UI.MaxStoredRecentPaths, recentTraces.Length); for (var traceI = 0; traceI < traceCount; traceI++) { var entry = recentTraces[traceI]; ImGui.TableNextRow(); if (ImGui.TableNextColumn()) { if (DrawRecentPathEntry(entry, false)) { if (File.Exists(entry.Path)) { System.Threading.Tasks.Task.Run(() => LoadTraceByPath(entry.Path)); /* * if (!LoadTraceByPath(entry.Path) && !_badPaths.Contains(entry.Path)) * { * _badPaths.Add(entry.Path); * }*/ } else if (!_missingPaths.Contains(entry.Path)) { _scheduleMissingPathCheck = true; _missingPaths.Add(entry.Path); } } } } } ImGui.EndTable(); } ImGui.PopStyleVar(); ImGui.EndChild(); } ImGui.PopStyleVar(5); ImGui.BeginGroup(); string versionString = $"rgat {CONSTANTS.PROGRAMVERSION.RGAT_VERSION}"; float width = ImGui.CalcTextSize(versionString).X; ImGui.SetCursorPos(ImGui.GetContentRegionMax() - new Vector2(width + 25, 40)); ImGui.Text(versionString); if (GlobalConfig.NewVersionAvailable) { Version currentVersion = CONSTANTS.PROGRAMVERSION.RGAT_VERSION_SEMANTIC; Version newVersion = GlobalConfig.Settings.Updates.UpdateLastCheckVersion; string updateString; if (newVersion.Major > currentVersion.Major || (newVersion.Major == currentVersion.Major && newVersion.Minor > currentVersion.Minor)) { updateString = "New version available "; } else { updateString = "Updates available "; } updateString += $"({newVersion})"; Vector2 textSize = ImGui.CalcTextSize(updateString); ImGui.SetCursorPos(ImGui.GetContentRegionMax() - new Vector2(textSize.X + 25, 55)); if (ImGui.Selectable(updateString, false, flags: ImGuiSelectableFlags.None, size: new Vector2(textSize.X, textSize.Y))) { ImGui.OpenPopup("New Version Available"); } if (ImGui.IsItemHovered()) { Updates.ChangesCounts(out int changes, out int versions); if (changes > 0) { ImGui.BeginTooltip(); ImGui.Text($"Click to see {changes} changes in {versions} newer rgat versions"); ImGui.EndTooltip(); } } } ImGui.EndGroup(); ImGui.PopStyleColor(); if (GlobalConfig.Settings.UI.EnableTortoise) { _splashRenderer?.Draw(); } if (StartupProgress < 1) { float originalY = ImGui.GetCursorPosY(); float ypos = ImGui.GetWindowSize().Y - 12; ImGui.SetCursorPosY(ypos); ImGui.ProgressBar((float)StartupProgress, new Vector2(-1, 4f)); ImGui.SetCursorPosY(originalY); } if (ImGui.IsPopupOpen("New Version Available")) { ImGui.SetNextWindowSize(new Vector2(600, 500), ImGuiCond.FirstUseEver); ImGui.SetNextWindowPos((ImGui.GetWindowSize() / 2) - new Vector2(600f / 2f, 500f / 2f), ImGuiCond.Appearing); bool isopen = true; if (ImGui.BeginPopupModal("New Version Available", ref isopen, flags: ImGuiWindowFlags.Modal)) { Updates.DrawChangesDialog(); isopen = isopen && !ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Escape)); if (!isopen) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } } }
public unsafe ImGuiHelper(Game game) { this.game = game; game.Keyboard.KeyDown += Keyboard_KeyDown; game.Keyboard.KeyUp += Keyboard_KeyUp; game.Keyboard.TextInput += Keyboard_TextInput; context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); SetKeyMappings(); var io = ImGui.GetIO(); io.WantSaveIniSettings = false; io.NativePtr->IniFilename = (byte *)0; //disable ini!! var fontConfigA = new ImFontConfigPtr(ImFontConfig_ImFontConfig()); var fontConfigB = new ImFontConfigPtr(ImFontConfig_ImFontConfig()); var fontConfigC = new ImFontConfigPtr(ImFontConfig_ImFontConfig()); ushort[] glyphRangesFull = new ushort[] { 0x0020, 0x00FF, //Basic Latin + Latin Supplement, 0x0400, 0x052F, //Cyrillic + Cyrillic Supplement 0x2DE0, 0x2DFF, //Cyrillic Extended-A 0xA640, 0xA69F, //Cyrillic Extended-B ImGuiExt.ReplacementHash, ImGuiExt.ReplacementHash, 0 }; var rangesPtrFull = Marshal.AllocHGlobal(sizeof(short) * glyphRangesFull.Length); for (int i = 0; i < glyphRangesFull.Length; i++) { ((ushort *)rangesPtrFull)[i] = glyphRangesFull[i]; } ushort[] glyphRangesLatin = new ushort[] { 0x0020, 0x00FF, //Basic Latin + Latin Supplement ImGuiExt.ReplacementHash, ImGuiExt.ReplacementHash, 0 }; var rangesPtrLatin = Marshal.AllocHGlobal(sizeof(short) * glyphRangesLatin.Length); for (int i = 0; i < glyphRangesLatin.Length; i++) { ((ushort *)rangesPtrLatin)[i] = glyphRangesLatin[i]; } fontConfigA.GlyphRanges = rangesPtrLatin; fontConfigB.GlyphRanges = rangesPtrFull; fontConfigC.GlyphRanges = rangesPtrFull; Default = io.Fonts.AddFontDefault(fontConfigA); using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.Roboto-Medium.ttf")) { var ttf = new byte[stream.Length]; stream.Read(ttf, 0, ttf.Length); ttfPtr = Marshal.AllocHGlobal(ttf.Length); Marshal.Copy(ttf, 0, ttfPtr, ttf.Length); Noto = io.Fonts.AddFontFromMemoryTTF(ttfPtr, ttf.Length, 15, fontConfigB); } using (var stream = typeof(ImGuiHelper).Assembly.GetManifestResourceStream("LibreLancer.ImUI.checkerboard.png")) { checkerboard = LibreLancer.ImageLib.Generic.FromStream(stream); CheckerboardId = RegisterTexture(checkerboard); } var monospace = Platform.GetMonospaceBytes(); fixed(byte *mmPtr = monospace) { SystemMonospace = io.Fonts.AddFontFromMemoryTTF((IntPtr)mmPtr, monospace.Length, 16, fontConfigC); } ImGuiExt.BuildFontAtlas((IntPtr)io.Fonts.NativePtr); byte *fontBytes; int fontWidth, fontHeight; io.Fonts.GetTexDataAsAlpha8(out fontBytes, out fontWidth, out fontHeight); io.Fonts.TexUvWhitePixel = new Vector2(10, 10); fontTexture = new Texture2D(fontWidth, fontHeight, false, SurfaceFormat.R8); var bytes = new byte[fontWidth * fontHeight]; Marshal.Copy((IntPtr)fontBytes, bytes, 0, fontWidth * fontHeight); fontTexture.SetData(bytes); fontTexture.SetFiltering(TextureFiltering.Linear); io.Fonts.SetTexID((IntPtr)FONT_TEXTURE_ID); io.Fonts.ClearTexData(); textShader = new Shader(vertex_source, text_fragment_source); colorShader = new Shader(vertex_source, color_fragment_source); dot = new Texture2D(1, 1, false, SurfaceFormat.Color); var c = new Color4b[] { Color4b.White }; dot.SetData(c); Theme.Apply(); //Required for clipboard function on non-Windows platforms utf8buf = Marshal.AllocHGlobal(8192); instance = this; setTextDel = SetClipboardText; getTextDel = GetClipboardText; io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(getTextDel); io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(setTextDel); }
/// <summary> /// Constructs a new ImGuiController. /// </summary> public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, int width, int height) { _gd = gd; _windowWidth = width; _windowHeight = height; Context = ImGui.CreateContext(); ImGui.SetCurrentContext(Context); ImGui.GetIO().Fonts.AddFontDefault(); var arial = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "arial.ttf"); var arialbd = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "arialbd.ttf"); var cfg = new ImFontConfig { FontDataOwnedByAtlas = 1, OversampleH = 5, OversampleV = 1, PixelSnapH = 0, GlyphMinAdvanceX = 0, GlyphMaxAdvanceX = float.MaxValue, RasterizerMultiply = 1.2f }; if (File.Exists(arial)) { unsafe { DefaultFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(arial, 14, new ImFontConfigPtr(&cfg)); LargeFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(arial, 24, new ImFontConfigPtr(&cfg)); } } else { DefaultFont = null; LargeFont = null; } if (File.Exists(arialbd)) { unsafe { BoldFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(arialbd, 14, new ImFontConfigPtr(&cfg)); } } else { BoldFont = null; } var style = ImGui.GetStyle(); style.WindowRounding = 0; style.WindowPadding = Vector2.Zero; style.WindowBorderSize = 0; style.AntiAliasedFill = false; style.AntiAliasedLines = false; CreateDeviceResources(gd, outputDescription); SetPerFrameImGuiData(1f / 60f); ImGui.NewFrame(); _frameBegun = true; }
public static unsafe void TintGlyphs(byte *data, int atlasWidth, int atlasHeight, ImFontPtr font) { foreach (var t in tints) { var glyph = ImGuiExt.igFontFindGlyph(font.NativePtr, t.Item1); var color = t.Item2; var offx = (int)(glyph->U0 * atlasWidth); var width = (int)(glyph->U1 * atlasWidth) - offx; var offy = (int)(glyph->V0 * atlasHeight); var height = (int)(glyph->V1 * atlasHeight) - offy; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { var offset = ((offy + y) * atlasWidth + offx + x) * 4; var r = data[offset + 2] / 255f; var g = data[offset + 1] / 255f; var b = data[offset] / 255f; r *= color.R; g *= color.G; b *= color.B; data[offset + 2] = (byte)(r * 255f); data[offset + 1] = (byte)(g * 255f); data[offset] = (byte)(b * 255f); } } } }
public static bool IsNull(this ImFontPtr pointer) { return(pointer.Equals(new ImFontPtr())); }
public unsafe override void OnAttach() { ImGuiController = new ImGuiController( Application.Get().MainWindow.CreateOpenGL(), Application.Get().MainWindow, Application.Get().MainWindow.CreateInput() ); ImGui.GetIO().NativePtr->IniFilename = null; if (!File.Exists(new DirectoryInfo(Environment.CurrentDirectory).Parent.FullName + @"/imgui.ini")) { ImGui.SaveIniSettingsToDisk(new DirectoryInfo(Environment.CurrentDirectory).Parent.FullName + @"/imgui.ini"); } ImGui.LoadIniSettingsFromDisk(new DirectoryInfo(Environment.CurrentDirectory).Parent.FullName + @"/imgui.ini"); ImGui.GetIO().ConfigFlags |= ImGuiConfigFlags.DockingEnable; ImGui.GetIO().ConfigWindowsMoveFromTitleBarOnly = true; FontDefault = ImGui.GetIO().Fonts.AddFontFromFileTTF (@"builtin\fonts\OpenSans\OpenSans-Regular.ttf", 20); ImGuiController.RecreateFontDeviceTexture(); FontDefaultHuge = ImGui.GetIO().Fonts.AddFontFromFileTTF (@"builtin\fonts\OpenSans\OpenSans-Regular.ttf", FontDefault.FontSize * 4); ImGuiController.RecreateFontDeviceTexture(); ImGuiStylePtr style = ImGui.GetStyle(); style.Alpha = 1.0f; style.WindowTitleAlign = new Vector2(0.5f, 0.5f); style.WindowMinSize = new Vector2(200, 200); style.FramePadding = new Vector2(4, 2); style.ItemSpacing = new Vector2(6, 3); style.ItemInnerSpacing = new Vector2(6, 4); style.WindowRounding = 0.0f; style.FrameRounding = 0.0f; style.ColumnsMinSpacing = 50.0f; style.GrabMinSize = 14.0f; style.GrabRounding = 6.0f; style.ScrollbarSize = 12.0f; style.ScrollbarRounding = 30.0f; style.AntiAliasedLines = true; style.AntiAliasedFill = true; style.Colors[(int)ImGuiCol.Text] = new Vector4(0.9999f, 1f, 0.99994284f, 0.78f); style.Colors[(int)ImGuiCol.TextDisabled] = new Vector4(0.9999f, 1f, 0.99994284f, 0.28f); style.Colors[(int)ImGuiCol.WindowBg] = new Vector4(-0.14471881f, -0.16687626f, -0.1732549f, 1f); style.Colors[(int)ImGuiCol.ChildBg] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0.58f); style.Colors[(int)ImGuiCol.PopupBg] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0.9f); style.Colors[(int)ImGuiCol.Border] = new Vector4(0.010645908f, 0.012275871f, 0.012745101f, 0.6f); style.Colors[(int)ImGuiCol.BorderShadow] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0f); style.Colors[(int)ImGuiCol.FrameBg] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 1f); style.Colors[(int)ImGuiCol.FrameBgHovered] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 0.78f); style.Colors[(int)ImGuiCol.FrameBgActive] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 1f); style.Colors[(int)ImGuiCol.TitleBg] = new Vector4(0.099400006f, 0.11461884f, 0.119f, 1f); style.Colors[(int)ImGuiCol.TitleBgActive] = new Vector4(0.18292941f, 0.21093717f, 0.219f, 1f); style.Colors[(int)ImGuiCol.TitleBgCollapsed] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0.75f); style.Colors[(int)ImGuiCol.MenuBarBg] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0.47f); style.Colors[(int)ImGuiCol.ScrollbarBg] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 1f); style.Colors[(int)ImGuiCol.ScrollbarGrab] = new Vector4(0.099400006f, 0.11461884f, 0.119f, 1f); style.Colors[(int)ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 0.78f); style.Colors[(int)ImGuiCol.ScrollbarGrabActive] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 1f); style.Colors[(int)ImGuiCol.CheckMark] = new Vector4(0.18292941f, 0.21093717f, 0.219f, 1f); style.Colors[(int)ImGuiCol.SliderGrab] = new Vector4(0.13594003f, 0.15675339f, 0.1627451f, 1f); style.Colors[(int)ImGuiCol.SliderGrabActive] = new Vector4(0.18292941f, 0.21093717f, 0.219f, 1f); style.Colors[(int)ImGuiCol.Button] = new Vector4(0.21946944f, 0.25307176f, 0.2627451f, 1f); style.Colors[(int)ImGuiCol.ButtonHovered] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 1f); style.Colors[(int)ImGuiCol.ButtonActive] = new Vector4(0.18292941f, 0.21093717f, 0.219f, 1f); style.Colors[(int)ImGuiCol.Header] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 0.76f); style.Colors[(int)ImGuiCol.HeaderHovered] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 0.86f); style.Colors[(int)ImGuiCol.HeaderActive] = new Vector4(0.18292941f, 0.21093717f, 0.219f, 1f); style.Colors[(int)ImGuiCol.Separator] = new Vector4(0.43f, 0.43f, 0.5f, 0.5f); style.Colors[(int)ImGuiCol.SeparatorHovered] = new Vector4(0.1f, 0.4f, 0.75f, 0.78f); style.Colors[(int)ImGuiCol.SeparatorActive] = new Vector4(0.1f, 0.4f, 0.75f, 1f); style.Colors[(int)ImGuiCol.ResizeGrip] = new Vector4(0.47f, 0.77f, 0.83f, 0.04f); style.Colors[(int)ImGuiCol.ResizeGripHovered] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 0.78f); style.Colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 1f); style.Colors[(int)ImGuiCol.Tab] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0.4f); style.Colors[(int)ImGuiCol.TabHovered] = new Vector4(0.18292941f, 0.21093717f, 0.219f, 1f); style.Colors[(int)ImGuiCol.TabActive] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 1f); style.Colors[(int)ImGuiCol.TabUnfocused] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0.4f); style.Colors[(int)ImGuiCol.TabUnfocusedActive] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0.7f); style.Colors[(int)ImGuiCol.DockingPreview] = new Vector4(0.18292941f, 0.21093717f, 0.219f, 0.3f); style.Colors[(int)ImGuiCol.DockingEmptyBg] = new Vector4(0.2f, 0.2f, 0.2f, 1f); style.Colors[(int)ImGuiCol.PlotLines] = new Vector4(0.9999f, 1f, 0.99994284f, 0.63f); style.Colors[(int)ImGuiCol.PlotLinesHovered] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 1f); style.Colors[(int)ImGuiCol.PlotHistogram] = new Vector4(0.9999f, 1f, 0.99994284f, 0.63f); style.Colors[(int)ImGuiCol.PlotHistogramHovered] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 1f); style.Colors[(int)ImGuiCol.TextSelectedBg] = new Vector4(0.1269647f, 0.14640388f, 0.152f, 0.43f); style.Colors[(int)ImGuiCol.DragDropTarget] = new Vector4(1f, 1f, 0f, 0.9f); style.Colors[(int)ImGuiCol.NavHighlight] = new Vector4(0.26f, 0.59f, 0.98f, 1f); style.Colors[(int)ImGuiCol.NavWindowingHighlight] = new Vector4(1f, 1f, 1f, 0.7f); style.Colors[(int)ImGuiCol.NavWindowingDimBg] = new Vector4(0.8f, 0.8f, 0.8f, 0.2f); style.Colors[(int)ImGuiCol.ModalWindowDimBg] = new Vector4(0.052410614f, 0.060435046f, 0.0627451f, 0.73f); }