Ejemplo n.º 1
0
        // This event occurs when you drag it around
        public override void TouchesMoved(NSSet touches, UIEvent e)
        {
            if (e.TouchesForView(this) != null)
            {
                var touch  = (UITouch)e.TouchesForView(this).AnyObject;
                var bounds = Bounds;

                // Make draggable only if user presses inside grabberView frame
                if (grabberView.Frame.Contains(startLocation))
                {
                    // Always refer to the StartLocation of the object that you've been dragging.
                    CGPoint tempLocation = new CGPoint(location.X, location.Y);
                    tempLocation.X += touch.LocationInView(this).X - startLocation.X;
                    tempLocation.Y += touch.LocationInView(this).Y - startLocation.Y;

                    // Make sure the toolBar stays inside parent frame
                    CGRect tempFrame  = new CGRect(tempLocation, bounds.Size);
                    CGRect leftRect   = new CGRect(-1, 0, 1, parentView.Frame.Height);
                    CGRect rightRect  = new CGRect(parentView.Frame.Width, 0, 1, parentView.Frame.Height);
                    CGRect topRect    = new CGRect(0, -1, parentView.Frame.Width, 1);
                    CGRect bottomRect = new CGRect(0, parentView.Frame.Bottom, parentView.Frame.Width, 44);
                    if (!tempFrame.IntersectsWith(leftRect) && !tempFrame.IntersectsWith(rightRect) && !tempFrame.IntersectsWith(topRect) && !tempFrame.IntersectsWith(bottomRect))
                    {
                        location = tempLocation;

                        this.Frame = tempFrame;

                        UpdateFrame(new CGRect(location.X, location.Y, this.Frame.Width, this.Frame.Height));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
        {
            var begin = 0;
            var end   = _unionRects.Count;
            List <UICollectionViewLayoutAttributes> attrs = new List <UICollectionViewLayoutAttributes> ();


            for (int i = 0; i < end; i++)
            {
                if (rect.IntersectsWith(_unionRects[i]))
                {
                    begin = i * (int)_unionSize;
                }
            }

            for (int i = end - 1; i >= 0; i--)
            {
                if (rect.IntersectsWith(_unionRects [i]))
                {
                    end = (int)Math.Min((i + 1) * (int)_unionSize, _allItemAttributes.Count);
                    break;
                }
            }

            for (int i = begin; i < end; i++)
            {
                var attr = _allItemAttributes [i];
                if (rect.IntersectsWith(attr.Frame))
                {
                    attrs.Add(attr);
                }
            }

            return(attrs.ToArray());
        }
Ejemplo n.º 3
0
 private bool IsPointInRect(CGRect rect, CGPoint p)
 {
     return(rect.IntersectsWith(new CGRect()
     {
         X = p.X, Y = p.Y, Height = 1, Width = 1
     }));
 }
Ejemplo n.º 4
0
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            if (_map.Lock)
            {
                return;
            }

            if ((uint)touches.Count == 1)
            {
                var touch = touches.AnyObject as UITouch;
                if (touch != null)
                {
                    var currentPos  = (CGPoint)touch.LocationInView((UIView)this);
                    var previousPos = (CGPoint)touch.PreviousLocationInView((UIView)this);

                    var cRect = new CGRect(new CGPoint((int)currentPos.X, (int)currentPos.Y), new CGSize(5, 5));
                    var pRect = new CGRect(new CGPoint((int)previousPos.X, (int)previousPos.Y), new CGSize(5, 5));

                    if (!cRect.IntersectsWith(pRect))
                    {
                        _map.Viewport.Transform(currentPos.X, currentPos.Y, previousPos.X, previousPos.Y);

                        RefreshGraphics();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);

            if (touches.Count == 1)
            {
                var touch = touches.AnyObject as UITouch;
                if (touch != null)
                {
                    var currentPos  = touch.LocationInView(this);
                    var previousPos = touch.PreviousLocationInView(this);

                    var cRect = new CGRect(new CGPoint((int)currentPos.X, (int)currentPos.Y), new CGSize(5, 5));
                    var pRect = new CGRect(new CGPoint((int)previousPos.X, (int)previousPos.Y), new CGSize(5, 5));

                    if (!cRect.IntersectsWith(pRect))
                    {
                        if (_previousTouchCount == touches.Count)
                        {
                            _map.Viewport.Transform(currentPos.X, currentPos.Y, previousPos.X, previousPos.Y);
                            RefreshGraphics();
                        }
                    }
                }
            }
            else if (touches.Count == 2)
            {
                nfloat centerX = 0;
                nfloat centerY = 0;

                var locations = touches.Select(t => ((UITouch)t).LocationInView(this)).ToList();

                foreach (var location in locations)
                {
                    centerX += location.X;
                    centerY += location.Y;
                }

                centerX = centerX / touches.Count;
                centerY = centerY / touches.Count;

                var radius   = Algorithms.Distance(centerX, centerY, locations [0].X, locations [0].Y);
                var rotation = Math.Atan2(locations [1].Y - locations [0].Y, locations [1].X - locations [0].X) * 180.0 / Math.PI;

                if (_previousTouchCount == touches.Count)
                {
                    _map.Viewport.Transform(centerX, centerY, _previousX, _previousY, radius / _previousRadius);
                    _map.Viewport.Rotation += rotation - _previousRotation;
                    RefreshGraphics();
                }

                _previousX        = centerX;
                _previousY        = centerY;
                _previousRadius   = radius;
                _previousRotation = rotation;
            }
            _previousTouchCount = touches.Count;
        }
Ejemplo n.º 6
0
        static void DrawSeparator(nfloat x, CGRect dirtyRect)
        {
            var sepRect = new CGRect(x - 6.5, MacSystemInformation.OsVersion >= MacSystemInformation.ElCapitan ? 4 : 3, 1, 16);

            if (sepRect.IntersectsWith(dirtyRect))
            {
                NSColor.LightGray.SetFill();
                NSBezierPath.FillRect(sepRect);
            }
        }
Ejemplo n.º 7
0
        public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
        {
            var layoutAttributes = new List <UICollectionViewLayoutAttributes>();

            foreach (var item in LayoutItems)
            {
                if (rect.IntersectsWith(item.Item1.Frame))
                {
                    layoutAttributes.Add(item.Item1);
                }
            }
            return(layoutAttributes.ToArray());
        }
        public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
        {
            var attributes = new List <UICollectionViewLayoutAttributes>();

            foreach (var attribute in _cachedAttributes)
            {
                if (rect.IntersectsWith(attribute.Frame))
                {
                    attributes.Add(attribute);
                }
            }

            return(attributes.ToArray());
        }
Ejemplo n.º 9
0
        public List <NSIndexPath> IndexPathsOfItemsInRect(CGRect rect)
        {
            var paths = new List <NSIndexPath>();

            foreach (var item in LayoutItems)
            {
                if (rect.IntersectsWith(item.Item1.Frame))
                {
                    paths.Add(item.Item2);
                }
            }

            return(paths);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the touching cell view by bounds.
        /// </summary>
        /// <returns>The touching cell view.</returns>
        /// <param name="viewBounds">View bounds.</param>
        public BaseCollectionViewCell GetTouchingCellView <T>(CGRect viewBounds) where T : BaseCollectionViewCell
        {
            var touchingCell = default(BaseCollectionViewCell);

            foreach (var cell in Cells.OfType <T>())
            {
                if (viewBounds.IntersectsWith(cell.Frame) && touchingCell == null)
                {
                    touchingCell = cell;
                }
            }

            _selectedCells = 0;

            return(touchingCell);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Checks the touching cell.
        /// </summary>
        /// <param name="viewBounds">View bounds.</param>
        public object GetTouchingCellBindingContext <T>(CGRect viewBounds) where T : BaseCollectionViewCell
        {
            var touchingCellBindingContext = default(object);

            foreach (var cell in Cells.OfType <T>())
            {
                if (viewBounds.IntersectsWith(cell.Frame) && touchingCellBindingContext == null)
                {
                    //touchingCellBindingContext = cell.DataContext;
                }

                cell.Selected = false;
            }

            _selectedCells = 0;

            return(touchingCellBindingContext);
        }
Ejemplo n.º 12
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);
            if (statusIcons.Count == 0 || buildResults.Hidden)
            {
                return;
            }

            var x       = LeftMostStatusItemX();
            var sepRect = new CGRect(x - 9, MacSystemInformation.OsVersion >= MacSystemInformation.ElCapitan ? 5 : 4, 1, 16);

            if (!sepRect.IntersectsWith(dirtyRect))
            {
                return;
            }

            NSColor.LightGray.SetFill();
            NSBezierPath.FillRect(sepRect);
        }
Ejemplo n.º 13
0
        static Rects ComputeDifferenceBetweenRect(CGRect oldRect, CGRect newRect)
        {
            if (!oldRect.IntersectsWith(newRect))
            {
                return(new Rects {
                    Added = new CGRect [] { newRect },
                    Removed = new CGRect [] { oldRect }
                });
            }

            var oldMaxY = oldRect.GetMaxY();
            var oldMinY = oldRect.GetMinY();
            var newMaxY = newRect.GetMaxY();
            var newMinY = newRect.GetMinY();

            var added   = new List <CGRect> ();
            var removed = new List <CGRect> ();

            if (newMaxY > oldMaxY)
            {
                added.Add(new CGRect(newRect.X, oldMaxY, newRect.Width, newMaxY - oldMaxY));
            }

            if (oldMinY > newMinY)
            {
                added.Add(new CGRect(newRect.X, newMinY, newRect.Width, oldMinY - newMinY));
            }

            if (newMaxY < oldMaxY)
            {
                removed.Add(new CGRect(newRect.X, newMaxY, newRect.Width, oldMaxY - newMaxY));
            }

            if (oldMinY < newMinY)
            {
                removed.Add(new CGRect(newRect.X, oldMinY, newRect.Width, newMinY - oldMinY));
            }

            return(new Rects {
                Added = added,
                Removed = removed
            });
        }
Ejemplo n.º 14
0
        private static Tuple <IEnumerable <CGRect>, IEnumerable <CGRect> > ComputeDifferenceBetweenRect(
            CGRect oldRect, CGRect newRect)
        {
            if (!newRect.IntersectsWith(oldRect))
            {
                return(new Tuple <IEnumerable <CGRect>, IEnumerable <CGRect> >(
                           new[] { newRect }, new[] { oldRect }));
            }

            var oldMaxY = oldRect.GetMaxY();
            var oldMinY = oldRect.GetMinY();
            var newMaxY = newRect.GetMaxY();
            var newMinY = newRect.GetMinY();

            var addedRects   = new List <CGRect>();
            var removedRects = new List <CGRect>();

            if (newMaxY > oldMaxY)
            {
                addedRects.Add(
                    new CGRect(newRect.X, oldMaxY, newRect.Width, newMaxY - oldMaxY));
            }
            if (oldMinY > newMinY)
            {
                addedRects.Add(
                    new CGRect(newRect.X, newMinY, newRect.Width, oldMinY - newMinY));
            }
            if (newMaxY < oldMaxY)
            {
                removedRects.Add(
                    new CGRect(newRect.X, newMaxY, newRect.Width, oldMaxY - newMaxY));
            }
            if (oldMinY < newMinY)
            {
                removedRects.Add(
                    new CGRect(newRect.X, oldMinY, newRect.Width, newMinY - oldMinY));
            }

            return(new Tuple <IEnumerable <CGRect>, IEnumerable <CGRect> >(
                       addedRects, removedRects));
        }
        public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
        {
            var allAttributes = new List <UICollectionViewLayoutAttributes>();

            foreach (var cellLayoutInfo in (_layoutInfos?.Values).Safe())
            {
                foreach (var layoutAttributes in cellLayoutInfo.Values)
                {
                    // Alias to avoid paying the price of interop twice.
                    var frame = layoutAttributes.Frame;

                    if (rect.Contains(frame) ||
                        rect.IntersectsWith(frame))
                    {
                        allAttributes.Add(layoutAttributes);
                    }
                }
            }

            return(allAttributes.ToArray());
        }
        static void ComputeDifferenceBetweenRect(CGRect oldRect, CGRect newRect, Action <CGRect> removedHandler, Action <CGRect> addedHandler)
        {
            if (!oldRect.IntersectsWith(newRect))
            {
                addedHandler(newRect);
                removedHandler(oldRect);
            }
            else
            {
                nfloat oldMaxY = oldRect.GetMaxY();
                nfloat oldMinY = oldRect.GetMinY();
                nfloat newMaxY = newRect.GetMaxY();
                nfloat newMinY = newRect.GetMinY();

                if (newMaxY > oldMaxY)
                {
                    var rectToAdd = new CGRect(newRect.X, oldMaxY, newRect.Width, newMaxY - oldMaxY);
                    addedHandler(rectToAdd);
                }

                if (oldMinY > newMinY)
                {
                    var rectToAdd = new CGRect(newRect.X, newMinY, newRect.Width, oldMinY - newMinY);
                    addedHandler(rectToAdd);
                }

                if (newMaxY < oldMaxY)
                {
                    var rectToRemove = new CGRect(newRect.X, newMaxY, newRect.Width, oldMaxY - newMaxY);
                    removedHandler(rectToRemove);
                }

                if (oldMinY < newMinY)
                {
                    var rectToRemove = new CGRect(newRect.X, oldMinY, newRect.Width, newMinY - oldMinY);
                    removedHandler(rectToRemove);
                }
            }
        }
Ejemplo n.º 17
0
 public bool IsVisibleInRect(CGRect r)
 {
     // Returns true if the layer for this segment is visible in the given rect.
     return(r.IntersectsWith(Layer.Frame));
 }
Ejemplo n.º 18
0
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);

            if (touches.Count == 1)
            {
                if (touches.AnyObject is UITouch touch)
                {
                    var currentPos  = touch.LocationInView(this);
                    var previousPos = touch.PreviousLocationInView(this);

                    var cRect = new CGRect(new CGPoint((int)currentPos.X, (int)currentPos.Y), new CGSize(5, 5));
                    var pRect = new CGRect(new CGPoint((int)previousPos.X, (int)previousPos.Y), new CGSize(5, 5));

                    if (!cRect.IntersectsWith(pRect))
                    {
                        if (_previousTouchCount == touches.Count)
                        {
                            _map.Viewport.Transform(currentPos.X, currentPos.Y, previousPos.X, previousPos.Y);
                            RefreshGraphics();
                        }
                    }
                }
            }
            else if (touches.Count == 2)
            {
                nfloat centerX = 0;
                nfloat centerY = 0;

                var locations = touches.Select(t => ((UITouch)t).LocationInView(this)).ToList();

                foreach (var location in locations)
                {
                    centerX += location.X;
                    centerY += location.Y;
                }

                centerX = centerX / touches.Count;
                centerY = centerY / touches.Count;

                var radius = Algorithms.Distance(centerX, centerY, locations[0].X, locations[0].Y);

                if (_previousTouchCount == touches.Count)
                {
                    _map.Viewport.Transform(centerX, centerY, _previousX, _previousY, radius / _previousRadius);

                    if (AllowPinchRotation)
                    {
                        var rotation = GetRotation(locations);

                        _innerRotation += rotation - _previousRotation;
                        _innerRotation %= 360;

                        if (_innerRotation > 180)
                        {
                            _innerRotation -= 360;
                        }
                        else if (_innerRotation < -180)
                        {
                            _innerRotation += 360;
                        }

                        if (_map.Viewport.Rotation == 0 && Math.Abs(_innerRotation) >= Math.Abs(UnSnapRotationDegrees))
                        {
                            _map.Viewport.Rotation = _innerRotation;
                        }
                        else if (_map.Viewport.Rotation != 0)
                        {
                            if (Math.Abs(_innerRotation) <= Math.Abs(ReSnapRotationDegrees))
                            {
                                _map.Viewport.Rotation = 0;
                            }
                            else
                            {
                                _map.Viewport.Rotation = _innerRotation;
                            }
                        }

                        _previousRotation = rotation;
                    }

                    RefreshGraphics();
                }

                _previousX      = centerX;
                _previousY      = centerY;
                _previousRadius = radius;
            }
            _previousTouchCount = touches.Count;
        }
Ejemplo n.º 19
0
		static void DrawSeparator (nfloat x, CGRect dirtyRect)
		{
			var sepRect = new CGRect (x - 6.5, MacSystemInformation.OsVersion >= MacSystemInformation.ElCapitan ? 4 : 3, 1, 16);
			if (sepRect.IntersectsWith (dirtyRect)) {
				NSColor.LightGray.SetFill ();
				NSBezierPath.FillRect (sepRect);
			}
		}
		static Rects ComputeDifferenceBetweenRect (CGRect oldRect, CGRect newRect)
		{
			if (!oldRect.IntersectsWith (newRect)) {
				return new Rects {
					Added = new CGRect [] { newRect },
					Removed = new CGRect [] { oldRect }
				};
			}

			var oldMaxY = oldRect.GetMaxY ();
			var oldMinY = oldRect.GetMinY ();
			var newMaxY = newRect.GetMaxY ();
			var newMinY = newRect.GetMinY ();

			var added = new List<CGRect> ();
			var removed = new List<CGRect> ();

			if (newMaxY > oldMaxY)
				added.Add (new CGRect (newRect.X, oldMaxY, newRect.Width, newMaxY - oldMaxY));

			if (oldMinY > newMinY)
				added.Add (new CGRect (newRect.X, newMinY, newRect.Width, oldMinY - newMinY));

			if (newMaxY < oldMaxY)
				removed.Add (new CGRect (newRect.X, newMaxY, newRect.Width, oldMaxY - newMaxY));

			if (oldMinY < newMinY)
				removed.Add (new CGRect (newRect.X, oldMinY, newRect.Width, newMinY - oldMinY));

			return new Rects {
				Added = added,
				Removed = removed
			};
		}
Ejemplo n.º 21
0
		public override void DrawRect (CGRect dirtyRect)
		{
			base.DrawRect (dirtyRect);
			if (statusIcons.Count == 0 || buildResults.Hidden) {
				return;
			}

			var x = LeftMostStatusItemX ();
			var sepRect = new CGRect (x - 9, MacSystemInformation.OsVersion >= MacSystemInformation.ElCapitan ? 5 : 4, 1, 16);
			if (!sepRect.IntersectsWith (dirtyRect)) {
				return;
			}

			NSColor.LightGray.SetFill ();
			NSBezierPath.FillRect (sepRect);
		}
		static void ComputeDifferenceBetweenRect (CGRect oldRect, CGRect newRect, Action<CGRect> removedHandler, Action<CGRect> addedHandler)
		{
			if (!oldRect.IntersectsWith (newRect)) {
				addedHandler (newRect);
				removedHandler (oldRect);
			} else {
				nfloat oldMaxY = oldRect.GetMaxY ();
				nfloat oldMinY = oldRect.GetMinY ();
				nfloat newMaxY = newRect.GetMaxY ();
				nfloat newMinY = newRect.GetMinY ();

				if (newMaxY > oldMaxY) {
					var rectToAdd = new CGRect (newRect.X, oldMaxY, newRect.Width, newMaxY - oldMaxY);
					addedHandler(rectToAdd);
				}

				if (oldMinY > newMinY) {
					var rectToAdd = new CGRect (newRect.X, newMinY, newRect.Width, oldMinY - newMinY);
					addedHandler(rectToAdd);
				}

				if (newMaxY < oldMaxY) {
					var rectToRemove = new CGRect (newRect.X, newMaxY, newRect.Width, oldMaxY - newMaxY);
					removedHandler(rectToRemove);
				}

				if (oldMinY < newMinY) {
					var rectToRemove = new CGRect (newRect.X, oldMinY, newRect.Width, newMinY - oldMinY);
					removedHandler(rectToRemove);
				}
			}
		}
		public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect (CGRect rect)
		{
			int begin = 0;
			int end = unionRects.Count;
			var attrs = new List<UICollectionViewLayoutAttributes> ();


			for (int i = 0; i < end; i++)
				if (rect.IntersectsWith (unionRects [i]))
					begin = i * (int)unionSize;

			for (int i = end - 1; i >= 0; i--) {
				if (rect.IntersectsWith (unionRects [i])) {
					end = Math.Min ((i + 1) * (int)unionSize, allItemAttributes.Count);
					break;
				}
			}

			for (int i = begin; i < end; i++) {
				var attr = allItemAttributes [i];
				if (rect.IntersectsWith (attr.Frame)) {
					attrs.Add (attr);
				}
			}

			return attrs.ToArray ();
		}
Ejemplo n.º 24
0
 private bool IsFrameValid(CGRect frame, CGRect forRefViewFrame)
 {
     return(!frame.IntersectsWith(forRefViewFrame));
 }
Ejemplo n.º 25
0
			public bool IsVisibleInRect (CGRect r)
			{
				// Returns true if the layer for this segment is visible in the given rect.
				return r.IntersectsWith (Layer.Frame);
			}
Ejemplo n.º 26
0
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
			if (_map.Lock) return;

            if ((uint)touches.Count == 1)
            {
                var touch = touches.AnyObject as UITouch;
                if (touch != null)
                {
                    var currentPos = (CGPoint)touch.LocationInView((UIView)this);
                    var previousPos = (CGPoint)touch.PreviousLocationInView((UIView)this);

                    var cRect = new CGRect(new CGPoint((int)currentPos.X, (int)currentPos.Y), new CGSize(5, 5));
                    var pRect = new CGRect(new CGPoint((int)previousPos.X, (int)previousPos.Y), new CGSize(5, 5));

                    if (!cRect.IntersectsWith(pRect))
                    {
                        _map.Viewport.Transform(currentPos.X, currentPos.Y, previousPos.X, previousPos.Y);

                        RefreshGraphics();
                    }
                }
            }
        }