private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Location.X >= Width - 5 && e.Location.Y > Height - 5) { Cursor = Cursors.SizeNWSE; direction = MouseDirection.Declining; } else { if (e.Location.X >= Width - 5) { Cursor = Cursors.SizeWE; direction = MouseDirection.Herizontal; } else { if (e.Location.Y >= Height - 5) { Cursor = Cursors.SizeNS; direction = MouseDirection.Vertical; } else { Cursor = Cursors.Arrow; } } } ResizeWindow(); }
/// <summary> /// Creates a ControlItem invoked by a combination of multiple keystrokes & mouse dragging. /// /// <example><code>new ControlItem("Convoluted nondescript example", new[] { KeyCode.LeftControl, KeyCode.LeftShift}, MouseDirection.Both, MouseButton.MiddleClick);</code></example> /// </summary> public ControlItem(string description, KeyCode[] keys, MouseDirection direction, MouseButton button) { this.description = description; this.direction = direction; this.button = button; this.keys = keys; }
/// <summary> /// Sends input based on the given enums /// </summary> protected void SendInput(MouseButton btn, MouseDirection dir) { var inputBuffer = new INPUT { type = 0U }; switch (btn) { case MouseButton.Left: inputBuffer.inputData.mi.dwFlags = dir == MouseDirection.Down ? 2U : 4U; break; case MouseButton.Right: inputBuffer.inputData.mi.dwFlags = dir == MouseDirection.Down ? 8U : 16U; break; case MouseButton.Middle: inputBuffer.inputData.mi.dwFlags = dir == MouseDirection.Down ? 32U : 64U; break; case MouseButton.Scroll: inputBuffer.inputData.mi.dwFlags = 2048U; inputBuffer.inputData.mi.mouseData = (uint)(dir == MouseDirection.Up ? WheelSpeed : -WheelSpeed); break; default: throw new ArgumentOutOfRangeException(nameof(btn), btn, null); } SendInput(inputBuffer); }
private void bottomPanel_MouseMove(object sender, MouseEventArgs e) { if (e.Location.X >= this.Width - 10 && e.Location.Y >= this.bottomPanel.Height - 10) { this.Cursor = Cursors.SizeNWSE; _direction = MouseDirection.Declining; } //只改变宽度 else if (e.Location.X >= this.Width - 6) { this.Cursor = Cursors.SizeWE; _direction = _direction == MouseDirection.Declining ? MouseDirection.Declining : MouseDirection.Horizontal; } else if (e.Location.Y >= this.bottomPanel.Height - 2) { this.Cursor = Cursors.SizeNS; _direction = _direction == MouseDirection.Declining ? MouseDirection.Declining : MouseDirection.Vertical; } else { this.Cursor = Cursors.Arrow; } //改变窗体大小 ResizeWindow(); }
private void MainForm_MouseMove(object sender, MouseEventArgs e) { //鼠标移动过程中,坐标时刻在改变 //当鼠标移动时横坐标距离窗体右边缘5像素以内且纵坐标距离下边缘也在5像素以内时,要将光标变为倾斜的箭头形状,同时拖拽方向direction置为MouseDirection.Declining if (e.Location.X >= this.Width - 5 && e.Location.Y > this.Height - 5) { this.Cursor = Cursors.SizeNWSE; direction = MouseDirection.Declining; } //当鼠标移动时横坐标距离窗体右边缘5像素以内时,要将光标变为倾斜的箭头形状,同时拖拽方向direction置为MouseDirection.Herizontal else if (e.Location.X >= this.Width - 5) { this.Cursor = Cursors.SizeWE; direction = MouseDirection.Herizontal; } //同理当鼠标移动时纵坐标距离窗体下边缘5像素以内时,要将光标变为倾斜的箭头形状,同时拖拽方向direction置为MouseDirection.Vertical else if (e.Location.Y >= this.Height - 5) { this.Cursor = Cursors.SizeNS; direction = MouseDirection.Vertical; } //否则,以外的窗体区域,鼠标星座均为单向箭头(默认) else { this.Cursor = Cursors.Arrow; } //设定好方向后,调用下面方法,改变窗体大小 ResizeWindow(); }
private static void MoveMouseRelative(MouseDirection d) { double wpx = GetGridHorizPx(); double hpx = GetGridVertPx(); var p = Pos(); Vector v = new Vector(p.X, p.Y); switch (d) { case MouseDirection.LEFT: v.X -= wpx; break; case MouseDirection.RIGHT: v.X += wpx; break; case MouseDirection.UP: v.Y -= hpx; break; case MouseDirection.DOWN: v.Y += hpx; break; } var x = SCREEN_CONVERT_AMOUNT * v.X / System.Windows.SystemParameters.PrimaryScreenWidth; var y = SCREEN_CONVERT_AMOUNT * v.Y / System.Windows.SystemParameters.PrimaryScreenHeight; InputHelper.SendMouse((uint)(InputHelper.MouseEventF.MOUSEEVENTF_ABSOLUTE | InputHelper.MouseEventF.MOUSEEVENTF_MOVE), 0, (int)x, (int)y); }
private void Form1_MouseMove(object sender, MouseEventArgs e) { //鼠标移动到边缘,改变鼠标的图标 if (e.Location.X >= this.Width - 5) { this.Cursor = Cursors.SizeWE; direction = MouseDirection.Herizontal; } else if (e.Location.Y >= this.Height - 5) { this.Cursor = Cursors.SizeNS; direction = MouseDirection.Vertical; } //否则,以外的窗体区域,鼠标星座均为单向箭头(默认) else { this.Cursor = Cursors.Arrow; } if (e.Location.X >= (this.Width + this.Left + 10) || (e.Location.Y > this.Height + this.Top + 10)) { isMouseDown = false; } //设定好方向后,调用下面方法,改变窗体大小 ResizeWindow(); }
private void Form1_MouseUp(object sender, MouseEventArgs e) { //label1.Text = e.Location.Y.ToString(); isMouseDown = false; direction = MouseDirection.None; //既然鼠标弹起了,那么就不能再改变窗体尺寸,拖拽方向置 none Properties.Settings.Default._size = this.Size; //使用Save方法保存更改 Properties.Settings.Default.Save(); //使用Save方法保存更改 }
private void Control_MouseUp(object sender, MouseEventArgs e) { // 鼠标弹起, isMouseDown = false; //既然鼠标弹起了,那么就不能再改变窗体尺寸,拖拽方向置 none direction = MouseDirection.None; }
/// <summary> /// Creates a ControlItem invoked by a combination of keystroke & mouse movement. /// /// <example><code>new ControlItem("Look around while zoomed", KeyCode.LeftControl, MouseDirection.Both);</code></example> /// </summary> public ControlItem(string description, KeyCode key, MouseDirection direction) { this.description = description; this.direction = direction; this.keys = new KeyCode[1] { key }; }
private void panel_MouseMove(object sender, MouseEventArgs e) { PictureBox parent = (PictureBox)this.Parent; Point point = GetPointToParent(e.Location); if (this.Focused == false) { return; } int validPixel = 8; if (e.Location.X >= this.Width - validPixel && e.Location.Y >= this.Height - validPixel) { this.Cursor = Cursors.SizeNWSE; direction = MouseDirection.Southeast; } else if (e.Location.X <= validPixel && e.Location.Y <= validPixel) { this.Cursor = Cursors.SizeNWSE; direction = MouseDirection.Northwest; } else if (e.Location.X <= validPixel && e.Location.Y >= this.Height - validPixel) { this.Cursor = Cursors.SizeNESW; direction = MouseDirection.Southwest; } else if (e.Location.X >= this.Width - validPixel && e.Location.Y <= validPixel) { this.Cursor = Cursors.SizeNESW; direction = MouseDirection.Northeast; } else { this.Cursor = Cursors.SizeAll; direction = MouseDirection.None; } if (e.Button == MouseButtons.Left) { if (direction != MouseDirection.None)//改变大小 { { Point oldLocation = this.Location; ResizeControl(e.Location); } } else { Point oldLocation = this.Location; this.Cursor = Cursors.SizeAll; Point location = GetPointToParent(new Point(e.Location.X - mouseDownPoint.X, e.Location.Y - mouseDownPoint.Y)); RelocationControl(location); } } }
protected override void OnMouseMoveEvent(MouseMoveEvent evt) { if (!m_Active || !target.HasMouseCapture() || EditorApplication.isPlaying) { return; } Timeline timeline = MarkerElement.Timeline; Asset asset = timeline.TargetAsset; TaggedAnimationClip clip = timeline.TaggedClip; if (m_StartingDrag) { Undo.RecordObject(asset, "Moving marker"); m_StartingDrag = false; } Vector2 position = evt.mousePosition; MouseDirection direction = GetMouseDirection(position); m_MousePreviousPosition = position; float framerate = clip.SampleRate; float dragPosition = position.x; if (m_Target.SnapValid(dragPosition)) { return; } bool canPreview = m_Target.Timeline.CanPreview(); TryToSnap(dragPosition, direction, framerate, out float newTime, snapToPlayhead: !canPreview); if (!FloatComparer.s_ComparerWithDefaultTolerance.Equals(MarkerElement.value, newTime)) { m_MarkerDragged = true; MarkerElement.value = newTime; MarkerElement.ShowManipulationLabel(); if (canPreview) { m_Target.Timeline.SetActiveTime(newTime); } } evt.StopPropagation(); }
private void Control_MouseMove(object sender, MouseEventArgs e) { Size thisZ = new Size(); if (sender is LayeredPanel) { LayeredPanel lpn = sender as LayeredPanel; thisZ = lpn.Size; } else if (sender is DuiButton) { DuiButton btn_Resize = sender as DuiButton; thisZ = btn_Resize.Size; } else if (sender is LayeredBaseControl) { LayeredBaseControl lns = sender as LayeredBaseControl; thisZ = lns.Size; } //鼠标移动过程中,坐标时刻在改变 //当鼠标移动时横坐标距离窗体右边缘5像素以内且纵坐标距离下边缘也在5像素以内时,要将光标变为倾斜的箭头形状,同时拖拽方向direction置为MouseDirection.Declining //(e.Location.X <= 5 && e.Location.Y <= 5) || (e.Location.X >= thisZ.Width - 5 && e.Location.Y <= 5) || (e.Location.X <= 4 && e.Location.Y >= thisZ.Height - 5) if ((e.Location.X >= thisZ.Width - 5 && e.Location.Y >= thisZ.Height - 5)) { this.Cursor = Cursors.SizeNWSE; direction = MouseDirection.Declining; } ////当鼠标移动时横坐标距离窗体右边缘5像素以内时,要将光标变为倾斜的箭头形状,同时拖拽方向direction置为MouseDirection.Herizontal //else if (e.Location.X <= 5 || e.Location.X >= thisZ.Width - 5) //{ // this.Cursor = Cursors.SizeWE; // direction = MouseDirection.Herizontal; //} ////同理当鼠标移动时纵坐标距离窗体下边缘5像素以内时,要将光标变为倾斜的箭头形状,同时拖拽方向direction置为MouseDirection.Vertical //else if (e.Location.Y <= 5 || e.Location.Y >= thisZ.Height - 5) //{ // this.Cursor = Cursors.SizeNS; // direction = MouseDirection.Vertical; //} //否则,以外的窗体区域,鼠标星座均为单向箭头(默认) else { this.Cursor = Cursors.Arrow; } //设定好方向后,调用下面方法,改变窗体大小 ResizeWindow(); }
private void ShowMouse(Rect texRect, MouseDirection direction, MouseButton button) { GUI.DrawTexture(texRect, mouseBase); switch (button) { case MouseButton.None: break; case MouseButton.LeftClick: GUI.DrawTexture(texRect, mouseLeftClick); break; case MouseButton.RightClick: GUI.DrawTexture(texRect, mouseRightClick); break; case MouseButton.BothClick: GUI.DrawTexture(texRect, mouseLeftClick); GUI.DrawTexture(texRect, mouseRightClick); break; case MouseButton.MiddleClick: GUI.DrawTexture(texRect, mouseMiddleClick); break; case MouseButton.ScrollWheel: GUI.DrawTexture(texRect, mouseWheel); break; default: Debug.LogError("Unsupported MouseButton " + button); return; } switch (direction) { case MouseDirection.None: break; case MouseDirection.Horizontal: GUI.DrawTexture(texRect, mouseHorizontal); break; case MouseDirection.Vertical: GUI.DrawTexture(texRect, mouseVertical); break; case MouseDirection.Both: GUI.DrawTexture(texRect, mouseHorizontalAndVertical); break; default: Debug.LogError("Unsupported MouseDirection " + direction); return; } }
/// <summary> /// Передвижение кнопки /// </summary> /// <param name="direction"> Направление движения мыши </param> /// <param name="distance"> Расстояние от курсора до центра кнопки </param> private void moveButton(MouseDirection direction, int distance) { int mouseSpeed = (SystemInformation.MouseSpeed / 10 + 1) * (int)(distance); switch (direction) { case MouseDirection.top: if (button.Top > 0) { button.Top -= button.Top - mouseSpeed < 0 ? button.Top : mouseSpeed; } break; case MouseDirection.left: if (button.Location.X > 0) { button.Left -= button.Left - mouseSpeed < 0 ? button.Left : mouseSpeed; } break; case MouseDirection.right: if (button.Left + button.Width < ClientSize.Width) { button.Left += button.Left + button.Width + mouseSpeed < ClientSize.Width ? mouseSpeed : ClientSize.Width - button.Left - button.Width; } break; case MouseDirection.bottom: if (button.Top + button.Height < ClientSize.Height) { button.Top += button.Top + button.Height + mouseSpeed < ClientSize.Height ? mouseSpeed : ClientSize.Height - button.Top - button.Height; } break; default: break; } }
/// <summary> /// Передвижение кнопки /// </summary> /// <param name="direction">Направление движения курсора</param> /// <param name="distance">Расстояние от курсора до центра кнопки</param> private void ButtonMoveButton(MouseDirection direction, int distance) { var mouseSpeed = (SystemInformation.MouseSpeed / 10 + 1) * distance; switch (direction) { case MouseDirection.Top: if (button.Top > 0) { button.Top -= button.Top - mouseSpeed < 0 ? button.Top : mouseSpeed; } break; case MouseDirection.Left: if (button.Location.X > 0) { button.Left -= button.Left - mouseSpeed < 0 ? button.Left : mouseSpeed; } break; case MouseDirection.Right: if (button.Left + button.Width < ClientSize.Width) { button.Left += button.Left + button.Width + mouseSpeed < ClientSize.Width ? mouseSpeed : ClientSize.Width - button.Left - button.Width; } break; case MouseDirection.Bottom: if (button.Top + button.Height < ClientSize.Height) { button.Top += button.Top + button.Height + mouseSpeed < ClientSize.Height ? mouseSpeed : ClientSize.Height - button.Top - button.Height; } break; case MouseDirection.NotMoving: break; } }
protected override void OnMouseMoveEvent(MouseMoveEvent evt) { if (!m_Active || !target.HasMouseCapture() || EditorApplication.isPlaying) { return; } if (Math.Abs(evt.mousePosition.x - m_MouseDownPosition.x) < k_MinDistance) { m_Target.style.visibility = Visibility.Hidden; m_Target.HideManipulationLabel(); m_Timeline.HideGuidelines(); return; } float dragPosition = evt.mousePosition.x; if (m_Target.SnapValid(dragPosition)) { return; } MouseDirection direction = GetMouseDirection(evt.mousePosition); m_MousePreviousPosition = evt.mousePosition; bool canPreview = m_Timeline.CanPreview(); TryToSnap(dragPosition, direction, m_Timeline.TaggedClip.SampleRate, out float mouseMoveTime, snapToPlayhead: !canPreview); m_Target.style.visibility = Visibility.Visible; float startTime = Math.Min(m_MouseDownTime, mouseMoveTime); float endTime = Math.Max(m_MouseDownTime, mouseMoveTime); if (canPreview) { m_Timeline.SetActiveTime(mouseMoveTime); } m_Timeline.ShowGuidelines(startTime, endTime); (m_Target as TagCreationElement).SetTimes(startTime, endTime); }
private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Location.X >= this.Width - 24 && e.Location.Y > this.Height - 24) { this.Cursor = Cursors.SizeNWSE; if (isMouseDown) { direction = MouseDirection.Declining; } } else if (e.Location.X >= this.Width - 12 && direction != MouseDirection.Declining) { this.Cursor = Cursors.SizeWE; if (isMouseDown) { direction = MouseDirection.Herizontal; } } else if (e.Location.Y >= this.Height - 12 && direction != MouseDirection.Declining) { this.Cursor = Cursors.SizeNS; if (isMouseDown) { direction = MouseDirection.Vertical; } } else { this.Cursor = Cursors.Arrow; } ResizeWindow(); if (direction == MouseDirection.Vertical || direction == MouseDirection.Herizontal || direction == MouseDirection.Declining) { return; } if (e.Button == MouseButtons.Left) { this.Cursor = Cursors.SizeAll; Location = new Point((Location.X + (e.X - p.X)), (Location.Y + (e.Y - p.Y))); Properties.Settings.Default._location = Location; Properties.Settings.Default.Save(); } }
SnappingElement FindSnapTarget(float dragPosition, MouseDirection direction) { SnappingElement snapTarget = SnapTo(m_Target, dragPosition); if (snapTarget != null) { float snapPosition = snapTarget.GetSnapPosition(dragPosition); if (snapPosition < dragPosition && direction == MouseDirection.Decreasing) { return(snapTarget); } if (snapPosition > dragPosition && direction == MouseDirection.Increasing) { return(snapTarget); } } return(null); }
/// <summary> /// Translates a mouse movement into a direction /// </summary> /// <param name="p">The new cursor coordinates</param> /// <returns>None for minimal movement, else up/down/left/right</returns> private MouseDirection OnMouseMoved(Point p) { MouseDirection direction = MouseDirection.None; int xMove = GetPointDeviation(false, p.X); int yMove = GetPointDeviation(true, p.Y); // using the pythagoras theorem to get the total movement length double TotalWay = Math.Sqrt(((double)((Math.Abs(xMove) * Math.Abs(xMove))) + (double)((Math.Abs(yMove) * Math.Abs(yMove))))); // set a direction only if movement exceeds a minimum limit // usually pushing the joystick knob once results in a one pixel movement. if (TotalWay > 0.9) { direction = GetDirection(xMove, yMove); } if (_verboseLogging) { Log.Debug("Centarea: Mouse movement of {0} pixels heading {1}", TotalWay, direction); } return(direction); }
void GetInputDirection() { inputDirection = MouseDirection.NULL; if (Input.GetMouseButtonDown(0)) { activeInput = true; mousePos = Input.mousePosition; } if (Input.GetMouseButton(0) && activeInput) { Vector3 vec = Input.mousePosition - mousePos; // vec.normalized 向量归一 // Vector2.up 方向向上的向量 if (vec.magnitude > 20) { var angleY = Mathf.Acos(Vector3.Dot(vec.normalized, Vector2.up)) * Mathf.Rad2Deg; var angleX = Mathf.Acos(Vector3.Dot(vec.normalized, Vector2.right)) * Mathf.Rad2Deg; if (angleY <= 45) { inputDirection = MouseDirection.up; } else if (angleY >= 135) { inputDirection = MouseDirection.down; } else if (angleX <= 45) { inputDirection = MouseDirection.right; } else if (angleX >= 135) { inputDirection = MouseDirection.left; } activeInput = false; } } }
private void MainForm_MouseLeave(object sender, EventArgs e) { isMouseDown = false; direction = MouseDirection.None; }
/// <summary> /// Let everybody know that this HID message may not be handled by anyone else /// </summary> /// <param name="msg">System.Windows.Forms.Message</param> /// <returns>Command handled</returns> public bool WndProc(ref Message msg) { if (_remoteActive) { if (msg.Msg == WM_KEYDOWN || msg.Msg == WM_SYSKEYDOWN || msg.Msg == WM_APPCOMMAND || msg.Msg == WM_LBUTTONDOWN || msg.Msg == WM_RBUTTONDOWN || msg.Msg == WM_MOUSEMOVE) { switch ((Keys)msg.WParam) { case Keys.ControlKey: break; case Keys.ShiftKey: break; case Keys.Menu: break; default: int keycode = (int)msg.WParam; AppCommands appCommand = (AppCommands)((msg.LParam.ToInt32() >> 16) & ~0xF000); // find out which request the MCE remote handled last if ((appCommand == InputDevices.LastHidRequest) && (appCommand != AppCommands.VolumeDown) && (appCommand != AppCommands.VolumeUp)) { if (Enum.IsDefined(typeof(AppCommands), InputDevices.LastHidRequest)) { // possible that it is the same request mapped to an app command? if (Environment.TickCount - InputDevices.LastHidRequestTick < 500) { return(true); } } } InputDevices.LastHidRequest = appCommand; // Due to the non-perfect placement of the OK button we allow the user to remap the joystick to okay. if (_mapMouseButton) { if (msg.Msg == WM_LBUTTONDOWN) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for left mouse button", keycode); } keycode = 13; } if (msg.Msg == WM_RBUTTONDOWN) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for right mouse button", keycode); } keycode = 10069; } } // Since mouse support is semi optimal we have this option to use the joystick like cursor keys if (_mapJoystick && GUIGraphicsContext.Fullscreen) { if (msg.Msg == WM_MOUSEMOVE) { Point p = new Point(msg.LParam.ToInt32()); _ignoreDupMsg++; // since our ResetCursor() triggers a mouse move MSG as well we ignore every second event if (_ignoreDupMsg % 2 == 0) { GUIGraphicsContext.ResetCursor(false); } // we ignore double actions for the configured time if (Environment.TickCount - _lastMouseTick < 400) { return(false); } MouseDirection mmove = OnMouseMoved(p); _lastMouseTick = Environment.TickCount; _ignoreDupMsg = 0; switch (mmove) { case MouseDirection.Up: keycode = 38; break; case MouseDirection.Right: keycode = 39; break; case MouseDirection.Down: keycode = 40; break; case MouseDirection.Left: keycode = 37; break; } if (mmove != MouseDirection.None) { GUIGraphicsContext.ResetCursor(false); if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for mouse movement", mmove.ToString()); } } } } // The Centarea Remote sends key combos. Therefore we use this trick to get a 1:1 mapping if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { keycode += 1000; } if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { keycode += 10000; } if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt) { keycode += 100000; } try { // Get & execute Mapping if (_inputHandler.MapAction(keycode)) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped", keycode); } } else { if (keycode > 0) { Log.Debug("Centarea: Command \"{0}\" not mapped", keycode); } return(false); } } catch (ApplicationException) { return(false); } msg.Result = new IntPtr(1); break; } return(true); } } return(false); }
protected override void OnMouseMoveEvent(MouseMoveEvent evt) { Timeline timeline = TagElement.Timeline; TaggedAnimationClip taggedAnimationClip = timeline.TaggedClip; if (!m_Active || !target.HasMouseCapture() || !taggedAnimationClip.Valid || EditorApplication.isPlaying) { return; } if (Math.Abs(m_MousePreviousPosition.x - evt.mousePosition.x) < k_MinDistanceForTagCreation) { if (Math.Abs(m_MouseDownPosition.y - evt.mousePosition.y) >= k_MinDistanceForTagCreation) { OnMouseMoveReorderEvent(evt); } return; } Vector2 position = evt.mousePosition; MouseDirection direction = GetMouseDirection(position); m_MousePreviousPosition = position; float framerate = taggedAnimationClip.SampleRate; TagAnnotation tag = TagElement.m_Tag; Asset asset = taggedAnimationClip.Asset; Mode mode = m_Mode; if (m_OverrideMode == Mode.None) { float mousePos = evt.mousePosition.x; float fromStart = Math.Abs(mousePos - TagElement.worldBound.x); float fromEnd = Math.Abs(mousePos - TagElement.worldBound.xMax); // If the tag element is this small it will be too difficult to accurately grab the center and even accurately pick either end // we'll figure out which side of the tag is closest and assume the user meant to click that side. if (TagElement.layout.width <= 14f) { if (fromStart <= fromEnd) { mode = Mode.StartTime; } else { mode = Mode.Duration; } m_OverrideMode = mode; } } else { mode = m_OverrideMode; } float newTime = float.NaN; float dragPosition = position.x; bool canPreview = timeline.CanPreview(); // when we're dragging the entire tag we need to snap the edges of the tag, not the mouse position so we'll handle that inside its switch case if (mode != Mode.Body) { if (m_Target.SnapValid(dragPosition)) { return; } TryToSnap(dragPosition, direction, taggedAnimationClip.SampleRate, out newTime, snapToPlayhead: !canPreview); } float previewTime = -1f; switch (mode) { case Mode.StartTime: float endTime = tag.startTime + tag.duration; Undo.RecordObject(asset, "Drag Tag start"); float delta = newTime - tag.startTime; if (tag.duration - delta < TagElement.MinTagDuration) { tag.startTime = endTime - TagElement.MinTagDuration; tag.duration = TagElement.MinTagDuration; } else { tag.startTime = newTime; tag.duration = endTime - tag.startTime; } TagElement.Timeline.ShowStartGuideline(tag.startTime); previewTime = newTime; break; case Mode.Duration: Undo.RecordObject(asset, "Drag Tag Duration"); float newDuration = newTime - tag.startTime; if (newDuration <= TagElement.MinTagDuration) { tag.duration = TagElement.MinTagDuration; } else { tag.duration = newDuration; } TagElement.Timeline.ShowEndGuideline(tag.EndTime); previewTime = tag.EndTime; break; case Mode.Body: Undo.RecordObject(asset, "Drag Tag"); newTime = m_Target.Timeline.WorldPositionToTime(position.x); if (TagElement.Timeline.TimelineUnits == TimelineViewMode.frames) { newTime = (float)TimelineUtility.RoundToFrame(newTime - m_TimeOffsetAtMouseDown, framerate); } else { newTime -= m_TimeOffsetAtMouseDown; } if (!m_Target.SnapValid(newTime) && !m_Target.SnapValid(newTime + tag.duration)) { float mouseOffset = TagElement.Timeline.TimeToWorldPos(newTime); if (!TryToSnap(mouseOffset, direction, taggedAnimationClip.SampleRate, out newTime, snapToPlayhead: !canPreview)) { float durationPos = TagElement.Timeline.TimeToWorldPos(newTime + tag.duration); //Try to snap via the end of the current tag if (TryToSnap(durationPos, direction, taggedAnimationClip.SampleRate, out float candidateEndTime, snapToPlayhead: !canPreview)) { newTime = candidateEndTime - tag.duration; } } tag.startTime = newTime; TagElement.Timeline.ShowGuidelines(tag.startTime, tag.EndTime); } previewTime = tag.EndTime; break; } if (canPreview && previewTime >= 0f) { TagElement.Timeline.SetActiveTime(previewTime); } tag.NotifyChanged(); TagElement.Timeline.SendTagModified(); evt.StopPropagation(); TagElement.ShowManipulationLabel(); }
private void bottomPanel_MouseUp(object sender, MouseEventArgs e) { _isChangeSize = false; _direction = MouseDirection.None; }
private void Form1_MouseUp(object sender, MouseEventArgs e) { isMouseDown = false; direction = MouseDirection.None; }
/// <summary> /// Map a WndProc message and optionally execute it /// </summary> /// <param name="msg"></param> /// <returns></returns> private Mapping MapWndProcMessage(Message msg, bool shouldRaiseAction = true) { Mapping result = null; if (msg.Msg == WM_KEYDOWN || msg.Msg == WM_SYSKEYDOWN || msg.Msg == Win32.Const.WM_APPCOMMAND || msg.Msg == WM_LBUTTONDOWN || msg.Msg == WM_RBUTTONDOWN || msg.Msg == WM_MOUSEMOVE) { switch ((Keys)msg.WParam) { case Keys.ControlKey: break; case Keys.ShiftKey: break; case Keys.Menu: break; default: int keycode = (int)msg.WParam; AppCommands appCommand = (AppCommands)Win32.Macro.GET_APPCOMMAND_LPARAM(msg.LParam); InputDevices.LastHidRequest = appCommand; // Due to the non-perfect placement of the OK button we allow the user to remap the joystick to okay. if (_mapMouseButton) { if (msg.Msg == WM_LBUTTONDOWN) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for left mouse button", keycode); } keycode = 13; } if (msg.Msg == WM_RBUTTONDOWN) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for right mouse button", keycode); } keycode = 10069; } } // Since mouse support is semi optimal we have this option to use the joystick like cursor keys if (_mapJoystick && GUIGraphicsContext.Fullscreen) { if (msg.Msg == WM_MOUSEMOVE) { Point p = new Point(msg.LParam.ToInt32()); _ignoreDupMsg++; // since our ResetCursor() triggers a mouse move MSG as well we ignore every second event if (_ignoreDupMsg % 2 == 0) { GUIGraphicsContext.ResetCursor(false); } // we ignore double actions for the configured time if (Environment.TickCount - _lastMouseTick < 400) { return(null); } MouseDirection mmove = OnMouseMoved(p); _lastMouseTick = Environment.TickCount; _ignoreDupMsg = 0; switch (mmove) { case MouseDirection.Up: keycode = 38; break; case MouseDirection.Right: keycode = 39; break; case MouseDirection.Down: keycode = 40; break; case MouseDirection.Left: keycode = 37; break; } if (mmove != MouseDirection.None) { GUIGraphicsContext.ResetCursor(false); if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped for mouse movement", mmove.ToString()); } } } } // The Centarea Remote sends key combos. Therefore we use this trick to get a 1:1 mapping if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { keycode += 1000; } if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { keycode += 10000; } if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt) { keycode += 100000; } try { result = _inputHandler.GetMapping(keycode.ToString()); if (shouldRaiseAction) { // Get & execute Mapping if (_inputHandler.MapAction(keycode)) { if (_verboseLogging) { Log.Debug("Centarea: Command \"{0}\" mapped", keycode); } } else { if (keycode > 0) { Log.Debug("Centarea: Command \"{0}\" not mapped", keycode); } return(null); } } } catch (ApplicationException ex) { Log.Error("CentAreaRemote:MapWndProcMessage: {0}", ex.Message); return(null); } msg.Result = new IntPtr(1); break; } } return(result); }
protected bool TryToSnap(float dragPosition, MouseDirection direction, float framerate, out float newTime, bool snapToClipStart = true, bool snapToClipDuration = true, bool snapToPlayhead = true) { Timeline timeline = m_Target.Timeline; if (SnappingEnabled) { m_Target.UnSnap(); SnappingElement snapTarget = FindSnapTarget(dragPosition, direction); if (snapTarget != null) { newTime = timeline.WorldPositionToTime(snapTarget.GetSnapPosition(dragPosition)); m_Target.SnapTo(snapTarget); if (timeline.TimelineUnits == TimelineViewMode.frames) { newTime = (float)TimelineUtility.RoundToFrame(newTime, framerate); } timeline.ShowSnap(newTime); return(true); } float zeroPos = timeline.TimeToWorldPos(0f); float duration = m_Target.Track.Clip.DurationInSeconds; float endPos = timeline.TimeToWorldPos(duration); if (snapToClipStart && Mathf.Abs(dragPosition - zeroPos) < k_SnapMoveDelta) { timeline.ShowSnap(0f); newTime = 0f; return(true); } if (snapToClipDuration && Mathf.Abs(dragPosition - endPos) < k_SnapMoveDelta) { newTime = duration; timeline.ShowSnap(newTime); return(true); } float activeTimePos = timeline.TimeToWorldPos(timeline.ActiveTime); if (snapToPlayhead && Mathf.Abs(dragPosition - activeTimePos) < k_SnapMoveDelta) { newTime = timeline.ActiveTime; timeline.ShowSnap(timeline.ActiveTime); return(true); } } newTime = timeline.WorldPositionToTime(dragPosition); if (timeline.TimelineUnits == TimelineViewMode.frames) { newTime = (float)TimelineUtility.RoundToFrame(newTime, framerate); } m_Target.UnSnap(); timeline.HideSnap(); return(false); }
/// <summary> /// Creates a ControlItem invoked by clicking & dragging. /// /// <example><code>new ControlItem("Create a box selection", MouseDirection.Both, MouseButton.LeftClick);</code></example> /// </summary> public ControlItem(string description, MouseDirection direction, MouseButton button) { this.description = description; this.direction = direction; this.button = button; }
private void panel_MouseMove(object sender, MouseEventArgs e) { try { PictureBox parent = (PictureBox)this.Parent; Point point = GetPointToParent(e.Location); ConstDef.ImageY = (int)(point.Y * ((double)parent.Image.Height / parent.Height)); ConstDef.ImageX = (int)(point.X * ((double)parent.Image.Width / (double)parent.Width)); BeginInvoke(MainForm.updateCoord); } catch (Exception ex) { LogHelper.AppLoger.Error(ex); } if (this.Focused == false) { return; } int validPixel = 8; if (e.Location.X >= this.Width - validPixel && e.Location.Y >= this.Height - validPixel) { this.Cursor = Cursors.SizeNWSE; direction = MouseDirection.Southeast; } else if (e.Location.X <= validPixel && e.Location.Y <= validPixel) { this.Cursor = Cursors.SizeNWSE; direction = MouseDirection.Northwest; } else if (e.Location.X <= validPixel && e.Location.Y >= this.Height - validPixel) { this.Cursor = Cursors.SizeNESW; direction = MouseDirection.Southwest; } else if (e.Location.X >= this.Width - validPixel && e.Location.Y <= validPixel) { this.Cursor = Cursors.SizeNESW; direction = MouseDirection.Northeast; } else { this.Cursor = Cursors.SizeAll; direction = MouseDirection.None; } if (e.Button == MouseButtons.Left) { OperatorForm.markOperation = MarkOperation.Modify; if (direction != MouseDirection.None)//改变大小 { { Point oldLocation = this.Location; ResizeControl(e.Location); } } else//移动位置 { { Point oldLocation = this.Location; this.Cursor = Cursors.SizeAll; Point location = GetPointToParent(new Point(e.Location.X - mouseDownPoint.X, e.Location.Y - mouseDownPoint.Y)); RelocationControl(location); } } } }
/// <summary> /// Creates a ControlItem invoked by a combination of keystroke & mouse dragging. /// /// <example><code>new ControlItem("Add a box selection", KeyCode.LeftShift, MouseDirection.Both, MouseButton.LeftClick);</code></example> /// </summary> public ControlItem(string description, KeyCode key, MouseDirection direction, MouseButton button) { this.description = description; this.direction = direction; this.button = button; this.keys = new KeyCode[1] { key }; }