Ejemplo n.º 1
0
        public ImGuiManager(ImGuiOptions options = null)
        {
            if (options == null)
            {
                options = new ImGuiOptions();
            }

            _gameWindowFirstPosition = options._gameWindowFirstPosition;
            _gameWindowTitle         = options._gameWindowTitle;
            _gameWindowFlags         = options._gameWindowFlags;

            LoadSettings();
            _renderer = new ImGuiRenderer(Core.Instance);

            _renderer.RebuildFontAtlas(options);
            Core.Emitter.AddObserver(CoreEvents.SceneChanged, OnSceneChanged);
            NezImGuiThemes.DarkTheme1();

            // find all Scenes
            _sceneSubclasses = ReflectionUtils.GetAllSubclasses(typeof(ECScene), true);

            // tone down indent
            ImGui.GetStyle().IndentSpacing = 12;
            ImGui.GetIO().ConfigWindowsMoveFromTitleBarOnly = true;

            // find all themes
            _themes = typeof(NezImGuiThemes).GetMethods(System.Reflection.BindingFlags.Static |
                                                        System.Reflection.BindingFlags.Public);
        }
Ejemplo n.º 2
0
        /// <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
        }