Exemplo n.º 1
0
 void Keyboard_TextInput(string text)
 {
     foreach (var c in text)
     {
         ImGui.AddInputCharacter(c);
     }
 }
Exemplo n.º 2
0
        public unsafe void UpdateImGuiInput(Window window, InputSnapshot snapshot)
        {
            IO io = ImGui.GetIO();

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

            foreach (char c in snapshot.KeyCharPresses)
            {
                ImGui.AddInputCharacter(c);
            }

            io.CtrlPressed  = false;
            io.AltPressed   = false;
            io.ShiftPressed = false;

            foreach (var keyEvent in snapshot.KeyEvents)
            {
                io.KeysDown[(int)keyEvent.Key] = keyEvent.Down;
                io.ShiftPressed |= ((keyEvent.Modifiers & ModifierKeys.Shift) != 0);
                io.CtrlPressed  |= ((keyEvent.Modifiers & ModifierKeys.Control) != 0);
                io.AltPressed   |= ((keyEvent.Modifiers & ModifierKeys.Alt) != 0);
            }
        }
Exemplo n.º 3
0
        private unsafe void UpdateImGuiInput(InputSnapshot snapshot)
        {
            IO io = ImGui.GetIO();

            Vector2 mousePosition = snapshot.MousePosition;

            io.MousePosition = 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.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.CtrlPressed  = _controlDown;
            io.AltPressed   = _altDown;
            io.ShiftPressed = _shiftDown;
        }
Exemplo n.º 4
0
        void MapInput()
        {
            var io = ImGui.GetIO();

            io.KeyMap[GuiKey.Tab]        = (int)Key.Tab;
            io.KeyMap[GuiKey.LeftArrow]  = (int)Key.Left;
            io.KeyMap[GuiKey.RightArrow] = (int)Key.Right;
            io.KeyMap[GuiKey.UpArrow]    = (int)Key.Up;
            io.KeyMap[GuiKey.DownArrow]  = (int)Key.Down;
            io.KeyMap[GuiKey.PageUp]     = (int)Key.PageUp;
            io.KeyMap[GuiKey.PageDown]   = (int)Key.PageDown;
            io.KeyMap[GuiKey.Home]       = (int)Key.Home;
            io.KeyMap[GuiKey.End]        = (int)Key.End;
            io.KeyMap[GuiKey.Delete]     = (int)Key.Delete;
            io.KeyMap[GuiKey.Backspace]  = (int)Key.BackSpace;
            io.KeyMap[GuiKey.Enter]      = (int)Key.Enter;
            io.KeyMap[GuiKey.Escape]     = (int)Key.Escape;
            io.KeyMap[GuiKey.A]          = (int)Key.A;
            io.KeyMap[GuiKey.C]          = (int)Key.C;
            io.KeyMap[GuiKey.V]          = (int)Key.V;
            io.KeyMap[GuiKey.X]          = (int)Key.X;
            io.KeyMap[GuiKey.Y]          = (int)Key.Y;
            io.KeyMap[GuiKey.Z]          = (int)Key.Z;

            window.KeyDown += (sender, e) => {
                if (WantKeyboard)
                {
                    ImGui.GetIO().KeysDown[(int)e.Key] = true;
                }
                else
                {
                    engine.KeyDown(e);
                }
            };
            window.KeyUp += (sender, e) => {
                if (WantKeyboard)
                {
                    ImGui.GetIO().KeysDown[(int)e.Key] = false;
                }
                else
                {
                    engine.KeyUp(e);
                }
            };
            window.KeyPress += (sender, e) => {
                ImGui.AddInputCharacter(e.KeyChar);
            };
        }
Exemplo n.º 5
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()
        {
            var io = ImGui.GetIO();

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

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

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

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

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

            ImGui.GetIO().FontAtlas.AddDefaultFont();
        }
Exemplo n.º 6
0
        private void NativeWindowOnKeyPress(object sender, KeyPressEventArgs keyPressEventArgs)
        {
            IO io = ImGui.GetIO();

            if (io.WantCaptureKeyboard)
            {
                ImGui.AddInputCharacter(keyPressEventArgs.KeyChar);
            }
            else
            {
                if (io.CtrlPressed || io.AltPressed)
                {
                    return;
                }
                editor.CharKey(keyPressEventArgs.KeyChar);
            }
        }
Exemplo n.º 7
0
        private void KeyboardMouseEvents_KeyPress(object sender, KeyPressEventArgs e)
        {
            var io = ImGui.GetIO();

            if (io.AltPressed)
            {
                return;
            }

            unsafe
            {
                if (ImGuiWantTextInput(io))
                {
                    ImGui.AddInputCharacter(e.KeyChar);
                    e.Handled = true;
                }
            }
        }
Exemplo n.º 8
0
 protected override void OnKeyPress(KeyPressEventArgs e)
 {
     ImGui.AddInputCharacter(e.KeyChar);
 }
Exemplo n.º 9
0
 private void OnKeyPress(object sender, KeyPressEventArgs e)
 {
     ImGui.AddInputCharacter(e.KeyChar);
 }
Exemplo n.º 10
0
        public static void newFrame(GameTime gt)
        {
            IO  io             = ImGui.GetIO();
            var graphicsDevice = _game.GraphicsDevice;
            var width          = graphicsDevice.PresentationParameters.BackBufferWidth;
            var height         = graphicsDevice.PresentationParameters.BackBufferHeight;

            io.DisplaySize             = new Vector2(width, height);
            io.DisplayFramebufferScale = new Vector2(_scaleFactor);
            io.DeltaTime = (float)gt.ElapsedGameTime.TotalSeconds;


            //MouseState cursorState = MouseCursor.ge  Mouse.get();
            MouseState mouseState = Mouse.GetState();

            if (_game.IsActive)
            {
                //Point windowPoint = _nativeWindow.PointToClient(new Point(cursorState.X, cursorState.Y));
                Point windowPoint = new Point(mouseState.X, mouseState.Y);
                io.MousePosition = new Vector2(windowPoint.X / io.DisplayFramebufferScale.X, windowPoint.Y / io.DisplayFramebufferScale.Y);
            }
            else
            {
                io.MousePosition = new Vector2(-1f, -1f);
            }

            io.MouseDown[0] = mouseState.LeftButton == ButtonState.Pressed;
            io.MouseDown[1] = mouseState.RightButton == ButtonState.Pressed;
            io.MouseDown[2] = mouseState.MiddleButton == ButtonState.Pressed;

            float newWheelPos = mouseState.ScrollWheelValue;
            float delta       = newWheelPos - _wheelPosition;

            _wheelPosition = newWheelPos;
            io.MouseWheel  = delta;

            var newKbState = Keyboard.GetState();
            var keys       = kbState.GetPressedKeys();

            for (var i = 0; i < keys.Length; i++)
            {
                io.KeysDown[(int)keys[i]] = false;
            }

            keys = newKbState.GetPressedKeys();
            for (var i = 0; i < keys.Length; i++)
            {
                io.KeysDown[(int)keys[i]] = true;
            }

            for (int i = _repeatDelay.Count - 1; i >= 0; i--)
            {
                if (newKbState.IsKeyUp(_repeatDelay[i].key))
                {
                    var lastIndex = _repeatDelay.Count - 1;
                    _repeatDelay[i] = _repeatDelay[lastIndex];
                    _repeatDelay.RemoveAt(lastIndex);
                }
                else
                {
                    var r = _repeatDelay[i];
                    r.delay        -= io.DeltaTime;
                    _repeatDelay[i] = r;
                }
            }

            io.AltPressed   = newKbState.IsKeyDown(Keys.LeftAlt) || newKbState.IsKeyDown(Keys.RightAlt);
            io.ShiftPressed = (newKbState.IsKeyDown(Keys.LeftShift) || newKbState.IsKeyDown(Keys.RightShift));
            io.CtrlPressed  = newKbState.IsKeyDown(Keys.LeftControl) || newKbState.IsKeyDown(Keys.RightControl);

            kbState = newKbState;

            for (var i = 0; i < keys.Length; i++)
            {
                var ch = ConvertKeyboardInput(keys[i], io.AltPressed, io.ShiftPressed, io.CtrlPressed, newKbState.CapsLock);
                if (ch != '\0')
                {
                    var index = -1;
                    for (var k = 0; k < _repeatDelay.Count; k++)
                    {
                        if (_repeatDelay[k].ch == ch)
                        {
                            index = k;
                            break;
                        }
                    }

                    if (index == -1)
                    {
                        _repeatDelay.Add(new KeyRepeat()
                        {
                            ch = ch, key = keys[i], delay = 0.25f
                        });
                        ImGui.AddInputCharacter(ch);
                    }
                    else if (_repeatDelay[index].delay <= 0)
                    {
                        var r = _repeatDelay[index];
                        r.delay            += 0.05f;
                        _repeatDelay[index] = r;
                        ImGui.AddInputCharacter(ch);
                    }
                }
            }

            ImGui.NewFrame();
        }
Exemplo n.º 11
0
        private unsafe void UpdateImGuiInput(OpenTKWindow window, InputSnapshot snapshot)
        {
            IO         io          = ImGui.GetIO();
            MouseState cursorState = Mouse.GetCursorState();
            MouseState mouseState  = Mouse.GetState();

            if (window.NativeWindow.Bounds.Contains(cursorState.X, cursorState.Y) && !RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                // TODO: This does not take into account viewport coordinates.
                if (window.Exists)
                {
                    Point windowPoint = window.NativeWindow.PointToClient(new Point(cursorState.X, cursorState.Y));
                    io.MousePosition = new System.Numerics.Vector2(
                        windowPoint.X / window.ScaleFactor.X,
                        windowPoint.Y / window.ScaleFactor.Y);
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                io.MousePosition = new System.Numerics.Vector2(
                    cursorState.X,
                    cursorState.Y);
            }
            else
            {
                io.MousePosition = new System.Numerics.Vector2(-1f, -1f);
            }

            io.MouseDown[0] = mouseState.LeftButton == ButtonState.Pressed;
            io.MouseDown[1] = mouseState.RightButton == ButtonState.Pressed;
            io.MouseDown[2] = mouseState.MiddleButton == ButtonState.Pressed;

            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.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.CtrlPressed  = _controlDown;
            io.AltPressed   = _altDown;
            io.ShiftPressed = _shiftDown;
        }
Exemplo n.º 12
0
 private void OnKeyPress(object sender, KeyPressEventArgs e)
 {
     Console.Write("Char typed: " + e.KeyChar);
     ImGui.AddInputCharacter(e.KeyChar);
 }
Exemplo n.º 13
0
 public static void OnTextInput(char c)
 {
     ImGui.AddInputCharacter(c);
 }
Exemplo n.º 14
0
 public static void AddKeyChar(char keyChar)
 {
     ImGui.AddInputCharacter(keyChar);
 }