예제 #1
0
        void OnEnable()
        {
            _usingURP = RenderUtils.IsUsingURP();
            if (_camera == null)
            {
                Fail(nameof(_camera));
            }
            if (_renderFeature == null && _usingURP)
            {
                Fail(nameof(_renderFeature));
            }

            _cmd = RenderUtils.GetCommandBuffer(CommandBufferTag);
            if (_usingURP)
            {
                _renderFeature.commandBuffer = _cmd;
            }
            else
            {
                _camera.AddCommandBuffer(CameraEvent.AfterEverything, _cmd);
            }

            ImGuiUn.SetUnityContext(_context);
            ImGuiIOPtr io = ImGui.GetIO();

            _initialConfiguration.ApplyTo(io);
            _style?.ApplyTo(ImGui.GetStyle());

            _context.textures.BuildFontAtlas(io, _fontAtlasConfiguration);
            _context.textures.Initialize(io);

            SetPlatform(Platform.Create(_platformType, _cursorShapes, _iniSettings), io);
            SetRenderer(RenderUtils.Create(_rendererType, _shaders, _context.textures), io);
            if (_platform == null)
            {
                Fail(nameof(_platform));
            }
            if (_renderer == null)
            {
                Fail(nameof(_renderer));
            }

            void Fail(string reason)
            {
                OnDisable();
                enabled = false;
                throw new System.Exception($"Failed to start: {reason}");
            }
        }
예제 #2
0
        private unsafe void UpdateImGuiInput(InputSnapshot snapshot)
        {
            ImGuiIOPtr io = ImGui.GetIO();

            Vector2 mousePosition = snapshot.MousePosition;

            io.MousePos     = mousePosition;
            io.MouseDown[0] = snapshot.IsMouseDown(MouseButton.Left);
            io.MouseDown[1] = snapshot.IsMouseDown(MouseButton.Right);
            io.MouseDown[2] = snapshot.IsMouseDown(MouseButton.Middle);

            float delta = snapshot.WheelDelta;

            io.MouseWheel = delta;

            ImGui.GetIO().MouseWheel = delta;

            IReadOnlyList <char> keyCharPresses = snapshot.KeyCharPresses;

            for (int i = 0; i < keyCharPresses.Count; i++)
            {
                char c = keyCharPresses[i];
                ImGui.GetIO().AddInputCharacter(c);
            }

            IReadOnlyList <KeyEvent> keyEvents = snapshot.KeyEvents;

            for (int i = 0; i < keyEvents.Count; i++)
            {
                KeyEvent keyEvent = keyEvents[i];
                io.KeysDown[(int)keyEvent.Key] = keyEvent.Down;
                if (keyEvent.Key == Key.ControlLeft)
                {
                    _controlDown = keyEvent.Down;
                }
                if (keyEvent.Key == Key.ShiftLeft)
                {
                    _shiftDown = keyEvent.Down;
                }
                if (keyEvent.Key == Key.AltLeft)
                {
                    _altDown = keyEvent.Down;
                }
            }

            io.KeyCtrl  = _controlDown;
            io.KeyAlt   = _altDown;
            io.KeyShift = _shiftDown;
        }
예제 #3
0
    void OnDestroy()
    {
        ImGuiIOPtr io = ImGui.GetIO();

        // DestroyContext will write the ini file
        ImGui.DestroyContext(context);
        // We must set it to null to clear the allocated buffer or Unity will complain
        io.SetIniFile(null);

        if (renderTexture != null)
        {
            renderTexture.Release();
            renderTexture = null;
        }
    }
예제 #4
0
        private void HookMouseMove(object sender, MouseEventArgs e)
        {
            if (!this.enable)
            {
                return;
            }

            ImGuiIOPtr io = ImGui.GetIO();

            io.MousePos = new Vector2(e.X - this.windowX, e.Y - this.windowY);

            // TODO: Show ImGUI Cursor/Hide ImGui Cursor
            //     ImGui.GetIO().MouseDrawCursor = true;
            //     Window32 API ShowCursor(false)
        }
예제 #5
0
        public void Initialize(ImGuiIOPtr io)
        {
            io.SetBackendRendererName("Unity Mesh");                                        // setup renderer info and capabilities
            io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset;                      // supports ImDrawCmd::VtxOffset to output large meshes while still using 16-bits indices

            _material = new Material(_shader)
            {
                hideFlags = HideFlags.HideAndDontSave & ~HideFlags.DontUnloadUnusedAsset
            };
            _mesh = new Mesh()
            {
                name = "DearImGui Mesh"
            };
            _mesh.MarkDynamic();
        }
예제 #6
0
        private void Display()
        {
            // this is more or less part of what reshade/etc do to avoid having to manually
            // set the cursor inside the ui
            // This will just tell ImGui to draw its own software cursor instead of using the hardware cursor
            // The scene internally will handle hiding and showing the hardware (game) cursor
            // If the player has the game software cursor enabled, we can't really do anything about that and
            // they will see both cursors.
            // Doing this here because it's somewhat application-specific behavior
            //ImGui.GetIO().MouseDrawCursor = ImGui.GetIO().WantCaptureMouse;
            this.LastImGuiIoPtr  = ImGui.GetIO();
            this.lastWantCapture = this.LastImGuiIoPtr.WantCaptureMouse;

            OnDraw?.Invoke();
        }
        private void CreateFontsTexture()
        {
            ImGuiIOPtr io = ImGui.GetIO();

            io.Fonts.GetTexDataAsRGBA32(out IntPtr pixels, out int width, out int height, out int bytesPerPixel);

            _fontTexture = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, _fontTexture);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixels);

            io.Fonts.TexID = (IntPtr)_fontTexture;
        }
예제 #8
0
        unsafe void CreateFontTexture()
        {
            // font data, important
            ImGui.GetIO().Fonts.AddFontDefault();

            ImGuiIOPtr io = ImGui.GetIO();

            io.Fonts.GetTexDataAsRGBA32(out byte *pixelData, out int width, out int height, out int bytesPerPixel);

            var newFontTexture = Texture.New2D(device, width, height, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource);

            newFontTexture.SetData(commandList, new DataPointer(pixelData, (width * height) * bytesPerPixel));

            fontTexture = newFontTexture;
        }
예제 #9
0
        /// <summary>
        /// Updates the <see cref="Effect" /> to the current matrices and texture
        /// </summary>
        protected virtual Effect UpdateEffect(Texture2D texture)
        {
            _effect ??= new BasicEffect(_graphicsDevice);

            ImGuiIOPtr io = ImGui.GetIO();

            _effect.World              = Matrix.Identity;
            _effect.View               = Matrix.Identity;
            _effect.Projection         = Matrix.CreateOrthographicOffCenter(0f, io.DisplaySize.X, io.DisplaySize.Y, 0f, -1f, 1f);
            _effect.TextureEnabled     = true;
            _effect.Texture            = texture;
            _effect.VertexColorEnabled = true;

            return(_effect);
        }
예제 #10
0
        public override bool OnMouseDown(MouseButtonEventArgs args)
        {
            ImGuiIOPtr io = ImGuiNET.ImGui.GetIO();

            if (!io.WantCaptureMouse)
            {
                return(false);
            }

            io.MouseDown[0] = args.Button == MouseButton.Left;
            io.MouseDown[1] = args.Button == MouseButton.Right;
            io.MouseDown[2] = args.Button == MouseButton.Middle;

            return(true);
        }
예제 #11
0
    public void UpdateKeyboard(ImGuiIOPtr io)
    {
        io.AddInputCharactersUTF8(Input.inputString);

        foreach (int key in trackedKeys)
        {
            io.KeysDown[key] = Input.GetKey((KeyCode)key);
        }

        io.KeyCtrl  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
        io.KeyAlt   = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
        io.KeyShift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
        io.KeySuper = Input.GetKey(KeyCode.LeftWindows) || Input.GetKey(KeyCode.RightWindows) ||
                      Input.GetKey(KeyCode.LeftCommand) || Input.GetKey(KeyCode.RightCommand);
    }
예제 #12
0
        public static void BeginFrame(double deltaTime)
        {
            ImGuiIOPtr io = ImGui.GetIO();

            io.DeltaTime = (float)deltaTime;

            if (_fontsTextureHandle <= 0)
            {
                createDeviceObjects();
            }

            updateInput();

            ImGui.NewFrame();
        }
예제 #13
0
        private void HookMouseWheelExt(object sender, MouseEventExtArgs e)
        {
            if (!this.enable)
            {
                return;
            }

            ImGuiIOPtr io = ImGui.GetIO();

            if (io.WantCaptureMouse)
            {
                io.MouseWheel = e.Delta / SystemInformation.MouseWheelScrollDelta;
                e.Handled     = true;
            }
        }
예제 #14
0
        /// <summary>
        /// Maps ImGui keys to XNA keys. We use this later on to tell ImGui what keys were pressed
        /// </summary>
        protected virtual void SetupInput()
        {
            ImGuiIOPtr io = ImGui.GetIO();

            _keys.Add(io.KeyMap[(int)ImGuiKey.Tab]        = (int)Keys.Tab);
            _keys.Add(io.KeyMap[(int)ImGuiKey.LeftArrow]  = (int)Keys.Left);
            _keys.Add(io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Keys.Right);
            _keys.Add(io.KeyMap[(int)ImGuiKey.UpArrow]    = (int)Keys.Up);
            _keys.Add(io.KeyMap[(int)ImGuiKey.DownArrow]  = (int)Keys.Down);
            _keys.Add(io.KeyMap[(int)ImGuiKey.PageUp]     = (int)Keys.PageUp);
            _keys.Add(io.KeyMap[(int)ImGuiKey.PageDown]   = (int)Keys.PageDown);
            _keys.Add(io.KeyMap[(int)ImGuiKey.Home]       = (int)Keys.Home);
            _keys.Add(io.KeyMap[(int)ImGuiKey.End]        = (int)Keys.End);
            _keys.Add(io.KeyMap[(int)ImGuiKey.Delete]     = (int)Keys.Delete);
            _keys.Add(io.KeyMap[(int)ImGuiKey.Backspace]  = (int)Keys.Back);
            _keys.Add(io.KeyMap[(int)ImGuiKey.Enter]      = (int)Keys.Enter);
            _keys.Add(io.KeyMap[(int)ImGuiKey.Escape]     = (int)Keys.Escape);
            _keys.Add(io.KeyMap[(int)ImGuiKey.Space]      = (int)Keys.Space);
            _keys.Add(io.KeyMap[(int)ImGuiKey.A]          = (int)Keys.A);
            _keys.Add(io.KeyMap[(int)ImGuiKey.C]          = (int)Keys.C);
            _keys.Add(io.KeyMap[(int)ImGuiKey.V]          = (int)Keys.V);
            _keys.Add(io.KeyMap[(int)ImGuiKey.X]          = (int)Keys.X);
            _keys.Add(io.KeyMap[(int)ImGuiKey.Y]          = (int)Keys.Y);
            _keys.Add(io.KeyMap[(int)ImGuiKey.Z]          = (int)Keys.Z);

            // MonoGame-specific //////////////////////
            _game.Window.TextInput += (s, a) =>
            {
                if (a.Character == '\t')
                {
                    return;
                }

                io.AddInputCharacter(a.Character);
            };
            ///////////////////////////////////////////

            // FNA-specific ///////////////////////////
            //TextInputEXT.TextInput += c =>
            //{
            //    if (c == '\t') return;

            //    ImGui.GetIO().AddInputCharacter(c);
            //};
            ///////////////////////////////////////////

            ImGui.GetIO().Fonts.AddFontDefault();
        }
예제 #15
0
        private void UpdateImGuiInput()
        {
            ImGuiIOPtr io = ImGuiNET.ImGui.GetIO();

            MouseState mouseState    = _input.Mice[0].CaptureState();
            var        keyboardState = _input.Keyboards[0];

            io.MouseDown[0] = mouseState.IsButtonPressed(MouseButton.Left);
            io.MouseDown[1] = mouseState.IsButtonPressed(MouseButton.Right);
            io.MouseDown[2] = mouseState.IsButtonPressed(MouseButton.Middle);

            var point = new System.Drawing.Point((int)mouseState.Position.X, (int)mouseState.Position.Y);

            //var screenPoint = new System.Drawing.Point((int) MouseState.Position.X, (int) MouseState.Position.Y);
            //var point = _view.PointToClient(screenPoint);
            io.MousePos = new System.Numerics.Vector2(point.X, point.Y);

            //var wheel = MouseState.GetScrollWheels()[0];
            //var prevWheel = PrevMouseState?.GetScrollWheels()[0] ?? default;
            //io.MouseWheel = wheel.Y - prevWheel.Y;
            //io.MouseWheelH = wheel.X - prevWheel.X;
            var wheel = mouseState.GetScrollWheels()[0];

            io.MouseWheel  = wheel.Y;
            io.MouseWheelH = wheel.X;

            foreach (Key key in Enum.GetValues(typeof(Key)))
            {
                if (key == Key.Unknown)
                {
                    continue;
                }
                io.KeysDown[(int)key] = keyboardState.IsKeyPressed(key);
            }

            foreach (var c in _pressedChars)
            {
                io.AddInputCharacter(c);
            }
            _pressedChars.Clear();

            io.KeyCtrl  = keyboardState.IsKeyPressed(Key.ControlLeft) || keyboardState.IsKeyPressed(Key.ControlRight);
            io.KeyAlt   = keyboardState.IsKeyPressed(Key.AltLeft) || keyboardState.IsKeyPressed(Key.AltRight);
            io.KeyShift = keyboardState.IsKeyPressed(Key.ShiftLeft) || keyboardState.IsKeyPressed(Key.ShiftRight);
            io.KeySuper = keyboardState.IsKeyPressed(Key.SuperLeft) || keyboardState.IsKeyPressed(Key.SuperRight);

            _prevMouseState = mouseState;
        }
예제 #16
0
        private void ProcessMouseMove(MouseEventArgs e, bool shouldSendToImGui)
        {
            if (shouldSendToImGui)
            {
                ImGuiIOPtr io = ImGui.GetIO();
                io.MousePos = new Vector2(e.X - this.windowX, e.Y - this.windowY);

                // TODO: Show ImGUI Cursor/Hide ImGui Cursor
                //     ImGui.GetIO().MouseDrawCursor = true;
                //     Window32 API ShowCursor(false)
            }
            else
            {
                this.PushMessage(HookControllerMessageType.MouseMove, e);
            }
        }
예제 #17
0
    public void RecreateFontDeviceTexture(bool sendToGPU)
    {
        ImGuiIOPtr io = ImGui.GetIO();
        IntPtr     pixels;
        int        width, height, bytesPerPixel;

        io.Fonts.GetTexDataAsRGBA32(out pixels, out width, out height, out bytesPerPixel);

        if (sendToGPU)
        {
            IntPtr fontTexID = ImGuiPluginHook.GenerateImGuiFontTexture(pixels, width, height, bytesPerPixel);
            io.Fonts.SetTexID(fontTexID);
        }

        io.Fonts.ClearTexData();
    }
예제 #18
0
        private void ProcessMouseUpDown(MouseEventExtArgs e, bool isDownEvent, bool shouldSendToImGui)
        {
            ImGuiIOPtr io = ImGui.GetIO();

            if (shouldSendToImGui)
            {
                switch (e.Button)
                {
                case MouseButtons.Left:
                    io.MouseDown[0] = isDownEvent;
                    break;

                case MouseButtons.Right:
                    io.MouseDown[1] = isDownEvent;
                    break;

                case MouseButtons.Middle:
                    io.MouseDown[2] = isDownEvent;
                    break;

                case MouseButtons.XButton1:
                    io.MouseDown[3] = isDownEvent;
                    break;

                case MouseButtons.XButton2:
                    io.MouseDown[4] = isDownEvent;
                    break;

                case MouseButtons.None:
                    // TODO: Find out what does this None mean
                    break;

                default:
                    // TODO: Make a Logger for the whole Overlay
                    break;
                }
            }
            else
            {
                this.PushMessage(HookControllerMessageType.MouseUpDown, e, isDownEvent);
            }

            if (io.WantCaptureMouse)
            {
                e.Handled = true;
            }
        }
예제 #19
0
        void OnDisable()
        {
            ImGuiUn.SetUnityContext(_context);
            ImGuiIOPtr io = ImGui.GetIO();

            SetRenderer(null, io);
            SetPlatform(null, io);

            ImGuiUn.SetUnityContext(null);

            _context.textures.Shutdown();
            _context.textures.DestroyFontAtlas(io);

#if HAS_HDRP
            _usingHDRP = RenderUtils.IsUsingHDRP();
            if (_usingHDRP)
            {
                // I know... I know... using a goto, but in this instance it makes things a lot cleaner
                // due to the preprocessor directives and how unity has grouped things.
                goto PostCommandBufferTeardown;
            }
#endif

            if (_usingURP)
            {
                if (_renderFeature != null)
                {
                    _renderFeature.commandBuffer = null;
                }
            }
            else
            {
                if (_camera != null)
                {
                    _camera.RemoveCommandBuffer(CameraEvent.AfterEverything, _cmd);
                }
            }

PostCommandBufferTeardown:


            if (_cmd != null)
            {
                RenderUtils.ReleaseCommandBuffer(_cmd);
            }
            _cmd = null;
        }
예제 #20
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));

            // If no font added, add default font.
            if (io.Fonts.Fonts.Size == 0)
            {
                io.Fonts.AddFontDefault();
            }
        }
예제 #21
0
 private void UpdateImGuiInput(ImGuiIOPtr io)
 {
     if (NativeMethods.IsWindowInForeground(_windowHandle))
     {
         io.MousePos = new Vector2(mouseState.X / io.DisplayFramebufferScale.X,
                                   mouseState.Y / io.DisplayFramebufferScale.Y);
     }
     else
     {
         io.MousePos = new Vector2(-1f, -1f);
     }
     io.MouseDown[0]  = mouseState.LMB;
     io.MouseDown[1]  = mouseState.RMB;
     io.MouseDown[2]  = mouseState.MMB;
     io.MouseWheel    = mouseState.Wheel;
     mouseState.Wheel = 0;
 }
예제 #22
0
        public ImGuiHost(GraphicsDeviceManager graphics, Microsoft.Xna.Framework.Game game, bool enableDocking) : base(game)
        {
            // Run after (and thus draw on top of) the normal SadConsole MonoGame component
            DrawOrder = 7;
            // Run before the normal SadConsole MonoGame component
            UpdateOrder = 3;

            _graphics = graphics;
            _game     = game;

            ImGuiRenderer = new ImGuiRenderer(_game);
            ImGuiRenderer.RebuildFontAtlas();

            ImGuiIOPtr io = ImGui.GetIO();

            io.ConfigFlags = io.ConfigFlags |= ImGuiConfigFlags.DockingEnable;
        }
예제 #23
0
        /// <summary>
        /// Sets per-frame data based on the associated window.
        /// This is called by Update(float).
        /// </summary>
        private void SetPerFrameImGuiData(float deltaSeconds)
        {
#if DEBUG
            using Profiler fullProfiler = new Profiler(GetType());
#endif
            ImGuiIOPtr io = ImGui.GetIO();
            io.DisplaySize = new Vector2(
                windowWidth / scaleFactor.X,
                windowHeight / scaleFactor.Y);
            io.DisplayFramebufferScale = scaleFactor;
            io.DeltaTime = deltaSeconds;             // DeltaTime is in seconds.

            ImGuiPlatformIOPtr plIo          = ImGui.GetPlatformIO();
            Sdl2Window         mainSdlWindow = mainWindow.SdlWindow;
            plIo.MainViewport.Pos  = new Vector2(mainSdlWindow.X, mainSdlWindow.Y);
            plIo.MainViewport.Size = new Vector2(mainSdlWindow.Width, mainSdlWindow.Height);
        }
예제 #24
0
        private void RecreateFontDeviceTexture()
        {
            ImGuiIOPtr io = ImGui.GetIO();

            io.Fonts.GetTexDataAsRGBA32(out IntPtr pixels, out int width, out int height, out _);

            fontTexture = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, fontTexture);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixels);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            io.Fonts.SetTexID((IntPtr)fontTexture);

            io.Fonts.ClearTexData();
        }
예제 #25
0
        public void Assign(ImGuiIOPtr io)
        {
            io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(_setClipboardText);
            io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(_getClipboardText);

            //io.ImeSetInputScreenPosFn = Marshal.GetFunctionPointerForDelegate(_imeSetInputScreenPos);



#if IMGUI_FEATURE_CUSTOM_ASSERT
            io.SetBackendPlatformUserData <CustomAssertData>(new CustomAssertData
            {
                LogAssertFn  = Marshal.GetFunctionPointerForDelegate(_logAssert),
                DebugBreakFn = Marshal.GetFunctionPointerForDelegate(_debugBreak),
            });
#endif
        }
예제 #26
0
        public ImGuiRenderer(string shaderPath, int width, int height)
        {
            shader = new Shader(shaderPath);

            this.height = height;
            this.width  = width;

            ImGui.SetCurrentContext(ImGui.CreateContext());
            io             = ImGui.GetIO();
            io.DisplaySize = new Vector2(
                width,
                height);
            io.DisplayFramebufferScale = Vector2.One;
            io.DeltaTime = 1f / 60.0f; // DeltaTime is in seconds.
            io.Fonts.AddFontDefault();

            unsafe
            {
                byte *pixelData;
                int   texWidth, texHeight, bytesPerPixel;

                io.Fonts.GetTexDataAsRGBA32(out pixelData, out texWidth, out texHeight, out bytesPerPixel);

                textureID = GL.GenTexture();
                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, textureID);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba
                              , texWidth, texHeight, 0,
                              PixelFormat.Rgba, PixelType.UnsignedByte, new IntPtr(pixelData));

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.NearestMipmapLinear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            }


            io.Fonts.SetTexID(new IntPtr(textureID));
            io.Fonts.ClearTexData();

            GenerateBuffers();
            SetKeyMappings();

            ImGui.NewFrame();
        }
예제 #27
0
        public override void OnAttach()
        {
            Imgui.CreateContext();
            Imgui.StyleColorsDark();

            ImGuiIOPtr io = Imgui.GetIO();

            io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors;
            io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos;

            // TEMPORARY: should eventually use Hazel key codes
            io.KeyMap[(int)ImGuiKey.Tab]        = (int)Keys.Tab;
            io.KeyMap[(int)ImGuiKey.LeftArrow]  = (int)Keys.Left;
            io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Keys.Right;
            io.KeyMap[(int)ImGuiKey.UpArrow]    = (int)Keys.Up;
            io.KeyMap[(int)ImGuiKey.DownArrow]  = (int)Keys.Down;
            io.KeyMap[(int)ImGuiKey.PageUp]     = (int)Keys.PageUp;
            io.KeyMap[(int)ImGuiKey.PageDown]   = (int)Keys.PageDown;
            io.KeyMap[(int)ImGuiKey.Home]       = (int)Keys.Home;
            io.KeyMap[(int)ImGuiKey.End]        = (int)Keys.End;
            io.KeyMap[(int)ImGuiKey.Insert]     = (int)Keys.Insert;
            io.KeyMap[(int)ImGuiKey.Delete]     = (int)Keys.Delete;
            io.KeyMap[(int)ImGuiKey.Backspace]  = (int)Keys.Backspace;
            io.KeyMap[(int)ImGuiKey.Space]      = (int)Keys.Space;
            io.KeyMap[(int)ImGuiKey.Enter]      = (int)Keys.Enter;
            io.KeyMap[(int)ImGuiKey.Escape]     = (int)Keys.Escape;
            io.KeyMap[(int)ImGuiKey.A]          = (int)Keys.A;
            io.KeyMap[(int)ImGuiKey.C]          = (int)Keys.C;
            io.KeyMap[(int)ImGuiKey.V]          = (int)Keys.V;
            io.KeyMap[(int)ImGuiKey.X]          = (int)Keys.X;
            io.KeyMap[(int)ImGuiKey.Y]          = (int)Keys.Y;
            io.KeyMap[(int)ImGuiKey.Z]          = (int)Keys.Z;

            try
            {
                ImGuiNative.ImGui_ImplOpenGL3_Init("#version 410");
            }
            catch (System.Exception ex)
            {
                foreach (var item in ex.Data)
                {
                    Debug.DLogWarning(item.ToString());
                }
            }
        }
예제 #28
0
 public void SetFrom(ImGuiIOPtr io)
 {
     KeyboardNavigation   = (io.ConfigFlags & ImGuiConfigFlags.NavEnableKeyboard) != 0;
     GamepadNavigation    = (io.ConfigFlags & ImGuiConfigFlags.NavEnableGamepad) != 0;
     NavSetMousePos       = (io.ConfigFlags & ImGuiConfigFlags.NavEnableSetMousePos) != 0;
     NavNoCaptureKeyboard = (io.ConfigFlags & ImGuiConfigFlags.NavNoCaptureKeyboard) != 0;
     DoubleClickTime      = io.MouseDoubleClickTime;
     DoubleClickMaxDist   = io.MouseDoubleClickMaxDist;
     DragThreshold        = io.MouseDragThreshold;
     KeyRepeatDelay       = io.KeyRepeatDelay;
     KeyRepeatRate        = io.KeyRepeatRate;
     FontGlobalScale      = io.FontGlobalScale;
     FontAllowUserScaling = io.FontAllowUserScaling;
     TextCursorBlink      = io.ConfigInputTextCursorBlink;
     ResizeFromEdges      = io.ConfigWindowsResizeFromEdges;
     MoveFromTitleOnly    = io.ConfigWindowsMoveFromTitleBarOnly;
     MemoryCompactTimer   = io.ConfigMemoryCompactTimer;
 }
예제 #29
0
 public void ApplyTo(ImGuiIOPtr io)
 {
     io.ConfigFlags                       = KeyboardNavigation ? io.ConfigFlags | ImGuiConfigFlags.NavEnableKeyboard : io.ConfigFlags & ~ImGuiConfigFlags.NavEnableKeyboard;
     io.ConfigFlags                       = GamepadNavigation ? io.ConfigFlags | ImGuiConfigFlags.NavEnableGamepad : io.ConfigFlags & ~ImGuiConfigFlags.NavEnableGamepad;
     io.ConfigFlags                       = NavSetMousePos ? io.ConfigFlags | ImGuiConfigFlags.NavEnableSetMousePos : io.ConfigFlags & ~ImGuiConfigFlags.NavEnableSetMousePos;
     io.ConfigFlags                       = NavNoCaptureKeyboard ? io.ConfigFlags | ImGuiConfigFlags.NavNoCaptureKeyboard : io.ConfigFlags & ~ImGuiConfigFlags.NavNoCaptureKeyboard;
     io.MouseDoubleClickTime              = DoubleClickTime;
     io.MouseDoubleClickMaxDist           = DoubleClickMaxDist;
     io.MouseDragThreshold                = DragThreshold;
     io.KeyRepeatDelay                    = KeyRepeatDelay;
     io.KeyRepeatRate                     = KeyRepeatRate;
     io.FontGlobalScale                   = FontGlobalScale;
     io.FontAllowUserScaling              = FontAllowUserScaling;
     io.ConfigInputTextCursorBlink        = TextCursorBlink;
     io.ConfigWindowsResizeFromEdges      = ResizeFromEdges;
     io.ConfigWindowsMoveFromTitleBarOnly = MoveFromTitleOnly;
     io.ConfigMemoryCompactTimer          = MemoryCompactTimer;
 }
예제 #30
0
        public void NewFrame(double elapsed)
        {
            ImGuiIOPtr io = ImGui.GetIO();

            io.DisplaySize             = new Vector2(game.Width, game.Height);
            io.DisplayFramebufferScale = new Vector2(1, 1);
            io.DeltaTime = (float)elapsed;
            //Update input
            io.MousePos           = new Vector2(game.Mouse.X, game.Mouse.Y);
            io.MouseDown[0]       = game.Mouse.IsButtonDown(MouseButtons.Left);
            io.MouseDown[1]       = game.Mouse.IsButtonDown(MouseButtons.Right);
            io.MouseDown[2]       = game.Mouse.IsButtonDown(MouseButtons.Middle);
            io.MouseWheel         = game.Mouse.MouseDelta / 2.5f;
            game.Mouse.MouseDelta = 0;
            game.TextInputEnabled = io.WantCaptureKeyboard;
            //TODO: Mouse Wheel
            ImGui.NewFrame();
        }