public void WPFMouseMove(MouseEventArgs e) { if (new Rectangle((int)e.GetPosition(MainWindow.mainWindow.Viewport).X, (int)e.GetPosition(MainWindow.mainWindow.Viewport).Y, 1, 1).Intersects(GetBoundingBox())) { MouseMovedEvent.Invoke(e); currentHover = true; hovered = true; } else { currentHover = false; hovered = false; } if (!previousHover && currentHover) { MouseEnterEvent.Invoke(e); } if (previousHover && !currentHover) { MouseLeaveEvent.Invoke(e); } previousHover = currentHover; }
public void OnPointerEnter(PointerEventData eventData) { OnMouseEnterEvent.Invoke(this.gameObject); }
void OnMouseEnter() { MouseEnterEvent?.Invoke(this.cell); }
public virtual void Update(GameTime gameTime, GameInfo info) { // Alignment if (Parent != null) { switch (HorizontalAlignment) { case EnumHorizontalAlignment.CENTER: Position.X = (Parent.Width / 2) - Width / 2; break; case EnumHorizontalAlignment.LEFT: Position.X = 0; break; case EnumHorizontalAlignment.RIGHT: Position.X = (Parent.Width) - Width; break; default: break; } switch (VerticalAlignment) { case EnumVerticalAlignment.CENTER: Position.Y = (Parent.Height / 2) - Height / 2; break; case EnumVerticalAlignment.TOP: Position.Y = 0; break; case EnumVerticalAlignment.BOTTOM: Position.Y = Parent.Height - Height; break; default: break; } } // Filling if (FillParent) { Position = new Vector2(0, 0); if (Parent != null) { Width = Parent.Width; Height = Parent.Height; } else { Width = (int)info.Resolution.X; Height = (int)info.Resolution.Y; } } // Events Rectangle RenderBox = GetBoundingBox(); if (info.guiManager.UseVirtualSize) { float scaleX = (float)info.graphicsDevice.PresentationParameters.BackBufferWidth / (float)info.guiManager.VirtualViewWidth; float scaleY = (float)info.graphicsDevice.PresentationParameters.BackBufferHeight / (float)info.guiManager.VirtualViewHeight; RenderBox = new Rectangle((int)((float)GetBoundingBox().X *scaleX), (int)((float)GetBoundingBox().Y *scaleY), (int)((float)GetBoundingBox().Width *scaleX), (int)((float)GetBoundingBox().Height *scaleY)); } if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(RenderBox) && Mouse.GetState().LeftButton == ButtonState.Pressed && _previousMouse.LeftButton == ButtonState.Released) { MouseClickedEvent.Invoke(new MouseEventArgs() { MouseState = Mouse.GetState(), Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y), gameInfo = info }); } if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(RenderBox) && Mouse.GetState().LeftButton == ButtonState.Released && _previousMouse.LeftButton == ButtonState.Pressed) { MouseReleasedEvent.Invoke(new MouseEventArgs() { MouseState = Mouse.GetState(), Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y), gameInfo = info }); } if (Mouse.GetState().Position != _previousMouse.Position) { MouseMovedEvent.Invoke(new MouseEventArgs() { MouseState = Mouse.GetState(), Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y), gameInfo = info }); } if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(RenderBox) && !new Rectangle(_previousMouse.X, _previousMouse.Y, 1, 1).Intersects(RenderBox)) { MouseEnterEvent.Invoke(new MouseEventArgs() { MouseState = Mouse.GetState(), Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y), gameInfo = info }); } if (!new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(RenderBox) && new Rectangle(_previousMouse.X, _previousMouse.Y, 1, 1).Intersects(RenderBox)) { MouseLeaveEvent.Invoke(new MouseEventArgs() { MouseState = Mouse.GetState(), Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y), gameInfo = info }); } if (Parent != null && Parent.Position != null) { RenderPosition = Position + Parent.RenderPosition; } else { RenderPosition = Position; } foreach (UIElement element in _Children) { element.Update(gameTime, info); } _previousMouse = Mouse.GetState(); }
public void RaiseMouseEnter() { MouseEnterEvent?.Invoke(this); }