public void Redraw(MouseButtons?click) { //CLICK if (Board.ShipsLeftToPlace.Length == 0) //all of the ships have been placed { if (IsPlayer) //show ships and markers { } else //show markers only { } } //MOVE else //not all of the ships have been placed { if (IsPlayer) //show the ship to be placed { if (click == MouseButtons.Right) //change orientation { orientation = orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal; } else if (click == MouseButtons.Left) //place boat { Board.Place(Board.ShipsLeftToPlace[0], x / (picView.Width / 10), y / (picView.Height / 10), orientation); } } } }
public virtual void OnMouseDown(MouseButtons mb) { _mouseButtonsDown = mb; var ev = MouseDown; if (ev != null) { ev(this, new GenericEventArgs <MouseButtons>(mb)); } if ((DateTime.Now - _lastDown).TotalMilliseconds < DoubleClickIntervalInMs) { // Double click OnDoubleClick(mb); var ev2 = DoubleClick; if (ev2 != null) { ev2(this, new GenericEventArgs <MouseButtons>(mb)); } _lastDown = DateTime.MinValue; } else { _lastDown = DateTime.Now; } }
public virtual void MouseDown(MouseControllerEventArgs e) { //flag = 0; Buttonside = e.Button; this.IsMouseDown = true; MoveDir = MovingDirection.None; this.grid.CurrentCell.Deactivate(); this.CurrentBaseRange = this.MouseDownRange = this.Gridmodel.SelectedCells; }
public virtual void OnMouseUp(MouseButtons mb) { _mouseButtonsDown = null; var ev = MouseUp; if (ev != null) { ev(this, new GenericEventArgs <MouseButtons>(mb)); } }
private void KeyboardMouseEvents_MouseDownExt(object sender, MouseEventArgs e) { if (!Settings.Enable || !GameController.Window.IsForeground()) { return; } if (e.Button == MouseButtons.Left) { _mouseButton = null; } }
private void KeyboardMouseEvents_MouseUpExt(object sender, MouseEventArgs e) { if (!Settings.Enable) { return; } if (e.Button == MouseButtons.Left) { _mouseEvent = null; } }
private void KeyboardMouseEvents_MouseUpExt(object sender, MouseEventArgs e) { if (!Settings.Enable || !GameController.Window.IsForeground()) { return; } if (e.Button == MouseButtons.Left) { MousePosition = GameController.Window.ScreenToClient(e.X, e.Y); _mouseButton = e.Button; } }
/// <summary> /// Acquire input from all devices. /// </summary> public void ReadInput() { lastState.CopyInput(currentState); currentState.ReadInput(); if (mouseDragButton == null) { if (currentState.MouseState.LeftButton == ButtonState.Pressed && lastState.MouseState.LeftButton == ButtonState.Pressed) { mouseDragButton = MouseButtons.Left; } else if (currentState.MouseState.RightButton == ButtonState.Pressed && lastState.MouseState.RightButton == ButtonState.Pressed) { mouseDragButton = MouseButtons.Right; } else if (currentState.MouseState.MiddleButton == ButtonState.Pressed && lastState.MouseState.MiddleButton == ButtonState.Pressed) { mouseDragButton = MouseButtons.Middle; } if (mouseDragButton != null) { mouseDragStart.X = lastState.MouseState.X; mouseDragStart.Y = lastState.MouseState.Y; Mouse.SetPosition((int)(mouseDragStart.X), (int)(mouseDragStart.Y)); } } else { if (mouseDragButton == MouseButtons.Left && currentState.MouseState.LeftButton != ButtonState.Pressed || mouseDragButton == MouseButtons.Middle && currentState.MouseState.MiddleButton != ButtonState.Pressed || mouseDragButton == MouseButtons.Right && currentState.MouseState.RightButton != ButtonState.Pressed) { mouseDragButton = null; } else { Mouse.SetPosition((int)(mouseDragStart.X), (int)(mouseDragStart.Y)); } } }
private void KeyboardMouseEvents_MouseDownExt(object sender, MouseEventArgs e) { if (!Settings.Enable) { return; } if (e.Button == MouseButtons.Left) { var position = GameController.Window.ScreenToClient(e.X, e.Y); ; var hitWindow = _rectChaosButton.Contains(position); var hitWindow2 = _rectMoveButton.Contains(position); if (hitWindow || hitWindow2) { MousePosition = GameController.Window.ScreenToClient(e.X, e.Y); _mouseEvent = e.Button; } } }
public static Color?ColorWas(MouseButtons?chk = null) { var t = chk ?? Form.MouseButtons; if (t == MouseButtons.Left) { return(Color.Black); } else if (t == MouseButtons.Right) { return(Color.Gray); } else if (t == MouseButtons.Middle) { return(Color.Yellow); } else { return(null); } }
/// <summary> /// Die Event Methode die aufgerufen wird, wenn das assoziierte Control eine /// MouseDown Notification erhält. /// </summary> /// <param name="e"> /// Die Argumente für den MouseDown Event. /// </param> public void OnMouseDown(MouseEventArgs e) { lastMousePosition = e.Location; currentButton = e.Button; }
public MouseEventArgs(MouseButtons?mouseButton, Vector2?mousePoint) { MouseButton = mouseButton ?? MouseButtons.None; MousePoint = mousePoint; }
/// <summary> /// Create a new input manager /// </summary> public InputManager() { currentState = new InputState(); lastState = new InputState(); mouseDragButton = null; }
/// <summary> /// Updates the state of the mouse. /// </summary> public void Update(GameTime gameTime) { Win32Point point; Win32Methods.GetCursorPos(out point); Win32Methods.ScreenToClient(this.host.Handle, ref point); if (point.X < 0 || point.Y < 0 || point.X >= this.host.DisplayWidth || point.Y >= this.host.DisplayHeight) { this.IsWithinDisplayArea = false; } else { this.IsWithinDisplayArea = true; } this.oldPosition = this.position; this.position = new Point(point.X, point.Y); for (int i = 0; i < ButtonCount; i++) this.oldButtons[i] = this.buttons[i]; this.buttons[(int)MouseButtons.Left] = (Win32Methods.GetAsyncKeyState(Win32Constants.VK_LBUTTON) != 0); this.buttons[(int)MouseButtons.Right] = (Win32Methods.GetAsyncKeyState(Win32Constants.VK_RBUTTON) != 0); this.buttons[(int)MouseButtons.Middle] = (Win32Methods.GetAsyncKeyState(Win32Constants.VK_MBUTTON) != 0); this.buttons[(int)MouseButtons.XButton1] = (Win32Methods.GetAsyncKeyState(Win32Constants.VK_XBUTTON1) != 0); this.buttons[(int)MouseButtons.XButton2] = (Win32Methods.GetAsyncKeyState(Win32Constants.VK_XBUTTON2) != 0); // Double click detection. this.doubleClickedButton = null; if (this.lastClickedButton != null) { this.elapsedSinceClick += gameTime.ElapsedTime; if (this.elapsedSinceClick > this.DoubleClickRate || this.elapsedSinceClick > TimeSpan.FromSeconds(5)) // Give up updating after 5 seconds { this.lastClickedButton = null; } } MouseButtons? clickedButton = null; if (this.IsButtonClicked(MouseButtons.Left)) { clickedButton = MouseButtons.Left; } else if (this.IsButtonClicked(MouseButtons.Right)) { clickedButton = MouseButtons.Right; } else if (this.IsButtonClicked(MouseButtons.Middle)) { clickedButton = MouseButtons.Middle; } else if (this.IsButtonClicked(MouseButtons.XButton1)) { clickedButton = MouseButtons.XButton1; } else if (this.IsButtonClicked(MouseButtons.XButton2)) { clickedButton = MouseButtons.XButton2; } if (clickedButton != null) { if (clickedButton.Value == this.lastClickedButton) { if (this.elapsedSinceClick <= this.DoubleClickRate) { this.doubleClickedButton = clickedButton; this.lastClickedButton = null; this.elapsedSinceClick = TimeSpan.Zero; } } else { this.lastClickedButton = clickedButton; this.elapsedSinceClick = TimeSpan.Zero; } } }
void Element_MouseDown(object sender, HtmlElementEventArgs e) { DateTime clickTime = DateTime.UtcNow; //TraceHlp2.AddMessage("div mouseDown @ {0}.{1}", clickTime, clickTime.Millisecond); e.BubbleEvent = false; HtmlElement div = (HtmlElement)sender; div.Style += "visibility:hidden;"; HtmlElement to = browser.Document.GetElementFromPoint(e.ClientMousePosition); div.Style += "visibility:visible;"; try { //Hack - не знаю как напрямую передать в обработчик события ButtonPressed = e.MouseButtonsPressed; to.RaiseEvent("onMouseDown"); } finally { ButtonPressed = null; } }
public void Redraw(MouseButtons?click) { //CLICK if (board != null) { Bitmap bmp = new Bitmap(picView.Width, picView.Height); Graphics g = Graphics.FromImage(bmp); Cell[,] cells = board.Cells; int width = picView.Width / board.Rows, height = picView.Height / board.Columns, column = x / width, row = y / height; for (int i = 0; i < board.Rows; i++) { for (int j = 0; j < board.Columns; j++) { Brush fill = Brushes.Yellow; if (Player == Player.Human && cells[i, j] == Cell.Ship) { fill = Brushes.Gray; } else if (Player == Player.Computer && cells[i, j] == Cell.Ship) { fill = Brushes.Blue; } else { if (cells[i, j] == Cell.Hit) { fill = Brushes.Red; } else if (cells[i, j] == Cell.Miss) { fill = Brushes.White; } else if (cells[i, j] == Cell.Water) { fill = Brushes.Blue; } } g.FillRectangle(fill, j * width, i * height, width, height); g.DrawRectangle(Pens.Black, j * width, i * height, width, height); } } picView.Image = bmp; if (board.ShipsLeftToPlace.Length == 0) //all of the ships have been placed { if (Player == Player.Computer && click == MouseButtons.Left) { if (Game.Fire(row, column) && ShotFired != null) { ShotFired(this, EventArgs.Empty); } } } //MOVE else //not all of the ships have been placed { if (Player == Player.Human) //show the ship to be placed { IShip ship = board.ShipsLeftToPlace[0]; if (click == MouseButtons.Right) //change orientation { orientation = orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal; } else if (click == MouseButtons.Left) //place boat { board.Place(board.ShipsLeftToPlace[0], row, column, orientation); if (board.ShipsLeftToPlace.Length == 0 && AllShipsPlaced != null) { AllShipsPlaced(this, EventArgs.Empty); } } if (board.ShipFits(ship, row, column, orientation)) { for (int i = 0; i < ship.Size; i++) { g.FillRectangle(Brushes.Gray, ((orientation == Orientation.Horizontal ? i : 0) + column) * width, ((orientation == Orientation.Vertical ? i : 0) + row) * height, width, height); g.DrawRectangle(Pens.Black, ((orientation == Orientation.Horizontal ? i : 0) + column) * width, ((orientation == Orientation.Vertical ? i : 0) + row) * height, width, height); } } } } } }
public override void Render() { try { _ingameState = GameController.Game.IngameState; if (!_ingameState.IngameUi.InventoryPanel.IsVisible) { return; } _inventory = _ingameState.IngameUi.InventoryPanel[InventoryIndex.PlayerInventory]; _inventoryZone = _inventory.InventoryUiElement.GetClientRect(); if (!_holdKey && WinApi.IsKeyDown(Settings.MoveKey.Value)) { _holdKey = true; if (_moveThread == null || !_moveThread.IsAlive) { _moveThread = _ingameState.IngameUi.OpenLeftPanel.IsVisible ? new Thread(ScanInventory) : new Thread(SellItems); _moveThread.Start(); Thread.Sleep(200); } else if (_run && _moveThread != null && _moveThread.IsAlive) { _run = false; LogMessage("Stop!", 3); Thread.Sleep(200); } } else if (_holdKey && !WinApi.IsKeyDown(Settings.MoveKey.Value)) { _holdKey = false; } if (!_holdKey && WinApi.IsKeyDown(Settings.ChaosKey.Value)) { _holdKey = true; if (_moveThread == null || !_moveThread.IsAlive) { _moveThread = new Thread(ChaosRecipe); _moveThread.Start(); Thread.Sleep(200); } else if (_run && _moveThread != null && _moveThread.IsAlive) { _run = false; LogMessage("Stop!", 3); Thread.Sleep(200); } } else if (_holdKey && !WinApi.IsKeyDown(Settings.ChaosKey.Value)) { _holdKey = false; } if (Settings.ShowButtons.Value) { var invPoint = _inventoryZone; float wCell = invPoint.Width / 12 * 2; float hCell = invPoint.Height / 5; _rectMoveButton = new RectangleF(_inventoryZone.X, _inventoryZone.Y - hCell, wCell, hCell * 0.7f); var invItem = _ingameState.UIHover.AsObject <NormalInventoryItem>(); if (_ingameState.IngameUi.InventoryPanel.IsVisible && (invItem.Item == null || !invItem.Item.IsValid) || _run) { #region MoveButton Utils.DrawButton(_rectMoveButton, 1, new Color(55, 21, 0), Color.DarkGoldenrod); if (_rectMoveButton.Contains(MousePosition) && _mouseButton == MouseButtons.Left) { _mouseButton = null; if (_moveThread == null || !_moveThread.IsAlive) { _moveThread = _ingameState.IngameUi.OpenLeftPanel.IsVisible ? new Thread(ScanInventory) : new Thread(SellItems); _moveThread.Start(); Thread.Sleep(65); } else if (_run && _moveThread != null && _moveThread.IsAlive) { _run = false; LogMessage("Stop!", 3); Thread.Sleep(200); } } if (_moveThread == null || !_moveThread.IsAlive) { if (_ingameState.IngameUi.InventoryPanel.IsVisible && !_ingameState.IngameUi.OpenLeftPanel.IsVisible) { Graphics.DrawText("<-Sell", 18, _rectMoveButton.Center, Color.DarkGoldenrod, FontDrawFlags.VerticalCenter | FontDrawFlags.Center); } else if (_ingameState.IngameUi.InventoryPanel.IsVisible && _ingameState.IngameUi.OpenLeftPanel.IsVisible) { Graphics.DrawText("<-Move", 18, _rectMoveButton.Center, Color.DarkGoldenrod, FontDrawFlags.VerticalCenter | FontDrawFlags.Center); } } else if (_run && _moveThread != null && _moveThread.IsAlive) { Graphics.DrawText("work...", 18, _rectMoveButton.Center, Color.DarkGoldenrod, FontDrawFlags.VerticalCenter | FontDrawFlags.Center); } #endregion #region ChaosButton if (_ingameState.IngameUi.OpenLeftPanel.IsVisible) { _rectChaosButton = _rectMoveButton; _rectChaosButton.Y = _rectMoveButton.Y - (_rectMoveButton.Height + 10); Utils.DrawButton(_rectChaosButton, 1, new Color(55, 21, 0), Color.DarkGoldenrod); if (_rectChaosButton.Contains(MousePosition) && _mouseButton == MouseButtons.Left) { _mouseButton = null; if (_moveThread == null || !_moveThread.IsAlive) { _moveThread = new Thread(ChaosRecipe); _moveThread.Start(); Thread.Sleep(65); } else if (_run && _moveThread != null && _moveThread.IsAlive) { _run = false; LogMessage("Stop!", 3); Thread.Sleep(200); } } if (_moveThread == null || !_moveThread.IsAlive) { if (_ingameState.IngameUi.InventoryPanel.IsVisible && _ingameState.IngameUi.OpenLeftPanel.IsVisible) { Graphics.DrawText("Set->", 18, _rectChaosButton.Center, Color.DarkGoldenrod, FontDrawFlags.VerticalCenter | FontDrawFlags.Center); } } else if (_run && _moveThread != null && _moveThread.IsAlive) { Graphics.DrawText("work...", 18, _rectChaosButton.Center, Color.DarkGoldenrod, FontDrawFlags.VerticalCenter | FontDrawFlags.Center); } } #endregion } } } catch (Exception e) { Log(e.Message); Log(e.Source); throw; } }
/// <summary> /// Die Event Methode die aufgerufen wird, wenn das assoziierte Control eine /// MouseUp Notification erhält. /// </summary> /// <param name="e"> /// Die Argumente für den MouseUp Event. /// </param> public void OnMouseUp(MouseEventArgs e) { currentButton = null; }
private void UpdateMouse(TimeSpan deltaTime) { // ----- Update mouse states. _previousMouseState = _newMouseState; _newMouseState = Mouse.GetState(); MousePosition = MousePositionRaw; MousePositionDelta = MousePositionDeltaRaw; // ----- Find pressed mouse button. MouseButtons? pressedMouseButton = null; foreach (MouseButtons button in _mouseButtons) { if (IsDown(ref _newMouseState, button) && IsUp(ref _previousMouseState, button)) { pressedMouseButton = button; break; } } // ----- Handle mouse button double clicks and button repetition. _lastMouseButton.IsDoubleClick = false; _lastMouseButton.IsVirtualPress = false; if (!pressedMouseButton.HasValue) { // No mouse button pressed. // Increase or reset down duration. if (IsDown(_lastMouseButton.Button)) { // Previously pressed mouse button is still down. // Increase down duration. _lastMouseButton.DownDuration += deltaTime; // If the start interval is exceeded, we generate a virtual button press. if (_lastMouseButton.DownDuration >= Settings.RepetitionDelay) { // Generate virtual button press. _lastMouseButton.IsVirtualPress = true; // Subtract repetition interval from down duration. This way the repetition interval // must pass until the if condition is true again. _lastMouseButton.DownDuration -= Settings.RepetitionInterval; } } else { // Reset down duration. _lastMouseButton.DownDuration = TimeSpan.Zero; } // Measure time between clicks. if (_lastMouseButton.TimeSinceLastClick != TimeSpan.MaxValue) _lastMouseButton.TimeSinceLastClick += deltaTime; } else { // Mouse button was pressed. // Check for double-click. if (pressedMouseButton == _lastMouseButton.Button && _lastMouseButton.TimeSinceLastClick < Settings.DoubleClickTime - deltaTime && Vector2F.Absolute(_lastMouseButton.MouseClickPosition - MousePosition) < Settings.DoubleClickSize) { // Double-click detected. _lastMouseButton.IsDoubleClick = true; // The current click cannot be used for another double-click. _lastMouseButton.TimeSinceLastClick = TimeSpan.MaxValue; } else { // Wrong button pressed or button pressed too late. // Restart double-click logic. _lastMouseButton.TimeSinceLastClick = TimeSpan.Zero; } _lastMouseButton.Button = pressedMouseButton.Value; _lastMouseButton.DownDuration = TimeSpan.Zero; _lastMouseButton.MouseClickPosition = MousePosition; } // ----- Reset mouse position if mouse-centering is enabled. if (EnableMouseCentering) if (GlobalSettings.PlatformID != PlatformID.WindowsPhone7 && GlobalSettings.PlatformID != PlatformID.WindowsPhone8 && GlobalSettings.PlatformID != PlatformID.Android && GlobalSettings.PlatformID != PlatformID.iOS) Mouse.SetPosition((int)Settings.MouseCenter.X, (int)Settings.MouseCenter.Y); }
/// <summary> /// Resets double click tracking for the mouse. /// </summary> public void ResetDoubleClick() { this.doubleClickedButton = null; this.lastClickedButton = null; this.elapsedSinceClick = TimeSpan.Zero; }