Esempio n. 1
0
 /// <summary>
 /// Raises event 'Press'
 /// </summary>
 protected virtual void OnPress()
 {
     if (Press != null)
     {
         Press.Invoke(this, System.EventArgs.Empty);
     }
 }
Esempio n. 2
0
 public void ButtonUp(T button)
 {
     if (buttonsDown.Contains(button))
     {
         buttonsDown.Remove(button);
         Press?.Invoke(button);
     }
 }
Esempio n. 3
0
 public virtual bool OnPress(object sender, MouseEventArgs args)
 {
     if (Press != null)
     {
         return(Press.Invoke(sender, args));
     }
     return(true);
 }
Esempio n. 4
0
        public override void Update(GameTime dt)
        {
            previousMS = currentMS;
            currentMS  = Mouse.GetState();

            var mouseBox = new Rectangle(currentMS.X, currentMS.Y, 1, 1);

            target = false;

            if (mouseBox.Intersects(button))
            {
                target = true;
                if (currentMS.LeftButton == ButtonState.Released && previousMS.LeftButton == ButtonState.Pressed)
                {
                    Press?.Invoke(this, new EventArgs());
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Handler for releasing the button.
        /// </summary>
        protected void HandleButtonReleased()
        {
            if (_debounceTime.Ticks > 0 && !IsPressed)
            {
                return;
            }

            _debounceStartTicks = DateTime.UtcNow.Ticks;
            _holdingTimer?.Dispose();
            _holdingTimer = null;

            IsPressed = false;

            ButtonUp?.Invoke(this, new EventArgs());
            Press?.Invoke(this, new EventArgs());

            if (IsHoldingEnabled && _holdingState == ButtonHoldingState.Started)
            {
                _holdingState = ButtonHoldingState.Completed;
                Holding?.Invoke(this, new ButtonHoldingEventArgs {
                    HoldingState = ButtonHoldingState.Completed
                });
            }

            if (IsDoublePressEnabled)
            {
                if (_lastPress == DateTime.MinValue.Ticks)
                {
                    _lastPress = DateTime.UtcNow.Ticks;
                }
                else
                {
                    if (DateTime.UtcNow.Ticks - _lastPress <= _doublePressTicks)
                    {
                        DoublePress?.Invoke(this, new EventArgs());
                    }

                    _lastPress = DateTime.MinValue.Ticks;
                }
            }
        }
Esempio n. 6
0
 private void Callback()
 {
     Press?.Invoke(this, new EventArgs());
 }
Esempio n. 7
0
 protected virtual void OnPress(T arg1, bool arg2)
 {
     Press?.Invoke(arg1, arg2);
 }
Esempio n. 8
0
        public override void Update(GameTime gameTime)
        {
            _prevousState = _currentState;
            _currentState = Mouse.GetState();

            Rectangle mouseRectangele = new Rectangle(_currentState.X, _currentState.Y, 1, 1);

            if (Game1.gameState == 0)
            {
                _isHovering = false;
                if (mouseRectangele.Intersects(Rectangle) && Game1.isDragging == -1 && _prevousState.LeftButton != ButtonState.Pressed)
                {
                    _isHovering = true;
                }
                if (_currentState.LeftButton == ButtonState.Pressed && !_isPressed && _isHovering)
                {
                    _isPressed       = true;
                    Game1.isDragging = ID;
                    Press?.Invoke(this, new IntEventArgs(ID));
                }
                else if (_currentState.LeftButton == ButtonState.Released && _isPressed)
                {
                    _isPressed       = false;
                    Game1.isDragging = -1;
                    _canMove         = true;
                    Release?.Invoke(this, new IntEventArgs(ID));
                }
                if (_isPressed && Game1.isDragging == ID)
                {
                    currentDraggingID = ID;
                    _canMove          = false;
                    _currentPosition  = new Vector2(_currentState.X - _textures[DisplayingID].Width / 2, _currentState.Y - _textures[DisplayingID].Height / 2);
                    Rectangle         = new Rectangle((int)_currentPosition.X, (int)_currentPosition.Y, _textures[DisplayingID].Width, _textures[DisplayingID].Height);
                    CenterRect        = new Rectangle((int)(Rectangle.X + Rectangle.Width / 2) - _centerLength, (int)(Rectangle.Y + Rectangle.Height / 2) - _centerLength, _centerLength, _centerLength);
                }
            }

            // Movement
            if (_canMove && Game1.gameState == 0)
            {
                _currentPosition += Vector2.Normalize(new Vector2(currentDirecton.X, currentDirecton.Y)) * MoveSpeed;
                Rectangle         = new Rectangle((int)_currentPosition.X, (int)_currentPosition.Y, _textures[DisplayingID].Width, _textures[DisplayingID].Height);
                CenterRect        = new Rectangle((int)(Rectangle.X + Rectangle.Width / 2) - _centerLength, (int)(Rectangle.Y + Rectangle.Height / 2) - _centerLength, _centerLength, _centerLength);

                if (Game1.GetRandomNumber(0, 240) == 5 && !_collided)
                {
                    ChangeDirection();
                }

                CheckCollision();
            }

            // obj in hand
            if (!interacted && objInBodies.Count > 0)
            {
                foreach (var item in objInBodies)
                {
                    if (item.Rectangle.Contains(new Rectangle(holdPoint.X + Rectangle.X - 10, holdPoint.Y + Rectangle.Y - 10, 20, 20)))
                    {
                        if (Game1.currentMouseState.LeftButton.Equals(ButtonState.Pressed) &&
                            //Game1.previousMouseState.LeftButton.Equals(ButtonState.Pressed) &&
                            item.Rectangle.Contains(Game1.currentMouseState.Position))
                        {
                            interacted       = true;
                            item.Rectangle   = new Rectangle(holdPoint.X - item.Rectangle.Width / 2, holdPoint.Y - item.Rectangle.Height / 2, item.Rectangle.Width, item.Rectangle.Height);
                            objinbody        = item;
                            item.InSpot      = true;
                            item.RenderOrder = RenderOrder + 1;
                            break;
                        }
                    }
                }
            }

            if (interacted)
            {
                objinbody.Rectangle = new Rectangle(Rectangle.X + holdPoint.X - objinbody.Rectangle.Width / 2, Rectangle.Y + holdPoint.Y - objinbody.Rectangle.Height / 2, objinbody.Rectangle.Width, objinbody.Rectangle.Height);
            }
        }
Esempio n. 9
0
 private void OnEvent() => Press?.Invoke(this, EventArgs.Empty);
 internal void OnPress(Key key, KeyModifiers modifiers)
 {
     Press?.Invoke(key, modifiers);
 }
Esempio n. 11
0
 private void HotkeyProc(int hkID)
 {
     Press?.Invoke(this, new EventArgs <int>(hkID));
 }
Esempio n. 12
0
 protected virtual void OnPress(Vector2 position)
 {
     Press?.Invoke(position);
 }