Esempio n. 1
0
 /// <summary>
 /// Handles the KeyReleased event of the <see cref="GameBase.RenderWindow"/>.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="SFML.Window.KeyEventArgs"/> instance containing the event data.</param>
 void rw_KeyReleased(object sender, KeyEventArgs e)
 {
     if (KeyReleased != null)
     {
         KeyReleased.Raise(this, e);
     }
 }
Esempio n. 2
0
        private void RaiseReleasedEvents(KeyboardState currentState)
        {
            var releasedKeys = Enum.GetValues(typeof(Keys))
                               .Cast <Keys>()
                               .Where(key => currentState.IsKeyUp(key) && _previousState.IsKeyDown(key));

            foreach (var key in releasedKeys)
            {
                KeyReleased.Raise(this, new KeyboardEventArgs(key, currentState));
            }
        }
Esempio n. 3
0
File: Input.cs Progetto: ndech/Alpha
        public void Update(double delta)
        {
            // Truncate mouse position to screen dimensions
            Point position = _form.PointToClient(Cursor.Position);

            _mousePosition = new Vector2I(position.X, position.Y);
            MouseMoved.Raise(_mousePosition);

            MouseButtons buttons = Control.MouseButtons;
            bool         leftMouseButtonPressed = (buttons == MouseButtons.Left);

            if (leftMouseButtonPressed && !_previousMouseButtons[0])
            {
                MouseClicked.Raise(_mousePosition, 0);
            }
            else if (_previousMouseButtons[0] && !leftMouseButtonPressed)
            {
                MouseReleased.Raise(_mousePosition, 0);
            }
            _previousMouseButtons[0] = leftMouseButtonPressed;

            bool rightMouseButtonPressed = (buttons == MouseButtons.Right);

            if (rightMouseButtonPressed && !_previousMouseButtons[1])
            {
                MouseClicked.Raise(_mousePosition, 1);
            }
            else if (_previousMouseButtons[1] && !rightMouseButtonPressed)
            {
                MouseReleased.Raise(_mousePosition, 1);
            }
            _previousMouseButtons[1] = rightMouseButtonPressed;


            foreach (Key key in _keys.Cast <Key>().Where(key => key != Key.None))
            {
                if (Keyboard.IsKeyDown(key))
                {
                    if (_pressedKeys.ContainsKey(key))
                    {
                        _pressedKeys[key] += delta;
                        if (_pressedKeys[key] > 0.1)
                        {
                            _pressedKeys[key] = 0.0;
                            KeyPressed.Raise(key, InputInterop.GetCharFromKey(key), true);
                        }
                    }
                    else
                    {
                        _pressedKeys.Add(key, -0.9);
                        KeyPressed.Raise(key, InputInterop.GetCharFromKey(key), false);
                    }
                }
                else
                {
                    if (_pressedKeys.ContainsKey(key))
                    {
                        _pressedKeys.Remove(key);
                        KeyReleased.Raise(key);
                    }
                }
            }
        }