Example #1
0
        private async void DoDrag(object?sender, Avalonia.Input.PointerPressedEventArgs e)
        {
            DataObject dragData = new DataObject();

            dragData.Set(DataFormats.Text, $"You have dragged text {++DragCount} times");
            var result = await DragDrop.DoDragDrop(e, dragData, DragDropEffects.Copy);

            switch (result)
            {
            case DragDropEffects.Copy:
                if (_DragState != null)
                {
                    _DragState.Text = "The text was copied";
                }
                break;

            case DragDropEffects.Link:
                if (_DragState != null)
                {
                    _DragState.Text = "The text was linked";
                }
                break;

            case DragDropEffects.None:
                if (_DragState != null)
                {
                    _DragState.Text = "The drag operation was canceled";
                }
                break;
            }
        }
 private void OnPointerPressed(object?sender, Avalonia.Input.PointerPressedEventArgs e)
 {
     if ((sender as Border)?.DataContext is not string ctx)
     {
         throw new Exception("Sample not found");
     }
     LoadContent(ctx.Replace('/', '.'));
 }
Example #3
0
        /// <inheritdoc/>
        protected override void OnPointerPressed(PointerPressedEventArgs e)
        {
            base.OnPointerPressed(e);

            if (e.MouseButton == MouseButton.Left)
            {
                e.Handled = UpdateSelectionFromEventSource(e.Source);
            }
        }
Example #4
0
        /// <summary>
        /// Captura os eventos do Ponteiro ao pressionar
        /// </summary>
        public void OnPointerPressed(object sender, Avalonia.Input.PointerPressedEventArgs e)
        {
            //var s = sender as IInputElement;
            //e.Pointer.Capture(s);
            //isPressed = true;
            //var o  = e.GetPosition(s);
            //origin = new Point(o.X, o.Y);

            //MassSpringIncludeWindow msiw = new MassSpringIncludeWindow();
            //msiw.Show();
        }
Example #5
0
        protected override void OnPointerPressed(PointerPressedEventArgs e)
        {
            e.Device.Capture(this);
            _lastPoint = e.GetPosition(this);

            var ev = new VectorEventArgs
            {
                RoutedEvent = DragStartedEvent,
                Vector = (Vector)_lastPoint,
            };

            RaiseEvent(ev);
        }
Example #6
0
		protected override void OnPointerPressed(PointerPressedEventArgs e)
		{
			if (topHorizontalGrip.IsPointerOver)
			{
				BeginResizeDrag(WindowEdge.North);
			}
			else if (bottomHorizontalGrip.IsPointerOver)
			{
				BeginResizeDrag(WindowEdge.South);
			}
			else if (leftVerticalGrip.IsPointerOver)
			{
				BeginResizeDrag(WindowEdge.West);
			}
			else if (rightVerticalGrip.IsPointerOver)
			{
				BeginResizeDrag(WindowEdge.East);
			}
			else if (topLeftGrip.IsPointerOver)
			{
				BeginResizeDrag(WindowEdge.NorthWest);
			}
			else if (bottomLeftGrip.IsPointerOver)
			{
				BeginResizeDrag(WindowEdge.SouthWest);
			}
			else if (topRightGrip.IsPointerOver)
			{
				BeginResizeDrag(WindowEdge.NorthEast);
			}
			else if (bottomRightGrip.IsPointerOver)
			{
				BeginResizeDrag(WindowEdge.SouthEast);
			}
			else if (titleBar.IsPointerOver)
			{
				mouseDown = true;
				mouseDownPosition = e.GetPosition(this);
			}
			else
			{
				mouseDown = false;
			}


			base.OnPointerPressed(e);
		}
Example #7
0
    private void ChartPointerPressed(object?sender, Avalonia.Input.PointerPressedEventArgs e)
    {
        var chart     = this.FindControl <CartesianChart>("chart");
        var viewModel = DataContext as ViewModel;

        // gets the point in the UI coordinates.
        var p = e.GetPosition(chart);

        // scales the UI coordintaes to the corresponging data in the chart.
        // ScaleUIPoint retuns an array of double
        var scaledPoint = chart.ScaleUIPoint(new LvcPoint((float)p.X, (float)p.Y));

        // where the X coordinate is in the first position
        var x = scaledPoint[0];

        // and the Y coordinate in the second position
        var y = scaledPoint[1];

        // finally add the new point to the data in our chart.
        viewModel?.Data.Add(new ObservablePoint(x, y));
    }
Example #8
0
        private void PointerPressedOutside(object sender, PointerPressedEventArgs e)
        {
            if (!StaysOpen)
            {
                var root = ((IVisual)e.Source).GetVisualRoot();

                if (root != this.PopupRoot)
                {
                    Close();
                    e.Handled = true;
                }
            }
        }
Example #9
0
        /// <inheritdoc/>
        protected override void OnPointerPressed(PointerPressedEventArgs e)
        {
            base.OnPointerPressed(e);

            if (e.MouseButton == MouseButton.Left || e.MouseButton == MouseButton.Right)
            {
                e.Handled = UpdateSelectionFromEventSource(
                    e.Source,
                    true,
                    (e.InputModifiers & InputModifiers.Shift) != 0,
                    (e.InputModifiers & InputModifiers.Control) != 0);
            }
        }
Example #10
0
 private void BottomRightCorner_PointerPressed(object?sender, Avalonia.Input.PointerPressedEventArgs e)
 {
     BeginResize?.Invoke(this, e);
 }
Example #11
0
        /// <inheritdoc/>
        protected override void OnPointerPressed(PointerPressedEventArgs e)
        {
            if (!IsDropDownOpen && ((IVisual)e.Source).GetVisualRoot() != typeof(PopupRoot))
            {
                IsDropDownOpen = true;
                e.Handled = true;
            }

            if (!e.Handled)
            {
                if (UpdateSelectionFromEventSource(e.Source))
                {
                    _popup?.Close();
                    e.Handled = true;
                }
            }

            base.OnPointerPressed(e);
        }
Example #12
0
        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();
            }
        }
Example #13
0
        /// <summary>
        /// Called when the pointer is pressed over the <see cref="MenuItem"/>.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected override void OnPointerPressed(PointerPressedEventArgs e)
        {
            base.OnPointerPressed(e);

            if (!HasSubMenu)
            {
                RaiseEvent(new RoutedEventArgs(ClickEvent));
            }
            else if (IsTopLevel)
            {
                IsSubMenuOpen = !IsSubMenuOpen;
            }
            else
            {
                IsSubMenuOpen = true;
            }

            e.Handled = true;
        }
Example #14
0
        /// <summary>
        /// Called when the pointer is pressed anywhere on the window.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event args.</param>
        private void TopLevelPreviewPointerPress(object sender, PointerPressedEventArgs e)
        {
            if (IsOpen)
            {
                var control = e.Source as ILogical;

                if (!this.IsLogicalParentOf(control))
                {
                    Close();
                }
            }
        }
Example #15
0
        private bool MouseDown(IMouseDevice device, uint timestamp, IInputElement root, Point p, MouseButton button, InputModifiers inputModifiers)
        {
            var hit = HitTest(root, p);

            if (hit != null)
            {
                IInteractive source = GetSource(hit);

                if (source != null)
                {
                    var settings = AvaloniaLocator.Current.GetService<IPlatformSettings>();
                    var doubleClickTime = settings.DoubleClickTime.TotalMilliseconds;

                    if (!_lastClickRect.Contains(p) || timestamp - _lastClickTime > doubleClickTime)
                    {
                        _clickCount = 0;
                    }

                    ++_clickCount;
                    _lastClickTime = timestamp;
                    _lastClickRect = new Rect(p, new Size())
                        .Inflate(new Thickness(settings.DoubleClickSize.Width / 2, settings.DoubleClickSize.Height / 2));

                    var e = new PointerPressedEventArgs
                    {
                        Device = this,
                        RoutedEvent = InputElement.PointerPressedEvent,
                        Source = source,
                        ClickCount = _clickCount,
                        MouseButton = button,
                        InputModifiers = inputModifiers
                    };

                    source.RaiseEvent(e);
                    return e.Handled;
                }
            }

            return false;
        }
Example #16
0
 /// <inheritdoc/>
 protected override void OnPointerPressed(PointerPressedEventArgs e)
 {
     // Ignore pointer presses.
 }
 private void Border_PointerPressed(object sender, PointerPressedEventArgs e)
 {
     switch (e.MouseButton)
     {
         case MouseButton.Right:
             {
                 if (_element != null)
                 {
                     Point point = e.GetPosition(_element);
                     point = FixInvalidPointPosition(point);
                     StartPan(point);
                     e.Device.Capture(_element);
                 }
             }
             break;
     }
 }
Example #18
0
 /// <summary>
 /// Called before the <see cref="PointerPressed"/> event occurs.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnPointerPressed(PointerPressedEventArgs e)
 {
 }
Example #19
0
        /// <inheritdoc/>
        protected override void OnPointerPressed(PointerPressedEventArgs e)
        {
            base.OnPointerPressed(e);

            PseudoClasses.Add(":pressed");
            e.Device.Capture(this);
            e.Handled = true;

            if (ClickMode == ClickMode.Press)
            {
                RaiseClickEvent();
            }
        }
 protected override void OnPointerPressed(PointerPressedEventArgs e)
 {
     _mouseDown = true;
     base.OnPointerPressed(e);
 }
Example #21
0
 /// <summary>
 /// Called before the <see cref="PointerPressed"/> event occurs.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnPointerPressed(PointerPressedEventArgs e)
 {
 }