示例#1
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            HidControllerButtons CurrentButton = 0;
            HidJoystickPosition  LeftJoystick;
            HidJoystickPosition  RightJoystick;

            int LeftJoystickDX  = 0;
            int LeftJoystickDY  = 0;
            int RightJoystickDX = 0;
            int RightJoystickDY = 0;

            if (Keyboard.HasValue)
            {
                KeyboardState Keyboard = this.Keyboard.Value;

                if (Keyboard[Key.Escape])
                {
                    this.Exit();
                }

                //RightJoystick
                if (Keyboard[(Key)Config.FakeJoyCon.Left.StickUp])
                {
                    LeftJoystickDY = short.MaxValue;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.StickDown])
                {
                    LeftJoystickDY = -short.MaxValue;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.StickLeft])
                {
                    LeftJoystickDX = -short.MaxValue;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.StickRight])
                {
                    LeftJoystickDX = short.MaxValue;
                }

                //LeftButtons
                if (Keyboard[(Key)Config.FakeJoyCon.Left.StickButton])
                {
                    CurrentButton |= HidControllerButtons.KEY_LSTICK;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.DPadUp])
                {
                    CurrentButton |= HidControllerButtons.KEY_DUP;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.DPadDown])
                {
                    CurrentButton |= HidControllerButtons.KEY_DDOWN;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.DPadLeft])
                {
                    CurrentButton |= HidControllerButtons.KEY_DLEFT;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.DPadRight])
                {
                    CurrentButton |= HidControllerButtons.KEY_DRIGHT;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.ButtonMinus])
                {
                    CurrentButton |= HidControllerButtons.KEY_MINUS;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.ButtonL])
                {
                    CurrentButton |= HidControllerButtons.KEY_L;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Left.ButtonZL])
                {
                    CurrentButton |= HidControllerButtons.KEY_ZL;
                }

                //RightJoystick
                if (Keyboard[(Key)Config.FakeJoyCon.Right.StickUp])
                {
                    RightJoystickDY = short.MaxValue;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.StickDown])
                {
                    RightJoystickDY = -short.MaxValue;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.StickLeft])
                {
                    RightJoystickDX = -short.MaxValue;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.StickRight])
                {
                    RightJoystickDX = short.MaxValue;
                }

                //RightButtons
                if (Keyboard[(Key)Config.FakeJoyCon.Right.StickButton])
                {
                    CurrentButton |= HidControllerButtons.KEY_RSTICK;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonA])
                {
                    CurrentButton |= HidControllerButtons.KEY_A;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonB])
                {
                    CurrentButton |= HidControllerButtons.KEY_B;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonX])
                {
                    CurrentButton |= HidControllerButtons.KEY_X;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonY])
                {
                    CurrentButton |= HidControllerButtons.KEY_Y;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonPlus])
                {
                    CurrentButton |= HidControllerButtons.KEY_PLUS;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonR])
                {
                    CurrentButton |= HidControllerButtons.KEY_R;
                }
                if (Keyboard[(Key)Config.FakeJoyCon.Right.ButtonZR])
                {
                    CurrentButton |= HidControllerButtons.KEY_ZR;
                }
            }

            LeftJoystick = new HidJoystickPosition
            {
                DX = LeftJoystickDX,
                DY = LeftJoystickDY
            };

            RightJoystick = new HidJoystickPosition
            {
                DX = RightJoystickDX,
                DY = RightJoystickDY
            };

            bool HasTouch = false;

            //Get screen touch position from left mouse click
            //OpenTK always captures mouse events, even if out of focus, so check if window is focused.
            if (Focused && Mouse?.LeftButton == ButtonState.Pressed)
            {
                MouseState Mouse = this.Mouse.Value;

                int ScrnWidth  = Width;
                int ScrnHeight = Height;

                if (Width > Height * TouchScreenRatioX)
                {
                    ScrnWidth = (int)(Height * TouchScreenRatioX);
                }
                else
                {
                    ScrnHeight = (int)(Width * TouchScreenRatioY);
                }

                int StartX = (Width - ScrnWidth) >> 1;
                int StartY = (Height - ScrnHeight) >> 1;

                int EndX = StartX + ScrnWidth;
                int EndY = StartY + ScrnHeight;

                if (Mouse.X >= StartX &&
                    Mouse.Y >= StartY &&
                    Mouse.X < EndX &&
                    Mouse.Y < EndY)
                {
                    int ScrnMouseX = Mouse.X - StartX;
                    int ScrnMouseY = Mouse.Y - StartY;

                    int MX = (int)(((float)ScrnMouseX / ScrnWidth) * TouchScreenWidth);
                    int MY = (int)(((float)ScrnMouseY / ScrnHeight) * TouchScreenHeight);

                    HidTouchPoint CurrentPoint = new HidTouchPoint
                    {
                        X = MX,
                        Y = MY,

                        //Placeholder values till more data is acquired
                        DiameterX = 10,
                        DiameterY = 10,
                        Angle     = 90
                    };

                    HasTouch = true;

                    Ns.Hid.SetTouchPoints(CurrentPoint);
                }
            }

            if (!HasTouch)
            {
                Ns.Hid.SetTouchPoints();
            }

            Ns.Hid.SetJoyconButton(
                HidControllerId.CONTROLLER_HANDHELD,
                HidControllerLayouts.Handheld_Joined,
                CurrentButton,
                LeftJoystick,
                RightJoystick);

            Ns.Hid.SetJoyconButton(
                HidControllerId.CONTROLLER_HANDHELD,
                HidControllerLayouts.Main,
                CurrentButton,
                LeftJoystick,
                RightJoystick);

            Ns.ProcessFrame();

            Renderer.RunActions();
        }
示例#2
0
        private new void UpdateFrame()
        {
            HidHotkeyButtons     currentHotkeyButtons = 0;
            HidControllerButtons currentButton        = 0;
            HidJoystickPosition  leftJoystick;
            HidJoystickPosition  rightJoystick;
            HidKeyboard?         hidKeyboard = null;

            int leftJoystickDx  = 0;
            int leftJoystickDy  = 0;
            int rightJoystickDx = 0;
            int rightJoystickDy = 0;

            // Keyboard Input
            if (_keyboard.HasValue)
            {
                KeyboardState keyboard = _keyboard.Value;

#if USE_PROFILING
                // Profiler input, lets the profiler get access to the main windows keyboard state
                _profileWindow.UpdateKeyInput(keyboard);
#endif

                // Normal Input
                currentHotkeyButtons = Configuration.Instance.KeyboardControls.GetHotkeyButtons(keyboard);
                currentButton        = Configuration.Instance.KeyboardControls.GetButtons(keyboard);

                if (Configuration.Instance.EnableKeyboard)
                {
                    hidKeyboard = Configuration.Instance.KeyboardControls.GetKeysDown(keyboard);
                }

                (leftJoystickDx, leftJoystickDy)   = Configuration.Instance.KeyboardControls.GetLeftStick(keyboard);
                (rightJoystickDx, rightJoystickDy) = Configuration.Instance.KeyboardControls.GetRightStick(keyboard);
            }

            if (!hidKeyboard.HasValue)
            {
                hidKeyboard = new HidKeyboard
                {
                    Modifier = 0,
                    Keys     = new int[0x8]
                };
            }

            currentButton |= Configuration.Instance.GamepadControls.GetButtons();

            // Keyboard has priority stick-wise
            if (leftJoystickDx == 0 && leftJoystickDy == 0)
            {
                (leftJoystickDx, leftJoystickDy) = Configuration.Instance.GamepadControls.GetLeftStick();
            }

            if (rightJoystickDx == 0 && rightJoystickDy == 0)
            {
                (rightJoystickDx, rightJoystickDy) = Configuration.Instance.GamepadControls.GetRightStick();
            }

            leftJoystick = new HidJoystickPosition
            {
                Dx = leftJoystickDx,
                Dy = leftJoystickDy
            };

            rightJoystick = new HidJoystickPosition
            {
                Dx = rightJoystickDx,
                Dy = rightJoystickDy
            };

            currentButton |= _device.Hid.UpdateStickButtons(leftJoystick, rightJoystick);

            bool hasTouch = false;

            // Get screen touch position from left mouse click
            // OpenTK always captures mouse events, even if out of focus, so check if window is focused.
            if (Focused && _mouse?.LeftButton == ButtonState.Pressed)
            {
                MouseState mouse = _mouse.Value;

                int scrnWidth  = Width;
                int scrnHeight = Height;

                if (Width > (Height * TouchScreenWidth) / TouchScreenHeight)
                {
                    scrnWidth = (Height * TouchScreenWidth) / TouchScreenHeight;
                }
                else
                {
                    scrnHeight = (Width * TouchScreenHeight) / TouchScreenWidth;
                }

                int startX = (Width - scrnWidth) >> 1;
                int startY = (Height - scrnHeight) >> 1;

                int endX = startX + scrnWidth;
                int endY = startY + scrnHeight;

                if (mouse.X >= startX &&
                    mouse.Y >= startY &&
                    mouse.X < endX &&
                    mouse.Y < endY)
                {
                    int scrnMouseX = mouse.X - startX;
                    int scrnMouseY = mouse.Y - startY;

                    int mX = (scrnMouseX * TouchScreenWidth) / scrnWidth;
                    int mY = (scrnMouseY * TouchScreenHeight) / scrnHeight;

                    HidTouchPoint currentPoint = new HidTouchPoint
                    {
                        X = mX,
                        Y = mY,

                        // Placeholder values till more data is acquired
                        DiameterX = 10,
                        DiameterY = 10,
                        Angle     = 90
                    };

                    hasTouch = true;

                    _device.Hid.SetTouchPoints(currentPoint);
                }
            }

            if (!hasTouch)
            {
                _device.Hid.SetTouchPoints();
            }

            if (Configuration.Instance.EnableKeyboard && hidKeyboard.HasValue)
            {
                _device.Hid.WriteKeyboard(hidKeyboard.Value);
            }

            HidControllerBase controller = _device.Hid.PrimaryController;

            controller.SendInput(currentButton, leftJoystick, rightJoystick);

            // Toggle vsync
            if (currentHotkeyButtons.HasFlag(HidHotkeyButtons.ToggleVSync) &&
                !_prevHotkeyButtons.HasFlag(HidHotkeyButtons.ToggleVSync))
            {
                _device.EnableDeviceVsync = !_device.EnableDeviceVsync;
            }

            _prevHotkeyButtons = currentHotkeyButtons;
        }
示例#3
0
        private new void UpdateFrame()
        {
            HidControllerButtons currentButton = 0;
            HidJoystickPosition  leftJoystick;
            HidJoystickPosition  rightJoystick;

            int leftJoystickDx  = 0;
            int leftJoystickDy  = 0;
            int rightJoystickDx = 0;
            int rightJoystickDy = 0;

            //Keyboard Input
            if (_keyboard.HasValue)
            {
                KeyboardState keyboard = _keyboard.Value;

                currentButton = Configuration.Instance.KeyboardControls.GetButtons(keyboard);

                (leftJoystickDx, leftJoystickDy) = Configuration.Instance.KeyboardControls.GetLeftStick(keyboard);

                (rightJoystickDx, rightJoystickDy) = Configuration.Instance.KeyboardControls.GetRightStick(keyboard);
            }

            currentButton |= Configuration.Instance.GamepadControls.GetButtons();

            //Keyboard has priority stick-wise
            if (leftJoystickDx == 0 && leftJoystickDy == 0)
            {
                (leftJoystickDx, leftJoystickDy) = Configuration.Instance.GamepadControls.GetLeftStick();
            }

            if (rightJoystickDx == 0 && rightJoystickDy == 0)
            {
                (rightJoystickDx, rightJoystickDy) = Configuration.Instance.GamepadControls.GetRightStick();
            }

            leftJoystick = new HidJoystickPosition
            {
                Dx = leftJoystickDx,
                Dy = leftJoystickDy
            };

            rightJoystick = new HidJoystickPosition
            {
                Dx = rightJoystickDx,
                Dy = rightJoystickDy
            };

            currentButton |= _device.Hid.UpdateStickButtons(leftJoystick, rightJoystick);

            bool hasTouch = false;

            //Get screen touch position from left mouse click
            //OpenTK always captures mouse events, even if out of focus, so check if window is focused.
            if (Focused && _mouse?.LeftButton == ButtonState.Pressed)
            {
                MouseState mouse = _mouse.Value;

                int scrnWidth  = Width;
                int scrnHeight = Height;

                if (Width > (Height * TouchScreenWidth) / TouchScreenHeight)
                {
                    scrnWidth = (Height * TouchScreenWidth) / TouchScreenHeight;
                }
                else
                {
                    scrnHeight = (Width * TouchScreenHeight) / TouchScreenWidth;
                }

                int startX = (Width - scrnWidth) >> 1;
                int startY = (Height - scrnHeight) >> 1;

                int endX = startX + scrnWidth;
                int endY = startY + scrnHeight;

                if (mouse.X >= startX &&
                    mouse.Y >= startY &&
                    mouse.X < endX &&
                    mouse.Y < endY)
                {
                    int scrnMouseX = mouse.X - startX;
                    int scrnMouseY = mouse.Y - startY;

                    int mX = (scrnMouseX * TouchScreenWidth) / scrnWidth;
                    int mY = (scrnMouseY * TouchScreenHeight) / scrnHeight;

                    HidTouchPoint currentPoint = new HidTouchPoint
                    {
                        X = mX,
                        Y = mY,

                        //Placeholder values till more data is acquired
                        DiameterX = 10,
                        DiameterY = 10,
                        Angle     = 90
                    };

                    hasTouch = true;

                    _device.Hid.SetTouchPoints(currentPoint);
                }
            }

            if (!hasTouch)
            {
                _device.Hid.SetTouchPoints();
            }

            HidControllerBase controller = _device.Hid.PrimaryController;

            controller.SendInput(currentButton, leftJoystick, rightJoystick);
        }
示例#4
0
        private new void UpdateFrame()
        {
            HidControllerButtons CurrentButton = 0;
            HidJoystickPosition  LeftJoystick;
            HidJoystickPosition  RightJoystick;

            int   LeftJoystickDX      = 0;
            int   LeftJoystickDY      = 0;
            int   RightJoystickDX     = 0;
            int   RightJoystickDY     = 0;
            float AnalogStickDeadzone = Config.GamePadDeadzone;

            //Keyboard Input
            if (Keyboard.HasValue)
            {
                KeyboardState Keyboard = this.Keyboard.Value;

                if (Keyboard[Key.Escape])
                {
                    this.Exit();
                }

                //LeftJoystick
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.StickUp])
                {
                    LeftJoystickDY = short.MaxValue;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.StickDown])
                {
                    LeftJoystickDY = -short.MaxValue;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.StickLeft])
                {
                    LeftJoystickDX = -short.MaxValue;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.StickRight])
                {
                    LeftJoystickDX = short.MaxValue;
                }

                //LeftButtons
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.StickButton])
                {
                    CurrentButton |= HidControllerButtons.KEY_LSTICK;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.DPadUp])
                {
                    CurrentButton |= HidControllerButtons.KEY_DUP;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.DPadDown])
                {
                    CurrentButton |= HidControllerButtons.KEY_DDOWN;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.DPadLeft])
                {
                    CurrentButton |= HidControllerButtons.KEY_DLEFT;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.DPadRight])
                {
                    CurrentButton |= HidControllerButtons.KEY_DRIGHT;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.ButtonMinus])
                {
                    CurrentButton |= HidControllerButtons.KEY_MINUS;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.ButtonL])
                {
                    CurrentButton |= HidControllerButtons.KEY_L;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Left.ButtonZL])
                {
                    CurrentButton |= HidControllerButtons.KEY_ZL;
                }

                //RightJoystick
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.StickUp])
                {
                    RightJoystickDY = short.MaxValue;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.StickDown])
                {
                    RightJoystickDY = -short.MaxValue;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.StickLeft])
                {
                    RightJoystickDX = -short.MaxValue;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.StickRight])
                {
                    RightJoystickDX = short.MaxValue;
                }

                //RightButtons
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.StickButton])
                {
                    CurrentButton |= HidControllerButtons.KEY_RSTICK;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.ButtonA])
                {
                    CurrentButton |= HidControllerButtons.KEY_A;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.ButtonB])
                {
                    CurrentButton |= HidControllerButtons.KEY_B;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.ButtonX])
                {
                    CurrentButton |= HidControllerButtons.KEY_X;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.ButtonY])
                {
                    CurrentButton |= HidControllerButtons.KEY_Y;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.ButtonPlus])
                {
                    CurrentButton |= HidControllerButtons.KEY_PLUS;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.ButtonR])
                {
                    CurrentButton |= HidControllerButtons.KEY_R;
                }
                if (Keyboard[(Key)Config.JoyConKeyboard.Right.ButtonZR])
                {
                    CurrentButton |= HidControllerButtons.KEY_ZR;
                }
            }

            //Controller Input
            if (Config.GamePadEnable)
            {
                GamePadState GamePad = OpenTK.Input.GamePad.GetState(Config.GamePadIndex);
                //LeftButtons
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.DPadUp))
                {
                    CurrentButton |= HidControllerButtons.KEY_DUP;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.DPadDown))
                {
                    CurrentButton |= HidControllerButtons.KEY_DDOWN;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.DPadLeft))
                {
                    CurrentButton |= HidControllerButtons.KEY_DLEFT;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.DPadRight))
                {
                    CurrentButton |= HidControllerButtons.KEY_DRIGHT;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.StickButton))
                {
                    CurrentButton |= HidControllerButtons.KEY_LSTICK;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.ButtonMinus))
                {
                    CurrentButton |= HidControllerButtons.KEY_MINUS;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.ButtonL))
                {
                    CurrentButton |= HidControllerButtons.KEY_L;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Left.ButtonZL))
                {
                    CurrentButton |= HidControllerButtons.KEY_ZL;
                }

                //RightButtons
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.ButtonA))
                {
                    CurrentButton |= HidControllerButtons.KEY_A;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.ButtonB))
                {
                    CurrentButton |= HidControllerButtons.KEY_B;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.ButtonX))
                {
                    CurrentButton |= HidControllerButtons.KEY_X;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.ButtonY))
                {
                    CurrentButton |= HidControllerButtons.KEY_Y;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.StickButton))
                {
                    CurrentButton |= HidControllerButtons.KEY_RSTICK;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.ButtonPlus))
                {
                    CurrentButton |= HidControllerButtons.KEY_PLUS;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.ButtonR))
                {
                    CurrentButton |= HidControllerButtons.KEY_R;
                }
                if (IsGamePadButtonPressedFromString(GamePad, Config.JoyConController.Right.ButtonZR))
                {
                    CurrentButton |= HidControllerButtons.KEY_ZR;
                }

                //LeftJoystick
                if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).X >= AnalogStickDeadzone ||
                    GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).X <= -AnalogStickDeadzone)
                {
                    LeftJoystickDX = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).X *short.MaxValue);
                }

                if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).Y >= AnalogStickDeadzone ||
                    GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).Y <= -AnalogStickDeadzone)
                {
                    LeftJoystickDY = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Left.Stick).Y *short.MaxValue);
                }

                //RightJoystick
                if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).X >= AnalogStickDeadzone ||
                    GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).X <= -AnalogStickDeadzone)
                {
                    RightJoystickDX = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).X *short.MaxValue);
                }

                if (GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).Y >= AnalogStickDeadzone ||
                    GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).Y <= -AnalogStickDeadzone)
                {
                    RightJoystickDY = (int)(GetJoystickAxisFromString(GamePad, Config.JoyConController.Right.Stick).Y *short.MaxValue);
                }
            }

            LeftJoystick = new HidJoystickPosition
            {
                DX = LeftJoystickDX,
                DY = LeftJoystickDY
            };

            RightJoystick = new HidJoystickPosition
            {
                DX = RightJoystickDX,
                DY = RightJoystickDY
            };

            bool HasTouch = false;

            //Get screen touch position from left mouse click
            //OpenTK always captures mouse events, even if out of focus, so check if window is focused.
            if (Focused && Mouse?.LeftButton == ButtonState.Pressed)
            {
                MouseState Mouse = this.Mouse.Value;

                int ScrnWidth  = Width;
                int ScrnHeight = Height;

                if (Width > Height * TouchScreenRatioX)
                {
                    ScrnWidth = (int)(Height * TouchScreenRatioX);
                }
                else
                {
                    ScrnHeight = (int)(Width * TouchScreenRatioY);
                }

                int StartX = (Width - ScrnWidth) >> 1;
                int StartY = (Height - ScrnHeight) >> 1;

                int EndX = StartX + ScrnWidth;
                int EndY = StartY + ScrnHeight;

                if (Mouse.X >= StartX &&
                    Mouse.Y >= StartY &&
                    Mouse.X < EndX &&
                    Mouse.Y < EndY)
                {
                    int ScrnMouseX = Mouse.X - StartX;
                    int ScrnMouseY = Mouse.Y - StartY;

                    int MX = (int)(((float)ScrnMouseX / ScrnWidth) * TouchScreenWidth);
                    int MY = (int)(((float)ScrnMouseY / ScrnHeight) * TouchScreenHeight);

                    HidTouchPoint CurrentPoint = new HidTouchPoint
                    {
                        X = MX,
                        Y = MY,

                        //Placeholder values till more data is acquired
                        DiameterX = 10,
                        DiameterY = 10,
                        Angle     = 90
                    };

                    HasTouch = true;

                    Ns.Hid.SetTouchPoints(CurrentPoint);
                }
            }

            if (!HasTouch)
            {
                Ns.Hid.SetTouchPoints();
            }

            Ns.Hid.SetJoyconButton(
                HidControllerId.CONTROLLER_HANDHELD,
                HidControllerLayouts.Handheld_Joined,
                CurrentButton,
                LeftJoystick,
                RightJoystick);

            Ns.Hid.SetJoyconButton(
                HidControllerId.CONTROLLER_HANDHELD,
                HidControllerLayouts.Main,
                CurrentButton,
                LeftJoystick,
                RightJoystick);
        }
示例#5
0
        private new void UpdateFrame()
        {
            HidControllerButtons CurrentButton = 0;
            HidJoystickPosition  LeftJoystick;
            HidJoystickPosition  RightJoystick;

            int LeftJoystickDX  = 0;
            int LeftJoystickDY  = 0;
            int RightJoystickDX = 0;
            int RightJoystickDY = 0;

            //Keyboard Input
            if (Keyboard.HasValue)
            {
                KeyboardState Keyboard = this.Keyboard.Value;

                CurrentButton = Config.JoyConKeyboard.GetButtons(Keyboard);

                (LeftJoystickDX, LeftJoystickDY) = Config.JoyConKeyboard.GetLeftStick(Keyboard);

                (RightJoystickDX, RightJoystickDY) = Config.JoyConKeyboard.GetRightStick(Keyboard);
            }

            //Controller Input
            CurrentButton |= Config.JoyConController.GetButtons();

            //Keyboard has priority stick-wise
            if (LeftJoystickDX == 0 && LeftJoystickDY == 0)
            {
                (LeftJoystickDX, LeftJoystickDY) = Config.JoyConController.GetLeftStick();
            }

            if (RightJoystickDX == 0 && RightJoystickDY == 0)
            {
                (RightJoystickDX, RightJoystickDY) = Config.JoyConController.GetRightStick();
            }

            LeftJoystick = new HidJoystickPosition
            {
                DX = LeftJoystickDX,
                DY = LeftJoystickDY
            };

            RightJoystick = new HidJoystickPosition
            {
                DX = RightJoystickDX,
                DY = RightJoystickDY
            };

            bool HasTouch = false;

            //Get screen touch position from left mouse click
            //OpenTK always captures mouse events, even if out of focus, so check if window is focused.
            if (Focused && Mouse?.LeftButton == ButtonState.Pressed)
            {
                MouseState Mouse = this.Mouse.Value;

                int ScrnWidth  = Width;
                int ScrnHeight = Height;

                if (Width > (Height * TouchScreenWidth) / TouchScreenHeight)
                {
                    ScrnWidth = (Height * TouchScreenWidth) / TouchScreenHeight;
                }
                else
                {
                    ScrnHeight = (Width * TouchScreenHeight) / TouchScreenWidth;
                }

                int StartX = (Width - ScrnWidth) >> 1;
                int StartY = (Height - ScrnHeight) >> 1;

                int EndX = StartX + ScrnWidth;
                int EndY = StartY + ScrnHeight;

                if (Mouse.X >= StartX &&
                    Mouse.Y >= StartY &&
                    Mouse.X < EndX &&
                    Mouse.Y < EndY)
                {
                    int ScrnMouseX = Mouse.X - StartX;
                    int ScrnMouseY = Mouse.Y - StartY;

                    int MX = (ScrnMouseX * TouchScreenWidth) / ScrnWidth;
                    int MY = (ScrnMouseY * TouchScreenHeight) / ScrnHeight;

                    HidTouchPoint CurrentPoint = new HidTouchPoint
                    {
                        X = MX,
                        Y = MY,

                        //Placeholder values till more data is acquired
                        DiameterX = 10,
                        DiameterY = 10,
                        Angle     = 90
                    };

                    HasTouch = true;

                    Device.Hid.SetTouchPoints(CurrentPoint);
                }
            }

            if (!HasTouch)
            {
                Device.Hid.SetTouchPoints();
            }

            Device.Hid.SetJoyconButton(
                HidControllerId.CONTROLLER_HANDHELD,
                HidControllerLayouts.Handheld_Joined,
                CurrentButton,
                LeftJoystick,
                RightJoystick);

            Device.Hid.SetJoyconButton(
                HidControllerId.CONTROLLER_HANDHELD,
                HidControllerLayouts.Main,
                CurrentButton,
                LeftJoystick,
                RightJoystick);
        }