예제 #1
0
 private void InvokeMouseButtonUp(int index, Vector3 wlorldPosition, Int2 slotCoords)
 {
     OnMouseButtonUp?.Invoke(new MouseButtonEventData
     {
         buttonIndex = index,
         position    = wlorldPosition,
         coords      = slotCoords
     });
 }
예제 #2
0
        public void Act()
        {
            if (Input.GetMouseButtonUp(0))
            {
                OnMouseButtonUp?.Invoke(ref selectedCard, ref heldCard);
            }

            if (!Input.GetMouseButton(0))
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                OnMouseButtonDown?.Invoke(ref selectedCard, ref heldCard, ref clickPoint);
            }

            OnMouseButtonLongPress?.Invoke(ref selectedCard, ref heldCard, clickPoint);
        }
예제 #3
0
        public override void PollEvents()
        {
            while (SDL.PollEvent(out ev) == 1)
            {
                switch (ev.Type)
                {
                case EventType.Quit:
                    OnQuit?.Invoke();
                    break;

                case EventType.KeyDown:
                    OnKeyDown?.Invoke(ev.Key.Keysym.Sym, ev.Key.Keysym.ScanCode);
                    break;

                case EventType.KeyUp:
                    OnKeyUp?.Invoke(ev.Key.Keysym.Sym, ev.Key.Keysym.ScanCode);
                    break;

                case EventType.MouseMotion:
                    OnMouseMove?.Invoke(ev.Motion.X, ev.Motion.Y);
                    break;

                case EventType.MouseButtonDown:
                    OnMouseButtonDown?.Invoke(ev.Button.Button);
                    break;

                case EventType.MouseButtonUp:
                    OnMouseButtonUp?.Invoke(ev.Button.Button);
                    break;

                case EventType.MouseWheel:
                    OnMouseScroll?.Invoke(ev.Wheel.X, ev.Wheel.Y);
                    break;

                case EventType.JoyDeviceAdded:
                    OnJoyDeviceAdd?.Invoke(ev.JDevice.Which);
                    break;

                case EventType.JoyDeviceRemoved:
                    OnJoyDeviceRemove?.Invoke(ev.JDevice.Which);
                    break;

                case EventType.JoyButtonDown:
                    OnJoyButtonDown?.Invoke(ev.JButton.Which, ev.JButton.Button);
                    break;

                case EventType.JoyButtonUp:
                    OnJoyButtonDown?.Invoke(ev.JButton.Which, ev.JButton.Button);
                    break;

                case EventType.JoyAxisMotion:
                    OnJoyAxisMove?.Invoke(ev.JAxis.Which, ev.JAxis.Axis, ev.JAxis.Value / (float)short.MaxValue);
                    break;

                case EventType.WindowEvent:
                    if (ev.Window.WindowID == windowID)
                    {
                        switch (ev.Window.Event)
                        {
                        case WindowEventID.Close:
                            OnWinClose?.Invoke();
                            break;

                        case WindowEventID.Shown:
                            OnWinShown?.Invoke();
                            break;

                        case WindowEventID.Hidden:
                            OnWinHidden?.Invoke();
                            break;

                        case WindowEventID.Exposed:
                            OnWinExposed?.Invoke();
                            break;

                        case WindowEventID.Moved:
                            OnWinMoved?.Invoke();
                            break;

                        case WindowEventID.Resized:
                            OnWinResized?.Invoke();
                            break;

                        case WindowEventID.Minimized:
                            OnWinMinimized?.Invoke();
                            break;

                        case WindowEventID.Maximized:
                            OnWinMaximized?.Invoke();
                            break;

                        case WindowEventID.Restored:
                            OnWinRestored?.Invoke();
                            break;

                        case WindowEventID.Enter:
                            OnWinEnter?.Invoke();
                            break;

                        case WindowEventID.Leave:
                            OnWinLeave?.Invoke();
                            break;

                        case WindowEventID.FocusGained:
                            OnWinFocusGained?.Invoke();
                            break;

                        case WindowEventID.FocusLost:
                            OnWinFocusLost?.Invoke();
                            break;

                        default:
                            OnWinOtherEvent?.Invoke((int)ev.Window.Event);
                            break;
                        }
                    }
                    break;

                default:
                    OnOtherEvent?.Invoke((int)ev.Type);
                    break;
                }
            }
        }
예제 #4
0
        void Update()
        {
            var mousePosition = Input.mousePosition;

            MouseMove = mousePosition - PreMousePosition;

            if (camera != null)
            {
                WorldMousePosition = camera.ScreenToWorldPoint(mousePosition);
                var preWorldMousePosition = camera.ScreenToWorldPoint(PreMousePosition);
                WorldMouseMove = WorldMousePosition - preWorldMousePosition;
            }

            PreMousePosition = mousePosition;
            if (Input.GetMouseButtonDown(0))
            {
                OnMouseButtonDown?.Invoke(MouseButtonType.Left);
            }
            if (Input.GetMouseButtonDown(1))
            {
                OnMouseButtonDown?.Invoke(MouseButtonType.Right);
            }
            if (Input.GetMouseButtonDown(2))
            {
                OnMouseButtonDown?.Invoke(MouseButtonType.Center);
            }
            if (Input.GetMouseButtonUp(0))
            {
                OnMouseButtonUp?.Invoke(MouseButtonType.Left);
            }
            if (Input.GetMouseButtonUp(1))
            {
                OnMouseButtonUp?.Invoke(MouseButtonType.Right);
            }
            if (Input.GetMouseButtonUp(2))
            {
                OnMouseButtonUp?.Invoke(MouseButtonType.Center);
            }


            foreach (var keyCode in keyCodes)
            {
                if (Input.GetKeyDown(keyCode))
                {
                    OnKeyDown?.Invoke(keyCode);
                    if (!pressedKeyCodes.Contains(keyCode))
                    {
                        pressedKeyCodes.Add(keyCode);
                    }
                    break;
                }
                else
                {
                    if (pressedKeyCodes.Contains(keyCode))
                    {
                        OnKeyUp?.Invoke(keyCode);
                        pressedKeyCodes.Remove(keyCode);
                    }
                }
            }
        }
예제 #5
0
        public void Update()
        {
            #region Keybaord
            KeyboardState      keyboardState  = Keyboard.GetState();
            Keys[]             keyPressed     = keyboardState.GetPressedKeys();
            IEnumerable <Keys> keyJustPressed = keyPressed.Where(key => !_pressedKeys.Any(k => k == key));

            foreach (Keys key in keyJustPressed)
            {
                OnKeyDown?.Invoke(null, key);
            }

            IEnumerable <Keys> keyJustUpped = _pressedKeys.Where(key => !keyPressed.Any(k => k == key));

            foreach (Keys key in keyJustUpped)
            {
                OnKeyUp?.Invoke(null, key);
            }
            _pressedKeys = keyPressed;
            #endregion Keybaord

            #region Mouse
            MouseState mouseState = Mouse.GetState();
            if (mouseState.LeftButton != _previousLeftButtonState)
            {
                _previousLeftButtonState = mouseState.LeftButton;
                if (_previousLeftButtonState == ButtonState.Pressed)
                {
                    OnMouseButtonDown?.Invoke(this, mouseState);
                }
                else
                {
                    OnMouseButtonUp?.Invoke(this, mouseState);
                }
            }

            if (mouseState.RightButton != _previousRightButtonState)
            {
                _previousRightButtonState = mouseState.RightButton;
                if (_previousRightButtonState == ButtonState.Pressed)
                {
                    OnMouseButtonDown?.Invoke(this, mouseState);
                }
                else
                {
                    OnMouseButtonUp?.Invoke(this, mouseState);
                }
            }

            if (mouseState.ScrollWheelValue != _previousScrollValue)
            {
                if (mouseState.ScrollWheelValue < _previousScrollValue)
                {
                    OnMouseWheelUp?.Invoke(this, mouseState);
                }
                else
                {
                    OnMouseWheelDown?.Invoke(this, mouseState);
                }
                _previousScrollValue = mouseState.ScrollWheelValue;
            }

            if (mouseState.Position != _previousMousePosition)
            {
                OnMouseMoved?.Invoke(this, mouseState);
                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    OnMouseDragged?.Invoke(this, mouseState);
                }
            }

            _previousMousePosition = mouseState.Position;
            #endregion Mouse
        }
예제 #6
0
        public void Update()
        {
            //Update keyboard states
            PrevKeyboardState    = CurrentKeyboardState;
            CurrentKeyboardState = Keyboard.GetState();
            //Update mouse states
            PrevMouseState    = CurrentMouseState;
            CurrentMouseState = Mouse.GetState();

            foreach (var key in KeySet)
            {
                var isDown  = CurrentKeyboardState.IsKeyDown(key);
                var wasDown = PrevKeyboardState.IsKeyDown(key);

                if (isDown)//Key is down
                {
                    //Key is currently held
                    OnKeyHeld?.Invoke(this, new KeyEventArgs(key));

                    if (!wasDown)//Key has just been pressed
                    {
                        OnKeyDown?.Invoke(this, new KeyEventArgs(key));
                    }
                }
                else  //Key is not down
                {
                    if (wasDown)//Key has just been released
                    {
                        OnKeyUp?.Invoke(this, new KeyEventArgs(key));
                    }
                }
            }

            foreach (var button in ButtonSet)
            {
                bool isDown  = false;
                bool wasDown = false;

                switch (button)
                {
                case MouseButton.left:
                {
                    isDown  = CurrentMouseState.LeftButton == ButtonState.Pressed;
                    wasDown = PrevMouseState.LeftButton == ButtonState.Pressed;
                }
                break;

                case MouseButton.right:
                {
                    isDown  = CurrentMouseState.RightButton == ButtonState.Pressed;
                    wasDown = PrevMouseState.RightButton == ButtonState.Pressed;
                }
                break;

                default:
                    break;
                }

                if (isDown)//Button is down
                {
                    OnMouseButtonHeld?.Invoke(this, new MouseEventArgs(button, CurrentMouseState));

                    if (!wasDown)//Button has just been pressed
                    {
                        OnMouseButtonDown?.Invoke(this, new MouseEventArgs(button, CurrentMouseState));
                    }
                }
                else
                {                //Button is not down
                    if (wasDown) //Button has just been released
                    {
                        OnMouseButtonUp?.Invoke(this, new MouseEventArgs(button, CurrentMouseState));
                    }
                }
            }
        }