Exemplo n.º 1
0
        // http://stackoverflow.com/questions/3552108/finding-closest-object-to-cgpoint b/c I'm lazy
        CGFloat distanceBetween(CGRect rect, CGPoint point)
        {
            if (rect.Contains(point))
            {
                return(0);
            }

            var closest = rect.Location;

            if ((rect.Location.X + rect.Size.Width < point.X))
            {
                closest.X += rect.Size.Width;
            }
            else
            if ((point.X > rect.Location.X))
            {
                closest.X = point.X;
            }

            if ((rect.Location.Y + rect.Size.Height < point.Y))
            {
                closest.Y += rect.Size.Height;
            }
            else
            if ((point.Y > rect.Location.Y))
            {
                closest.Y = point.Y;
            }

            var a = Math.Pow((double)(closest.Y - point.Y), 2);
            var b = Math.Pow((double)(closest.X - point.X), 2);

            return((CGFloat)(Math.Sqrt(a + b)));
        }
Exemplo n.º 2
0
        private void HandleSingleTap(UITapGestureRecognizer gesture)
        {
            CGPoint point = gesture.LocationInView(customTab);

            if (typesRect.Contains(point))
            {
                featuresCollectionView.Hidden  = true;
                typesCollectionView.Hidden     = false;
                typeSampleView.Hidden          = false;
                featureSampleView.Hidden       = true;
                IsTypesSampleView              = true;
                selectedTabHighlightView.Frame = new CGRect(0, customTabHeight - 5, this.View.Frame.Size.Width / 2, 5);
                typeSampleView.ViewWillAppear();
                featureSampleView.ViewWillDisappear();
            }
            else if (featuresRect.Contains(point))
            {
                typesCollectionView.Hidden     = true;
                featuresCollectionView.Hidden  = false;
                typeSampleView.Hidden          = true;
                featureSampleView.Hidden       = false;
                IsTypesSampleView              = false;
                selectedTabHighlightView.Frame = new CGRect(this.View.Frame.Size.Width / 2, customTabHeight - 5, this.View.Frame.Size.Width / 2, 5);
                if (firstTimeLoad)
                {
                    LoadSample();
                    firstTimeLoad = false;
                }
                else
                {
                    featureSampleView.ViewWillAppear();
                    typeSampleView.ViewWillDisappear();
                }
            }
        }
Exemplo n.º 3
0
        protected virtual void CenterViewInScroll(UIView viewToCenter, UIScrollView scrollView, nfloat keyboardHeight)
        {
            var contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardHeight, 0.0f);

            scrollView.ContentInset          = contentInsets;
            scrollView.ScrollIndicatorInsets = contentInsets;

            // Position of the active field relative isnside the scroll view
            // If activeField is hidden by keyboard, scroll it so it's visible
            CGRect viewRectAboveKeyboard = new CGRect(View.Frame.Location, new CGSize(View.Frame.Width, View.Frame.Size.Height - keyboardHeight));

            CGRect activeFieldAbsoluteFrame = ViewToCenterOnKeyboardShown.Superview.ConvertRectToView(ViewToCenterOnKeyboardShown.Frame, View);

            // activeFieldAbsoluteFrame is relative to this.View so does not include any scrollView.ContentOffset
            //fix y position
            if (activeFieldAbsoluteFrame.Y < viewRectAboveKeyboard.Y)
            {
                activeFieldAbsoluteFrame.Y += viewRectAboveKeyboard.Y;
            }
            else
            {
                activeFieldAbsoluteFrame.Y += 5f;
            }

            // Check if the activeField will be partially or entirely covered by the keyboard
            if (!viewRectAboveKeyboard.Contains(activeFieldAbsoluteFrame))
            {
                ScrollToPointKeyboardAction(scrollView, activeFieldAbsoluteFrame, viewRectAboveKeyboard, keyboardHeight);
            }
        }
Exemplo n.º 4
0
        void CheckCollision(UITouch touch, IStorage contactBase, TouchActionEventArgs.TouchActionType type)
        {
            long       id             = touch.Handle.ToInt64();
            List <int> contactIndexes = new List <int>();
            List <Xamarin.Forms.View> contactViews = new List <Xamarin.Forms.View>();

            isInContact = false;
            if (contactBase != null)
            {
                var coordinate = touch.LocationInView(null);


                foreach (var cell in contactBase.GetGridCells())
                {
                    var child = cell.GetButton();

                    var contactRect = new CGRect(child.GetAbsolutePosition().X, child.GetAbsolutePosition().Y, child.Width, child.Height);
                    if (contactRect.Contains(coordinate))
                    {
                        isInContact = true;

                        contactIndexes.Add(cell.Index);
                        contactViews.Add(child);
                    }
                }
            }
            if (isInContact)
            {
                FireEvent(idToTouchDictionary[id], id, type, touch, true, contactIndexes, contactViews);
            }
            else
            {
                FireEvent(idToTouchDictionary[id], id, type, touch, false, null, null);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Determines whether this instance can start sliding given the touch position and the
 /// current location/size of the top view.
 /// Note that touchPosition is in Screen coordinate.
 /// </summary>
 /// <returns>true</returns>
 /// <c>false</c>
 /// <param name="touchPosition">Touch position.</param>
 /// <param name="topViewCurrentFrame">Top view's current frame.</param>
 public override bool CanStartSliding(CGPoint touchPosition, CGRect topViewCurrentFrame)
 {
     if (!IsVisible)
     {
         return(touchPosition.X >= View.Bounds.Size.Width - EdgeTolerance && touchPosition.X <= View.Bounds.Size.Width);
     }
     return(topViewCurrentFrame.Contains(touchPosition));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Determines whether this instance can start sliding given the touch position and the
 /// current location/size of the top view.
 /// Note that touchPosition is in Screen coordinate.
 /// </summary>
 /// <returns>true</returns>
 /// <c>false</c>
 /// <param name="touchPosition">Touch position.</param>
 /// <param name="topViewCurrentFrame">Top view's current frame.</param>
 public override bool CanStartSliding(CGPoint touchPosition, CGRect topViewCurrentFrame)
 {
     if (!IsVisible)
     {
         return(touchPosition.X >= 0.0f && touchPosition.X <= EdgeTolerance);
     }
     return(topViewCurrentFrame.Contains(touchPosition));
 }
Exemplo n.º 7
0
        bool IsLeftPointContainedWithinBezelRect(CGPoint point)
        {
            nfloat bezelWidth    = SlideMenuOptions.LeftBezelWidth;
            CGRect leftBezelRect = new CGRect(0, 0, 0, 0);
            CGRect tempRect      = new CGRect(0, 0, 0, 0);

            View.Bounds.Divide(bezelWidth, CGRectEdge.MinXEdge, out leftBezelRect, out tempRect);

            return(leftBezelRect.Contains(point));
        }
Exemplo n.º 8
0
        public override bool PointInside(CGPoint point, UIEvent uievent)
        {
            if (uievent.Type == UIEventType.Touches)
            {
                var rect = new CGRect(0, 0, Frame.Width, Frame.Height + AutoCompleteTableView.Frame.Height);
                return(rect.Contains(point));
            }

            return(base.PointInside(point, uievent));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Points the inside.
        /// </summary>
        /// <returns><c>true</c>, if inside was pointed, <c>false</c> otherwise.</returns>
        /// <param name="point">Point.</param>
        /// <param name="uievent">Uievent.</param>
        public override bool PointInside(CGPoint point, UIEvent uievent)
        {
            CGRect rect = Bounds;

            rect.X      -= Inset.Left;
            rect.Y      -= Inset.Top;
            rect.Width  += Inset.Left + Inset.Right;
            rect.Height += Inset.Top + Inset.Bottom;

            return(rect.Contains(point));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Registers a scroll view with the current controller to handle adjusting the view
        /// when a keyboard is shown to prevent edit fields from being hidden by the keyboard.
        /// </summary>
        /// <param name="scrollView">A scroll view.</param>
        protected void RegisterKeyboardHooksForScrollView(UIScrollView scrollView)
        {
            if (this.scrollView != null)
            {
                throw new InvalidOperationException("A scroll view has already been registered.");
            }

            // TODO: what if keyboard is already shown?
            this.scrollView = scrollView;

            this.RegisterKeyboardDidShow(e =>
            {
                this.originalContentInsets = this.scrollView.ContentInset;

                NSValue keyboardFrame      = (NSValue)e.Notification.UserInfo.ObjectForKey(UIKeyboard.FrameBeginUserInfoKey);
                nfloat keyboardHeight      = keyboardFrame.CGRectValue.Height;
                UIEdgeInsets contentInsets = new UIEdgeInsets(this.originalContentInsets.Value.Top, 0, keyboardHeight, 0);

                this.scrollView.ContentInset          = contentInsets;
                this.scrollView.ScrollIndicatorInsets = contentInsets;

                UIView firstResponder = this.FindFirstResponder(this.scrollView);
                if (firstResponder != null)
                {
                    CGRect visibleRect =
                        new CGRect(
                            this.View.Frame.X,
                            this.View.Frame.Y,
                            this.View.Frame.Width,
                            this.View.Frame.Height - keyboardHeight);

                    CGPoint locationInScrollView = this.scrollView.ConvertPointFromView(firstResponder.Frame.Location, firstResponder);
                    if (!visibleRect.Contains(locationInScrollView))
                    {
                        this.scrollView.ScrollRectToVisible(new CGRect(locationInScrollView, firstResponder.Frame.Size), false);
                    }
                }
            });

            this.RegisterKeyboardWillBeHidden(e =>
            {
                // If the current view controller does not have the keyboard visible and then pushes another
                // view controller onto the stack, this delegate (on the parent) will get invoked if the child
                // view controller has the keyboard visible when navigating back to the parent view controller.

                if (this.originalContentInsets.HasValue)
                {
                    this.scrollView.ContentInset          = this.originalContentInsets.Value;
                    this.scrollView.ScrollIndicatorInsets = this.originalContentInsets.Value;
                }

                this.originalContentInsets = null;
            });
        }
Exemplo n.º 11
0
        bool IsRightPointContainedWithinBezelRect(CGPoint point)
        {
            nfloat rightBezelWidth = SlideMenuOptions.RightBezelWidth;
            CGRect rightBezelRect  = new CGRect(0, 0, 0, 0);
            CGRect tempRect        = new CGRect(0, 0, 0, 0);

            nfloat bezelWidth = View.Bounds.Width - rightBezelWidth;

            View.Bounds.Divide(bezelWidth, CGRectEdge.MinXEdge, out rightBezelRect, out tempRect);
            return(rightBezelRect.Contains(point));
        }
Exemplo n.º 12
0
        public override bool PointInside(CGPoint point, UIEvent uievent)
        {
            var extendedArea = new CGRect
            {
                X      = this.Bounds.Location.X - ExtendedArea,
                Y      = this.Bounds.Location.Y - ExtendedArea,
                Width  = this.Bounds.Size.Width + ExtendedArea * 2,
                Height = this.Bounds.Size.Width + ExtendedArea * 2
            };

            return(extendedArea.Contains(point));
        }
Exemplo n.º 13
0
        public override void RenderPointLabels(TKChartSeries series, CGRect bounds, CGContext ctx)
        {
            if (labelLayer != null)
            {
                labelLayer.RemoveFromSuperLayer();
            }

            for (int i = 0; i < series.Items.Length; i++)
            {
                TKChartData dataPoint = (TKChartData)series.Items [i];
                CGPoint     location  = base.LocationForDataPoint(dataPoint, series, bounds);
                if (!bounds.Contains(location))
                {
                    continue;
                }

                TKChartPointLabel      label = this.LabelForDataPoint(dataPoint, series, (uint)i);
                CGRect                 labelRect;
                TKChartPointLabelStyle labelStyle = series.Style.PointLabelStyle;
                if (this.isSelectedPoint)
                {
                    labelRect = new CGRect((float)(location.X - 17.5), (float)(location.Y - 10 - 2.5 * Math.Abs(labelStyle.LabelOffset.Vertical)), 35, 30);
                    if (labelRect.Y < bounds.Y)
                    {
                        this.labelLayer.IsOutsideBounds = true;
                        labelRect.Y = (float)(location.Y + 10 + 2.5 * Math.Abs(labelStyle.LabelOffset.Vertical) - labelRect.Size.Height);
                    }
                    else
                    {
                        this.labelLayer.IsOutsideBounds = false;
                    }

                    this.labelLayer.Frame = labelRect;
                    this.Render.AddSublayer(this.labelLayer);
                    this.labelLayer.SetNeedsDisplay();
                }
                else
                {
                    CGSize labelSize = label.SizeThatFits(bounds.Size);
                    labelRect = new CGRect((float)(location.X - labelSize.Width / 2.0 + labelStyle.LabelOffset.Horizontal),
                                           (float)(location.Y - labelSize.Height / 2.0 + labelStyle.LabelOffset.Vertical), labelSize.Width, labelSize.Height);

                    if (labelRect.Y < this.Render.Bounds.Y)
                    {
                        labelRect.Y = (float)(location.Y - labelSize.Height / 2.0 + Math.Abs(labelStyle.LabelOffset.Vertical));
                    }

                    label.DrawInContext(ctx, labelRect, new TKChartVisualPoint(new PointF(0, 0)), UIColor.White);
                }
            }
        }
Exemplo n.º 14
0
        public static void ReactToKeyboardWillShowNotification(UIView notifiedView, UIView activeView, bool isCalledFromChildView, NSNotification notification)
        {
            var topView = isCalledFromChildView ? notifiedView.Superview : notifiedView;

            if (activeView == null)
            {
                return;
            }

            var scrollView = activeView.FindSuperviewOfType(notifiedView, typeof(UIScrollView)) as UIScrollView;

            if (scrollView == null)
            {
                return;
            }

            // find the topmost scrollview (fix problem with RootElement)
            var nextSuperView = scrollView;

            while (nextSuperView != null)
            {
                scrollView    = nextSuperView;
                nextSuperView = scrollView.FindSuperviewOfType(notifiedView, typeof(UIScrollView)) as UIScrollView;
            }

            var keyboardBounds = ((NSValue)notification.UserInfo.ValueForKey(UIKeyboard.FrameEndUserInfoKey)).RectangleFValue;

            var contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardBounds.Size.Height + topView.Frame.Y, 0.0f);

            scrollView.ContentInset          = contentInsets;
            scrollView.ScrollIndicatorInsets = contentInsets;

            // If activeField is hidden by keyboard, scroll it so it's visible
            var viewRectAboveKeyboard = new CGRect(topView.Frame.Location, new CGSize(topView.Frame.Width, topView.Frame.Size.Height - keyboardBounds.Size.Height));

            var activeFieldAbsoluteFrame = activeView.Superview.ConvertRectToView(activeView.Frame, topView);

            // activeFieldAbsoluteFrame is relative to topView so does not include any scrollView.ContentOffset
            activeFieldAbsoluteFrame.Y = activeFieldAbsoluteFrame.Y + topView.Frame.Y;

            // change width of control before checking because we only check vertically
            activeFieldAbsoluteFrame.Width = 10f;

            // Check if the activeField will be partially or entirely covered by the keyboard
            if (!viewRectAboveKeyboard.Contains(activeFieldAbsoluteFrame))
            {
                // Scroll to the activeField Y position + activeField.Height + current scrollView.ContentOffset.Y - the keyboard Height
                var scrollPoint = new CGPoint(0.0f, activeFieldAbsoluteFrame.Location.Y + activeFieldAbsoluteFrame.Height + scrollView.ContentOffset.Y - viewRectAboveKeyboard.Height);
                scrollView.SetContentOffset(scrollPoint, true);
            }
        }
Exemplo n.º 15
0
        private int GetCharacterIndexAtPoint(Point point)
        {
            if (!_drawRect.Contains(point))
            {
                return(-1);
            }

            // Find the tapped character's index
            var partialFraction      = (nfloat)0;
            var pointInTextContainer = new CGPoint(point.X - _drawRect.X, point.Y - _drawRect.Y);
            var characterIndex       = (int)_layoutManager.CharacterIndexForPoint(pointInTextContainer, _layoutManager.TextContainers.FirstOrDefault(), ref partialFraction);

            return(characterIndex);
        }
        /// <summary>
        /// Determines whether this instance can start sliding given the touch position and the
        /// current location/size of the top view.
        /// Note that touchPosition is in Screen coordinate.
        /// </summary>
        /// <returns>true</returns>
        /// <c>false</c>
        /// <param name="touchPosition">Touch position.</param>
        /// <param name="topViewCurrentFrame">Top view's current frame.</param>
        public override bool CanStartSliding(CGPoint touchPosition, CGRect topViewCurrentFrame)
        {
            // touchPosition is in Screen coordinate.

            nfloat offset = 0.0f;

            touchPosition.Y += offset;

            if (!IsVisible)
            {
                return(touchPosition.Y >= (View.Bounds.Height - EdgeTolerance) && touchPosition.Y <= View.Bounds.Height);
            }
            return(topViewCurrentFrame.Contains(touchPosition));
        }
Exemplo n.º 17
0
        public override void MouseUp(NSEvent theEvent)
        {
            CGPoint location  = theEvent.LocationInWindow;
            CGRect  frame     = ExpiredInfoView.Frame;
            bool    isInFrame = frame.Contains(location);

            if (IsExpired && isInFrame)
            {
                TitleInfoClick(null);
                return;
            }

            base.MouseUp(theEvent);
        }
Exemplo n.º 18
0
        public override bool TryGetLocalCoordinate(CGPoint hostCoordinate, out CGPoint localCoordinate)
        {
            localCoordinate = CGPoint.Empty;

            if (!appBounds.Contains(hostCoordinate))
            {
                return(false);
            }

            localCoordinate.X = (hostCoordinate.X - appBounds.X) * scale;
            localCoordinate.Y = (hostCoordinate.Y - appBounds.Y) * scale;

            return(true);
        }
Exemplo n.º 19
0
        public static UIColor ColorAtPixel(CGPoint point, UIImage image)
        {
            CGRect rect = new CGRect(0, 0, image.Size.Width, image.Size.Height);

            // CancelIf pointIs outside Image coordinates
            if (!rect.Contains(point))
            {
                return(null);
            }

            // Create a 1x1 pixel byte array and bitmap context to draw the pixelInto.
            // Reference: http://stackoverflow.com/questions/1042830/retrieving-a-pixel-alpha-value-for-a-uiImage
            int          pointX           = Convert.ToInt16(Math.Truncate(point.X));
            int          pointY           = Convert.ToInt16(Math.Truncate(point.Y));
            CGImage      cgimage          = image.CGImage;
            int          width            = Convert.ToInt16(image.Size.Width);
            int          height           = Convert.ToInt16(image.Size.Height);
            CGColorSpace colorSpace       = CGColorSpace.CreateDeviceRGB();
            int          bytesPerPixel    = 4;
            int          bytesPerRow      = bytesPerPixel * 1;
            int          bitsPerComponent = 8;

            byte []   pixelData = { 0, 0, 0, 0 };
            CGContext context   = new CGBitmapContext(pixelData,
                                                      1,
                                                      1,
                                                      bitsPerComponent,
                                                      bytesPerRow,
                                                      colorSpace,
                                                      CGImageAlphaInfo.PremultipliedLast /*| CGBitmapFlags.ByteOrder32Big*/);

            //			colorSpace.Dispose ();
            context.SetFillColorSpace(colorSpace);              //    CGColorSpaceRelease(colorSpace); //TODO Not Sure
            context.SetBlendMode(CGBlendMode.Copy);

            // Draw the pixel we areInterestedIn onto the bitmap context
            context.TranslateCTM(-pointX, pointY - (nfloat)height);
            context.DrawImage(new CGRect(0.0f, 0.0f, (nfloat)width, (nfloat)height), image.CGImage);
            context.Dispose();               // CGContextRelease(context); //TODO Not Sure

            // Convert color values [0..255] to floats [0.0..1.0]
            nfloat red   = (nfloat)pixelData [0] / 255.0f;
            nfloat green = (nfloat)pixelData [1] / 255.0f;
            nfloat blue  = (nfloat)pixelData [2] / 255.0f;
            nfloat alpha = (nfloat)pixelData [3] / 255.0f;

            return(UIColor.FromRGBA(red, green, blue, alpha));
        }
Exemplo n.º 20
0
        private int GetCharacterIndexAtPoint(Point point)
        {
            if (!_drawRect.Contains(point))
            {
                return(-1);
            }

            // Find the tapped character's index
            var partialFraction      = (nfloat)0;
            var pointInTextContainer = new CGPoint(point.X - _drawRect.X, point.Y - _drawRect.Y);

#pragma warning disable CS0618 // Type or member is obsolete (For VS2017 compatibility)
            var characterIndex = (int)_layoutManager.CharacterIndexForPoint(pointInTextContainer, _layoutManager.TextContainers.FirstOrDefault(), ref partialFraction);
#pragma warning restore CS0618 // Type or member is obsolete

            return(characterIndex);
        }
Exemplo n.º 21
0
        public void HandleTapAtPoint(CGPoint point)
        {
            var    bigCubeRect    = new CGRect(70, 210, 180, 180);
            CGRect scrollviewRect = ScrollableFrame;

            if (bigCubeRect.Contains(point.X, point.Y))
            {
                HandleBigCubeTap();
            }
            else if (scrollviewRect.Contains(point.X, point.Y))
            {
                var adjustedX = point.X + scrollOffset.X;

                int cubeIndex = (int)Math.Floor(adjustedX / LittleCubeWidth);
                HandleLittleCubeTap(cubeIndex);
            }
        }
Exemplo n.º 22
0
        public override bool PointInside(CGPoint point, UIEvent uievent)
        {
            CGRect rect     = this.Bounds;
            var    isInside = rect.Contains(point);

            if (!isInside)
            {
                foreach (UIView view in this.Subviews)
                {
                    isInside = view.Frame.Contains(point);
                    if (isInside)
                    {
                        break;
                    }
                }
            }
            return(isInside);
        }
Exemplo n.º 23
0
        private AvailableVehicle[] Clusterize(AvailableVehicle[] vehicles)
        {
            // Divide the map in 25 cells (5*5)
            const int numberOfRows    = 5;
            const int numberOfColumns = 5;
            // Maximum number of vehicles in a cell before we start displaying a cluster
            const int cellThreshold = 1;

            var result = new List <AvailableVehicle>();

            var bounds        = Bounds;
            var clusterWidth  = bounds.Width / numberOfColumns;
            var clusterHeight = bounds.Height / numberOfRows;

            var list = new List <AvailableVehicle>(vehicles);

            for (var rowIndex = 0; rowIndex < numberOfRows; rowIndex++)
            {
                for (var colIndex = 0; colIndex < numberOfColumns; colIndex++)
                {
                    var rect = new CGRect(Bounds.X + colIndex * clusterWidth, Bounds.Y + rowIndex * clusterHeight, clusterWidth, clusterHeight);

                    var vehiclesInRect = list.Where(v => rect.Contains(ConvertCoordinate(new CLLocationCoordinate2D(v.Latitude, v.Longitude), this))).ToArray();
                    if (vehiclesInRect.Length > cellThreshold)
                    {
                        var clusterBuilder = new VehicleClusterBuilder();
                        foreach (var v in vehiclesInRect)
                        {
                            clusterBuilder.Add(v);
                        }
                        result.Add(clusterBuilder.Build());
                    }
                    else
                    {
                        result.AddRange(vehiclesInRect);
                    }
                    foreach (var v in vehiclesInRect)
                    {
                        list.Remove(v);
                    }
                }
            }
            return(result.ToArray());
        }
Exemplo n.º 24
0
        public override bool PointInside(CGPoint point, UIEvent uievent)
        {
            CGRect rect     = Bounds;
            bool   isInside = rect.Contains(point);

            if (!isInside)
            {
                foreach (UIView view in Subviews)
                {
                    isInside = view.Frame.Contains(point);
                    if (isInside)
                    {
                        //Aktion stehen die ausgeführt wird
                        break;
                    }
                }
            }

            return(isInside);
        }
Exemplo n.º 25
0
		public override void RenderPointLabels (TKChartSeries series, CGRect bounds, CGContext ctx)
		{
			if (labelLayer != null) {
				labelLayer.RemoveFromSuperLayer ();
			}

			for (int i = 0; i < series.Items.Length; i++) {
				TKChartData dataPoint = (TKChartData)series.Items [i];
				CGPoint location = base.LocationForDataPoint (dataPoint, series, bounds);
				if (!bounds.Contains(location)) {
					continue;
				}

				TKChartPointLabel label = this.LabelForDataPoint (dataPoint, series, (uint)i);
				CGRect labelRect;
				TKChartPointLabelStyle labelStyle = series.Style.PointLabelStyle;
				if (this.isSelectedPoint) {
					labelRect = new CGRect ((float)(location.X - 17.5), (float)(location.Y - 10 - 2.5 * Math.Abs (labelStyle.LabelOffset.Vertical)), 35, 30);
					if (labelRect.Y < bounds.Y) {
						this.labelLayer.IsOutsideBounds = true;
						labelRect.Y = (float)(location.Y + 10 + 2.5 * Math.Abs (labelStyle.LabelOffset.Vertical) - labelRect.Size.Height);
					} else {
						this.labelLayer.IsOutsideBounds = false;
					}

					this.labelLayer.Frame = labelRect;
					this.Render.AddSublayer (this.labelLayer);
					this.labelLayer.SetNeedsDisplay ();
				} else {
					CGSize labelSize = label.SizeThatFits (bounds.Size);
					labelRect = new CGRect ((float)(location.X - labelSize.Width / 2.0 + labelStyle.LabelOffset.Horizontal),
						(float)(location.Y - labelSize.Height / 2.0 + labelStyle.LabelOffset.Vertical), labelSize.Width, labelSize.Height);

					if (labelRect.Y < this.Render.Bounds.Y) {
						labelRect.Y = (float)(location.Y - labelSize.Height / 2.0 + Math.Abs (labelStyle.LabelOffset.Vertical));
					}

					label.DrawInContext (ctx, labelRect, new TKChartVisualPoint(new PointF(0, 0)), UIColor.White);
				}
			}
		}
        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());
        }
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);
            var touch = touches.AnyObject as UITouch;

            if (touch != null)
            {
                endPoint = touch.LocationInView(this);
                if (!currentFrame.Contains(this.endPoint))
                {
                    return;
                }

                StoreEndCoordinate();
                swiped = true;
                co_ordinates.Add(new ScratchedPoints {
                    startPoint = startPoint, endPoint = endPoint
                });
                startPoint = endPoint;
                SetNeedsDisplay();
            }
        }
Exemplo n.º 28
0
                void CellTapped(UITapGestureRecognizer tapRecognizer)
                {
                    var point      = tapRecognizer.LocationInView(this);
                    var totalWidth = Columns * 75 + (Columns - 1) * 4;
                    var startX     = (Bounds.Size.Width - totalWidth) / 2;

                    var frame = new CGRect(startX, 2, 75, 75);

                    for (int i = 0; i < RowAssets.Count; ++i)
                    {
                        if (frame.Contains(point))
                        {
                            ELCAsset asset = RowAssets[i];
                            asset.Selected = !asset.Selected;
                            var overlayView = OverlayViewArray[i];
                            overlayView.Hidden = !asset.Selected;
                            break;
                        }
                        var x = frame.X + frame.Width + 4;
                        frame = new CGRect(x, frame.Y, frame.Width, frame.Height);
                    }
                }
        protected virtual void CenterViewInScroll(UIView viewToCenter, UIScrollView scrollView, nfloat keyboardHeight)
        {
            var contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardHeight, 0.0f);

            scrollView.ContentInset          = contentInsets;
            scrollView.ScrollIndicatorInsets = contentInsets;

            // Position of the active field relative isnside the scroll view
            // If activeField is hidden by keyboard, scroll it so it's visible
            CGRect viewRectAboveKeyboard = new CGRect(this.View.Frame.Location, new CGSize(this.View.Frame.Width, this.View.Frame.Size.Height - keyboardHeight));

            CGRect activeFieldAbsoluteFrame = ViewToCenterOnKeyboardShown.Superview.ConvertRectToView(ViewToCenterOnKeyboardShown.Frame, this.View);

            // activeFieldAbsoluteFrame is relative to this.View so does not include any scrollView.ContentOffset

            // Check if the activeField will be partially or entirely covered by the keyboard
            if (!viewRectAboveKeyboard.Contains(activeFieldAbsoluteFrame))
            {
                // Scroll to the activeField Y position + activeField.Height + current scrollView.ContentOffset.Y - the keyboard Height
                CGPoint scrollPoint = new CGPoint(0.0f, activeFieldAbsoluteFrame.Location.Y + activeFieldAbsoluteFrame.Height + scrollView.ContentOffset.Y - viewRectAboveKeyboard.Height + VerticalSpacingFromKeyboard);
                scrollView.SetContentOffset(scrollPoint, true);
            }
        }
Exemplo n.º 30
0
        private void tapAction()
        {
            if (punchTextView.IsFirstResponder)
            {
                punchTextView.ResignFirstResponder();
            }

            else
            {
                CGRect  deletionAreaRect = new CGRect(0, this.Frame.Height / 2 - 25, 44, 50);
                CGPoint point            = tap.LocationInView(this);

                if (deletionAreaRect.Contains(point))
                {
                    int         buttonClicked = -1;
                    UIAlertView alert1        = new UIAlertView(@"Alert", @"Are you sure you want to delete?", null, NSBundle.MainBundle.LocalizedString("Cancel", "Cancel"), NSBundle.MainBundle.LocalizedString("OK", "OK"));
                    alert1.Show();

                    alert1.Clicked += (sender, buttonArgs) => {
                        buttonClicked = (int)buttonArgs.ButtonIndex;
                    };

                    //Wait for a button press.
                    while (buttonClicked == -1)
                    {
                        NSRunLoop.Current.RunUntil(NSDate.FromTimeIntervalSinceNow(0.5));
                    }

                    if (buttonClicked == 1)
                    {
                        this.punchItems.Remove(this.punch);
                        this.optionsTableView.ReloadData();
                        IsPunchValueChanged = true;
                    }
                }
            }
        }
        private void ScrollViewToShowCurrentResponder(NSNotification notification)
        {
            var    keyboardInfoValue = notification.UserInfo[UIKeyboard.FrameEndUserInfoKey] as NSValue;
            CGRect rawFrame          = keyboardInfoValue.CGRectValue;
            CGRect keyboardFrame     = View.ConvertRectFromView(rawFrame, null);
            nfloat keyboardHeight    = keyboardFrame.Height;

            UIEdgeInsets contentInsets = new UIEdgeInsets(0, 0, keyboardHeight, 0);

            ContentScrollView.ContentInset          = contentInsets;
            ContentScrollView.ScrollIndicatorInsets = contentInsets;

            CGRect aRect = View.Frame;

            aRect.Size = new CGSize(aRect.Size.Width, keyboardHeight);

            var responder = View.GetFirstResponder();

            if (!aRect.Contains(responder.Frame))
            {
                PointF scrollPoint = new PointF(0.0f, (float)responder.Frame.Y - (float)keyboardHeight);
                ContentScrollView.SetContentOffset(scrollPoint, true);
            }
        }
		/// <summary>
		/// Determines whether this instance can start sliding given the touch position and the 
		/// current location/size of the top view. 
		/// Note that touchPosition is in Screen coordinate.
		/// </summary>
		/// <returns>true</returns>
		/// <c>false</c>
		/// <param name="touchPosition">Touch position.</param>
		/// <param name="topViewCurrentFrame">Top view's current frame.</param>
		public override bool CanStartSliding(CGPoint touchPosition, CGRect topViewCurrentFrame)
		{
			if (!IsVisible)
			{
				return (touchPosition.X >= View.Bounds.Size.Width - EdgeTolerance && touchPosition.X <= View.Bounds.Size.Width);
			}
			else
			{
				return topViewCurrentFrame.Contains (touchPosition);
			}
		}
		/// <summary>
		/// Determines whether this instance can start sliding given the touch position and the 
		/// current location/size of the top view. 
		/// Note that touchPosition is in Screen coordinate.
		/// </summary>
		/// <returns>true</returns>
		/// <c>false</c>
		/// <param name="touchPosition">Touch position.</param>
		/// <param name="topViewCurrentFrame">Top view's current frame.</param>
		public override bool CanStartSliding(CGPoint touchPosition, CGRect topViewCurrentFrame)
		{
			if (!IsVisible)
			{
				return (touchPosition.X >= 0.0f && touchPosition.X <= EdgeTolerance);
			}
			else
			{
				return topViewCurrentFrame.Contains (touchPosition);
			}
		}
Exemplo n.º 34
0
		bool TouchIsInRect (UITouch touch, CGRect rect)
		{
			rect = CGAffineTransform.CGRectApplyAffineTransform (rect, CGAffineTransform.MakeScale (Bounds.Width, Bounds.Height));
			return rect.Contains (touch.LocationInView (this));
		}
		/// <summary>
		/// Determines whether this instance can start sliding given the touch position and the 
		/// current location/size of the top view. 
		/// Note that touchPosition is in Screen coordinate.
		/// </summary>
		/// <returns>true</returns>
		/// <c>false</c>
		/// <param name="touchPosition">Touch position.</param>
		/// <param name="topViewCurrentFrame">Top view's current frame.</param>
		public override bool CanStartSliding(CGPoint touchPosition, CGRect topViewCurrentFrame)
		{
			// touchPosition is in Screen coordinate.

			float offset = 0;
			touchPosition.Y += offset;

			if (!IsVisible)
			{
				return (touchPosition.Y >= (View.Bounds.Height - EdgeTolerance) && touchPosition.Y <= View.Bounds.Height);
			}
			else
			{
				return topViewCurrentFrame.Contains (touchPosition);
			}
		}
Exemplo n.º 36
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;
			}
		}
Exemplo n.º 37
0
        public void TappedTickerView(UITapGestureRecognizer recog)
        {
            if (tapHandler==null)
                return;

            CGPoint point = recog.LocationInView(this);
            point.X = point.X + VisibleContentRect.X;
            UIView tappedView = null;
            Console.WriteLine("point is " + point.ToString());
            foreach (UIView v in scrollView.Subviews)
            {
                if (!(v is UIImageView))
                {
                    Console.WriteLine("v with tag {0} and frame {1}",v.Tag,v.Frame.ToString());
                    tempFrame = v.Frame;
                    tempFrame.Height = Bounds.Height;
                    if (tempFrame.Contains(point))
                    {
                        tappedView = v;
                        break;
                    }
                }
            }

            if (tapHandler!=null && tappedView!=null)
                tapHandler(tappedView);
        }
                void CellTapped(UITapGestureRecognizer tapRecognizer)
                {
                    var point = tapRecognizer.LocationInView (this);
                    var totalWidth = Columns * 75 + (Columns - 1) * 4;
                    var startX = (Bounds.Size.Width - totalWidth) / 2;

                    var frame = new CGRect (startX, 2, 75, 75);
                    for (int i = 0; i < RowAssets.Count; ++i) {
                        if (frame.Contains (point)) {
                            ELCAsset asset = RowAssets [i];
                            asset.Selected = !asset.Selected;
                            var overlayView = OverlayViewArray [i];
                            overlayView.Hidden = !asset.Selected;
                            break;
                        }
                        var x = frame.X + frame.Width + 4;
                        frame = new CGRect (x, frame.Y, frame.Width, frame.Height);
                    }
                }