Ejemplo n.º 1
0
        /// <summary>
        /// Trigger a dragging event when the user moves the mouse while the left mouse button is pressed
        /// </summary>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (_userClickedThisElement && !_dragActive)
            {
                _dragActive = true;
                DragStart?.Invoke(this, e);
            }

            if (_dragActive)
            {
                Point curMouseScreenPos = e.GetPosition(this);

                if (!curMouseScreenPos.Equals(_previousMouseScreenPos))
                {
                    double xDelta = curMouseScreenPos.X - _previousMouseScreenPos.X;
                    double yDelta = curMouseScreenPos.Y - _previousMouseScreenPos.Y;

                    var dragEvent = new DragMoveEventArgs(e, xDelta, yDelta);
                    DragMove?.Invoke(this, dragEvent);

                    ApplyDragToChildren(dragEvent);

                    _previousMouseScreenPos = curMouseScreenPos;
                }
            }

            base.OnMouseMove(e);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Raises the DragStart event.
        /// </summary>
        /// <param name="mousePt">Mouse point at time of event.</param>
        /// <param name="offset">Offset of mouse compared to element.</param>
        /// <param name="c">Control that starts the drag operation.</param>
        protected virtual void OnDragStart(Point mousePt, Point offset, Control c)
        {
            // Convert point from client to screen coordinates
            mousePt = Target.OwningControl.PointToScreen(mousePt);
            DragStartEventCancelArgs ce = new(mousePt, offset, c);

            DragStart?.Invoke(this, ce);

            // If event is not cancelled then allow dragging
            _dragging = !ce.Cancel;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Handler para this.MouseDown
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MDown(object sender, MouseEventArgs e)
 {
     // Aqui invocamos nossos eventos custom para escapar da estrutura imposta pela framework
     // para checar o andamento de uma operação drag & drop
     if (DragStart != null)
     {
         DragStart.Invoke(this, e);
     }
     this.DoDragDrop(this.Tarefa, DragDropEffects.Move);
     if (DragEnd != null)
     {
         DragEnd.Invoke(this, e);
     }
 }
Ejemplo n.º 4
0
    private void StartDrag(RaycastHit forHitInfo)
    {
        if (forHitInfo.rigidbody != null && !forHitInfo.rigidbody.isKinematic)
        {
            IsDragging = true;

            _currentDraggable      = forHitInfo.rigidbody;
            _initialDragValue      = _currentDraggable.drag;
            _currentDraggable.drag = 10;
            _dragStartCameraPos    = Camera.main.transform.position;

            Cursor.visible   = false;
            Cursor.lockState = CursorLockMode.Confined;

            DragStart?.Invoke(_currentDraggable.gameObject);
        }
    }
Ejemplo n.º 5
0
        private void dragField_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragStart?.Invoke(this, EventArgs.Empty);
                DragDropEffects ef = DragDrop.DoDragDrop(this, Id + "\n" + BaseString + "\n" + TranslatedString, DragDropEffects.Move);
                DragEnd?.Invoke(this, EventArgs.Empty);

                if (ef == DragDropEffects.None)
                {
                    // no drop happened
                }
                else
                {
                    // drop happened
                }
            }
        }
Ejemplo n.º 6
0
        private void TargetWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (CanDragStart != null && !CanDragStart.Invoke())
            {
                return;
            }

            if (hHook == IntPtr.Zero)
            {
                ptDragStart = Win32.GetCursorPos();
                ptMaxDiff   = new Point(0, 0);
                bDragStart  = true;
                SetHook();
                DragStart?.Invoke(this, new EventArgs());
            }
            else
            {
                UnHook();
            }
        }
Ejemplo n.º 7
0
        private void Update()
        {
            if (EventSystem.current && EventSystem.current.currentSelectedGameObject)
            {
                return;
            }

            NormalizedDeltaInput = Vector3.zero;
            NormalizedGroundAlignedDeltaInput = Vector3.zero;
            var isInput = IsInput;

            switch (isInput)
            {
            case true:
                var inputPos = InputPos;
                if (_lastPos.HasValue)      // Continue Drag
                {
                    var delta           = inputPos - _lastPos.Value;
                    var normalizedDelta = delta / _screenWidth;

                    Drag?.Invoke(delta);
                    DragNormalized?.Invoke(normalizedDelta);

                    NormalizedDeltaInput = normalizedDelta;
                    NormalizedGroundAlignedDeltaInput = new Vector3(NormalizedDeltaInput.x, 0, NormalizedDeltaInput.y);
                }
                else        // Start Drag
                {
                    DragStart?.Invoke(inputPos);
                }

                _lastPos = inputPos;
                break;

            // Stop Drag
            case false when _lastPos.HasValue:
                _lastPos = null;
                DragEnd?.Invoke();
                break;
            }
        }
Ejemplo n.º 8
0
        private void Source_MouseMove(object s, MouseEventArgs e)
        {
            if (IsInitialized())
            {
                if (!IsDragging)
                {
                    if (IsMouseDetecting)
                    {
                        // Get the current mouse position
                        Point  mousePos = e.GetPosition(null);
                        Vector diff     = StartPoint - mousePos;

                        if (e.LeftButton == MouseButtonState.Pressed &&
                            Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                            Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
                        {
                            DragStartEventArgs ea = new DragStartEventArgs();

                            // Invoke the DragStart event on the source to allow it to set the package contents.
                            DragStart.GetInvocationList().Where(d => d.Target == s).First().DynamicInvoke(ea);

                            DataObject dragData = new DataObject(Name, ea.Package);

                            IsMouseDetecting = false;
                            IsDragging       = true;
                            currentSource    = s as UIElement;

                            // This blocks until the drop operation completes.
                            System.Windows.DragDrop.DoDragDrop((s as UIElement), dragData, DragDropEffects.Move | DragDropEffects.None);

                            IsDragging    = false;
                            currentSource = null;
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public override void OnMouseButton(MouseButton button, Vector2 currentPosition, ButtonState buttonState)
        {
            if (button == MouseButton.Left)
            {
                if (buttonState == ButtonState.Pressed)
                {
                    if (this.hoverable.IsHovered && !IsDragging)
                    {
                        IsDragging = true;
                        this.accumulatedDragDelta = Vector2.Zero;
                        DragStart?.Invoke(currentPosition, this.accumulatedDragDelta);
                    }
                }
                else
                {
                    if (IsDragging)
                    {
                        DragEnd?.Invoke(currentPosition, this.accumulatedDragDelta);
                    }

                    IsDragging = false;
                }
            }
        }
Ejemplo n.º 10
0
            private void SomeTextCodeInit(Point p, string title, UIElement element)
            {
                this.Background = Brushes.WhiteSmoke;
                this.BorderThickness = new Thickness(2);
                this.BorderBrush = Brushes.GhostWhite;
                this.CornerRadius = new CornerRadius(2);

                mainpanel = new StackPanel();
                bclose = new Button();
                bedit = new Button();
                toppanel = new DockPanel();
                titleblock = new TextBlock();

                mainpanel.Orientation = Orientation.Vertical;
                toppanel.Background = Brushes.AliceBlue;
                toppanel.Name = "DragnDropPanel";

                StackPanel buttonPanel = new StackPanel();
                buttonPanel.HorizontalAlignment = HorizontalAlignment.Right;
                buttonPanel.Orientation = Orientation.Horizontal;

                bclose.Content = "x";
                bclose.Click += new RoutedEventHandler(bclose_Click);
                bclose.Margin = new Thickness(2);

                bedit.Click += new RoutedEventHandler(bedit_Click);
                bedit.Margin = new Thickness(2);

                buttonPanel.Children.Add(bedit);
                buttonPanel.Children.Add(bclose);

                titleblock.Text = title;
                titleblock.HorizontalAlignment = HorizontalAlignment.Left;

                toppanel.Children.Add(titleblock);
                toppanel.Children.Add(buttonPanel);

                mainpanel.Children.Add(toppanel);
                mainpanel.Children.Add(element);
                this.Child = mainpanel;
                Canvas.SetLeft(this, p.X); Canvas.SetTop(this, p.Y);

                ITheoryElement theoryElement = GetTheoryElement();
                visualinfo = new EVisualInfo();
                visualinfo.Updated += new Protsenko.TheoryEditor.Core.Events.Updated(visualinfo_Updated);

                toppanel.MouseLeftButtonDown += new MouseButtonEventHandler(toppanel_MouseLeftButtonDown);
                toppanel.MouseLeftButtonUp += new MouseButtonEventHandler(toppanel_MouseLeftButtonUp);

                DragStart += new DragStart(TheoryVisualDecorator_DragStart);
                DragEnd += new DragEnd(TheoryVisualDecorator_DragEnd);
                WantsToBeEdited += new Protsenko.TheoryEditor.Core.Events.Updated(TheoryVisualDecorator_WantsToBeEdited);
                LanguageResource.Updated +=new Protsenko.TheoryEditor.Core.Events.Updated(LanguageResource_Updated);
                LanguageResource_Updated(null);
            }
Ejemplo n.º 11
0
 public void RaiseDragStart()
 {
     DragStart?.Invoke(this);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Event handler for <see cref="DragStart"/> event callback.
 /// </summary>
 /// <param name="eventArgs">Supplies information about an drag event that is being raised.</param>
 /// <returns>A task that represents the asynchronous operation.</returns>
 protected virtual Task OnDragStartHandler(DragEventArgs eventArgs)
 {
     return(DragStart.InvokeAsync(eventArgs));
 }
Ejemplo n.º 13
0
 private void Command_MouseDown(object sender, MouseEventArgs e)
 {
     DragStart?.Invoke(this);
 }
Ejemplo n.º 14
0
 private void StartDrag()
 {
     state = DragState.Dragging;
     DragStart?.Invoke();
 }
Ejemplo n.º 15
0
 private void PartDidStartDrag()
 {
     DragStart?.Invoke(this);
     _dropPoint.gameObject.SetActive(true);
 }
Ejemplo n.º 16
0
        /// <summary> Unity callback. Called when the EditorWindow is created. </summary>
        void OnEnable()
        {
            changes      = new List <Edit>();
            DragListener =
                new EventListener().AddListener(EventType.DragUpdated,
                                                delegate {
                DragAndDrop.visualMode = Behaviour && GetObjectHitboxes(DragAndDrop.objectReferences).Any()
                            ? DragAndDropVisualMode.Generic
                            : DragAndDropVisualMode.None;
            })
                .AddListeners(new[] { EventType.DragExited, EventType.DragPerform },
                              delegate {
                if (Events == null)
                {
                    return;
                }
                DragAndDrop.AcceptDrag();
                foreach (Hitbox hb in GetObjectHitboxes(DragAndDrop.objectReferences))
                {
                    Events.AddHitbox(hb);
                }
            });

            GeneralEventListener = new EventListener().AddListener(EventType.MouseDrag,
                                                                   delegate(Event evt) {
                if (dragStart == DragStart.SeekBar)
                {
                    SetSeekTime(evt);
                }
                if (dragStart == DragStart.Keyframe)
                {
                    SetKeyframeTime(evt, selectedKeyframe);
                }
            })
                                   .AddListener(EventType.MouseUp, delegate { dragStart = DragStart.None; })
                                   .AddListener(EventType.KeyDown,
                                                delegate(Event evt) {
                if (evt.keyCode == KeyCode.Delete && selectedKeyframe != null)
                {
                    Events.DeleteKeyframe(selectedKeyframe);
                    Repaint();
                }
            });

            SeekListener = new EventListener().AddListeners(new[] { EventType.MouseDown, EventType.MouseDrag },
                                                            delegate(Event evt) {
                if (evt.type == EventType.MouseDown)
                {
                    dragStart = DragStart.SeekBar;
                }
                if (evt.type == EventType.MouseDrag && dragStart != DragStart.SeekBar)
                {
                    return;
                }
                SetSeekTime(evt);
            });

            SetListener = new EventListener().AddListeners(new[] { EventType.MouseDown, EventType.MouseDrag },
                                                           delegate(Event evt) {
                if (evt.type == EventType.MouseDown)
                {
                    dragStart = DragStart.EditArea;
                }
                if (evt.type == EventType.MouseDrag && dragStart != DragStart.EditArea)
                {
                    return;
                }
                Hitbox.Type type = evt.button == 0 ? state : GetTypeOrDefault(hitboxIndex);
                if (Events == null || Events.GetState(hitboxIndex, keyframeIndex) == type)
                {
                    return;
                }
                changes.Add(new Edit {
                    index = hitboxIndex, keyframe = keyframeIndex, type = type
                });
            });

            KeyframeListener = new EventListener().AddListener(EventType.MouseDown,
                                                               delegate {
                dragStart        = DragStart.Keyframe;
                selectedKeyframe = Keyframes[keyframeIndex];
            });

            HitboxListener = new EventListener().AddListener(EventType.MouseDown,
                                                             delegate {
                Hitbox hitbox = GetHitbox(IDs[hitboxIndex]);
                if (hitbox != null)
                {
                    Selection.activeGameObject = hitbox.gameObject;
                }
            });

            OnAssetEdit += Repaint;

            Characters = new ObjectSelector <CharacterData>(c => c.name, c => c != null);

            Characters.SelectionChanged += UpdateCharacter;
            Refresh();
        }
        public bool OnTouch(View view, MotionEvent motionEvent)
        {
            var action = motionEvent.Action;

            if (action == MotionEventActions.Down)
            {
                handler.PostDelayed(mLongPressed, 1000);
                var moveView = GetMovableView(view);
                downRawX = motionEvent.RawX;
                downRawY = motionEvent.RawY;
                dX       = moveView.GetX() - downRawX;
                dY       = moveView.GetY() - downRawY;
                DragStart?.Invoke(this, new FabDragEvent(dX, dY));
                moveView.Animate()
                .ScaleX(0.6f)
                .ScaleY(0.6f)
                .SetDuration(1000)
                .Start();
                return(true); // Consumed
            }

            if (action == MotionEventActions.Move)
            {
                handler.RemoveCallbacks(mLongPressed);
                var moveView   = GetMovableView(view);
                int viewWidth  = moveView.Width;
                int viewHeight = moveView.Height;

                View viewParent   = (View)moveView.Parent;
                int  parentWidth  = viewParent.Width;
                int  parentHeight = viewParent.Height;

                float newX = motionEvent.RawX + dX;
                newX = Java.Lang.Math.Max(0, newX);                       // Don't allow the FAB past the left hand side of the parent
                newX = Java.Lang.Math.Min(parentWidth - viewWidth, newX); // Don't allow the FAB past the right hand side of the parent

                float newY = motionEvent.RawY + dY;
                newY = Java.Lang.Math.Max(0, newY);                         // Don't allow the FAB past the top of the parent
                newY = Java.Lang.Math.Min(parentHeight - viewHeight, newY); // Don't allow the FAB past the bottom of the parent
                if (moveView.ScaleX == 1f)
                {
                    moveView.Animate()
                    .ScaleX(0.6f)
                    .ScaleY(0.6f)
                    .SetDuration(1000)
                    .Start();
                }
                moveView.Animate()
                .X(newX)
                .Y(newY)
                .SetDuration(0)
                .Start();
                Dragging?.Invoke(this, new FabDragEvent(newX + moveView.Width / 2, newY + moveView.Height / 2));
                return(true); // Consumed
            }

            if (action == MotionEventActions.Up)
            {
                handler.RemoveCallbacks(mLongPressed);
                var   moveView = GetMovableView(view);
                float upRawX   = motionEvent.RawX;
                float upRawY   = motionEvent.RawY;

                float upDX = upRawX - downRawX;
                float upDY = upRawY - downRawY;

                if (Java.Lang.Math.Abs(upDX) < CLICK_DRAG_TOLERANCE && Java.Lang.Math.Abs(upDY) < CLICK_DRAG_TOLERANCE)
                { // A click
                    moveView.Animate()
                    .ScaleX(1f)
                    .ScaleY(1f)
                    .SetDuration(1000)
                    .Start();
                    return(base.PerformClick());
                }

                // A drag
                DragEnd?.Invoke(this, new FabDragEvent(moveView.GetX() + moveView.Width / 2, moveView.GetY() + moveView.Height / 2));
                View viewParent = (View)moveView.Parent;
                moveView.Animate()
                .X(viewParent.Width - moveView.Width - 10)
                .Y(viewParent.Height - moveView.Height - 10)
                .SetDuration(1000)
                .Start();
                moveView.Animate()
                .ScaleX(1f)
                .ScaleY(1f)
                .SetDuration(1000)
                .Start();
                return(true); // Consumed
            }

            return(OnTouchEvent(motionEvent));
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Raises the <see cref="E:DragStart"/> event.
 /// </summary>
 /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
 protected virtual void OnDragStart(MarkerEventArgs e)
 {
     DragStart?.Invoke(this, e);
 }