Exemplo n.º 1
0
 // проверка: находится ли узел связи впределах прямоугольника
 public static Boolean InArea(IDrag element, Rectangle rect)
 {
     if ((element.Location.X <= rect.X + rect.Width) && (element.Location.X >= rect.X) &&
         (element.Location.Y >= rect.Y) && (element.Location.Y <= rect.Y + rect.Height))
         return true;
     return false;
 }
Exemplo n.º 2
0
        public override UIView HitTest(CoreGraphics.CGPoint point, UIEvent uievent)
        {
            UIView hitTestView = base.HitTest(point, uievent);

            if (LayoutElement.GestureEnabled)
            {
                foreach (var child in LayoutElement.Children)
                {
                    if (child.Bounds.Contains((double)point.X, (double)point.Y))
                    {
                        var draggable = child as IDrag;
                        if (draggable != null && draggable.DragEnabled)
                        {
                            lastTouchX       = point.X;
                            lastTouchY       = point.Y;
                            dragMightStart   = true;
                            currentDraggable = draggable;
                            return(this);
                        }
                    }
                }
            }

            return(hitTestView);
        }
Exemplo n.º 3
0
        public void OnDraggableRemoved(IDrag draggable)
        {
            //System.Diagnostics.Debug.WriteLine("Box {0} OnDraggableRemoved", Date.ToString("d"));

            DraggableChildren.Remove(draggable);
            Status = DroppableState.Accepting;
            Debug.WriteLine("RemovedChildren" + DraggableChildren.Count);
        }
Exemplo n.º 4
0
        public async void StopDragging()
        {
            _currDraggableWidth  = -1;
            _currDraggableHeight = -1;
            foreach (var child in DraggableChildren)
            {
                IDrop target;
                //System.Diagnostics.Debug.WriteLine("Child.Status = {0}", child.Status);
                if (child.Status == DragState.Running || child.Status == DragState.Started)
                {
                    //System.Diagnostics.Debug.WriteLine("child is running, see if there's a droppable target nearby");
                    if (MatchNearby(child, out target) && target.DropEnabled)
                    {
                        //System.Diagnostics.Debug.WriteLine("\tfound");
                        child.OnDragCompleted(target);
                        target.OnDraggableDropped(child);
                    }
                    else
                    {
                        //System.Diagnostics.Debug.WriteLine("\tnot found");
                        child.OnDragAborted();
                    }
                }
            }

            await Task.Delay(10);   // allow changes to propagate (esp on Android)

            // where lack of a delay caused the draggable to be removed as soon as it was dropped

            // check the droppables
            foreach (var child in DroppableChildren)
            {
                if (child.DraggableChildren != null && child.DraggableChildren.Count > 0)
                {
                    // check if draggable still within bounds
                    var   view             = child as View;
                    bool  draggableRemoved = false;
                    IDrag draggableChild   = null;
                    foreach (var drag in child.DraggableChildren)
                    {
                        //System.Diagnostics.Debug.WriteLine("{0}\t{1}", view.Bounds, drag.CurrentBounds);
                        if (view != null && !view.Bounds.Contains((drag).CurrentBounds.Center))
                        {
                            draggableChild   = drag;
                            draggableRemoved = true;
                        }
                    }

                    if (draggableRemoved)
                    {
                        child.OnDraggableRemoved(draggableChild);
                    }
                }
            }

            this.InvalidateLayout();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Drag in canvas
        /// </summary>
        /// <param name="dragTarget">drag target</param>
        /// <param name="dragElement">drag element</param>
        /// <param name="bound">bound</param>
        /// <returns></returns>
        public static bool BindDrag(this FrameworkElement dragTarget, FrameworkElement dragElement, DragBound bound, Action <Point, bool> positonChangeCallback = null)
        {
            bool result = false;

            if (dragTarget.Parent != null && (dragTarget.Parent as Canvas) != null)
            {
                Canvas moveCvs = dragTarget.Parent as Canvas;

                Point          positionOnElement = new Point();
                bool           isDrag            = false;
                int            deviceId          = 0;
                DragBoundCheck check             = new DragBoundCheck(dragTarget, bound);
                dragElement.PreviewTouchDown += delegate(object sender, TouchEventArgs e)
                {
                    IDrag dragObj = dragTarget as IDrag;
                    if (dragObj != null && dragObj.IsDrag == false)
                    {
                        return;
                    }
                    if (isDrag == false)
                    {
                        deviceId          = e.TouchDevice.Id;
                        positionOnElement = e.GetTouchPoint(dragTarget).Position;
                        isDrag            = true;
                        dragElement.CaptureTouch(e.TouchDevice);
                    }
                };
                dragElement.PreviewTouchMove += delegate(object sender, TouchEventArgs e)
                {
                    if (isDrag && e.TouchDevice.Id == deviceId)
                    {
                        SetNewMovPosition(dragTarget, positonChangeCallback, moveCvs, positionOnElement, false, e);
                    }
                };


                dragElement.PreviewTouchUp += delegate(object sender, TouchEventArgs e)
                {
                    if (isDrag && deviceId == e.TouchDevice.Id)
                    {
                        isDrag = false;
                        SetNewMovPosition(dragTarget, positonChangeCallback, moveCvs, positionOnElement, true, e);
                        dragElement.ReleaseTouchCapture(e.TouchDevice);
                    }
                };
                result = true;
            }
            return(result);
        }
Exemplo n.º 6
0
        public void OnDraggableDropped(IDrag draggable)
        {
            //System.Diagnostics.Debug.WriteLine("Box {0} OnDraggableDropped", Date.ToString("d"));
            this.Scale = 1;

            if (DraggableChildren == null)
            {
                DraggableChildren = new List <IDrag>();
            }

            DraggableChildren.Add(draggable);

            Status = DroppableState.Accepting;
            Debug.WriteLine("DraggableChildren: " + DraggableChildren.Count);
        }
Exemplo n.º 7
0
        public override bool OnTouchEvent(Android.Views.MotionEvent e)
        {
            double x = (e.GetX() * LayoutElement.Width) / this.Width;
            double y = (e.GetY() * LayoutElement.Height) / this.Height;

            switch (e.Action)
            {
            case Android.Views.MotionEventActions.Down:
                HandleTouchStart(x, y);
                startX = x;
                startY = y;
                break;

            case Android.Views.MotionEventActions.Move:
                if (LayoutElement.Dragging)
                {
                    LayoutElement.HandleTouch(x, y);
                }
                break;

            case Android.Views.MotionEventActions.Up:
                if (currentDraggable != null && ((currentDraggable.Status == DragState.None || currentDraggable.Status == DragState.Started) || BelowTapThreshold(x, y)))
                {
                    if (currentDraggable.TapEnabled)
                    {
                        currentDraggable.OnTapped();
                    }
                    currentDraggable = null;
                }

                if (LayoutElement.Dragging)
                {
                    MessagingCenter.Send <DragAndDropLayoutRenderer, bool>(this, "IsDragging", false);
                    LayoutElement.StopDragging();
                    LayoutElement.Dragging = false;
                    currentDraggable       = null;
                }
                break;

            default:
                break;
            }

            return(true);
        }
Exemplo n.º 8
0
        public static Point CheckElementPosition(IDrag element, Int32 width, Int32 height)
        {
            Int32 i_x;
            Int32 i_y;
            Int32 x = i_x = element.Location.X;
            Int32 y = i_y = element.Location.Y;

            if (i_x > width)
                x = width - Drawing.xOffset;
            else if (i_x < 0)
                x = Drawing.xOffset;

            if (i_y > height)
                y = height - Drawing.yOffset;
            else if (i_y < 0)
                y = Drawing.yOffset;

            return new Point(x, y);
        }
Exemplo n.º 9
0
        public override bool OnInterceptTouchEvent(Android.Views.MotionEvent ev)
        {
            if (!LayoutElement.GestureEnabled)
            {
                return(false);
            }

            double x = (ev.GetX() * LayoutElement.Width) / this.Width;
            double y = (ev.GetY() * LayoutElement.Height) / this.Height;

            IDrag draggable;

            if (LayoutElement.IDragTouched(x, y, out draggable))
            {
                currentDraggable = draggable;
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        public override void TouchesEnded(Foundation.NSSet touches, UIEvent evt)
        {
            base.TouchesEnded(touches, evt);

            if (currentDraggable != null && (currentDraggable.Status == DragState.None || currentDraggable.Status == DragState.Started))
            {
                if (currentDraggable.TapEnabled)
                {
                    currentDraggable.OnTapped();
                }
                currentDraggable = null;
            }

            if (LayoutElement.Dragging)
            {
                LayoutElement.StopDragging();
                LayoutElement.Dragging = false;
                dragMightStart         = false;
                currentDraggable       = null;
            }
        }
Exemplo n.º 11
0
        public bool IDragTouched(double x, double y, out IDrag draggable)
        {
            draggable = null;
            foreach (var child in DraggableChildren)
            {
                if (!child.DragEnabled)
                {
                    continue;
                }

                var view = child as View;
                if (view.Bounds.Contains(x, y))
                {
                    draggable = child;
                    if (draggable != null)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 12
0
        bool MatchNearby(IDrag child, out IDrop container)
        {
            var view = child as View;

            container = null;

            if (child.TargetType == null || DroppableChildren.Count == 0)
            {
                return(false);
            }

            //find all possible targets
            var targetCandidates = DroppableChildren.FindAll((t) => {
                var v     = t as View;
                bool near = v.Bounds.IntersectsWith(view.Bounds);
                return(t.GetType() == child.TargetType && near && t.DropEnabled);
            });

            if (targetCandidates.Count == 0)
            {
                return(false);
            }

            // find the match which *contains* the draggable
            foreach (var target in targetCandidates)
            {
                container = target as IDrop;
                var targetView = target as View;
                if (targetView.Bounds.Contains(view.Bounds.Center))
                {
                    return(true);
                }
            }

            // otherwise return the first one that intersects it
            container = targetCandidates[0] as IDrop;
            return(true);
        }