Exemple #1
0
        public UiElement()
        {
            InputManager.MousePosition.Subscribe(pos =>
            {
                if (DrawRectangle.Contains(pos))
                {
                    IsHovered = true;
                    hover.OnNext(new UiEvent()
                    {
                        Source = this
                    });
                }
                else
                {
                    IsHovered = false;
                }
            });

            InputManager.LeftMouseButtonState.DistinctUntilChanged().Subscribe(mouseEvent =>
            {
                if (DrawRectangle.Contains(mouseEvent.Position))
                {
                    if (mouseEvent.Pressed)
                    {
                        click.OnNext(new UiEvent()
                        {
                            Source = this
                        });
                    }
                }
            });

            font = ContentLoader.GetFont("x32");
        }
Exemple #2
0
        public void Update(float dt)
        {
            MouseState input         = Mouse.GetState();
            Point      mousePosition = new Point(input.X, input.Y);

            if (DrawRectangle.Contains(mousePosition) && input.LeftButton == ButtonState.Pressed)
            {
                Console.WriteLine("clicked");
                // change color of button or text?
            }
        }
 /// <summary>
 /// Computes whether a given screen-space position is contained within this drawable.
 /// Mouse input events are only received when this function is true, or when the drawable
 /// is in focus.
 /// </summary>
 /// <param name="screenSpacePos">The screen space position to be checked against this drawable.</param>
 public virtual bool Contains(Vector2 screenSpacePos) => DrawRectangle.Contains(ToLocalSpace(screenSpacePos));
 public virtual bool Contains(Vector2 screenSpacePos)
 {
     return(DrawRectangle.Contains(GetLocalPosition(screenSpacePos)));
 }