private DragDropHandler(PointerPressedEventArgs e, string dragTypeIdentifier, Control dragControl = null, object dragContext = null, Vector clickOffset = default) { if (!(e.Source is IControl)) { return; } Source = e.Source as IControl; Source.PointerMoved += DrawingLayer_PointerMoved; Source.PointerReleased += Cleanup; if (dragControl != null) { drawingCanvas.Children.Add(dragControl); AdornerLayer.GetAdornerLayer(Source).Children.Add(drawingCanvas); Canvas.SetTop(dragControl, e.GetPosition(drawingCanvas).Y - clickOffset.Y); Canvas.SetLeft(dragControl, e.GetPosition(drawingCanvas).X - clickOffset.X); } this.DragControl = dragControl; this.DragContext = dragContext; this.DragTypeIdentifier = dragTypeIdentifier; this.ClickOffset = clickOffset; }
private void HandlePointerPressed(PointerPressedEventArgs e) { var properties = e.GetCurrentPoint(RelativeTo).Properties; if (properties.IsLeftButtonPressed) { if (InputTarget != null) { var point = AdjustGetPosition(e.GetPosition(RelativeTo)); var args = new InputArgs(point.X, point.Y, GetModifier(e.KeyModifiers)); if (InputTarget.IsLeftDownAvailable()) { InputTarget.LeftDown(args); } } } else if (properties.IsRightButtonPressed) { if (InputTarget != null) { var point = AdjustGetPosition(e.GetPosition(RelativeTo)); var args = new InputArgs(point.X, point.Y, GetModifier(e.KeyModifiers)); if (InputTarget.IsRightDownAvailable()) { InputTarget.RightDown(args); } } } }
private void HandlePointerPressed(PointerPressedEventArgs e) { if (e.MouseButton == MouseButton.Left) { if (InputTarget != null) { var point = AdjustGetPosition(e.GetPosition(RelativeTo)); var args = new InputArgs(point.X, point.Y, GetModifier(e.InputModifiers)); if (InputTarget.IsLeftDownAvailable()) { InputTarget.LeftDown(args); } } } else if (e.MouseButton == MouseButton.Right) { if (InputTarget != null) { var point = AdjustGetPosition(e.GetPosition(RelativeTo)); var args = new InputArgs(point.X, point.Y, GetModifier(e.InputModifiers)); if (InputTarget.IsRightDownAvailable()) { InputTarget.RightDown(args); } } } }
private void Canvas_PointerPressed(object sender, PointerPressedEventArgs e) { switch (e.MouseButton) { case MouseButton.Left: { canvas.Focus(); var point = e.GetPosition(canvas); try { _vm.Editor.LeftDown(point.X, point.Y); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } break; case MouseButton.Right: { canvas.Focus(); var point = e.GetPosition(canvas); try { _vm.Editor.RightDown(point.X, point.Y); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } break; case MouseButton.Middle: { canvas.Focus(); var point = e.GetPosition(canvas); try { _vm.Editor.MiddleDown(point.X, point.Y); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } break; } }
private void Canvas_PointerPressed(object sender, PointerPressedEventArgs e) { var props = e.GetPointerPoint(_canvas).Properties; if (props.IsLeftButtonPressed) { _canvas.Focus(); var point = e.GetPosition(_canvas); try { _vm.Editor.LeftDown(point.X, point.Y); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } else if (props.IsRightButtonPressed) { _canvas.Focus(); var point = e.GetPosition(_canvas); try { _vm.Editor.RightDown(point.X, point.Y); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } else if (props.IsMiddleButtonPressed) { _canvas.Focus(); var point = e.GetPosition(_canvas); try { _vm.Editor.MiddleDown(point.X, point.Y); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } }
protected override void OnPointerPressed(PointerPressedEventArgs e) { base.OnPointerPressed(e); pressed = true; var line = new AuraLine(); currentShape = line; line.HandleStart(e.GetPosition(this)); line.HandleEnd(e.GetPosition(this)); shapes.Add(line); InvalidateVisual(); }
private void PointerPressedHandler(object sender, PointerPressedEventArgs e) { if (sender is ListBox source) { _dragStart = e.GetPosition(source); if (source.Name == "ModList") { _modSourceItem = GetPointerItem(source); if (_modSourceItem is null) { source.SelectedItem = null; } } if (source.Name == "ModpackList") { _modpackSourceItem = GetPointerItem(source); if (_modpackSourceItem is null) { source.SelectedItem = null; } } } }
protected override void OnPointerPressed(PointerPressedEventArgs e) { var point = e.GetPosition(_presenter); var index = CaretIndex = _presenter.GetCaretIndex(point); var text = Text; if (text != null) { switch (e.ClickCount) { case 1: SelectionStart = SelectionEnd = index; break; case 2: if (!StringUtils.IsStartOfWord(text, index)) { SelectionStart = StringUtils.PreviousWord(text, index); } SelectionEnd = StringUtils.NextWord(text, index); break; case 3: SelectionStart = 0; SelectionEnd = text.Length; break; } } e.Device.Capture(_presenter); e.Handled = true; }
protected override void OnPointerPressed(PointerPressedEventArgs e) { var pointer = e.GetPosition(this); var position = ToPosition(pointer); var textPosition = position.OffsetBy(0, ViewTop); if (!Connected || (Connected && !Terminal.X10SendMouseXYOnButton && !Terminal.X11SendMouseXYOnButton && !Terminal.SgrMouseMode && !Terminal.CellMotionMouseTracking && !Terminal.UseAllMouseTracking)) { if (e.InputModifiers.HasFlag(InputModifiers.LeftMouseButton)) { MousePressedAt = textPosition; } else if (e.InputModifiers.HasFlag(InputModifiers.RightMouseButton)) { PasteClipboard(); } } if (Connected && position.Column >= 0 && position.Row >= 0 && position.Column < Columns && position.Row < Rows) { var controlPressed = e.InputModifiers.HasFlag(InputModifiers.Control); var shiftPressed = e.InputModifiers.HasFlag(InputModifiers.Shift); var button = e.InputModifiers.HasFlag(InputModifiers.LeftMouseButton) ? 0 : e.InputModifiers.HasFlag(InputModifiers.RightMouseButton) ? 1 : 2; // Middle button Terminal.MousePress(position.Column, position.Row, button, controlPressed, shiftPressed); } }
private static void GraphCanvas_PointerPressed(object?sender, PointerPressedEventArgs e) { var canvas = (Canvas)sender; mousePastyPos = e.GetPosition(canvas); mousePressed = true; }
// 鼠标按下 protected override void OnPointerPressed(PointerPressedEventArgs e) { base.OnPointerPressed(e); if (e.MouseButton != MouseButton.Left) { return; } // 所在面板无法在构造函数里求得 if (parentIVisual == null) { parentIVisual = this.Parent.Parent.Parent; } isPressed = true; pressPoint = e.GetPosition(parentIVisual); oldLocation = new Point(NetworkItemVM.X, NetworkItemVM.Y); // 记录每个锚点的旧位置 if (NetworkItemVM.ConnectorVMs != null) { foreach (Connector_VM connectorVM in NetworkItemVM.ConnectorVMs) { connectorVM.OldPos = connectorVM.Pos; } } //ResourceManager.mainWindowVM.Tips = "鼠标按下,记录图形位置:" + oldLocation; e.Handled = true; }
/* todo: maybe have to handle oncapturelost, doing some type of pointer release stuff, in case an ancestor steals control * https://github.com/AvaloniaUI/Avalonia/issues/2586 */ public void DraggablePointerPressed(PointerPressedEventArgs e) { /* * if a descendant is pressed, * it will be the "captured" control for the life of the drag operation, * so rn we are transferring capture. * if this ever doesn't work i think we can just fix it by listening for * InputElement.PointerMoved and InputElement.PointerReleased events even with the Handled property set to true */ if (dragOp != null) { /* this is likely A: * common(unavoidable?) issue where a pointer release event is not fired. * or B: * this is a different pointing device from the first. * EITHER WAY the easiest way to handle this is to just: * CANCEL the old drag. */ dragOp.Dispose(); dragOp = null; draggable.InvalidateVisual(); e.Pointer.Capture(null); } else { if (e.Pointer.Captured != draggable) { e.Pointer.Capture(draggable); } dragOp = dragFactory(draggable, e.GetPosition(draggable)); } e.Handled = true; }
private void MousePressed(object sender, PointerPressedEventArgs e) { var pos = e.GetPosition(image); var newPos = new Point(((int)pos.X) / pixelsize * pixelsize, ((int)pos.Y) / pixelsize * pixelsize); Canvas.SetTop(rect[0], newPos.Y - 160); Canvas.SetLeft(rect[0], newPos.X); Canvas.SetTop(rect[1], newPos.Y - 160 + 18); Canvas.SetLeft(rect[1], newPos.X); Canvas.SetTop(rect[2], newPos.Y - 160 + 2); Canvas.SetLeft(rect[2], newPos.X); Canvas.SetTop(rect[3], newPos.Y - 160 + 2); Canvas.SetLeft(rect[3], newPos.X + pixelsize - 2); var vm = DataContext as MainWindowViewModel; positionInPalette = (int)newPos.X / pixelsize + (int)(newPos.Y) / pixelsize * 32; var color = vm.File.Palette.ArrayPaletten[vm.File.Palette.ActualPalette, positionInPalette]; byte r, g, b, a; Utility.ReadColor(color, out r, out g, out b, out a); vm.ColorAsText = "#" + a.ToString("X2") + r.ToString("X2") + g.ToString("X2") + b.ToString("X2"); vm.Red = r; vm.Green = g; vm.Blue = b; }
private void CallerPanel_OnPointerPressed(object sender, PointerPressedEventArgs e) { Pointers.Push(e.Pointer); var panel = sender as Control; var pointer = e.GetPosition(panel); CallerPanel_OnPointerPressOrMove(panel, pointer); }
public void SetupInitialValues(PointerPressedEventArgs e, Control parent) { Width = 0; Height = 0; var pointer = e.GetPosition(parent); Margin = new Thickness(pointer.X, pointer.Y, 0, 0); }
private void PointerPressedHandler(object?sender, PointerPressedEventArgs e) { var position = e.GetPosition(this); UpdateXAxisCursorPosition(position.X); Cursor = new Cursor(StandardCursorType.SizeWestEast); _captured = true; }
public void RunFirstStep(PointerPressedEventArgs e, Control parent) { Width = maxDiam; Height = maxDiam; var pointer = e.GetPosition(parent); Margin = new Thickness(-endX / 2, -endY / 2, 0, 0); }
private void element_PointerPressedEvent(object sender, PointerPressedEventArgs e) { if (e.GetPointerUpdateKind() == PointerUpdateKind.LeftButtonPressed) { start_point = e.GetPosition(element); is_dragging = false; } }
protected override void OnPointerPressed(PointerPressedEventArgs e) { e = e.ThrowIfNull(nameof(e)); PressPoint = e.GetPosition(this).ToPixelPoint(); IsPointerPressed = true; base.OnPointerPressed(e); }
protected override void OnPointerPressed(PointerPressedEventArgs e) { if (e.Source.InteractiveParent.InteractiveParent == TextView) { var point = e.GetPosition(TextView.TextSurface); var index = TextView.GetOffsetFromPoint(point); if (index != -1) { CaretIndex = index; var text = TextDocument; switch (e.ClickCount) { case 1: SelectionStart = SelectionEnd = index; break; case 2: SelectionStart = TextUtilities.GetNextCaretPosition(TextDocument, index, TextUtilities.LogicalDirection.Backward, TextUtilities.CaretPositioningMode.WordStart); SelectionEnd = TextUtilities.GetNextCaretPosition(TextDocument, index, TextUtilities.LogicalDirection.Forward, TextUtilities.CaretPositioningMode.WordBorder); break; case 3: SelectionStart = 0; SelectionEnd = text.TextLength; break; } e.Device.Capture(TextView); e.Handled = true; InvalidateVisual(); if (CaretChangedByPointerClick != null) { CaretChangedByPointerClick(this, e); } } else if (TextDocument?.TextLength == 0) { SelectionStart = SelectionEnd = CaretIndex = 0; e.Device.Capture(TextView); e.Handled = true; InvalidateVisual(); } SetHighestColumn(); } }
#pragma warning disable private void OnPointerPressed(object _, PointerPressedEventArgs e) { if (e.MouseButton != MouseButton.Left) { return; } e.Handled = true; LastPoint = e.GetPosition(AssociatedObject); }
public void BeginPan(object sender, PointerPressedEventArgs args) { var transform = (TranslateTransform)((TransformGroup)image.RenderTransform) .Children.First(x => x is TranslateTransform); start = args.GetPosition(this); origin = new Point(transform.X, transform.Y); panning = true; }
//User has selected a pixel to draw to public void IconMouseDown(IVisual sender, PointerPressedEventArgs e) { int XposOriginal = (int)e.GetPosition(sender).X / 11; int YposOriginal = (int)e.GetPosition(sender).Y / 11; int Xpos = (int)e.GetPosition(sender).X / 11; int Ypos = (int)e.GetPosition(sender).Y / 11; if (Xpos > 15) { Xpos = 15; } if (Ypos > 15) { Ypos = 15; } if (Xpos < 0) { Xpos = 0; } if (Ypos < 0) { Ypos = 0; } XText = "X: " + Xpos.ToString(); YText = "Y: " + Ypos.ToString(); //Draw pixels if arrow is in range and left mouse button is pressed if (XposOriginal >= 0 && XposOriginal <= 15 && YposOriginal >= 0 && YposOriginal <= 15) { //Color with first selected color if (e.KeyModifiers == KeyModifiers.None) { putPixel(Xpos, Ypos, 0); } //Color with second selected colro if (e.KeyModifiers == KeyModifiers.Control) { putPixel(Xpos, Ypos, 1); } } }
private void HandlePointerPressed(PointerPressedEventArgs e) { if (e.MouseButton == MouseButton.Left) { if (this.DataContext is LayerContainerViewModel vm) { var point = AdjustGetPosition(e.GetPosition(RelativeTo)); vm.CurrentTool.LeftDown(vm, point.X, point.Y, GetModifier(e.InputModifiers)); } } else if (e.MouseButton == MouseButton.Right) { if (this.DataContext is LayerContainerViewModel vm) { var point = AdjustGetPosition(e.GetPosition(RelativeTo)); vm.CurrentTool.RightDown(vm, point.X, point.Y, GetModifier(e.InputModifiers)); } } }
/// <summary> /// Converts <see cref="MouseButtonEventArgs" /> to <see cref="OxyMouseEventArgs" /> for a mouse down event. /// </summary> /// <param name="e">The <see cref="MouseButtonEventArgs" /> instance containing the event data.</param> /// <param name="relativeTo">The <see cref="IInputElement" /> that the event is relative to.</param> /// <returns>A <see cref="OxyMouseEventArgs" /> containing the converted event arguments.</returns> public static OxyMouseDownEventArgs ToMouseDownEventArgs(this PointerPressedEventArgs e, IInputElement relativeTo) { return(new OxyMouseDownEventArgs { ChangedButton = e.MouseButton.Convert(), ClickCount = e.ClickCount, Position = e.GetPosition(relativeTo).ToScreenPoint(), ModifierKeys = e.InputModifiers.ToModifierKeys() }); }
private void ColorCanvas_PointerPressed(object sender, PointerPressedEventArgs e) { var position = e.GetPosition(_colorCanvas); _updating = true; MoveThumb(_colorCanvas, _colorThumb, position.X, position.Y); UpdateValuesFromThumbs(); UpdateColorFromThumbs(); _updating = false; _captured = true; }
private void PointerPressedHandler(object sender, PointerPressedEventArgs e) { var p = e.GetPosition(ParentContainer); var x = (int)(Math.Round(p.X + 7) / 15) * 15; var y = (int)(Math.Round(p.Y + 7) / 15) * 15; var point = new Point(x, y); ViewModel.CurrentPoint = point; }
void AlphaCanvas_PointerPressed(object?sender, PointerPressedEventArgs e) { var position = e.GetPosition(alphaCanvas); updating = true; MoveThumb(alphaCanvas, alphaThumb, position.X, 0); UpdateValuesFromThumbs(); UpdateColorFromThumbs(); updating = false; captured = true; }
void HueCanvas_PointerPressed(object?sender, PointerPressedEventArgs e) { var position = e.GetPosition(hueCanvas); updating = true; MoveThumb(hueCanvas, hueThumb, 0, position.Y); UpdateValuesFromThumbs(); UpdateColorFromThumbs(); updating = false; captured = true; }
private void MouseDownCanvas(object sender, PointerPressedEventArgs args) { if (!args.GetCurrentPoint(this).Properties.IsRightButtonPressed) { return; } _last = args.GetPosition(this); Cursor = new Cursor(StandardCursorType.Hand); isDragged = true; }