Example #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(Scene), 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);
        }
Example #2
0
        public ImGuiManager(ImGuiOptions options = null)
        {
            _renderer = new ImGuiRenderer(Core.instance);

            if (options != null)
            {
                foreach (var font in options._fonts)
                {
                    ImGui.GetIO().Fonts.AddFontFromFileTTF(font.Item1, font.Item2);
                }
            }

            _renderer.rebuildFontAtlas(options?._includeDefaultFont ?? true);
            Core.emitter.addObserver(CoreEvents.SceneChanged, onSceneChanged);
            applyTheme();

            // find all Scenes
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (type.BaseType == typeof(Scene))
                    {
                        if (type.GetConstructor(Type.EmptyTypes) != null)
                        {
                            _sceneSubclasses.Add(type);
                        }
                    }
                }
            }

            // find all themes
            _themes = typeof(NezImGuiThemes).GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
        }
Example #3
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 != null)
            {
                if (options._includeDefaultFont)
                {
                    defaultFontPtr = io.Fonts.AddFontDefault();
                }

                foreach (var font in options._fonts)
                {
                    io.Fonts.AddFontFromFileTTF(font.Item1, font.Item2);
                }
            }
            else
            {
                defaultFontPtr = io.Fonts.AddFontDefault();
            }

            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
        }
Example #4
0
        public ImGuiManager(ImGuiOptions options = null)
        {
            loadSettings();
            _renderer = new ImGuiRenderer(Core.instance);

            _renderer.rebuildFontAtlas(options);
            Core.emitter.addObserver(CoreEvents.SceneChanged, onSceneChanged);
            NezImGuiThemes.darkTheme1();

            // find all Scenes
            _sceneSubclasses = ReflectionUtils.getAllSubclasses(typeof(Scene), true);

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

            // find all themes
            _themes = typeof(NezImGuiThemes).GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
        }