Beispiel #1
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.Space:
            {
                Glfw.GetWindowPos(window, out int xpos, out int ypos);
                Glfw.SetWindowPos(window, xpos, ypos);
                break;
            }

            case Glfw.KeyCode.Escape:
            {
                Glfw.SetWindowShouldClose(window, true);
                break;
            }

            default:
                break;
            }
        }
Beispiel #2
0
        static string GetActioName(Glfw.InputState action)
        {
            switch (action)
            {
            case Glfw.InputState.Press:
            {
                return("pressed");
            }

            case Glfw.InputState.Release:
            {
                return("released");
            }

            case Glfw.InputState.Repeat:
            {
                return("repeated");
            }

            default:
                break;
            }

            return("caused unknown action");
        }
Beispiel #3
0
 static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
 {
     if (state == Glfw.InputState.Press && key == Glfw.KeyCode.Escape)
     {
         Glfw.SetWindowShouldClose(window, true);
     }
 }
Beispiel #4
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.Escape:
            {
                Glfw.SetWindowShouldClose(window, true);
                break;
            }

            case Glfw.KeyCode.Space:
            {
                m_CurIconColor = (m_CurIconColor + 1) % 5;
                SetIcon(window, m_CurIconColor);
                break;
            }

            case Glfw.KeyCode.X:
            {
                Glfw.SetWindowIcon(window, null);
                break;
            }

            default:
                break;
            }
        }
Beispiel #5
0
 static void MouseButtonCallback(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods)
 {
     var slot = m_Slots[window];
     Log("{0} to {1} at {2}: Mouse button {3} ({4}) ({5}) was {6}",
         m_Counter++, slot.Number, Glfw.GetTime(), button,
         GetButtonName(button),
         GetModsName(mods),
         GetActioName(state));
 }
Beispiel #6
0
        static string GetActioName(Glfw.InputState action)
        {
            switch (action)
            {
                case Glfw.InputState.Press:
                    return "pressed";
                case Glfw.InputState.Release:
                    return "released";
                case Glfw.InputState.Repeat:
                    return "repeated";
            }

            return "caused unknown action";
        }
Beispiel #7
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.Space:
                Glfw.SetTime(0.0);
                break;
            }
        }
Beispiel #8
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.Q:
            case Glfw.KeyCode.Escape:
                Glfw.SetWindowShouldClose(window, true);
                break;
            }
        }
Beispiel #9
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.Escape:
            {
                Glfw.SetWindowShouldClose(window, true);
                break;
            }

            case Glfw.KeyCode.V:
            {
                if (mods == Glfw.KeyMods.Control)
                {
                    string str = Glfw.GetClipboardString(window);
                    if (!string.IsNullOrEmpty(str))
                    {
                        Log("Clipboard contains \"{0}\"", str);
                    }
                    else
                    {
                        Log("Clipboard does not contain a string");
                    }
                }
                break;
            }

            case Glfw.KeyCode.C:
            {
                if (mods == Glfw.KeyMods.Control)
                {
                    const string str = "Hello GLFW World!";
                    Glfw.SetClipboardString(window, str);
                    Log("Setting clipboard to \"{0}\"", str);
                }
                break;
            }

            default:
                break;
            }
        }
Beispiel #10
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.Up:
            {
                if (swapInterval + 1 > swapInterval)
                {
                    SetSwapInterval(window, swapInterval + 1);
                }
                break;
            }

            case Glfw.KeyCode.Down:
            {
                if (swapTear)
                {
                    if (swapInterval - 1 < swapInterval)
                    {
                        SetSwapInterval(window, swapInterval - 1);
                    }
                }
                else
                {
                    if (swapInterval - 1 >= 0)
                    {
                        SetSwapInterval(window, swapInterval - 1);
                    }
                }
                break;
            }

            case Glfw.KeyCode.Escape:
            {
                Glfw.SetWindowShouldClose(window, true);
                break;
            }

            default:
                break;
            }
        }
Beispiel #11
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            var    slot = m_Slots[window];
            string name = Glfw.GetKeyName(key, scancode);

            if (!string.IsNullOrEmpty(name))
            {
                Log("{0} to {1} at {2}: Key 0x{3} Scancode 0x{4} ({5}) ({6}) ({7}) was {8}",
                    m_Counter++, slot.Number, Glfw.GetTime(), (int)key, scancode,
                    GetKeyName(key),
                    name,
                    GetModsName(mods),
                    GetActioName(state));
            }
            else
            {
                Log("{0} to {1} at {2}: Key 0x{3} Scancode 0x{4} ({5}) ({6}) was {7}",
                    m_Counter++, slot.Number, Glfw.GetTime(), (int)key, scancode,
                    GetKeyName(key),
                    GetModsName(mods),
                    GetActioName(state));
            }

            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.C:
            {
                slot.Closeable = !slot.Closeable;

                Log("(( closing {0} ))", slot.Closeable ? "enabled" : "disabled");
                break;
            }

            default:
                break;
            }
        }
Beispiel #12
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.Escape:
            {
                Glfw.SetWindowShouldClose(window, true);
                break;
            }

            case Glfw.KeyCode.NumpadAdd:
            case Glfw.KeyCode.Up:
            case Glfw.KeyCode.Q:
            {
                SetGamma(window, m_GammaValue + kStepSize);
                break;
            }

            case Glfw.KeyCode.NumpadSubtract:
            case Glfw.KeyCode.Down:
            case Glfw.KeyCode.W:
            {
                if (m_GammaValue - kStepSize > 0f)
                {
                    SetGamma(window, m_GammaValue - kStepSize);
                }

                break;
            }

            default:
                break;
            }
        }
Beispiel #13
0
        /// <summary>
        /// The callback method for the keyboard, will set the key from a keycode and a state
        /// </summary>
        /// <param name="window"></param>
        /// <param name="key"></param>
        /// <param name="scancode"></param>
        /// <param name="state"></param>
        /// <param name="mods"></param>
        private void KeyboardCallBack(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            int keyCode = (int)key;

            switch (state)
            {
            case Glfw.InputState.Repeat:
                Input.SetKey(keyCode, Input.InputAction.Repeated);
                break;

            case Glfw.InputState.Press:
                Input.SetKey(keyCode, Input.InputAction.Pressed);
                break;

            case Glfw.InputState.Release:
                Input.SetKey(keyCode, Input.InputAction.Released);
                break;
            }

            Debug.Log("Input Keyboard " + key, Debug.DebugLayer.Input, Debug.DebugLevel.Information);
        }
Beispiel #14
0
        private static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            var engineWindow = dictionary[window];

            if (state == Glfw.InputState.Press || state == Glfw.InputState.Repeat)
            {
                engineWindow.KeyPressed?.Invoke(engineWindow, new KeyEventArgs()
                {
                    Key       = key,
                    ScanCode  = scancode,
                    Modifiers = mods
                });
            }
            else if (state == Glfw.InputState.Release)
            {
                engineWindow.KeyReleased?.Invoke(engineWindow, new KeyEventArgs()
                {
                    Key       = key,
                    ScanCode  = scancode,
                    Modifiers = mods
                });
            }
        }
Beispiel #15
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.A:
            {
                animateCursor = !animateCursor;
                if (!animateCursor)
                {
                    Glfw.SetCursor(window, Glfw.Cursor.None);
                }

                break;
            }

            case Glfw.KeyCode.Escape:
            {
                Glfw.SetWindowShouldClose(window, true);
                break;
            }

            case Glfw.KeyCode.N:
            {
                Glfw.SetInputMode(window, Glfw.InputMode.Cursor, Glfw.CursorMode.Normal);
                Log("(( cursor is normal ))");
                break;
            }

            case Glfw.KeyCode.D:
            {
                Glfw.SetInputMode(window, Glfw.InputMode.Cursor, Glfw.CursorMode.Disabled);
                Log("(( cursor is disabled ))");
                break;
            }

            case Glfw.KeyCode.H:
            {
                Glfw.SetInputMode(window, Glfw.InputMode.Cursor, Glfw.CursorMode.Hidden);
                Log("(( cursor is hidden ))");
                break;
            }

            case Glfw.KeyCode.Space:
            {
                swapInterval = 1 - swapInterval;
                Log("(( swap interval: {0} ))", swapInterval);
                Glfw.SwapInterval(swapInterval);
                break;
            }

            case Glfw.KeyCode.W:
            {
                waitEvents = !waitEvents;
                Log("(( {0}ing for events ))", waitEvents ? "wait" : "poll");
                break;
            }

            case Glfw.KeyCode.T:
            {
                trackCursor = !trackCursor;
                break;
            }

            case Glfw.KeyCode.Alpha0:
            {
                Glfw.SetCursor(window, Glfw.Cursor.None);
                break;
            }

            case Glfw.KeyCode.Alpha1:
            {
                Glfw.SetCursor(window, standardCursors[0]);
                break;
            }

            case Glfw.KeyCode.Alpha2:
            {
                Glfw.SetCursor(window, standardCursors[1]);
                break;
            }

            case Glfw.KeyCode.Alpha3:
            {
                Glfw.SetCursor(window, standardCursors[2]);
                break;
            }

            case Glfw.KeyCode.Alpha4:
            {
                Glfw.SetCursor(window, standardCursors[3]);
                break;
            }

            case Glfw.KeyCode.Alpha5:
            {
                Glfw.SetCursor(window, standardCursors[4]);
                break;
            }

            case Glfw.KeyCode.Alpha6:
            {
                Glfw.SetCursor(window, standardCursors[5]);
                break;
            }

            default:
                break;
            }
        }
Beispiel #16
0
        static void KeyCallback(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState state, Glfw.KeyMods mods)
        {
            Log("{0} Key %s",
                Glfw.GetTime(),
                state == Glfw.InputState.Press ? "pressed" : "released");

            if (state != Glfw.InputState.Press)
            {
                return;
            }

            switch (key)
            {
            case Glfw.KeyCode.I:
                Glfw.IconifyWindow(window);
                break;

            case Glfw.KeyCode.M:
                Glfw.MaximizeWindow(window);
                break;

            case Glfw.KeyCode.R:
                Glfw.RestoreWindow(window);
                break;

            case Glfw.KeyCode.Escape:
                Glfw.SetWindowShouldClose(window, true);
                break;

            case Glfw.KeyCode.F11:
            case Glfw.KeyCode.Enter:
            {
                if (mods != Glfw.KeyMods.Alt)
                {
                    return;
                }

                if (Glfw.GetWindowMonitor(window))
                {
                    Glfw.SetWindowMonitor(window, Glfw.Monitor.None,
                                          m_WindowedXPos, m_WindowedYPos,
                                          m_WindowedWidth, m_WindowedHeight,
                                          0);
                }
                else
                {
                    var monitor = Glfw.GetPrimaryMonitor();
                    if (monitor)
                    {
                        var mode = Glfw.GetVideoMode(monitor);
                        Glfw.GetWindowPos(window, out m_WindowedXPos, out m_WindowedYPos);
                        Glfw.GetWindowSize(window, out m_WindowedWidth, out m_WindowedHeight);
                        Glfw.SetWindowMonitor(window, monitor,
                                              0, 0, mode.Width, mode.Height,
                                              mode.RefreshRate);
                    }
                }

                break;
            }
            }
        }
Beispiel #17
0
        private static void MouseButtonCallback(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods)
        {
            var engineWindow = dictionary[window];

            if (state == Glfw.InputState.Press || state == Glfw.InputState.Repeat)
            {
                engineWindow.MousePressed?.Invoke(engineWindow, new MouseButtonEventArgs()
                {
                    Button    = button,
                    Modifiers = mods
                });
            }
            else if (state == Glfw.InputState.Release)
            {
                engineWindow.MouseReleased?.Invoke(engineWindow, new MouseButtonEventArgs()
                {
                    Button    = button,
                    Modifiers = mods
                });
            }
        }
Beispiel #18
0
 private void KeyInput(Glfw.Window window, Glfw.KeyCode key, int scancode, Glfw.InputState action, Glfw.KeyMods mods)
 {
     UpdateKeyStatus((Key)key, action == Glfw.InputState.Press || action == Glfw.InputState.Repeat);
 }
Beispiel #19
0
        private void MouseButtonKeyInput(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods)
        {
            Key key = button switch
            {
                Glfw.MouseButton.ButtonLeft => Key.MouseKeyLeft,
                Glfw.MouseButton.ButtonRight => Key.MouseKeyRight,
                Glfw.MouseButton.Button3 => Key.MouseKeyMiddle,
                Glfw.MouseButton.Button4 => Key.MouseKey4,
                Glfw.MouseButton.Button5 => Key.MouseKey5,
                _ => Key.Unknown
            };

            UpdateKeyStatus(key, state == Glfw.InputState.Press || state == Glfw.InputState.Repeat);
        }
Beispiel #20
0
        /// <summary>
        /// The mouse button callback, will set the mouse button from a button and its state
        /// </summary>
        /// <param name="window"></param>
        /// <param name="button"></param>
        /// <param name="state"></param>
        /// <param name="mods"></param>
        private void MouseButtonCallBack(Glfw.Window window, Glfw.MouseButton button, Glfw.InputState state, Glfw.KeyMods mods)
        {
            switch (state)
            {
            case Glfw.InputState.Press:
                Input.SetMouseButton((int)button, Input.InputAction.Pressed);
                break;

            case Glfw.InputState.Release:
                Input.SetMouseButton((int)button, Input.InputAction.Released);
                break;

            case Glfw.InputState.Repeat:
                Input.SetMouseButton((int)button, Input.InputAction.Repeated);
                break;
            }

            Debug.Log("Input Mouse button " + button, Debug.DebugLayer.Input, Debug.DebugLevel.Information);
        }