Exemplo n.º 1
0
        public void IsClicked(MouseState state, Vector2 cursorPos)
        {
            if (ParentScreen.Visible)
            {
                if (!_clicked && state.LeftButton == ButtonState.Pressed || state.RightButton == ButtonState.Pressed)
                {
                    if (Viewport.Bounds.Contains(cursorPos.X, cursorPos.Y))
                    {
                        if (state.LeftButton == ButtonState.Pressed)
                        {
                            _clickedButton = ClickedMouseButton.Left;
                        }
                        else if (state.RightButton == ButtonState.Pressed)
                        {
                            _clickedButton = ClickedMouseButton.Right;
                        }
                        _clicked = true;
                    }
                }
                else if (_clicked)
                {
                    if (_clickedButton == ClickedMouseButton.Left && state.LeftButton == ButtonState.Released)
                    {
                        _clicked = false;
                    }
                    else if (_clickedButton == ClickedMouseButton.Right && state.RightButton == ButtonState.Released)
                    {
                        _clicked = false;
                    }
                    if (!_clicked)
                    {
                        bool inScreen = Viewport.Bounds.Contains(cursorPos.X, cursorPos.Y);
                        var  args     = new ViewportEventArgs(this, (int)((float)(cursorPos.X - this.Viewport.X) / ((float)this.Viewport.Width / (float)this.MaxWidth)), (int)(cursorPos.Y / ((float)this.Viewport.Height / (float)this.MaxHeight)), this._clickedButton, inScreen);
                        OnClick(args);
                    }
                }
                else if (!_clicked && state.LeftButton == ButtonState.Released && state.RightButton == ButtonState.Released)
                {
                    if (Viewport.Bounds.Contains(cursorPos.X, cursorPos.Y))
                    {
                        var args = new ViewportEventArgs(this, (int)((float)(cursorPos.X - this.Viewport.X) / ((float)this.Viewport.Width / (float)this.MaxWidth)), (int)(cursorPos.Y / ((float)this.Viewport.Height / (float)this.MaxHeight)), this._clickedButton, true);
                        OnMouseOver(args);
                    }
                }

                if (!cursorPos.Equals(_lastMousePosition) &&
                    Viewport.Bounds.Contains(cursorPos.X, cursorPos.Y) &&
                    state.LeftButton == ButtonState.Pressed)
                {
                    _lastMousePosition = new Vector2(cursorPos.X, cursorPos.Y);
                    var args = new ViewportEventArgs(this, (int)((float)(cursorPos.X - this.Viewport.X) / ((float)this.Viewport.Width / (float)this.MaxWidth)), (int)(cursorPos.Y / ((float)this.Viewport.Height / (float)this.MaxHeight)), this._clickedButton, true);
                    OnMouseDownMove(args);
                }
            }
        }
Exemplo n.º 2
0
        protected virtual void OnClick(ViewportEventArgs e)
        {
            var handler = Click;

            if (handler != null)
            {
                if (ParentScreen.Name == Storage.Instance.CurrentScreen.Name)
                {
                    handler(this, e);
                }
            }
        }
Exemplo n.º 3
0
        protected virtual void OnMouseDownMove(ViewportEventArgs e)
        {
            var handler = MouseDownMove;

            handler?.Invoke(this, e);
        }