示例#1
0
文件: ImFont.cs 项目: rje/ImGuiSharp
        //~ImFont();

        void Clear()
        {
            FontSize        = 0.0f;
            DisplayOffset   = new ImVec2(0.0f, 1.0f);
            ConfigData      = null;
            ConfigDataCount = 0;
            Ascent          = Descent = 0.0f;
            ContainerAtlas  = null;
            Glyphs.clear();
            FallbackGlyph    = null;
            FallbackXAdvance = 0.0f;
            IndexXAdvance.clear();
            IndexLookup.clear();
        }
示例#2
0
        /// <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;
        }
示例#3
0
        public static void AddFontFromFileTTF(string filename,
                                              float sizePixels,
                                              ImFontConfig config,
                                              char[] glyphRanges)
        {
            ImGuiIOPtr io = ImGui.GetIO();

            config.OversampleH        = 1;
            config.OversampleV        = 1;
            config.RasterizerMultiply = 1;

            unsafe
            {
                fixed(char *glyphs = &glyphRanges[0])
                {
                    io.Fonts.AddFontFromFileTTF(filename, sizePixels, &config, (IntPtr)glyphs);
                }
            }
        }
示例#4
0
        protected override void OnLoad(EventArgs e)
        {
            CursorVisible = true;
            GL.ClearColor(0.2f, 0.2f, 0.2f, 1);

            Logger.Log()(LogLevel.INFO, "Initialized LSDView");

            var io = ImGui.GetIO();

            ImFontConfig cfg = new ImFontConfig
            {
                MergeMode        = 1,
                PixelSnapH       = 1,
                GlyphOffset      = new Vector2(1, 1),
                GlyphMinAdvanceX = 20,
            };

            ImGuiRenderer.AddFontFromFileTTF("Fonts/fa-solid-900.ttf", 16, cfg,
                                             new[] { (char)FontAwesome5.IconMin, (char)FontAwesome5.IconMax, (char)0 });
        }
            public static void AddIconsToDefaultFont(float fontSize)
            {
                var fontFilePath = "IcoMoon-Free.ttf";
                var ranges       = new [] { '\ue900', '\ueaea' };
                var rangesIntPtr = Marshal.UnsafeAddrOfPinnedArrayElement(ranges, 0);

                ImFontConfig config = new ImFontConfig {
                    MergeMode            = 1,
                    OversampleH          = 3, OversampleV = 3,
                    GlyphOffset          = Vector2.UnitY * 2,
                    FontDataOwnedByAtlas = 1,
                    PixelSnapH           = 1,
                    GlyphMaxAdvanceX     = float.MaxValue,
                    RasterizerMultiply   = 1.0f
                };

                var configHandle = GCHandle.Alloc(config, GCHandleType.Pinned);

                ImGui.GetIO().Fonts.AddFontFromFileTTF(fontFilePath, fontSize, configHandle.AddrOfPinnedObject(), rangesIntPtr);

                configHandle.Free();
            }
示例#6
0
    void RebuildFonts()
    {
        ImGuiIOPtr io = ImGui.GetIO();

        // Default font
        ImFontAtlasPtr fonts = io.Fonts;

        fonts.Clear();
        using (ImFontConfig config = new ImFontConfig())
        {
            config.SizePixels  = 13.0f * uiScale;   // ImGui default font size is 13 pixels
            config.OversampleH = 1;
            fonts.AddFontDefault(config);
        }

#if !UNITY_ANDROID
        // Icon font
        if (iconFont.Length > 0)
        {
            using (ImFontConfig config = new ImFontConfig())
            {
                config.MergeMode = true;
                if (iconFontMinAdvanceX > 0)
                {
                    config.GlyphMinAdvanceX = iconFontMinAdvanceX;
                    config.GlyphMaxAdvanceX = iconFontMinAdvanceX;
                }
                config.PixelSnapH  = true;
                config.OversampleH = 1;
                ushort rangeMin = ushort.Parse(iconRangeMin, NumberStyles.HexNumber);
                ushort rangeMax = ushort.Parse(iconRangeMax, NumberStyles.HexNumber);
                if (rangeMin != 0 && rangeMax != 0)
                {
                    ushort[] icon_ranges = { rangeMin, rangeMax, 0 };
                    ImGui.AddFontFromFileTTF(fonts, Application.streamingAssetsPath + "/" + iconFont, iconFontPixelSize * uiScale, config, icon_ranges);
                }
            }
        }

        // Custom fonts
        imFonts = new ImFontPtr[customFonts.Length];
        for (int i = 0; i < customFonts.Length; i++)
        {
            using (ImFontConfig config = new ImFontConfig())
            {
                config.OversampleH = 1;
                config.OversampleV = 1;
                imFonts[i]         = fonts.AddFontFromFileTTF(Application.streamingAssetsPath + "/" + customFonts[i], customFontPixelSize * uiScale, config);
            }
        }
#endif

        if (useFreetype)
        {
            // Freetype rasterizer
            ImGui.BuildFontAtlas(fonts, freetype_flags);
        }
        else
        {
            fonts.Build();
        }
        RecreateFontTexture();
    }
示例#7
0
        /// <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;
        }