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 virtual void Update(GameTime gameTime, GameInfo gameInfo) { // Update children foreach (GameObject d in _children) { d.Update(gameTime, gameInfo); } // Events if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(GetBoundingBox()) && 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) }); } if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(GetBoundingBox())) { MouseMovedEvent.Invoke(new MouseEventArgs() { MouseState = Mouse.GetState(), Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y) }); } previousMouse = Mouse.GetState(); }
/// <summary> /// Method for grabbing a slice of raw input and triggering an event. /// </summary> /// <param name="gameTime">Current game time.</param> public static void update(GameTime gameTime) { MouseState curMouseState = Mouse.GetState(); KeyboardState curKeyboardState = Keyboard.GetState(); // mouse moved if (curMouseState.X != mouseLastState.X || curMouseState.Y != mouseLastState.Y) { if (MouseMovedEvent != null) { MouseMovedEvent.Invoke(InputManager.The, new MouseEventArgs(curMouseState)); } } // left click if (curMouseState.LeftButton.Equals(ButtonState.Pressed)) { leftClick = ButtonState.Pressed; } else if (leftClick.Equals(ButtonState.Pressed)) { // Left click detected leftClick = ButtonState.Released; if (LeftMouseUpEvent != null) { LeftMouseUpEvent.Invoke(InputManager.The, new MouseEventArgs(curMouseState)); } } // right click if (curMouseState.RightButton.Equals(ButtonState.Pressed)) { rightClick = ButtonState.Pressed; } else if (rightClick.Equals(ButtonState.Pressed)) { // Right click detected rightClick = ButtonState.Released; if (RightMouseUpEvent != null) { RightMouseUpEvent.Invoke(InputManager.The, new MouseEventArgs(curMouseState)); } } // key press DetectKeyStroke(curKeyboardState); mouseLastState = curMouseState; }
void Update() { if (Input.GetMouseButtonUp(0)) { RaiseClickTap(Camera.main.ScreenToWorldPoint(Input.mousePosition)); if (Time.time < lastClickDeltaTime + DoubleTapCatchTime) { RaiseDoubleTap(); } lastClickDeltaTime = Time.time; } if (Input.GetAxis("Mouse X") != 0f) { MouseMovedEvent?.Invoke(Camera.main.ScreenToWorldPoint(Input.mousePosition)); } }
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 Update() { MouseState mouseState = Mouse.GetState(); KeyboardState keyboardState = Keyboard.GetState(); // MouseClick / MousePress handling if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released && keyboardState.IsKeyUp(Keys.LeftShift)) { LeftClickEvent?.Invoke(mouseState.X, mouseState.Y); MouseLeftPressedEvent?.Invoke(mouseState.X, mouseState.Y); } if (lastMouseState.LeftButton == ButtonState.Pressed && mouseState.LeftButton == ButtonState.Released) { MouseLeftReleasedEvent?.Invoke(mouseState.X, mouseState.Y); } // Shift + MouseLeftPress handling if (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released && keyboardState.IsKeyDown(Keys.LeftShift)) { MouseShiftLeftPressedEvent?.Invoke(mouseState.X, mouseState.Y); } if ((lastMouseState.LeftButton == ButtonState.Pressed && mouseState.LeftButton == ButtonState.Released) || keyboardState.IsKeyUp(Keys.LeftShift)) { MouseShiftLeftReleasedEvent?.Invoke(mouseState.X, mouseState.Y); } // MouseMoved handling if (lastMouseState.X != mouseState.X || lastMouseState.Y != mouseState.Y) { MouseMovedEvent?.Invoke(mouseState.X, mouseState.Y); } // MouseScroll Handling if (lastMouseState.ScrollWheelValue > mouseState.ScrollWheelValue) { MouseScrollDown?.Invoke(mouseState.X, mouseState.Y); MouseMovedEvent?.Invoke(mouseState.X, mouseState.Y); } if (lastMouseState.ScrollWheelValue < mouseState.ScrollWheelValue) { MouseScrollUp?.Invoke(mouseState.X, mouseState.Y); MouseMovedEvent?.Invoke(mouseState.X, mouseState.Y); } // G-key tapping if (IsKeyTapped(keyboardState, Keys.G)) { KeyTappedEvent?.Invoke(Keys.G); } // ESC-key tapping if (IsKeyTapped(keyboardState, Keys.Escape)) { KeyTappedEvent?.Invoke(Keys.Escape); } // Delete-key tapping if (IsKeyTapped(keyboardState, Keys.Delete)) { KeyTappedEvent?.Invoke(Keys.Delete); } if (IsKeyTapped(keyboardState, Keys.D)) { KeyTappedEvent.Invoke(Keys.D); } lastMouseState = mouseState; lastKeyboardState = keyboardState; }