Example #1
0
 private static Tuple <ControlCorner, CGPoint> Tuple(ControlCorner corner, CGPoint point)
 {
     return(new Tuple <ControlCorner, CGPoint>(corner, point));
 }
Example #2
0
		static Tuple<ControlCorner, CGPoint> Tuple (ControlCorner corner, CGPoint point)
		{
			return new Tuple<ControlCorner, CGPoint> (corner, point);
		}
Example #3
0
        private void ResizeRegionOfInterestWithGestureRecognizer(UIPanGestureRecognizer gestureRecognizer)
        {
            var touchLocation       = gestureRecognizer.LocationInView(gestureRecognizer.View);
            var oldRegionOfInterest = this.RegionOfInterest;

            switch (gestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
                // When the gesture begins, save the corner that is closes to
                // the resize region of interest gesture recognizer's touch location.
                this.currentControlCorner = CornerOfRect(oldRegionOfInterest, touchLocation);
                break;


            case UIGestureRecognizerState.Changed:
                var newRegionOfInterest = oldRegionOfInterest;

                switch (this.currentControlCorner)
                {
                case ControlCorner.None:
                    // Update the new region of interest with the gesture recognizer's translation.
                    var translation = gestureRecognizer.TranslationInView(gestureRecognizer.View);

                    // Move the region of interest with the gesture recognizer's translation.
                    if (this.RegionOfInterest.Contains(touchLocation))
                    {
                        newRegionOfInterest.X += translation.X;
                        newRegionOfInterest.Y += translation.Y;
                    }

                    // If the touch location goes outside the preview layer,
                    // we will only translate the region of interest in the
                    // plane that is not out of bounds.
                    var normalizedRect = new CGRect(0, 0, 1, 1);
                    if (!normalizedRect.Contains(this.VideoPreviewLayer.PointForCaptureDevicePointOfInterest(touchLocation)))
                    {
                        if (touchLocation.X < RegionOfInterest.GetMinX() || touchLocation.X > RegionOfInterest.GetMaxX())
                        {
                            newRegionOfInterest.Y += translation.Y;
                        }
                        else if (touchLocation.Y < RegionOfInterest.GetMinY() || touchLocation.Y > RegionOfInterest.GetMaxY())
                        {
                            newRegionOfInterest.X += translation.X;
                        }
                    }

                    // Set the translation to be zero so that the new gesture
                    // recognizer's translation is in respect to the region of
                    // interest's new position.
                    gestureRecognizer.SetTranslation(CGPoint.Empty, gestureRecognizer.View);
                    break;

                case ControlCorner.TopLeft:
                    newRegionOfInterest = new CGRect(touchLocation.X, touchLocation.Y,
                                                     oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
                                                     oldRegionOfInterest.Height + oldRegionOfInterest.Y - touchLocation.Y);
                    break;

                case ControlCorner.TopRight:
                    newRegionOfInterest = new CGRect(newRegionOfInterest.X,
                                                     touchLocation.Y,
                                                     touchLocation.X - newRegionOfInterest.X,
                                                     oldRegionOfInterest.Height + newRegionOfInterest.Y - touchLocation.Y);
                    break;


                case ControlCorner.BottomLeft:
                    newRegionOfInterest = new CGRect(touchLocation.X,
                                                     oldRegionOfInterest.Y,
                                                     oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
                                                     touchLocation.Y - oldRegionOfInterest.Y);
                    break;

                case ControlCorner.BottomRight:
                    newRegionOfInterest = new CGRect(oldRegionOfInterest.X,
                                                     oldRegionOfInterest.Y,
                                                     touchLocation.X - oldRegionOfInterest.X,
                                                     touchLocation.Y - oldRegionOfInterest.Y);
                    break;
                }

                // Update the region of interest with a valid CGRect.
                this.SetRegionOfInterestWithProposedRegionOfInterest(newRegionOfInterest);
                break;

            case UIGestureRecognizerState.Ended:
                this.RegionOfInterestChanged?.Invoke(this, EventArgs.Empty);

                // Reset the current corner reference to none now that the resize.
                // gesture recognizer has ended.
                this.currentControlCorner = ControlCorner.None;
                break;

            default:
                return;
            }
        }
Example #4
0
		void ResizeRegionOfInterestWithGestureRecognizer (UIPanGestureRecognizer pan)
		{
			var touchLocation = pan.LocationInView (pan.View);
			var oldRegionOfInterest = RegionOfInterest;

			switch (pan.State) {
			case UIGestureRecognizerState.Began:
				// When the gesture begins, save the corner that is closes to
				// the resize region of interest gesture recognizer's touch location.
				currentControlCorner = CornerOfRect (oldRegionOfInterest, touchLocation);
				break;


			case UIGestureRecognizerState.Changed:
				var newRegionOfInterest = oldRegionOfInterest;

				switch (currentControlCorner) {
				case ControlCorner.None:
					// Update the new region of interest with the gesture recognizer's translation.
					var translation = pan.TranslationInView (pan.View);
					// Move the region of interest with the gesture recognizer's translation.
					if (RegionOfInterest.Contains (touchLocation)) {
						newRegionOfInterest.X += translation.X;
						newRegionOfInterest.Y += translation.Y;
					}

					// If the touch location goes outside the preview layer,
					// we will only translate the region of interest in the
					// plane that is not out of bounds.
					var normalizedRect = new CGRect (0, 0, 1, 1);
					if (!normalizedRect.Contains (VideoPreviewLayer.PointForCaptureDevicePointOfInterest (touchLocation))) {
						if (touchLocation.X < RegionOfInterest.GetMinX () || touchLocation.X > RegionOfInterest.GetMaxX ()) {
							newRegionOfInterest.Y += translation.Y;
						} else if (touchLocation.Y < RegionOfInterest.GetMinY () || touchLocation.Y > RegionOfInterest.GetMaxY ()) {
							newRegionOfInterest.X += translation.X;
						}
					}

					// Set the translation to be zero so that the new gesture
					// recognizer's translation is in respect to the region of
					// interest's new position.
					pan.SetTranslation (CGPoint.Empty, pan.View);
					break;

				case ControlCorner.TopLeft:
					newRegionOfInterest = new CGRect (touchLocation.X, touchLocation.Y,
													 oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
													 oldRegionOfInterest.Height + oldRegionOfInterest.Y - touchLocation.Y);
					break;

				case ControlCorner.TopRight:
					newRegionOfInterest = new CGRect (newRegionOfInterest.X,
												 touchLocation.Y,
												 touchLocation.X - newRegionOfInterest.X,
												 oldRegionOfInterest.Height + newRegionOfInterest.Y - touchLocation.Y);
					break;


				case ControlCorner.BottomLeft:
					newRegionOfInterest = new CGRect (touchLocation.X, oldRegionOfInterest.Y,
												 oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
												 touchLocation.Y - oldRegionOfInterest.Y);
					break;

				case ControlCorner.BottomRight:
					newRegionOfInterest = new CGRect (oldRegionOfInterest.X, oldRegionOfInterest.Y,
												 touchLocation.X - oldRegionOfInterest.X,
												 touchLocation.Y - oldRegionOfInterest.Y);
					break;
				}

				// Update the region of intresest with a valid CGRect.
				SetRegionOfInterestWithProposedRegionOfInterest (newRegionOfInterest);
				break;

			case UIGestureRecognizerState.Ended:
				RegionOfInterestDidChange?.Invoke (this, EventArgs.Empty);

				// Reset the current corner reference to none now that the resize.
				// gesture recognizer has ended.
				currentControlCorner = ControlCorner.None;
				break;

			default:
				return;
			}
		}