Example #1
0
 private void HandlePointerReleased(PointerReleasedEventArgs 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.IsLeftUpAvailable())
             {
                 InputTarget.LeftUp(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.IsRightUpAvailable())
             {
                 InputTarget.RightUp(args);
             }
         }
     }
 }
 private void HandlePointerReleased(PointerReleasedEventArgs e)
 {
     if (e.MouseButton == MouseButton.Left)
     {
         if (this.DataContext is LayerContainerViewModel vm)
         {
             var point = AdjustGetPosition(e.GetPosition(RelativeTo));
             if (vm.Mode == EditMode.Mouse)
             {
                 vm.CurrentTool.LeftUp(vm, point.X, point.Y, GetModifier(e.InputModifiers));
             }
             else if (vm.Mode == EditMode.Touch)
             {
                 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.RightUp(vm, point.X, point.Y, GetModifier(e.InputModifiers));
         }
     }
 }
Example #3
0
        /// <inheritdoc />
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);
            Point mousePosition;

            if (IncreaseButton != null && IncreaseButton.IsEnabled == false)
            {
                mousePosition = e.GetPosition(IncreaseButton);
                if (mousePosition.X > 0 && mousePosition.X < IncreaseButton.Width &&
                    mousePosition.Y > 0 && mousePosition.Y < IncreaseButton.Height)
                {
                    e.Handled = true;
                }
            }

            if (DecreaseButton != null && DecreaseButton.IsEnabled == false)
            {
                mousePosition = e.GetPosition(DecreaseButton);
                if (mousePosition.X > 0 && mousePosition.X < DecreaseButton.Width &&
                    mousePosition.Y > 0 && mousePosition.Y < DecreaseButton.Height)
                {
                    e.Handled = true;
                }
            }
        }
        /// <summary>
        /// Invoked when an unhandled MouseUp routed event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. The event data reports that the mouse button was released.</param>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);
            if (e.Handled)
            {
                return;
            }

            e.Pointer.Capture(null);

            if (e.Pointer.Type == PointerType.Touch)
            {
                var position = e.GetPosition(this).ToScreenPoint();

                var touchEventArgs = new OxyTouchEventArgs()
                {
                    ModifierKeys     = e.KeyModifiers.ToModifierKeys(),
                    Position         = position,
                    DeltaTranslation = new ScreenVector(0, 0),
                    DeltaScale       = new ScreenVector(1, 1),
                };

                TouchPositions.Remove(e.Pointer.Id);

                if (TouchPositions.Count == 0)
                {
                    e.Handled = ActualController.HandleTouchCompleted(this, touchEventArgs);
                }
            }
            else
            {
                e.Handled = ActualController.HandleMouseUp(this, e.ToMouseReleasedEventArgs(this));

                // Open the context menu
                var p = e.GetPosition(this).ToScreenPoint();
                var d = p.DistanceTo(mouseDownPoint);

                if (ContextMenu != null)
                {
                    if (Math.Abs(d) < 1e-8 && e.InitialPressMouseButton == MouseButton.Right)
                    {
                        ContextMenu.DataContext = DataContext;
                        ContextMenu.IsVisible   = true;
                    }
                    else
                    {
                        ContextMenu.IsVisible = false;
                    }
                }
            }
        }
        private void DataGridColumnHeader_PointerReleased(object sender, PointerReleasedEventArgs e)
        {
            if (OwningColumn == null || e.Handled || !IsEnabled || e.MouseButton != MouseButton.Left)
            {
                return;
            }

            Point mousePosition = e.GetPosition(this);
            Point mousePositionHeaders = e.GetPosition(OwningGrid.ColumnHeaders);
            bool handled = e.Handled;
            OnMouseLeftButtonUp(ref handled, e, mousePosition, mousePositionHeaders);
            e.Handled = handled;

            ApplyState();
        }
Example #6
0
        /// <summary>
        /// handels pointer capturing on release
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            if (/*e.Pointer.Captured.*/ this.IsDragging)
            {
                e.Handled = true;
                // now we are in normal mode
                this.ClearValue(IsDraggingProperty);
                // release the captured mouse
                e.Pointer.Capture(null);
                //this.ReleaseMouseCapture();
                // get the current mouse position and call the completed event with the horizontal/vertical change
                PixelPoint currentMouseScreenPoint = this.PointToScreen(e.GetPosition(this));
                var        horizontalChange        = currentMouseScreenPoint.X - this.startDragScreenPoint.X;
                var        verticalChange          = currentMouseScreenPoint.Y - this.startDragScreenPoint.Y;

                var args = new VectorEventArgs()
                {
                    Handled     = false,
                    RoutedEvent = DragCompletedEvent,
                    Vector      = new Vector(horizontalChange, verticalChange)
                };

                this.RaiseEvent(args);
            }
        }
Example #7
0
        /// <summary>
        /// Invoked when an unhandled MouseUp routed event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. The event data reports that the mouse button was released.</param>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);
            if (e.Handled)
            {
                return;
            }

            var releasedArgs = (PointerReleasedEventArgs)e;

            ((TopLevel)this.VisualRoot).PlatformImpl.MouseDevice.Capture(null);

            e.Handled = ActualController.HandleMouseUp(this, releasedArgs.ToMouseReleasedEventArgs(this));

            // Open the context menu
            var p = e.GetPosition(this).ToScreenPoint();
            var d = p.DistanceTo(mouseDownPoint);

            if (ContextMenu != null)
            {
                if (Math.Abs(d) < 1e-8 && releasedArgs.InitialPressMouseButton == MouseButton.Right)
                {
                    ContextMenu.DataContext = DataContext;
                    ContextMenu.IsVisible   = true;
                }
                else
                {
                    ContextMenu.IsVisible = false;
                }
            }
        }
Example #8
0
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            previewPointVisible = true;

            var textView = TextView;

            var offset = _editor.GetOffsetFromPoint(e.GetPosition(this));

            if (offset != -1)
            {
                var lineClicked = -1;
                lineClicked = textView.Document.GetLineByOffset(offset).LineNumber; // convert from text line to visual line.

                var currentBreakPoint =
                    _manager.OfType <Breakpoint>().FirstOrDefault(bp => bp.FileName == _editor.Editor.SourceFile.FilePath && bp.Line == lineClicked) as BreakEvent;

                if (currentBreakPoint != null)
                {
                    _manager.Remove(currentBreakPoint);
                }
                else
                {
                    if (!string.IsNullOrEmpty(_editor.Editor.SourceFile.FilePath))
                    {
                        _manager.Add(_editor.Editor.SourceFile.FilePath, lineClicked);
                    }
                }
            }

            InvalidateVisual();
        }
Example #9
0
        private void Canvas_PointerReleased(object sender, PointerReleasedEventArgs e)
        {
            switch (e.MouseButton)
            {
            case MouseButton.Left:
            {
                var point = e.GetPosition(canvas);

                try
                {
                    _vm.Editor.LeftUp(point.X, point.Y);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
            }
            break;

            case MouseButton.Right:
                break;

            case MouseButton.Middle:
                break;
            }
        }
Example #10
0
        void TextAreaMouseUp(object sender, PointerReleasedEventArgs e)
        {
            if (mouseDownPos == null)
            {
                return;
            }
            Vector dragDistance = e.GetPosition(this) - mouseDownPos.Value;

            if (Math.Abs(dragDistance.X) < SystemParameters.MinimumHorizontalDragDistance &&
                Math.Abs(dragDistance.Y) < SystemParameters.MinimumVerticalDragDistance &&
                e.MouseButton == MouseButton.Left)
            {
                // click without moving mouse
                var referenceSegment = GetReferenceSegmentAtMousePosition(e.Device);
                if (referenceSegment == null)
                {
                    ClearLocalReferenceMarks();
                }
                else
                {
                    JumpToReference(referenceSegment);
                    textEditor.TextArea.ClearSelection();
                }
                // TODO: cancel mouse selection to avoid AvaloniaEdit selecting between the new
                // cursor position and the mouse position.
                //textEditor.TextArea.MouseSelectionMode = MouseSelectionMode.None;
            }
        }
 private void OnClick(object sender, PointerReleasedEventArgs e)
 {
     if (e.InitialPressMouseButton == MouseButton.Left &&
         this.GetVisualsAt(e.GetPosition(this)).Any(x => this == x || this.IsVisualAncestorOf(x)))
     {
         ViewModelClickHandler.OnLeftClick();
     }
 }
 /// <summary>
 /// Converts <see cref="MouseButtonEventArgs" /> to <see cref="OxyMouseEventArgs" /> for a mouse up 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 OxyMouseEventArgs ToMouseReleasedEventArgs(this PointerReleasedEventArgs e, IInputElement relativeTo)
 {
     return(new OxyMouseEventArgs
     {
         Position = e.GetPosition(relativeTo).ToScreenPoint(),
         ModifierKeys = e.InputModifiers.ToModifierKeys()
     });
 }
Example #13
0
 private void OnClick(object sender, PointerReleasedEventArgs e)
 {
     if (e.InitialPressMouseButton == MouseButton.Right &&
         this.GetVisualsAt(e.GetPosition(this)).Any(x => this == x || this.IsVisualAncestorOf(x)))
     {
         ClickHandler.OnRightClick(e.KeyModifiers == KeyModifiers.Control);
     }
 }
Example #14
0
        private void HandlePotentialDrop(object sender, PointerReleasedEventArgs e)
        {
            var pos = e.GetPosition(this);

            startPosition = new PixelPoint((int)(startPosition.X + pos.X - mouseOffsetToOrigin.X), (int)(startPosition.Y + pos.Y - mouseOffsetToOrigin.Y));
            ((Window)this.VisualRoot).Position = startPosition;
            isPointerPressed = false;
        }
Example #15
0
        private static void GraphCanvas_PointerReleased(object?sender, PointerReleasedEventArgs e)
        {
            var   canvas      = (Canvas)sender;
            Point mouseEndPos = e.GetPosition(canvas);

            Offset = new Point(mouseEndPos.X - mousePastyPos.X + Offset.X, mouseEndPos.Y - mousePastyPos.Y + Offset.Y);
            UpdateCanvas();
            mousePressed = false;
        }
 public void KeyboardPointerReleased(object sender, PointerReleasedEventArgs args)
 {
     if (keyboardPlayState != null)
     {
         var element = (TrackBackground)sender;
         keyboardPlayState.End(args.Pointer, args.GetPosition(element));
         keyboardPlayState = null;
     }
 }
Example #17
0
 public void DraggablePointerReleased(PointerReleasedEventArgs e)
 {
     if (e.Pointer.Captured == draggable)
     {
         dragOp !.Release(e.GetPosition(draggable));
         dragOp    = null;
         e.Handled = true;
     }
 }
Example #18
0
 protected override void OnPointerReleased(PointerReleasedEventArgs e)
 {
     if (e.InitialPressMouseButton == MouseButton.Left)
     {
         if (GetXButtonRect().Contains(e.GetPosition(this)))
         {
             _tab.Close();
         }
     }
     base.OnPointerReleased(e);
 }
Example #19
0
        private void Cleanup(object sender, PointerReleasedEventArgs e)
        {
            if (DragControl != null)
            {
                AdornerLayer.GetAdornerLayer(Source).Children.Remove(drawingCanvas);
            }

            (Source.VisualRoot.Renderer.HitTest(e.GetPosition(Source.VisualRoot), Source.VisualRoot, null).Where(x => x is IDragRecepticle).FirstOrDefault() as IDragRecepticle)?.EndDrag(this, e);
            Source.PointerMoved    -= DrawingLayer_PointerMoved;
            Source.PointerReleased -= Cleanup;
        }
Example #20
0
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);

            if (e.InitialPressMouseButton == MouseButton.Left &&
                ClickMode == ClickMode.Release &&
                this.GetVisualsAt(e.GetPosition(this)).Any(c => this == c || this.IsVisualAncestorOf(c)))
            {
                OnClick();
            }
        }
Example #21
0
        /// <inheritdoc/>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);

            e.Device.Capture(null);
            PseudoClasses.Remove(":pressed");
            e.Handled = true;

            if (ClickMode == ClickMode.Release && new Rect(Bounds.Size).Contains(e.GetPosition(this)))
            {
                RaiseClickEvent();
            }
        }
Example #22
0
 protected override void OnPointerReleased(PointerReleasedEventArgs e)
 {
     if (e.InitialPressMouseButton == MouseButton.Left && e.Pointer.Type != PointerType.Mouse)
     {
         var container = GetContainerFromEventSource(e.Source);
         if (container != null &&
             container.GetVisualsAt(e.GetPosition(container))
             .Any(c => container == c || container.IsVisualAncestorOf(c)))
         {
             e.Handled = UpdateSelectionFromEventSource(e.Source);
         }
     }
 }
Example #23
0
 private void PointerReleasedHandler(object?sender, PointerReleasedEventArgs e)
 {
     if (_captured)
     {
         var position           = e.GetPosition(this);
         var cursorHitTestRect  = GetXAxisCursorHitTestRect();
         var cursorSizeWestEast = cursorHitTestRect.Contains(position);
         if (!cursorSizeWestEast)
         {
             Cursor = new Cursor(StandardCursorType.Arrow);
         }
         _captured = false;
     }
 }
        private void Canvas_PointerReleased(object sender, PointerReleasedEventArgs e)
        {
            var point = e.GetPosition(_canvas);

            try
            {
                _vm.Editor.LeftUp(point.X, point.Y);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }
        }
Example #25
0
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            if (_lastPoint.HasValue)
            {
                e.Device.Capture(null);
                _lastPoint = null;

                var ev = new VectorEventArgs
                {
                    RoutedEvent = DragCompletedEvent,
                    Vector      = (Vector)e.GetPosition(this),
                };

                RaiseEvent(ev);
            }
        }
Example #26
0
        /// <inheritdoc/>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);

            if (IsPressed && e.MouseButton == MouseButton.Left)
            {
                e.Device.Capture(null);
                IsPressed = false;
                e.Handled = true;

                if (ClickMode == ClickMode.Release && new Rect(Bounds.Size).Contains(e.GetPosition(this)))
                {
                    OnClick();
                }
            }
        }
Example #27
0
        /// <inheritdoc/>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);

            if (IsPressed && e.MouseButton == MouseButton.Left)
            {
                IsPressed = false;
                e.Handled = true;

                if (ClickMode == ClickMode.Release &&
                    this.GetVisualsAt(e.GetPosition(this)).Any(c => this == c || this.IsVisualAncestorOf(c)))
                {
                    OnClick();
                }
            }
        }
        /// <summary>
        /// Handles the <see cref="E:PointerReleased" /> event.
        /// </summary>
        /// <param name="e">The <see cref="PointerReleasedEventArgs" /> instance containing the event data.</param>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);

            if (e.GetCurrentPoint(null).Properties.PointerUpdateKind == PointerUpdateKind.LeftButtonReleased)
            {
                var hoveredItemContent = GetHoveredItem(e.GetPosition(this))?.Content;
                if (draggedItemContent != null && hoveredItemContent != null && hoveredItemContent != draggedItemContent)
                {
                    ItemDragged?.Invoke(draggedItemContent, hoveredItemContent);
                }
                ClearDragStyles();
                draggedItemContent = null;
                Cursor             = originalCursor;
            }
        }
Example #29
0
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            if (_lastPoint.HasValue)
            {
                e.Handled  = true;
                _lastPoint = null;

                var ev = new VectorEventArgs
                {
                    RoutedEvent = DragCompletedEvent,
                    Vector      = (Vector)e.GetPosition(this),
                };

                RaiseEvent(ev);
            }

            PseudoClasses.Remove(":pressed");
        }
Example #30
0
        /// <inheritdoc/>
        protected override void OnPointerReleased(PointerReleasedEventArgs e)
        {
            base.OnPointerReleased(e);

            if (IsPressed && e.MouseButton == MouseButton.Left)
            {
                e.Device.Capture(null);
                IsPressed = false;
                e.Handled = true;

                var hittest = this.GetVisualsAt(e.GetPosition(this));

                if (ClickMode == ClickMode.Release &&
                    hittest.Any(c => c == this || (c as IStyledElement)?.TemplatedParent == this))
                {
                    OnClick();
                }
            }
        }