public virtual void StopDrag(Point point) { if (IsBeingDragged) { DragAction?.Invoke(false, point, this); DragElement = null; DragPosition = null; TempDragPoint = null; } }
public virtual void PerformClick(Point point, bool right, bool release, bool hold) { if (OutOfBounds || Disabled) { return; } if ((ClickAction != null || IsSelectable) && Bounds.Contains(point)) { if (IsSelectable && !right && release) { if (IsSelected) { Deselect(); } else { Select(); } } if (IsDraggable && !right && hold && DragElement == null && DragAction != null && DragAction.Invoke(true, point, this) && !IsBeingDragged) { DragElement = this; DragPosition = null; TempDragPoint = null; if (DragPoint == Vector2.Zero) { var b = Bounds; TempDragPoint = new Point(point.X - b.X, point.Y - b.Y); } PerformMouseMove(point); } if (IsBeingDragged && release && DragAction != null && DragAction.Invoke(false, point, this)) { DragPosition = null; DragElement = null; TempDragPoint = null; } ClickAction?.Invoke(point, right, release, hold, this); } foreach (UIElement child in Children.Where(c => c.Visible)) { try { child.PerformClick(point, right, release, hold); } catch { } } }
/// <summary> /// Handle dragging the mouse within the game world. /// </summary> /// <param name="onStart">The method to be executed when mouse button is clicked first. Gets the mouse position as argument.</param> /// <param name="onDrag">The method to be executed when the mouse button remains clicked. Gets the mouse position as argument.</param> /// <param name="onStop">The method to be executed when the mouse button is released. Gets the mouse position as argument.</param> private void HandleWorldDrag(DragAction onStart, DragAction onDrag, DragAction onStop) { bool dragStart = Input.GetMouseButtonDown(0); bool dragContinued = Input.GetMouseButton(0); bool dragStopped = Input.GetMouseButtonUp(0); if (dragStart) { onStart.Invoke(Input.mousePosition); } if (dragContinued) { onDrag.Invoke(Input.mousePosition); } if (dragStopped) { onStop.Invoke(Input.mousePosition); } }