Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
0
        public static void Init()
        {
            if (_Initialized)
            {
                return;
            }
            _Initialized = true;

            IntPtr context = ImGui.CreateContext();

            ImGui.SetCurrentContext(context);

            ImGuiIOPtr io = ImGui.GetIO();


            io.KeyMap[(int)ImGuiKey.Tab]        = (int)SDL.SDL_Keycode.SDLK_TAB;
            io.KeyMap[(int)ImGuiKey.LeftArrow]  = (int)SDL.SDL_Scancode.SDL_SCANCODE_LEFT;
            io.KeyMap[(int)ImGuiKey.RightArrow] = (int)SDL.SDL_Scancode.SDL_SCANCODE_RIGHT;
            io.KeyMap[(int)ImGuiKey.UpArrow]    = (int)SDL.SDL_Scancode.SDL_SCANCODE_UP;
            io.KeyMap[(int)ImGuiKey.DownArrow]  = (int)SDL.SDL_Scancode.SDL_SCANCODE_DOWN;
            io.KeyMap[(int)ImGuiKey.PageUp]     = (int)SDL.SDL_Scancode.SDL_SCANCODE_PAGEUP;
            io.KeyMap[(int)ImGuiKey.PageDown]   = (int)SDL.SDL_Scancode.SDL_SCANCODE_PAGEDOWN;
            io.KeyMap[(int)ImGuiKey.Home]       = (int)SDL.SDL_Scancode.SDL_SCANCODE_HOME;
            io.KeyMap[(int)ImGuiKey.End]        = (int)SDL.SDL_Scancode.SDL_SCANCODE_END;
            io.KeyMap[(int)ImGuiKey.Delete]     = (int)SDL.SDL_Keycode.SDLK_DELETE;
            io.KeyMap[(int)ImGuiKey.Backspace]  = (int)SDL.SDL_Keycode.SDLK_BACKSPACE;
            io.KeyMap[(int)ImGuiKey.Enter]      = (int)SDL.SDL_Keycode.SDLK_RETURN;
            io.KeyMap[(int)ImGuiKey.Escape]     = (int)SDL.SDL_Keycode.SDLK_ESCAPE;
            io.KeyMap[(int)ImGuiKey.A]          = (int)SDL.SDL_Keycode.SDLK_a;
            io.KeyMap[(int)ImGuiKey.C]          = (int)SDL.SDL_Keycode.SDLK_c;
            io.KeyMap[(int)ImGuiKey.V]          = (int)SDL.SDL_Keycode.SDLK_v;
            io.KeyMap[(int)ImGuiKey.X]          = (int)SDL.SDL_Keycode.SDLK_x;
            io.KeyMap[(int)ImGuiKey.Y]          = (int)SDL.SDL_Keycode.SDLK_y;
            io.KeyMap[(int)ImGuiKey.Z]          = (int)SDL.SDL_Keycode.SDLK_z;


            //io.GetClipboardTextFn((userData) => SDL.SDL_GetClipboardText());

            //io.SetSetClipboardTextFn((userData, text) => SDL.SDL_SetClipboardText(text));


            unsafe
            {
                string         rf        = "Resources";
                ImFontAtlasPtr fontAtlas = ImGui.GetIO().Fonts;
                var            builder   = new ImFontGlyphRangesBuilderPtr(ImGuiNative.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder());
                builder.AddText("Ωων");
                //builder.AddRanges(fontAtlas.GetGlyphRangesDefault());
                builder.BuildRanges(out ImVector ranges);
                fontAtlas.AddFontFromFileTTF(Path.Combine(rf, "ProggyClean.ttf"), 13);
                ImFontConfig *  rawPtr = ImGuiNative.ImFontConfig_ImFontConfig();
                ImFontConfigPtr config = new ImFontConfigPtr(rawPtr);
                config.MergeMode = true;
                fontAtlas.AddFontFromFileTTF(Path.Combine(rf, "DejaVuSans.ttf"), 13, config, ranges.Data);
            }

            if (io.Fonts.Fonts.Size == 0)
            {
                io.Fonts.AddFontDefault();
            }
        }