private void MouseMoved(object sender, MouseMoveEventArgs args) { GetBorders(out int x1, out int y1, out int x2, out int y2); bool mouseMove = (_mouseX != (_mouseX = (int)((Mouse.X - x1) / ScaleX))) | (_mouseY != (_mouseY = (int)((Mouse.Y - y1) / ScaleY))); if (!mouseMove) { return; } MouseState mouse = Mouse.GetState(); CButton buttons = CButton.None; if (mouse.IsButtonDown(MouseButton.Left)) { buttons |= CButton.Left; } if (mouse.IsButtonDown(MouseButton.Right)) { buttons |= CButton.Right; } _runtime.InvokeMouseMove(new ScreenEventArgs(_mouseX, _mouseY, buttons)); }
protected override void OnUpdateFrame(FrameEventArgs e) { KeyboardState input = Keyboard.GetState(); game.UpdateFPS(this.RenderFrequency); //Console.WriteLine(graphics.fps); MouseState mouseState = Mouse.GetCursorState(); CheckKey(input); Point cPoint = this.PointToClient(new Point(mouseState.X, mouseState.Y)); if (this.Focused) { game.UpdateMousePoint(cPoint.X, cPoint.Y, mouseState.IsButtonDown(MouseButton.Left), mouseState.IsButtonDown(MouseButton.Middle), mouseState.IsButtonDown(MouseButton.Right)); } game.Update(); game.CleanUp(); if (input.IsKeyDown(Key.Escape) || game.DoQuit() || game.DoReload()) { Exit(); } base.OnUpdateFrame(e); }
public static bool LeftMouseButtonDown() { if (!foc) { return(false); } lock (msLocker) { return(msState.IsButtonDown(MouseButton.Left)); } }
public bool WasButtonPressed(MouseButtons button) { if (!_game.IsActive) { return(false); } return(_lastMouseState.IsButtonUp(button) && _currentMouseState.IsButtonDown(button)); }
public static bool GetMouseButtonDown(MouseButton button) { if (mouseState.IsButtonDown(button) && !mouseInput[(int)button].pressed) { mouseInput[(int)button].pressed = true; pressedButtons.Add((int)button); } return(mouseInput[(int)button].pressed && !mouseInput[(int)button].held); }
/// <override></override> public override bool ProcessMouseEvent(IDiagramPresenter diagramPresenter, MouseEventArgsDg e) { if (diagramPresenter == null) { throw new ArgumentNullException("diagramPresenter"); } bool result = false; MouseState newMouseState = MouseState.Empty; newMouseState.Buttons = e.Buttons; newMouseState.Modifiers = e.Modifiers; diagramPresenter.ControlToDiagram(e.Position, out newMouseState.Position); diagramPresenter.SuspendUpdate(); try { switch (e.EventType) { case MouseEventType.MouseDown: timer.Stop(); break; case MouseEventType.MouseMove: if (CurrentMouseState.Position != newMouseState.Position) { if (newMouseState.IsButtonDown(MouseButtonsDg.Left) && diagramPresenter.Project.SecurityManager.IsGranted(Permission.Insert)) { diagramPresenter.ControlToDiagram(e.Position, out p); currentStroke.Add(p.X, p.Y); } diagramPresenter.SetCursor(penCursorId); } Invalidate(diagramPresenter); break; case MouseEventType.MouseUp: if (newMouseState.IsButtonDown(MouseButtonsDg.Left) && diagramPresenter.Project.SecurityManager.IsGranted(Permission.Insert)) { StartToolAction(diagramPresenter, 0, newMouseState, false); strokeSet.Add(currentStroke); currentStroke = new Stroke(); timer.Start(); } break; default: throw new NShapeUnsupportedValueException(e.EventType); } } finally { diagramPresenter.ResumeUpdate(); } base.ProcessMouseEvent(diagramPresenter, e); return(result); }
public static bool GetMouseDown(MouseButton button) { if (!Engine.MainWindow.IsFocused) { return(false); } if (!mouseState.WasButtonDown(button) && mouseState.IsButtonDown(button)) { return(true); } return(false); }
public bool SatisfiesCondition(KeyboardState prevkb, MouseState prevMb, KeyboardState kb, MouseState mb) { var pressed = kb.GetPressedKeys(); var isctrl = ((int)modifiers & (int)Modifiers.Ctrl) == (int)Modifiers.Ctrl; var isshift = ((int)modifiers & (int)Modifiers.Shift) == (int)Modifiers.Shift; var isalt = ((int)modifiers & (int)Modifiers.Alt) == (int)Modifiers.Alt; if (isctrl) { if (!pressed.Contains(Keys.LeftControl) && !pressed.Contains(Keys.RightControl)) { return(false); } } if (isshift) { if (!pressed.Contains(Keys.LeftShift) && !pressed.Contains(Keys.RightShift)) { return(false); } } if (isalt) { if (!pressed.Contains(Keys.LeftAlt) && !pressed.Contains(Keys.RightAlt)) { return(false); } } switch (type) { case InputBindingType.Pressed: return(mb.IsButtonDown(button) && !prevMb.IsButtonDown(button)); case InputBindingType.Released: return(!mb.IsButtonDown(button) && prevMb.IsButtonDown(button)); case InputBindingType.Held: return(mb.IsButtonDown(button) && prevMb.IsButtonDown(button)); case InputBindingType.StateChanged: return(mb.X != prevMb.X || mb.Y != prevMb.Y); case InputBindingType.None: return(true); default: return(false); } }
public InputState State(Layer.Input.MouseButton button) { if (_nativeMouse.IsButtonDown((OpenTK.Windowing.GraphicsLibraryFramework.MouseButton)button)) { if (_nativeMouse.WasButtonDown((OpenTK.Windowing.GraphicsLibraryFramework.MouseButton)button)) { return(InputState.Repeat); } return(InputState.Press); } return(InputState.Release); }
public bool this[MouseButton mb] { get { return(state.IsButtonDown(mb)); } }
private void checkmouse() { MouseState mstate = Mouse.GetState(); Vector2 CurrentMousePosition = new Vector2(mstate.X, mstate.Y); if (mstate.IsButtonDown(MouseButton.Left) && mic) { Vector2 delta = CurrentMousePosition - PreviousMousePosition; cam.AddRotation(-delta.X, -delta.Y); Rectangle glControlScreenRect = lakiToolGLControl1.RectangleToScreen(lakiToolGLControl1.ClientRectangle); if (Cursor.Position.X < glControlScreenRect.Left) { Cursor.Position = new Point(glControlScreenRect.Right, Cursor.Position.Y); } else if (Cursor.Position.X > glControlScreenRect.Right) { Cursor.Position = new Point(glControlScreenRect.Left, Cursor.Position.Y); } if (Cursor.Position.Y < glControlScreenRect.Top) { Cursor.Position = new Point(Cursor.Position.X, glControlScreenRect.Bottom); } else if (Cursor.Position.Y > glControlScreenRect.Bottom) { Cursor.Position = new Point(Cursor.Position.X, glControlScreenRect.Top); } } PreviousMousePosition = CurrentMousePosition; }
internal override void Update(Vector2 a_resolution) { if (m_focused) { MouseState mouseState = Mouse.GetState(); if (mouseState.IsButtonDown(MouseButton.Left)) { Vector2 cursorPos = Input.GetCursorPosition(); Vector2 pos = (TruePosition + a_resolution) / 2; Vector2 size = TrueSize; Vector2 halfSize = size / 2; if (cursorPos.X < pos.X - halfSize.X || cursorPos.Y < pos.Y - halfSize.Y && cursorPos.X > pos.X + halfSize.X || cursorPos.Y > pos.Y + halfSize.Y) { m_focused = false; } } if (Input.IsKeyPressed(Key.BackSpace) && Text.Length != 0) { Text = Text.Substring(0, Text.Length - 1); } } }
public void SetMouse(MouseState mouse) { MouseDown = mouse.IsButtonDown(MouseButton.Left); var currPos = new Vector2(mouse.X, mouse.Y); MouseDiff = MousePos - currPos; MousePos = currPos; }
public static MouseButton[] GetDownButtons() { if (!AcceptKeyboard) { return(new MouseButton[0]); } List <MouseButton> list = new List <MouseButton>(); for (var i = 0; i < (int)MouseButton.LastButton; i++) { if (mouse.IsButtonDown((MouseButton)i)) { list.Add((MouseButton)i); } } return(list.ToArray()); }
private void HandleMouse(GameTime gameTime) { MouseState state = Mouse.GetCursorState(); if (state.IsButtonDown(MouseButton.Left)) { if (!_hasFirstClicked) { _hasFirstClicked = true; _mouseStartState = state; } if (state != _mouseStartState) { float diffX = state.Y - _mouseStartState.Y; float diffY = state.X - _mouseStartState.X; if (Math.Abs(diffX) > MAX_REST_DIFF) { _velocity.X = diffX * 0.5f; } if (Math.Abs(diffY) > MAX_REST_DIFF) { _velocity.Y = diffY * 0.5f; } } } if (state.Wheel != _lastWheelValue) { var change = _wheelChange + state.Wheel - _lastWheelValue; _lastWheelValue = state.Wheel; if (Math.Abs(change) >= _maxWheelValue) { return; } _wheelChange = change; float addWheelValue = 1.0f; if (_wheelChange > 0) { addWheelValue -= Math.Min(1.0f, _wheelChange / _maxWheelValue); } else if (_wheelChange < 0) { addWheelValue -= Math.Max(-1.0f, _wheelChange / _maxWheelValue); } _wheelPower = addWheelValue; } }
public bool MouseCheck(MouseButtons buttons) { switch (buttons) { case MouseButtons.WheelDown: return(_mouseCurrent.ScrollWheelValue > _mousePrevious.ScrollWheelValue); case MouseButtons.WheelUp: return(_mouseCurrent.ScrollWheelValue < _mousePrevious.ScrollWheelValue); case MouseButtons.WheelLeft: return(_mouseCurrent.HorizontalScrollWheelValue < _mousePrevious.HorizontalScrollWheelValue); case MouseButtons.WheelRight: return(_mouseCurrent.HorizontalScrollWheelValue > _mousePrevious.HorizontalScrollWheelValue); default: return(_mouseCurrent.IsButtonDown(buttons)); } }
protected override void OnMouseMove(MouseMoveEventArgs e) { base.OnMouseMove(e); if (MouseState.IsButtonDown(MouseButton.Button2)) { CameraPitch -= e.DeltaY * 0.005f; CameraPitch = Math.Clamp(CameraPitch, -MathHelper.PiOver2, MathHelper.PiOver2); CameraYaw += e.DeltaX * 0.005f; ActiveCamera.Rotation = Quaternion.FromAxisAngle(Vector3.UnitY, CameraYaw) * Quaternion.FromAxisAngle(Vector3.UnitX, CameraPitch); } }
public bool isClickedRising(MouseButton b) { if (Game.window.Focused) { return(currentMouseState.IsButtonDown(b) && lastMouseState.IsButtonUp(b)); } else { return(false); } }
public static void Update() { #region Keyboard Input keyboardState = Keyboard.GetState(); bool keysReleased = false; for (int i = 0; i < pressedKeys.Count; i++) { if (keyboardState.IsKeyDown((Key)pressedKeys[i])) { keyboardInput[pressedKeys[i]].held = true; } else { keyboardInput[pressedKeys[i]].pressed = false; keyboardInput[pressedKeys[i]].held = false; pressedKeys[i] = -1; keysReleased = true; } } if (keysReleased) { pressedKeys.RemoveAll(x => x == -1); keysReleased = false; } #endregion #region Mouse Input mouseState = Mouse.GetState(); bool buttonsReleased = false; for (int i = 0; i < pressedButtons.Count; i++) { if (mouseState.IsButtonDown((MouseButton)pressedButtons[i])) { mouseInput[pressedButtons[i]].held = true; } else { mouseInput[pressedButtons[i]].pressed = false; mouseInput[pressedButtons[i]].held = false; pressedButtons[i] = -1; buttonsReleased = true; } } if (buttonsReleased) { pressedButtons.RemoveAll(x => x == -1); buttonsReleased = false; } var mousePos = new Vector2(mouseState.X, mouseState.Y); MouseDelta = mousePos - lastMousePos; lastMousePos = mousePos; #endregion }
/// <summary> /// Update the AngleAroundPlayer of the Camera from the previous frame. /// </summary> private void UpdateAngleAroundPlayer() { MouseState mouse = Mouse.GetState(); float mouseXCurrentPosition = mouse.X; if (mouse.IsButtonDown(MouseButton.Right)) { float mouseXDeltaPosition = mouseXCurrentPosition - MouseXPreviousPosition; float angleChange = mouseXDeltaPosition * 0.001f; AngleAroundPlayer -= angleChange; } MouseXPreviousPosition = mouseXCurrentPosition; }
public void MouseUpdate() { KeyboardState keybState = Keyboard.GetState(); MouseState mouseState = Mouse.GetState(); Vector2 mousePos = new Vector2(mouseState.X, mouseState.Y); Vector2 delta = (refMousePos - mousePos); if (keybState.IsKeyDown(Key.LShift) && mouseState.IsButtonDown(MouseButton.Middle)) { orientation.AddDelta(delta.X, delta.Y); } else if (keybState.IsKeyDown(Key.LShift) && mouseState.IsButtonDown(MouseButton.Left) && mouseState.IsButtonDown(MouseButton.Right)) { position.Current = new Vector3(0f); position.Reference = new Vector3(0f); } else if (mouseState.IsButtonDown(MouseButton.Left)) { delta *= zoom; position.AddDelta(delta.X, delta.Y); } }
/// <summary> /// Update the Pitch of the Camera from the previous frame. /// </summary> private void UpdatePitch() { MouseState mouse = Mouse.GetState(); float mouseYCurrentPosition = mouse.Y; if (mouse.IsButtonDown(MouseButton.Right)) { float mouseYDeltaPosition = mouseYCurrentPosition - MouseYPreviousPosition; float pitchChange = mouseYDeltaPosition * 0.001f; Pitch += pitchChange; } MouseYPreviousPosition = mouseYCurrentPosition; }
public bool MouseCheckReleased(MouseButtons buttons) { switch (buttons) { case MouseButtons.WheelDown: case MouseButtons.WheelUp: case MouseButtons.WheelLeft: case MouseButtons.WheelRight: return(false); default: return(_mouseCurrent.IsButtonUp(buttons) && _mousePrevious.IsButtonDown(buttons)); } }
private void UpdateImGuiInput() { ImGuiIOPtr io = ImGui.GetIO(); MouseState MouseState = Window.MouseState; KeyboardState KeyboardState = Window.KeyboardState; io.MouseDown[0] = MouseState.IsButtonDown(MouseButton.Left); io.MouseDown[1] = MouseState.IsButtonDown(MouseButton.Right); io.MouseDown[2] = MouseState.IsButtonDown(MouseButton.Middle); var point = new Vector2i((int)MouseState.X, (int)MouseState.Y); // TODO: check io.MousePos = new System.Numerics.Vector2(point.X, point.Y); io.MouseWheel = MouseScroll.Y; io.MouseWheelH = MouseScroll.X; MouseScroll = Vector2.Zero; foreach (Key key in Enum.GetValues(typeof(Key))) { if (key != Key.Unknown) { io.KeysDown[(int)key] = KeyboardState.IsKeyDown(key); } } foreach (var c in PressedChars) { io.AddInputCharacter(c); } PressedChars.Clear(); io.KeyCtrl = KeyboardState.IsKeyDown(Key.ControlLeft) || KeyboardState.IsKeyDown(Key.ControlRight); io.KeyAlt = KeyboardState.IsKeyDown(Key.AltLeft) || KeyboardState.IsKeyDown(Key.AltRight); io.KeyShift = KeyboardState.IsKeyDown(Key.ShiftLeft) || KeyboardState.IsKeyDown(Key.ShiftRight); io.KeySuper = KeyboardState.IsKeyDown(Key.WinLeft) || KeyboardState.IsKeyDown(Key.WinRight); }
private void UpdateImGuiInput() { ImGuiIOPtr io = ImGui.GetIO(); MouseState MouseState = Engine.MainWindow.MouseState; KeyboardState KeyboardState = Engine.MainWindow.KeyboardState; io.MouseDown[0] = MouseState.IsButtonDown(MouseButton.Left); io.MouseDown[1] = MouseState.IsButtonDown(MouseButton.Right); io.MouseDown[2] = MouseState.IsButtonDown(MouseButton.Middle); var point = MouseState.Position; io.MousePos = new Vector2(point.X, point.Y); io.MouseWheel = MouseState.ScrollDelta.Y; io.MouseWheelH = MouseState.ScrollDelta.X; foreach (Keys key in Enum.GetValues(typeof(Keys))) { if (key != Keys.Unknown) { io.KeysDown[(int)key] = KeyboardState.IsKeyDown(key); } } foreach (var c in PressedChars) { io.AddInputCharacter(c); } PressedChars.Clear(); io.KeyCtrl = KeyboardState.IsKeyDown(Keys.LeftControl) || KeyboardState.IsKeyDown(Keys.RightControl); io.KeyAlt = KeyboardState.IsKeyDown(Keys.LeftAlt) || KeyboardState.IsKeyDown(Keys.RightAlt); io.KeyShift = KeyboardState.IsKeyDown(Keys.LeftShift) || KeyboardState.IsKeyDown(Keys.RightShift); io.KeySuper = KeyboardState.IsKeyDown(Keys.LeftSuper) || KeyboardState.IsKeyDown(Keys.RightSuper); }
void HandleKeyboard() { var keyState = Keyboard.GetState(); if (keyState.IsKeyDown(Key.Escape)) { m_mainWindow.Exit(); } MouseState mouseState = Mouse.GetState(); if (mouseState.IsButtonDown(MouseButton.Left)) { //Console.WriteLine("mouse left btn down"); } }
public override void ManageInput(KeyboardState keyboardState, MouseState mouseState, float mouseWheelDelta, Point mousePosition) { if (keyboardState.IsKeyDown(Key.Space)) { begin = true; } if (keyboardState.IsKeyDown(Key.BackSpace)) { Reset(); } if (mouseState.IsButtonDown(MouseButton.Left) && mousePosition != null) { Vector3 mousePositionCartesianCoordinates = GetMousePositionCartesianCoordinates(GetMousePositionUnitCoordinates(mousePosition)); CreateNode(loader, mousePositionCartesianCoordinates, new Vector3(0, 1, 0)); } }
private static void DrawNode(SpriteBatch spriteBatch, Node node, int startX, ref int startY) { if (startY > JackApp.WindowHeight) { // note: maybe add some scroll instead of stopping drawing return; } Rectangle textBounds = _font.GetBounds(node.Name); Rectangle rectangle = new Rectangle( // note: multiply with scale startX - 10, startY - 20, textBounds.Width, textBounds.Height ); bool hovered = rectangle.Includes(Input.MousePosition); if (hovered && _focusedNode != node) { MouseState ms = Mouse.GetState(); if (ms.IsButtonDown(MouseButton.Left)) { _focusedNode = node; } } spriteBatch.DrawString(node.Name, new Vector2(startX, startY), new Vector2(2.0f), hovered ? _accentColor : Color.White, _font); if (node.Children != null) { for (int i = 0; i < node.Children.Count; i++) { spriteBatch.DrawLine( new Vector2(startX, startY + _yStep), new Vector2(startX, startY + _yStep / 2), 2, Color.DeepPink ); int sx = startX + _xStep; startY += _yStep; spriteBatch.DrawLine( new Vector2(startX, startY), new Vector2(startX + _xStep - 15, startY), 2, Color.DeepPink ); DrawNode(spriteBatch, node.Children[i], sx, ref startY); } } }
public bool test(KeyboardState ks, MouseState ms) { if (!isMouse) { if (ks.IsKeyDown(key) && testModifiers(ks)) { return(true); } } else { if (ms.IsButtonDown(button) && testModifiers(ks)) { return(true); } } return(false); }
/// <summary> /// Tick operation for control inputs. /// </summary> public static void ControlTick() { MouseState ms = Mouse.GetState(); if (ms.IsButtonDown(MouseButton.Left)) { GameInternal.Angle -= (ms.X - MouseCoords.X) * 0.005f; //GameInternal.Angle = (GameInternal.Angle < 0f) ? 360f : (GameInternal.Angle > 360f) ? 0f : GameInternal.Angle; GameInternal.Pitch -= (ms.Y - MouseCoords.Y) * 0.005f; GameInternal.Pitch = (GameInternal.Pitch < -GameInternal.Degrees89) ? -GameInternal.Degrees89 : (GameInternal.Pitch > GameInternal.Degrees89) ? GameInternal.Degrees89 : GameInternal.Pitch; } MouseCoords = new Vector2(ms.X, ms.Y); Quaternion Q = GameInternal.GetRotation(); if (InputHelpers.CurrentVector != Vector3.Zero) { GameInternal.Center += Vector3.Transform(InputHelpers.CurrentVector, Q); } }
private bool ProcessMouseClick(IDiagramPresenter diagramPresenter, MouseState mouseState) { Debug.Print("ProcessMouseClick"); bool result = false; switch (CurrentAction) { case Action.None: if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { if (diagramPresenter.SelectedShapes.Count > 0) diagramPresenter.UnselectAll(); ShapeAtCursorInfo targetShapeInfo = FindShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.Glue, diagramPresenter.ZoomedGripSize, false); if (IsExtendLineFeasible(CurrentAction, targetShapeInfo.Shape, targetShapeInfo.ControlPointId)) { if (diagramPresenter.Project.SecurityManager.IsGranted(Permission.Layout, targetShapeInfo.Shape)) { ExtendLine(diagramPresenter, mouseState, targetShapeInfo); result = true; } } else { // If no other ToolAction is in Progress (e.g. drawing a line or moving a point), // a normal MouseClick starts a new line in Point-By-Point mode if (diagramPresenter.Project.SecurityManager.IsGranted(Permission.Insert, Template.Shape)) { CreateLine(diagramPresenter, mouseState); result = true; } } } else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) { Cancel(); result = true; } break; case Action.CreateLine: case Action.ExtendLine: if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { Invalidate(ActionDiagramPresenter); bool doFinishLine = false; // If the line has reached the MaxVertexCount limit, create it if (PreviewLinearShape.VertexCount >= PreviewLinearShape.MaxVertexCount) doFinishLine = true; else { // Check if it has to be connected to a shape or connection point ShapeAtCursorInfo shapeAtCursorInfo = base.FindShapeAtCursor(ActionDiagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.Connect, diagramPresenter.ZoomedGripSize, false); if (!shapeAtCursorInfo.IsEmpty && !shapeAtCursorInfo.IsCursorAtGluePoint) doFinishLine = true; else AddNewPoint(ActionDiagramPresenter, mouseState); } // Create line if necessary if (doFinishLine) { if (CurrentAction == Action.CreateLine) FinishLine(ActionDiagramPresenter, mouseState, false); else FinishExtendLine(ActionDiagramPresenter, mouseState, false); while (IsToolActionPending) EndToolAction(); OnToolExecuted(ExecutedEventArgs); } } else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) { #if DEBUG_DIAGNOSTICS Assert(PreviewShape != null); #endif // When creating a line, the new line has to have more than the minimum number of // vertices because the last vertex (sticking to the mouse cursor) will not be created. if (CurrentAction == Action.CreateLine) { if (PreviewLinearShape.VertexCount <= PreviewLinearShape.MinVertexCount) Cancel(); else FinishLine(ActionDiagramPresenter, mouseState, true); } else { // When extending a line, the new line has to have more than the minimum number of // vertices and more than the original line because the last vertex will not be created. if (PreviewLinearShape.VertexCount <= PreviewLinearShape.MinVertexCount || PreviewLinearShape.VertexCount - 1 == modifiedLinearShape.VertexCount) Cancel(); else FinishExtendLine(ActionDiagramPresenter, mouseState, true); } while (IsToolActionPending) EndToolAction(); OnToolExecuted(ExecutedEventArgs); } result = true; break; default: throw new NShapeUnsupportedValueException(CurrentAction); } Invalidate(diagramPresenter); return result; }
/// <summary> /// Decide which tool action is suitable for the current mouse state. /// </summary> private Action DetermineMouseMoveAction(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) { switch (CurrentAction) { case Action.None: case Action.MoveHandle: case Action.MoveShape: case Action.SelectWithFrame: // Do not change the current action return CurrentAction; case Action.Select: case Action.EditCaption: if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { // Check if cursor is over a control point and moving grips or rotating is feasible if (SelectedShapeAtCursorInfo.IsCursorAtGrip) { if (IsMoveHandleFeasible(diagramPresenter, SelectedShapeAtCursorInfo)) return Action.MoveHandle; else if (IsRotatatingFeasible(diagramPresenter, SelectedShapeAtCursorInfo)) return Action.PrepareRotate; else return Action.SelectWithFrame; } else { // If there is no shape under the cursor, start a SelectWithFrame action, // otherwise start a MoveShape action bool canMove = false; if (!SelectedShapeAtCursorInfo.IsEmpty) { // If there are selected shapes, check these shapes... canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, SelectedShapeAtCursorInfo); } else { // ... otherwise check the shape under the cursor as it will be selected // before starting a move action canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, shapeAtCursorInfo); } if (canMove) return Action.MoveShape; else return Action.SelectWithFrame; } } return CurrentAction; case Action.PrepareRotate: if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { // If the mouse has left the min rotate range, start 'real' rotating if (IsMinRotateRangeExceeded(diagramPresenter, mouseState)) return Action.Rotate; else return CurrentAction; } else return CurrentAction; case Action.Rotate: if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { // If the mouse has entered the min rotate range, start showing rotating hint if (!IsMinRotateRangeExceeded(diagramPresenter, mouseState)) return Action.PrepareRotate; else return CurrentAction; } else return CurrentAction; default: throw new NShapeUnsupportedValueException(CurrentAction); } }
/// <summary> /// Decide which tool action is suitable for the current mouse state. /// </summary> private Action DetermineMouseDownAction(IDiagramPresenter diagramPresenter, MouseState mouseState) { if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { if (!SelectedShapeAtCursorInfo.IsEmpty && IsEditCaptionFeasible(diagramPresenter, mouseState, SelectedShapeAtCursorInfo)) { // If the cursor is not over a caption of a selected shape when clicking left mouse button, // we assume the user wants to select something // Same thing if no other action is granted. return Action.EditCaption; } else { // Moving shapes and handles is initiated as soon as the user starts drag action (move mouse // while mouse button is pressed) // If the user does not start a drag action, this will result in (un)selecting shapes. return Action.Select; } } else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) { // Abort current action when clicking right mouse button return Action.None; } else { // Ignore other pressed mouse buttons return CurrentAction; } }
private bool ProcessMouseMove(IDiagramPresenter diagramPresenter, MouseState mouseState) { bool result = true; if (!SelectedShapeAtCursorInfo.IsEmpty && !diagramPresenter.SelectedShapes.Contains(SelectedShapeAtCursorInfo.Shape)) SelectedShapeAtCursorInfo.Clear(); Action newAction; switch (CurrentAction) { case Action.None: result = false; SetSelectedShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, diagramPresenter.ZoomedGripSize, ControlPointCapabilities.All); Invalidate(diagramPresenter); break; case Action.Select: case Action.EditCaption: // Find unselected shape under the mouse cursor ShapeAtCursorInfo shapeAtCursorInfo = ShapeAtCursorInfo.Empty; newAction = CurrentAction; if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { if (IsDragActionFeasible(mouseState, MouseButtonsDg.Left)) { // Determine new drag action shapeAtCursorInfo = FindShapeAtCursor(ActionDiagramPresenter, ActionStartMouseState.X, ActionStartMouseState.Y, ControlPointCapabilities.None, 0, true); newAction = DetermineMouseMoveAction(ActionDiagramPresenter, ActionStartMouseState, shapeAtCursorInfo); } } else newAction = DetermineMouseMoveAction(ActionDiagramPresenter, ActionStartMouseState, shapeAtCursorInfo); // If the action has changed, prepare and start the new action if (newAction != CurrentAction) { switch (newAction) { // Select --> SelectWithFrame case Action.SelectWithFrame: #if DEBUG_DIAGNOSTICS Assert(CurrentAction == Action.Select); #endif StartToolAction(diagramPresenter, (int)newAction, ActionStartMouseState, true); PrepareSelectionFrame(ActionDiagramPresenter, ActionStartMouseState); break; // Select --> (Select shape and) move shape case Action.MoveShape: case Action.MoveHandle: case Action.PrepareRotate: #if DEBUG_DIAGNOSTICS Assert(CurrentAction == Action.Select || CurrentAction == Action.EditCaption); #endif if (SelectedShapeAtCursorInfo.IsEmpty) { // Select shape at cursor before start dragging it PerformSelection(ActionDiagramPresenter, ActionStartMouseState, shapeAtCursorInfo); SetSelectedShapeAtCursor(diagramPresenter, ActionStartMouseState.X, ActionStartMouseState.Y, 0, ControlPointCapabilities.None); #if DEBUG_DIAGNOSTICS Assert(!SelectedShapeAtCursorInfo.IsEmpty); #endif } // Init moving shape #if DEBUG_DIAGNOSTICS Assert(!SelectedShapeAtCursorInfo.IsEmpty); #endif CreatePreviewShapes(ActionDiagramPresenter); StartToolAction(diagramPresenter, (int)newAction, ActionStartMouseState, true); PrepareMoveShapePreview(ActionDiagramPresenter, ActionStartMouseState); break; // Select --> (Select shape and) rotate shape / edit shape caption case Action.Rotate: case Action.EditCaption: case Action.None: case Action.Select: Debug.Fail("Unhandled change of CurrentAction."); break; default: Debug.Fail(string.Format("Unexpected {0} value: {1}", CurrentAction.GetType().Name, CurrentAction)); break; } //currentToolAction = newAction; } Invalidate(ActionDiagramPresenter); break; case Action.SelectWithFrame: PrepareSelectionFrame(ActionDiagramPresenter, mouseState); break; case Action.MoveHandle: #if DEBUG_DIAGNOSTICS Assert(IsMoveHandleFeasible(ActionDiagramPresenter, SelectedShapeAtCursorInfo)); #endif PrepareMoveHandlePreview(ActionDiagramPresenter, mouseState); break; case Action.MoveShape: PrepareMoveShapePreview(diagramPresenter, mouseState); break; case Action.PrepareRotate: case Action.Rotate: #if DEBUG_DIAGNOSTICS Assert(IsRotatatingFeasible(ActionDiagramPresenter, SelectedShapeAtCursorInfo)); #endif newAction = CurrentAction; // Find unselected shape under the mouse cursor newAction = DetermineMouseMoveAction(ActionDiagramPresenter, mouseState, SelectedShapeAtCursorInfo); // If the action has changed, prepare and start the new action if (newAction != CurrentAction) { switch (newAction) { // Rotate shape -> Prepare shape rotation case Action.PrepareRotate: #if DEBUG_DIAGNOSTICS Assert(CurrentAction == Action.Rotate); #endif EndToolAction(); ClearPreviews(); break; // Prepare shape rotation -> Rotate shape case Action.Rotate: #if DEBUG_DIAGNOSTICS Assert(CurrentAction == Action.PrepareRotate); #endif StartToolAction(ActionDiagramPresenter, (int)newAction, mouseState, false); CreatePreviewShapes(ActionDiagramPresenter); break; case Action.SelectWithFrame: case Action.MoveShape: case Action.EditCaption: case Action.MoveHandle: case Action.None: case Action.Select: Debug.Fail("Unhandled change of CurrentAction."); break; default: Debug.Fail(string.Format("Unexpected {0} value: {1}", CurrentAction.GetType().Name, CurrentAction)); break; } //currentToolAction = newAction; } PrepareRotatePreview(ActionDiagramPresenter, mouseState); break; default: throw new NShapeUnsupportedValueException(typeof(Action), CurrentAction); } int cursorId = DetermineCursor(diagramPresenter, mouseState); if (CurrentAction == Action.None) diagramPresenter.SetCursor(cursorId); else ActionDiagramPresenter.SetCursor(cursorId); return result; }
private bool ProcessMouseUp(IDiagramPresenter diagramPresenter, MouseState mouseState) { bool result = false; if (!selectedShapeAtCursorInfo.IsEmpty && !diagramPresenter.SelectedShapes.Contains(selectedShapeAtCursorInfo.Shape)) selectedShapeAtCursorInfo.Clear(); switch (CurrentAction) { case Action.None: // do nothing break; case Action.Select: // Perform selection, but only if it was with the left mouse button. If it was right mouse, ignore it. (Select is only // initiated on right mouse earlier (in ProcessMouseDown) to allow it to 'refine' into other drag actions. If it's // still a select by MouseUp, then we can ignore it.) if (!mouseState.IsButtonDown(MouseButtonsDg.Right)) { ShapeAtCursorInfo shapeAtCursorInfo = FindShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.None, 0, false); result = PerformSelection(ActionDiagramPresenter, mouseState, shapeAtCursorInfo); SetSelectedShapeAtCursor(ActionDiagramPresenter, mouseState.X, mouseState.Y, ActionDiagramPresenter.ZoomedGripSize, ControlPointCapabilities.All); } EndToolAction(); break; case Action.SelectWithFrame: // select all selectedShapes within the frame result = PerformFrameSelection(ActionDiagramPresenter, mouseState); while (IsToolActionPending) EndToolAction(); break; case Action.MoveHandle: result = PerformMoveHandle(ActionDiagramPresenter); while (IsToolActionPending) EndToolAction(); break; case Action.MoveShape: result = PerformMoveShape(ActionDiagramPresenter); while (IsToolActionPending) EndToolAction(); break; case Action.ConnectShapes: result = FinishConnection(ActionDiagramPresenter); while (IsToolActionPending) EndToolAction(); break; default: throw new NShapeUnsupportedValueException(CurrentAction); } SetSelectedShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, diagramPresenter.ZoomedGripSize, ControlPointCapabilities.All); diagramPresenter.SetCursor(DetermineCursor(diagramPresenter, mouseState)); OnToolExecuted(ExecutedEventArgs); return result; }
public void Update() { state = OpenTK.Input.Mouse.GetState(); if(HWUpdate) { var p = gameWindow.PointToClient(new System.Drawing.Point(state.X, state.Y)); if(!lastHWUpdate) { var lastx = x; var lasty = y; offsetx = x - p.X; offsety = y - p.Y; } x = p.X + offsetx; y = p.Y + offsety; } else { x = gameWindow.Mouse.X; y = gameWindow.Mouse.Y; } lastHWUpdate = HWUpdate; var wheelValue = state.WheelPrecise; wheel = state.WheelPrecise; for(int i = 0; i < allButtons.Length; i++) { MouseButton button = allButtons[i]; if (state.IsButtonDown(button)) { MouseDown(button); } else if(downButtons[button]) { MouseUp(button); } } }
private bool IsDragActionFeasible(MouseState mouseState, MouseButtonsDg button) { int dx = 0, dy = 0; if (mouseState.IsButtonDown(button) && IsToolActionPending) { // Check the minimum drag distance before switching to a drag action dx = Math.Abs(mouseState.X - ActionStartMouseState.X); dy = Math.Abs(mouseState.Y - ActionStartMouseState.Y); } return (dx >= MinimumDragDistance.Width || dy >= MinimumDragDistance.Height); }
/// <summary> /// Decide which tool action is suitable for the current mouse state. /// </summary> private Action DetermineMouseMoveAction(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) { switch (CurrentAction) { case Action.None: case Action.MoveHandle: case Action.MoveShape: case Action.SelectWithFrame: case Action.ConnectShapes: // Do not change the current action return CurrentAction; case Action.Select: if (mouseState.IsButtonDown(MouseButtonsDg.Left)) { // if we're doing something with the left mouse button, it will be a 'drag' style action if (!IsDragActionFeasible(mouseState)) { return CurrentAction; } // Check if cursor is over a control point and moving grips is feasible if (selectedShapeAtCursorInfo.IsCursorAtGrip) { if (IsMoveHandleFeasible(diagramPresenter, mouseState, selectedShapeAtCursorInfo)) return Action.MoveHandle; else return Action.SelectWithFrame; } else { // If there is no shape under the cursor, start a SelectWithFrame action, // otherwise start a MoveShape action bool canMove = false; if (!selectedShapeAtCursorInfo.IsEmpty) { // If there are selected shapes, check these shapes... canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, selectedShapeAtCursorInfo); } else { // ... otherwise check the shape under the cursor as it will be selected // before starting a move action canMove = IsMoveShapeFeasible(diagramPresenter, mouseState, shapeAtCursorInfo); } return canMove ? Action.MoveShape : Action.SelectWithFrame; } } else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) { if (IsConnectFromShapeFeasible(diagramPresenter, mouseState, shapeAtCursorInfo)) { return Action.ConnectShapes; } } return CurrentAction; default: throw new NShapeUnsupportedValueException(CurrentAction); } }
/// <summary> /// Decide which tool action is suitable for the current mouse state. /// </summary> private Action DetermineMouseDownAction(IDiagramPresenter diagramPresenter, MouseState mouseState) { if (mouseState.IsButtonDown(MouseButtonsDg.Left) || mouseState.IsButtonDown(MouseButtonsDg.Right)) { // if left or right buttons are down, start a 'select' action. This will refine to an // appropriate drag action later on (when mouse moving) based on the mouse button, otherwise // it will (de)select the shape on mouseup return Action.Select; } // Ignore other pressed mouse buttons return CurrentAction; }