コード例 #1
0
        public override void Draw(CGRect rect)
        {
            using (var context = UIGraphics.GetCurrentContext())
            {
                switch (_maskType)
                {
                case MaskType.Black:
                    UIColor.FromWhiteAlpha(0f, 0.5f).SetColor();
                    context.FillRect(Bounds);
                    break;

                case MaskType.Gradient:
                    nfloat[] colors    = new nfloat[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f };
                    nfloat[] locations = new nfloat[] { 0.0f, 1.0f };
                    using (var colorSpace = CGColorSpace.CreateDeviceRGB())
                    {
                        using (var gradient = new CGGradient(colorSpace, colors, locations))
                        {
                            var   center = new CGPoint(Bounds.Size.Width / 2, Bounds.Size.Height / 2);
                            float radius = Math.Min((float)Bounds.Size.Width, (float)Bounds.Size.Height);
                            context.DrawRadialGradient(gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation);
                        }
                    }

                    break;
                }
            }
        }
コード例 #2
0
 //Set the bounds for the rectangle that will need to be redrawn to show the drawn path.
 void resetBounds(CGPoint point)
 {
     minX = point.X - 1;
     maxX = point.X + 1;
     minY = point.Y - 1;
     maxY = point.Y + 1;
 }
コード例 #3
0
		public void ValidPointsArrayDoesGetLoaded ()
		{
			SignaturePadView signature = new SignaturePadView ();
			CGPoint [] points = new CGPoint [] { new CGPoint (0, 0), new CGPoint (10, 30), new CGPoint (50, 70) };
			signature.LoadPoints (points);
			Assert.That (signature.Points.Count () > 0);
		}
コード例 #4
0
        public void Focus(CGPoint pointOfInterest)
        {
            //Get the device
            if (AVMediaType.Video == null)
            {
                return;
            }

            var device = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);

            if (device == null)
            {
                return;
            }

            //See if it supports focusing on a point
            if (device.FocusPointOfInterestSupported && !device.AdjustingFocus)
            {
                NSError err = null;

                //Lock device to config
                if (device.LockForConfiguration(out err))
                {
                    Console.WriteLine("Focusing at point: " + pointOfInterest.X + ", " + pointOfInterest.Y);

                    //Focus at the point touched
                    device.FocusPointOfInterest = pointOfInterest;
                    device.FocusMode            = AVCaptureFocusMode.ContinuousAutoFocus;
                    device.UnlockForConfiguration();
                }
            }
        }
コード例 #5
0
        CGPoint PointOnCircle(CGPoint center, float radius, float angleInDegrees)
        {
            float x = radius * (float)Math.Cos(angleInDegrees * Math.PI / 180) + radius;
            float y = radius * (float)Math.Sin(angleInDegrees * Math.PI / 180) + radius;

            return(new CGPoint(x, y));
        }
コード例 #6
0
        public void ValidPointsArrayDoesGetLoaded()
        {
            SignaturePadView signature = new SignaturePadView();

            CGPoint [] points = new CGPoint [] { new CGPoint(0, 0), new CGPoint(10, 30), new CGPoint(50, 70) };
            signature.LoadPoints(points);
            Assert.That(signature.Points.Count() > 0);
        }
コード例 #7
0
		public void EmptyPointsArrayDoesntChangeAnything ()
		{
			SignaturePadView signature = new SignaturePadView ();
			CGPoint [] points = new CGPoint [] { new CGPoint (0, 0), new CGPoint (10, 30), new CGPoint (50, 70) };
			signature.LoadPoints (points);
			signature.LoadPoints (new CGPoint [0]);
			Assert.That (signature.Points.Count () > 0);
		}
コード例 #8
0
        public void EmptyPointsArrayDoesntChangeAnything()
        {
            SignaturePadView signature = new SignaturePadView();

            CGPoint [] points = new CGPoint [] { new CGPoint(0, 0), new CGPoint(10, 30), new CGPoint(50, 70) };
            signature.LoadPoints(points);
            signature.LoadPoints(new CGPoint [0]);
            Assert.That(signature.Points.Count() > 0);
        }
コード例 #9
0
        static CGPoint RotatePoint(CGPoint center, nfloat radius, double phi)
        {
            var sinPhi = Math.Sin(phi);
            var cosPhi = Math.Cos(phi);

            var x = center.X + radius * cosPhi;
            var y = center.Y + radius * sinPhi;

            return(new CGPoint((nfloat)x, (nfloat)y));
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SomeTestProject.MapMarker"/> class.
        /// </summary>
        /// <param name="point">Point.</param>
        /// <param name="image">Bitmap.</param>
        /// <param name="alignment">Alignment.</param>
        public MapMarker(CGPoint point, MapControlAlignmentType alignment, UIImage image)
            : base(new UIButton(UIButtonType.Custom), point, alignment, (int)image.Size.Width, (int)image.Size.Height)
        {
            _image = image;

            this.View.SetImage(image, UIControlState.Normal);
            this.View.SetImage(image, UIControlState.Highlighted);
            this.View.SetImage(image, UIControlState.Disabled);

            this.View.TouchUpInside += view_TouchUpInside;
            this.TogglePopupOnClick  = true;
        }
コード例 #11
0
 public GADBannerView(GADAdSize size, global::System.Drawing.PointF origin)
     : base(NSObjectFlag.Empty)
 {
     IsDirectBinding = GetType().Assembly == global::ApiDefinition.Messaging.this_assembly;
     if (IsDirectBinding)
     {
         Handle = ApiDefinition.Messaging.IntPtr_objc_msgSend_GADAdSize_PointF(this.Handle, selInitWithAdSizeOrigin_Handle, size, origin);
     }
     else
     {
         Handle = ApiDefinition.Messaging.IntPtr_objc_msgSendSuper_GADAdSize_PointF(this.SuperHandle, selInitWithAdSizeOrigin_Handle, size, origin);
     }
 }
コード例 #12
0
        public override void Draw(CGRect rect)
        {
            var context = UIGraphics.GetCurrentContext();
            var bounds  = Bounds;

            UIColor background = Enabled ? pressed ? HighlightedColor : NormalColor : DisabledColor;
            float   alpha      = 1;

            CGPath container;

            container = GraphicsUtil.MakeRoundedRectPath(bounds, 14);
            context.AddPath(container);
            context.Clip();

            using (var cs = CGColorSpace.CreateDeviceRGB()){
                var topCenter    = new CGPoint(bounds.GetMidX(), 0);
                var midCenter    = new CGPoint(bounds.GetMidX(), bounds.GetMidY());
                var bottomCenter = new CGPoint(bounds.GetMidX(), bounds.GetMaxY());

                using (var gradient = new CGGradient(cs, new nfloat [] { 0.23f, 0.23f, 0.23f, alpha, 0.47f, 0.47f, 0.47f, alpha }, new nfloat [] { 0, 1 })){
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }

                container = GraphicsUtil.MakeRoundedRectPath(bounds.Inset(1, 1), 13);
                context.AddPath(container);
                context.Clip();
                using (var gradient = new CGGradient(cs, new nfloat [] { 0.05f, 0.05f, 0.05f, alpha, 0.15f, 0.15f, 0.15f, alpha }, new nfloat [] { 0, 1 })){
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }

                var nb = bounds.Inset(4, 4);
                container = GraphicsUtil.MakeRoundedRectPath(nb, 10);
                context.AddPath(container);
                context.Clip();

                background.SetFill();
                context.FillRect(nb);

                using (var gradient = new CGGradient(cs, new nfloat [] { 1, 1, 1, .35f, 1, 1, 1, 0.06f }, new nfloat [] { 0, 1 })){
                    context.DrawLinearGradient(gradient, topCenter, midCenter, 0);
                }
                context.SetLineWidth(2);
                context.AddPath(container);
                context.ReplacePathWithStrokedPath();
                context.Clip();

                using (var gradient = new CGGradient(cs, new nfloat [] { 1, 1, 1, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f }, new nfloat [] { 0, 1 })){
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }
            }
        }
コード例 #13
0
        CAShapeLayer CreateRingLayer(CGPoint center, float radius, float lineWidth, UIColor color)
        {
            var smoothedPath = CreateCirclePath(center, radius, 72);
            var slice        = new CAShapeLayer();

            slice.Frame       = new CGRect(center.X - radius, center.Y - radius, radius * 2, radius * 2);
            slice.FillColor   = UIColor.Clear.CGColor;
            slice.StrokeColor = color.CGColor;
            slice.LineWidth   = lineWidth;
            slice.LineCap     = CAShapeLayer.JoinBevel;
            slice.LineJoin    = CAShapeLayer.JoinBevel;
            slice.Path        = smoothedPath.CGPath;
            return(slice);
        }
コード例 #14
0
        public RadialProgressLayer(nfloat startRadius, nfloat endRadius, nfloat backgroundWidth, nfloat progressLayerWidth)
            : this()
        {
            this.startRadius        = startRadius;
            this.endRadius          = endRadius;
            this.backgroundWidth    = backgroundWidth;
            this.progressLayerWidth = progressLayerWidth;

            Bounds     = new CGRect(CGPoint.Empty, new CGSize(progressLayerWidth, progressLayerWidth));
            BackBounds = new CGRect(CGPoint.Empty, new CGSize(backgroundWidth, backgroundWidth));

            CenterPoint       = new CGPoint(Bounds.GetMidX(), Bounds.GetMidY());
            fullProgressImage = GenerateFullProgressImage();
        }
コード例 #15
0
        public override void TouchesMoved(Foundation.NSSet touches, UIEvent evt)
        {
            UITouch touch = touches.AnyObject as UITouch;

            //Obtain the location of the touch and add it to the current path and current_points array.
            CGPoint touchLocation = touch.LocationInView(this);

            currentPath.AddLineTo(touchLocation);
            currentPoints.Add(touchLocation);

            updateBounds(touchLocation);
            SetNeedsDisplayInRect(new CGRect(minX, minY,
                                             (nfloat)Math.Abs(maxX - minX),
                                             (nfloat)Math.Abs(maxY - minY)));
        }
コード例 #16
0
        /// <summary>
        /// </summary>
        /// <param name='progressType'>
        /// Progress type.
        /// </param>
        public RadialProgressView(Func <nfloat, string> labelText = null, RadialProgressViewStyle progressType = RadialProgressViewStyle.Big, UIColor bgprogressColor1 = null, int width = 10)
        {
            this.progressType   = progressType;
            LabelTextDelegate   = labelText;
            radialProgressLayer = GetRadialLayerByType(progressType);
            Bounds                         = radialProgressLayer.BackBounds;
            bgprogressColor                = bgprogressColor1;
            CenterPoint                    = new CGPoint(Bounds.GetMidX(), Bounds.GetMidY());
            UserInteractionEnabled         = false;
            Layerwidth                     = width;
            MinValue                       = DefaultMinValue;
            MaxValue                       = DefaultMaxValue;
            radialProgressLayer.Layerwidth = Layerwidth;

            InitSubviews();
        }
コード例 #17
0
        /// <summary>
        /// </summary>
        /// <param name='progressType'>
        /// Progress type.
        /// </param>
        public RadialProgressView(Func <nfloat, string> labelText = null, RadialProgressViewStyle progressType = RadialProgressViewStyle.Big)
        {
            this.progressType   = progressType;
            LabelTextDelegate   = labelText;
            radialProgressLayer = GetRadialLayerByType(progressType);
            Bounds = radialProgressLayer.BackBounds;

            CenterPoint            = new CGPoint(Bounds.GetMidX(), Bounds.GetMidY());
            BackgroundColor        = UIColor.Clear;
            UserInteractionEnabled = false;

            MinValue = DefaultMinValue;
            MaxValue = DefaultMaxValue;

            InitSubviews();
        }
コード例 #18
0
ファイル: MonkeyView.cs プロジェクト: sdhakal/imageProject
		public void Update(Monkey monkey, CGRect bounds)
		{
			var transform = CGAffineTransform.MakeIdentity ();
			transform.Rotate (monkey.Rotation);
			transform.Scale (monkey.Scale, monkey.Scale);
			Transform = transform;

			// Convert location from top/left to center coords.
			var widthOffset = Frame.Width * 0.5f;
			var heightOffset = Frame.Width * 0.5f;

			var x = bounds.Width * monkey.X;
			var y = bounds.Height * monkey.Y;

			Center = new CGPoint (x + widthOffset, y + heightOffset);
		}
コード例 #19
0
 //Update the bounds for the rectangle to be redrawn if necessary for the given point.
 void updateBounds(CGPoint point)
 {
     if (point.X < minX + 1)
     {
         minX = point.X - 1;
     }
     if (point.X > maxX - 1)
     {
         maxX = point.X + 1;
     }
     if (point.Y < minY + 1)
     {
         minY = point.Y - 1;
     }
     if (point.Y > maxY - 1)
     {
         maxY = point.Y + 1;
     }
 }
コード例 #20
0
        UIBezierPath CreateCirclePath(CGPoint center, float radius, int sampleCount)
        {
            var     smoothedPath = new UIBezierPath();
            CGPoint startPoint   = PointOnCircle(center, radius, -90);

            smoothedPath.MoveTo(startPoint);

            float delta          = 360 / sampleCount;
            float angleInDegrees = -90;

            for (int i = 1; i < sampleCount; i++)
            {
                angleInDegrees += delta;
                var point = PointOnCircle(center, radius, angleInDegrees);
                smoothedPath.AddLineTo(point);
            }
            smoothedPath.AddLineTo(startPoint);
            return(smoothedPath);
        }
コード例 #21
0
        public override UIImage GenerateBackgroundImage()
        {
            UIImage resultImage;

            UIGraphics.BeginImageContextWithOptions(BackBounds.Size, false, UIScreen.MainScreen.Scale);
            var center = new CGPoint(BackBounds.GetMidX(), BackBounds.GetMidY());

            using (var context = UIGraphics.GetCurrentContext())
                using (var innerBorderBagelPath = BezierPathGenerator.Bagel(center, startRadius, endRadius, 0f, FullCircleAngle))
                {
                    context.SaveState();
                    context.SetFillColor(BGColors.CGColor);
                    innerBorderBagelPath.Fill();
                    context.RestoreState();

                    resultImage = UIGraphics.GetImageFromCurrentImageContext();
                }

            return(resultImage);
        }
コード例 #22
0
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            UITouch touch = touches.AnyObject as UITouch;

            //Obtain the location of the touch and add it to the current path and current_points array.
            CGPoint touchLocation = touch.LocationInView(this);

            currentPath.AddLineTo(touchLocation);
            currentPoints.Add(touchLocation);

            //Obtain the smoothed path and the points array for that path.
            currentPath = smoothedPathWithGranularity(40, out currentPoints);
            //Add the smoothed path and points array to their Lists.
            paths.Add(currentPath);
            points.Add(currentPoints.ToArray());

            //Obtain the image for the imported signature and display it in the image view.
            imageView.Image = GetImage(false);
            updateBounds(touchLocation);
            SetNeedsDisplay();
        }
コード例 #23
0
        public override void TouchesBegan(Foundation.NSSet touches, UIEvent evt)
        {
            //Create a new path and set the options.
            currentPath               = UIBezierPath.Create();
            currentPath.LineWidth     = StrokeWidth;
            currentPath.LineJoinStyle = CGLineJoin.Round;

            currentPoints.Clear();

            UITouch touch = touches.AnyObject as UITouch;

            //Obtain the location of the touch, move the path to that position and add it to the
            //current_points array.
            CGPoint touchLocation = touch.LocationInView(this);

            currentPath.MoveTo(touchLocation);
            currentPoints.Add(touchLocation);

            resetBounds(touchLocation);

            btnClear.Hidden = false;
        }
コード例 #24
0
        public static UIBezierPath Bagel(CGPoint center, nfloat startRadius, nfloat endRadius, nfloat startAngle, nfloat endAngle)
        {
            var bagelPath = new UIBezierPath();

            var rotationShift = -HalfMathPi;

            var centerRadius     = (startRadius + endRadius) / 2f;
            var roundingArcWidth = (endRadius - startRadius) / 2f;

            bagelPath.AddArc(RotatePoint(center, centerRadius, startAngle + rotationShift),
                             roundingArcWidth, -HalfMathPi, -3f * HalfMathPi, true);

            bagelPath.AddArc(center, startRadius, startAngle + rotationShift, endAngle + rotationShift, true);

            bagelPath.AddArc(RotatePoint(center, centerRadius, endAngle + rotationShift),
                             roundingArcWidth, HalfMathPi + endAngle, 3f * HalfMathPi + endAngle, false);

            bagelPath.AddArc(center, endRadius, endAngle + rotationShift, startAngle + rotationShift, false);

            bagelPath.ClosePath();

            return(bagelPath);
        }
コード例 #25
0
		public override void Draw (CGRect rect)
		{
			var context = UIGraphics.GetCurrentContext ();
			var bounds = Bounds;
			
			UIColor background = Enabled ? pressed ? HighlightedColor : NormalColor : DisabledColor;
			float alpha = 1;
			
			CGPath container;
			container = GraphicsUtil.MakeRoundedRectPath (bounds, 14);
			context.AddPath (container);
			context.Clip ();
			
			using (var cs = CGColorSpace.CreateDeviceRGB ()){
				var topCenter = new CGPoint (bounds.GetMidX (), 0);
				var midCenter = new CGPoint (bounds.GetMidX (), bounds.GetMidY ());
				var bottomCenter = new CGPoint (bounds.GetMidX (), bounds.GetMaxY ());

				using (var gradient = new CGGradient (cs, new nfloat [] { 0.23f, 0.23f, 0.23f, alpha, 0.47f, 0.47f, 0.47f, alpha }, new nfloat [] {0, 1})){
					context.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
				}
				
				container = GraphicsUtil.MakeRoundedRectPath (bounds.Inset (1, 1), 13);
				context.AddPath (container);
				context.Clip ();
				using (var gradient = new CGGradient (cs, new nfloat [] { 0.05f, 0.05f, 0.05f, alpha, 0.15f, 0.15f, 0.15f, alpha}, new nfloat [] {0, 1})){
					context.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
				}
				
				var nb = bounds.Inset (4, 4);
				container = GraphicsUtil.MakeRoundedRectPath (nb, 10);
				context.AddPath (container);
				context.Clip ();
				
				background.SetFill ();
				context.FillRect (nb);
				
				using (var gradient = new CGGradient (cs, new nfloat [] { 1, 1, 1, .35f, 1, 1, 1, 0.06f }, new nfloat [] { 0, 1 })){
					context.DrawLinearGradient (gradient, topCenter, midCenter, 0);
				}
				context.SetLineWidth (2);
				context.AddPath (container);
				context.ReplacePathWithStrokedPath ();
				context.Clip ();

				using (var gradient = new CGGradient (cs, new nfloat [] { 1, 1, 1, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f }, new nfloat [] { 0, 1 })){
					context.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
				}
			}
		}
コード例 #26
0
ファイル: ProgressHUD.cs プロジェクト: nicwise/BTProgressHUD
        void PositionHUD(NSNotification notification)
        {
            nfloat keyboardHeight = 0;
            double animationDuration = 0;

            Frame = UIScreen.MainScreen.Bounds;

            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
            bool ignoreOrientation = UIDevice.CurrentDevice.CheckSystemVersion (8, 0);

            if (notification != null) {
                var keyboardFrame = UIKeyboard.FrameEndFromNotification (notification);
                animationDuration = UIKeyboard.AnimationDurationFromNotification (notification);

                if (notification.Name == UIKeyboard.WillShowNotification || notification.Name == UIKeyboard.DidShowNotification) {
                    if (ignoreOrientation || IsPortrait (orientation))
                        keyboardHeight = keyboardFrame.Size.Height;
                    else
                        keyboardHeight = keyboardFrame.Size.Width;
                } else
                    keyboardHeight = 0;

            } else {
                keyboardHeight = VisibleKeyboardHeight;
            }

            CGRect orientationFrame = UIApplication.SharedApplication.KeyWindow.Bounds;

            CGRect statusBarFrame = UIApplication.SharedApplication.StatusBarFrame;

            if (!ignoreOrientation && IsLandscape (orientation)) {
                orientationFrame.Size = new CGSize (orientationFrame.Size.Height, orientationFrame.Size.Width);
                statusBarFrame.Size = new CGSize (statusBarFrame.Size.Height, statusBarFrame.Size.Width);

            }

            var activeHeight = orientationFrame.Size.Height;

            if (keyboardHeight > 0)
                activeHeight += statusBarFrame.Size.Height * 2;

            activeHeight -= keyboardHeight;
            nfloat posY = (float)Math.Floor (activeHeight * 0.45);
            nfloat posX = orientationFrame.Size.Width / 2;
            nfloat textHeight = _stringLabel.Frame.Height / 2 + 40;

            switch (toastPosition) {
            case ToastPosition.Bottom:
                posY = activeHeight - textHeight;
                break;
            case ToastPosition.Center:
                    // Already set above
                break;
            case ToastPosition.Top:
                posY = textHeight;
                break;
            default:
                break;
            }

            CGPoint newCenter;
            float rotateAngle;

            if (ignoreOrientation) {
                rotateAngle = 0.0f;
                newCenter = new CGPoint (posX, posY);
            } else {
                switch (orientation) {
                case UIInterfaceOrientation.PortraitUpsideDown:
                    rotateAngle = (float)Math.PI;
                    newCenter = new CGPoint (posX, orientationFrame.Size.Height - posY);
                    break;
                case UIInterfaceOrientation.LandscapeLeft:
                    rotateAngle = (float)(-Math.PI / 2.0f);
                    newCenter = new CGPoint (posY, posX);
                    break;
                case UIInterfaceOrientation.LandscapeRight:
                    rotateAngle = (float)(Math.PI / 2.0f);
                    newCenter = new CGPoint (orientationFrame.Size.Height - posY, posX);
                    break;
                default: // as UIInterfaceOrientationPortrait
                    rotateAngle = 0.0f;
                    newCenter = new CGPoint (posX, posY);
                    break;
                }
            }

            if (notification != null) {
                UIView.Animate (animationDuration,
                    0, UIViewAnimationOptions.AllowUserInteraction, delegate {
                    MoveToPoint (newCenter, rotateAngle);
                }, null);

            } else {
                MoveToPoint (newCenter, rotateAngle);
            }
        }
コード例 #27
0
ファイル: ProgressHUD.cs プロジェクト: nicwise/BTProgressHUD
 CGPoint PointOnCircle(CGPoint center, float radius, float angleInDegrees)
 {
     float x = radius * (float)Math.Cos (angleInDegrees * Math.PI / 180) + radius;
     float y = radius * (float)Math.Sin (angleInDegrees * Math.PI / 180) + radius;
     return new CGPoint (x, y);
 }
コード例 #28
0
ファイル: ProgressHUD.cs プロジェクト: nicwise/BTProgressHUD
 void MoveToPoint(CGPoint newCenter, float angle)
 {
     HudView.Transform = CGAffineTransform.MakeRotation (angle);
     HudView.Center = newCenter;
 }
コード例 #29
0
ファイル: ProgressHUD.cs プロジェクト: nicwise/BTProgressHUD
 CAShapeLayer CreateRingLayer(CGPoint center, float radius, float lineWidth, UIColor color)
 {
     var smoothedPath = CreateCirclePath (center, radius, 72);
     var slice = new CAShapeLayer ();
     slice.Frame = new CGRect (center.X - radius, center.Y - radius, radius * 2, radius * 2);
     slice.FillColor = UIColor.Clear.CGColor;
     slice.StrokeColor = color.CGColor;
     slice.LineWidth = lineWidth;
     slice.LineCap = CAShapeLayer.JoinBevel;
     slice.LineJoin = CAShapeLayer.JoinBevel;
     slice.Path = smoothedPath.CGPath;
     return slice;
 }
コード例 #30
0
ファイル: ProgressHUD.cs プロジェクト: nicwise/BTProgressHUD
        UIBezierPath CreateCirclePath(CGPoint center, float radius, int sampleCount)
        {
            var smoothedPath = new UIBezierPath ();
            CGPoint startPoint = PointOnCircle (center, radius, -90);

            smoothedPath.MoveTo (startPoint);

            float delta = 360 / sampleCount;
            float angleInDegrees = -90;
            for (int i = 1; i < sampleCount; i++) {
                angleInDegrees += delta;
                var point = PointOnCircle (center, radius, angleInDegrees);
                smoothedPath.AddLineTo (point);
            }
            smoothedPath.AddLineTo (startPoint);
            return smoothedPath;
        }
コード例 #31
0
        CGRect getCroppedRectangle(CGPoint [] cachedPoints)
        {
            var xMin = cachedPoints.Where (point => !point.IsEmpty).Min (point => point.X) - strokeWidth / 2;
            var xMax = cachedPoints.Where (point => !point.IsEmpty).Max (point => point.X) + strokeWidth / 2;
            var yMin = cachedPoints.Where (point => !point.IsEmpty).Min (point => point.Y) - strokeWidth / 2;
            var yMax = cachedPoints.Where (point => !point.IsEmpty).Max (point => point.Y) + strokeWidth / 2;

            xMin = (nfloat)Math.Max (xMin, 0);
            xMax = (nfloat)Math.Min (xMax, Bounds.Width);
            yMin = (nfloat)Math.Max (yMin, 0);
            yMax = (nfloat)Math.Min (yMax, Bounds.Height);

            return new CGRect (xMin, yMin, xMax - xMin, yMax - yMin);
        }
コード例 #32
0
 void MoveToPoint(CGPoint newCenter, float angle)
 {
     HudView.Transform = CGAffineTransform.MakeRotation(angle);
     HudView.Center    = newCenter;
 }
コード例 #33
0
        /*
         * Obtain a smoothed path with the specified granularity from the current path using Catmull-Rom spline.
         * Implemented using a modified version of the code in the solution at
         * http://stackoverflow.com/questions/8702696/drawing-smooth-curves-methods-needed.
         * Also outputs a List of the points corresponding to the smoothed path.
         */
        UIBezierPath smoothedPathWithGranularity(int granularity, out List <CGPoint> smoothedPoints)
        {
            List <CGPoint> pointsArray = currentPoints;

            smoothedPoints = new List <CGPoint> ();

            //Not enough points to smooth effectively, so return the original path and points.
            if (pointsArray.Count < 4)
            {
                smoothedPoints = pointsArray;
                return(currentPath);
            }

            //Create a new bezier path to hold the smoothed path.
            UIBezierPath smoothedPath = UIBezierPath.Create();

            smoothedPath.LineWidth     = StrokeWidth;
            smoothedPath.LineJoinStyle = CGLineJoin.Round;

            //Duplicate the first and last points as control points.
            pointsArray.Insert(0, pointsArray [0]);
            pointsArray.Add(pointsArray [pointsArray.Count - 1]);

            //Add the first point
            smoothedPath.MoveTo(pointsArray [0]);
            smoothedPoints.Add(pointsArray [0]);

            for (var index = 1; index < pointsArray.Count - 2; index++)
            {
                CGPoint p0 = pointsArray [index - 1];
                CGPoint p1 = pointsArray [index];
                CGPoint p2 = pointsArray [index + 1];
                CGPoint p3 = pointsArray [index + 2];

                //Add n points starting at p1 + dx/dy up until p2 using Catmull-Rom splines
                for (var i = 1; i < granularity; i++)
                {
                    float t   = (float)i * (1f / (float)granularity);
                    float tt  = t * t;
                    float ttt = tt * t;

                    //Intermediate point
                    CGPoint mid = default(CGPoint);
                    mid.X = 0.5f * (2f * p1.X + (p2.X - p0.X) * t +
                                    (2f * p0.X - 5f * p1.X + 4f * p2.X - p3.X) * tt +
                                    (3f * p1.X - p0.X - 3f * p2.X + p3.X) * ttt);
                    mid.Y = 0.5f * (2 * p1.Y + (p2.Y - p0.Y) * t +
                                    (2 * p0.Y - 5 * p1.Y + 4 * p2.Y - p3.Y) * tt +
                                    (3 * p1.Y - p0.Y - 3 * p2.Y + p3.Y) * ttt);

                    smoothedPath.AddLineTo(mid);
                    smoothedPoints.Add(mid);
                }

                //Add p2
                smoothedPath.AddLineTo(p2);
                smoothedPoints.Add(p2);
            }

            //Add the last point
            smoothedPath.AddLineTo(pointsArray [pointsArray.Count - 1]);
            smoothedPoints.Add(pointsArray [pointsArray.Count - 1]);

            return(smoothedPath);
        }
コード例 #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SomeTestProject.MapMarker"/> class.
 /// </summary>
 /// <param name="point">Point.</param>
 /// <param name="marker">Alignment.</param>
 public MapMarker(CGPoint point, MapControlAlignmentType alignment)
     : this(point, alignment, MapMarker.GetDefaultImage())
 {
 }
コード例 #35
0
        public static CGPoint ConvertViewPointToPdfPoint(CGPoint viewPoint, CGRect cropBox, nuint rotation, CGRect bounds)
        {
            IntPtr viewPointPtr = Marshal.AllocHGlobal (Marshal.SizeOf (viewPoint));
            IntPtr cropBoxPtr = Marshal.AllocHGlobal (Marshal.SizeOf (cropBox));
            IntPtr rotationPtr = Marshal.AllocHGlobal (Marshal.SizeOf (rotation));
            IntPtr boundsPtr = Marshal.AllocHGlobal (Marshal.SizeOf (bounds));

            IntPtr resultPtr;
            CGPoint result;

            try {
                Marshal.StructureToPtr ((object)viewPoint, viewPointPtr, true);
                Marshal.StructureToPtr ((object)cropBox, cropBoxPtr, true);
                Marshal.StructureToPtr ((object)rotation, rotationPtr, true);
                Marshal.StructureToPtr ((object)bounds, boundsPtr, true);

                resultPtr = PSPDFConvertViewPointToPDFPoint (viewPointPtr, cropBoxPtr, rotationPtr, boundsPtr);
                result = (CGPoint)Marshal.PtrToStructure (resultPtr, typeof (CGPoint));
            }
            finally {
                Marshal.FreeHGlobal (viewPointPtr);
                Marshal.FreeHGlobal (cropBoxPtr);
                Marshal.FreeHGlobal (rotationPtr);
                Marshal.FreeHGlobal (boundsPtr);
            }
            return result;
        }
コード例 #36
0
 //Update the bounds for the rectangle to be redrawn if necessary for the given point.
 void updateBounds(CGPoint point)
 {
     if (point.X < minX + 1)
         minX = point.X - 1;
     if (point.X > maxX - 1)
         maxX = point.X + 1;
     if (point.Y < minY + 1)
         minY = point.Y - 1;
     if (point.Y > maxY - 1)
         maxY = point.Y + 1;
 }
コード例 #37
0
 //Set the bounds for the rectangle that will need to be redrawn to show the drawn path.
 void resetBounds(CGPoint point)
 {
     minX = point.X - 1;
     maxX = point.X + 1;
     minY = point.Y - 1;
     maxY = point.Y + 1;
 }
コード例 #38
0
        /// <summary>
        /// Draw the contents of the Cell
        /// </summary>
        /// <param name="rect">Rect.</param>
        private void ReDraw(CGRect rect)
        {
            foreach (var aView in this.Subviews)
            {
                aView.RemoveFromSuperview();
            }

            mContentView = null;

            CGContext ctx = UIGraphics.GetCurrentContext();

            switch (Processor.Style)
            {
            case CellStyle.Blank:
            {
                GridView.Theme.BackgroundColor.ToUIColor().SetFill();
            }
            break;

            case CellStyle.Cell:
            {
                if (Processor.ShowSelection && Processor.IsSelected)
                {
                    GridView.Theme.CellBackgroundHighlight.ToUIColor().SetFill();
                }
                else
                {
                    var alterColor = (GridView.Theme.CellBackground2 != null) ? GridView.Theme.CellBackground2.ToUIColor()
                                                                 : GridView.Theme.CellBackground.ToUIColor();
                    var aColor = (Processor.IsOdd) ? GridView.Theme.CellBackground.ToUIColor() : alterColor;
                    aColor.SetFill();
                }
            }
            break;

            case CellStyle.Header:
            {
                GridView.Theme.HeaderBackground.ToUIColor().SetFill();
            }
            break;
            }


            ctx.SetLineWidth(GridView.Theme.CellBorderWidth);
            GridView.Theme.BorderColor.ToUIColor().SetStroke();

            CGPath _path = new CGPath();

            var aRect = new CGRect(rect.X, rect.Y, rect.Width - 0, rect.Height - 0);

            _path.AddRect(aRect);

            _path.CloseSubpath();

            ctx.AddPath(_path);
            ctx.DrawPath(CGPathDrawingMode.Fill);

            var topLeftPoint     = new CGPoint(0, 0);
            var topRightPoint    = new CGPoint(aRect.Width, 0);
            var bottomLeftPoint  = new CGPoint(0, aRect.Height);
            var bottomRightPoint = new CGPoint(aRect.Width, aRect.Height);

            switch (GridView.Theme.CellBorderStyle)
            {
            case BorderStyle.Full:
            {
                if (Processor.RowIndex != 0 && Processor.Style != CellStyle.Blank)
                {
                    //draw the upper line
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint });
                }

                if (Processor.Style != CellStyle.Blank && Processor.ColumnIndex != 0)
                {
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint });
                }

                //ctx.StrokeRect(aRect);
            }
            break;

            case BorderStyle.HorizontalOnly:
            {
                if (Processor.RowIndex != 0 && Processor.Style != CellStyle.Blank)
                {
                    //draw the upper line
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint });
                }
            }
            break;

            case BorderStyle.VerticalOnly:
            {
                if (Processor.Style != CellStyle.Blank && Processor.ColumnIndex != 0)
                {
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint });
                }
            }
            break;
            }

            ctx.SetAllowsAntialiasing(true);


            //do nothing else if the row is blank
            if (Processor.Style == CellStyle.Blank)
            {
                return;
            }

//			//get the row index, -1 if it's a header style
//			var index = (this.Style == CellStyle.Header) ? -1 : this.RowIndex;
//
//			var Value = GridView.GetValue (index, this.ColumnName).Value;

            if (Processor.Style != CellStyle.Blank && Processor.ValueObject.Value != null)
            {
                //update to work with different datatypes
                //check to see if the formatter is a DSViewFormatter
                if (Processor.Formatter != null && Processor.Formatter is DSViewFormatter)
                {
                    var viewFormatter = Processor.Formatter as DSViewFormatter;

                    var aView = viewFormatter.View;

                    if (!(aView is UIView))
                    {
                        throw new Exception("DSViewFormatter has type that isn't a UIView");
                    }

                    aView.Style = Processor.Style;
                    aView.Value = Processor.ValueObject.Value;
                    var aFrame = rect;

                    if (Processor.Formatter.Size != null)
                    {
                        aFrame.Width  = Processor.Formatter.Size.Width;
                        aFrame.Height = Processor.Formatter.Size.Height;
                    }

                    aView.ViewFrame    = aFrame.ToDSRectangle();
                    aView.IsReadOnly   = Processor.IsReadOnly;
                    aView.UpdateAction = (obj) => {
                        GridView.Processor.SetValue(Processor.Index, Processor.ColumnName, obj);
                    };
                    //aView.IsReadOnly =
                    mContentView = (UIView)aView;
                    this.AddSubview(mContentView);
                }
                else if (Processor.ValueObject.Value is UIImage || Processor.ValueObject.Value is DSBitmap)
                {
                    UIImage image = null;

                    if (Processor.ValueObject.Value is UIImage)
                    {
                        image = (UIImage)Processor.ValueObject.Value;
                    }
                    else if (Processor.ValueObject.Value is DSBitmap)
                    {
                        image = ((DSBitmap)Processor.ValueObject.Value).ToUIImage();
                    }

                    mContentView = new UIImageView(image);

                    var aFrame = mContentView.Frame;

                    if (Processor.Formatter != null)
                    {
                        aFrame.Width  = Processor.Formatter.Size.Width;
                        aFrame.Height = Processor.Formatter.Size.Height;

                        //anView.Frame = aFrame;
                    }

                    //try a centralize the image
                    var xPos = (this.Frame.Width / 2) - (aFrame.Size.Width / 2);
                    var yPos = (this.Frame.Height / 2) - (aFrame.Size.Height / 2);
                    aFrame.X = xPos;
                    aFrame.Y = yPos;

                    if (Processor.Formatter != null && Processor.Formatter is DSImageFormatter)
                    {
                        var formta = Processor.Formatter as DSImageFormatter;

                        if (formta.Margin != null)
                        {
                            //apply the margins to the frame
                            var mRect = aFrame.ToDSRectangle();

                            mRect.ApplyMargin(formta.Margin);

                            aFrame = mRect.ToRectangleF();
                        }
                    }

                    mContentView.Frame = aFrame.Integral();
                    this.AddSubview(mContentView);
                }
                else if (Processor.ValueObject.Value is Boolean && Processor.Formatter != null && Processor.Formatter is DSBooleanFormatter)
                {
                    var boolFormatter = Processor.Formatter as DSBooleanFormatter;

                    if (boolFormatter.Style == BooleanFormatterStyle.Text)
                    {
                        UILabel label = new UILabel(rect.Inset(5, 5));
                        label.BackgroundColor = UIColor.Clear;
                        label.Font            = (Processor.Style == CellStyle.Header) ? GridView.Theme.HeaderTextFont.ToUIFont() : GridView.Theme.CellTextFont.ToUIFont();
                        label.Text            = ((bool)Processor.ValueObject.Value) ? boolFormatter.TrueValue.ToString() : boolFormatter.FalseValue.ToString();

                        if (Processor.Style == CellStyle.Header)
                        {
                            label.TextAlignment = (UITextAlignment)GridView.Theme.HeaderTextAlignment;
                            label.TextColor     = GridView.Theme.HeaderTextForeground.ToUIColor();
                        }
                        else
                        {
                            var alterColor = (GridView.Theme.CellTextForeground2 != null) ? GridView.Theme.CellTextForeground2.ToUIColor()
                                                                 : GridView.Theme.CellTextForeground.ToUIColor();
                            var aColor = (Processor.IsOdd) ? GridView.Theme.CellTextForeground.ToUIColor() : alterColor;

                            label.TextColor = (Processor.ShowSelection && Processor.IsSelected) ? GridView.Theme.CellTextHighlight.ToUIColor() : aColor;

                            label.TextAlignment = (UITextAlignment)boolFormatter.TextAlignment;
                        }

                        mContentView = label;
                        this.AddSubview(mContentView);
                    }
                    else
                    {
                        var bValue = ((bool)Processor.ValueObject.Value) ? boolFormatter.TrueValue : boolFormatter.FalseValue;


                        UIImage image = null;

                        if (bValue != null)
                        {
                            if (bValue is String)
                            {
                                var fileName = bValue as String;

                                if (!String.IsNullOrWhiteSpace(fileName))
                                {
                                    image = new UIImage(fileName);
                                }
                            }
                            else if (bValue is UIImage)
                            {
                                image = (UIImage)bValue;
                            }
                            else if (bValue is DSBitmap)
                            {
                                image = ((DSBitmap)bValue).ToUIImage();
                            }
                        }

                        if (image != null)
                        {
                            var anView = new UIImageView(image);

                            var aFrame = anView.Frame;

                            if (Processor.Formatter != null)
                            {
                                aFrame.Width  = Processor.Formatter.Size.Width;
                                aFrame.Height = Processor.Formatter.Size.Height;
                            }

                            //try a centralize the image
                            var xPos = (this.Frame.Width / 2) - (aFrame.Size.Width / 2);
                            var yPos = (this.Frame.Height / 2) - (aFrame.Size.Height / 2);
                            aFrame.X = xPos;
                            aFrame.Y = yPos;

                            anView.Frame = aFrame.Integral();

                            mContentView = anView;
                            this.AddSubview(mContentView);
                        }
                    }
                }
                else
                {
                    var label = new UILabel(rect.Inset(5, 5));
                    label.BackgroundColor = this.BackgroundColor;
                    label.Font            = (Processor.Style == CellStyle.Header) ? GridView.Theme.HeaderTextFont.ToUIFont()
                                             : GridView.Theme.CellTextFont.ToUIFont();
                    label.Text          = Processor.ValueObject.Value.ToString();
                    label.LineBreakMode = UILineBreakMode.TailTruncation;

                    if (Processor.Style == CellStyle.Header)
                    {
                        int numLines = Processor.ValueObject.Value.ToString().Split('\n').Length;
                        label.Lines = (label.Frame.Height >= 13) ? numLines : 1;

                        var textAlignment = GridView.Theme.HeaderTextAlignment;

                        if (Processor.Formatter != null && Processor.Formatter is DSTextFormatter)
                        {
                            textAlignment = ((DSTextFormatter)Processor.Formatter).Alignment;
                        }
                        label.TextAlignment = (UITextAlignment)textAlignment;
                        label.TextColor     = GridView.Theme.HeaderTextForeground.ToUIColor();
                    }
                    else
                    {
                        var alterColor = (GridView.Theme.CellTextForeground2 != null) ? GridView.Theme.CellTextForeground2.ToUIColor() : GridView.Theme.CellTextForeground.ToUIColor();
                        var aColor     = (Processor.IsOdd) ? GridView.Theme.CellTextForeground.ToUIColor() : alterColor;

                        label.TextColor = (Processor.ShowSelection && Processor.IsSelected) ? GridView.Theme.CellTextHighlight.ToUIColor() : aColor;

                        var textAlignment = GridView.Theme.CellContentAlignment;

                        if (Processor.Formatter != null && Processor.Formatter is DSTextFormatter)
                        {
                            textAlignment = ((DSTextFormatter)Processor.Formatter).Alignment;
                        }

                        label.TextAlignment = (UITextAlignment)textAlignment;
                    }

                    mContentView = label;
                    this.AddSubview(mContentView);
                }
            }

            //Set the border
            if (Processor.Style != CellStyle.Blank)
            {
                ctx.SetLineWidth(GridView.Theme.BorderWidth);
                GridView.Theme.BorderColor.ToUIColor().SetStroke();

                switch (Processor.PositionType)
                {
                case CellPositionType.LeftTop:
                {
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint });
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint });
                }
                break;

                case CellPositionType.LeftMiddle:
                {
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint });
                }
                break;

                case CellPositionType.LeftBottom:
                {
                    ctx.StrokeLineSegments(new CGPoint[] { bottomLeftPoint, bottomRightPoint });
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint });
                }
                break;

                case CellPositionType.CenterTop:
                {
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint });
                }
                break;

                case CellPositionType.CenterMiddle:
                {
                }
                break;

                case CellPositionType.CenterBottom:
                {
                    ctx.StrokeLineSegments(new CGPoint[] { bottomLeftPoint, bottomRightPoint });
                }
                break;

                case CellPositionType.RightTop:
                {
                    ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint });
                    ctx.StrokeLineSegments(new CGPoint[] { topRightPoint, bottomRightPoint });
                }
                break;

                case CellPositionType.RightMiddle:
                {
                    ctx.StrokeLineSegments(new CGPoint[] { topRightPoint, bottomRightPoint });
                }
                break;

                case CellPositionType.RightBottom:
                {
                    ctx.StrokeLineSegments(new CGPoint[] { bottomLeftPoint, bottomRightPoint });
                    ctx.StrokeLineSegments(new CGPoint[] { topRightPoint, bottomRightPoint });
                }
                break;
                }
            }

            if (Processor.Style == CellStyle.Header && Processor.SortStyle != SortIndicatorStyle.None)
            {
                //draw the up indicator
                DSBitmap anImage;

                switch (Processor.SortStyle)
                {
                case SortIndicatorStyle.Ascending:
                    anImage = GridView.Theme.HeaderSortIndicatorUp;
                    break;

                case SortIndicatorStyle.Descending:
                    anImage = GridView.Theme.HeaderSortIndicatorDown;
                    break;

                case SortIndicatorStyle.Default:
                    anImage = GridView.Theme.HeaderSortIndicatorDefault;
                    break;

                default:
                    anImage = null;
                    break;
                }

                if (anImage != null)
                {
                    var aUIImage = anImage.ToUIImage();

                    //if iOS7 or above set as template image
                    if (iOSHelper.IsiOS7)
                    {
                        aUIImage = aUIImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                    }

                    UIImageView aView = new UIImageView(aUIImage);

                    //if iOS7 tint the image with the header text color
                    if (iOSHelper.IsiOS7)
                    {
                        aView.TintColor = GridView.Theme.HeaderTextForeground.ToUIColor();
                    }

                    var aLeft = this.Bounds.Width - aView.Image.Size.Width;
                    var atop  = (this.Bounds.Height - aView.Image.Size.Height) / 2;

                    aView.Frame = new CGRect(aLeft, atop, aView.Image.Size.Width, aView.Image.Size.Height).Integral();

                    this.AddSubview(aView);
                }
            }
        }
コード例 #39
0
ファイル: ProgressHUD.cs プロジェクト: nicwise/BTProgressHUD
        public override void Draw(CGRect rect)
        {
            using (var context = UIGraphics.GetCurrentContext ()) {
                switch (_maskType) {
                case MaskType.Black:
                    UIColor.FromWhiteAlpha (0f, 0.5f).SetColor ();
                    context.FillRect (Bounds);
                    break;
                case MaskType.Gradient:
                    nfloat[] colors = new nfloat[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f };
                    nfloat[] locations = new nfloat[] { 0.0f, 1.0f };
                    using (var colorSpace = CGColorSpace.CreateDeviceRGB ()) {
                        using (var gradient = new CGGradient (colorSpace, colors, locations)) {
                            var center = new CGPoint (Bounds.Size.Width / 2, Bounds.Size.Height / 2);
                            float radius = Math.Min ((float)Bounds.Size.Width, (float)Bounds.Size.Height);
                            context.DrawRadialGradient (gradient, center, 0, center, radius, CGGradientDrawingOptions.DrawsAfterEndLocation);
                        }
                    }

                    break;
                }
            }
        }
コード例 #40
0
ファイル: MapView.cs プロジェクト: UnifyKit/OsmSharp
        /// <summary>
        /// Pan the specified some.
        /// </summary>
        /// <param name="some">Some.</param>
        private void Pan(UIPanGestureRecognizer pan)
        {
            CGRect rect = this.Frame;
            if (this.MapAllowPan &&
                rect.Width > 0 && this.Map != null)
            {
                this.StopCurrentAnimation();
                CGPoint offset = pan.TranslationInView(this);
                if (pan.State == UIGestureRecognizerState.Ended)
                {
                    this.NotifyMovementByInvoke();

                    // raise map touched event.
                    this.RaiseMapTouched();
                    this.RaiseMapTouchedUp();
                }
                else if (pan.State == UIGestureRecognizerState.Began)
                {
                    _prevOffset = new CGPoint(0, 0);
                    this.RaiseMapTouchedDown();
                }
                else if (pan.State == UIGestureRecognizerState.Changed)
                {
                    View2D view = this.CreateView(rect);
                    double centerXPixels = rect.Width / 2.0f - (offset.X - _prevOffset.X);
                    double centerYPixels = rect.Height / 2.0f - (offset.Y - _prevOffset.Y);

                    _prevOffset = offset;

                    double[] sceneCenter = view.FromViewPort(rect.Width, rect.Height,
                        centerXPixels, centerYPixels);

                    this.MapCenter = this.Map.Projection.ToGeoCoordinates(
                        sceneCenter[0], sceneCenter[1]);

                    this.NotifyMovementByInvoke();

                    // raise map move event.
                    this.RaiseMapMove();
                }
            }
        }
コード例 #41
0
        //Allow the user to import an array of points to be used to draw a signature in the view, with new
        //lines indicated by a CGPoint.Empty in the array.
        public void LoadPoints(CGPoint[] loadedPoints)
        {
            if (loadedPoints == null || loadedPoints.Count () == 0)
                return;

            var startIndex = 0;
            var emptyIndex = loadedPoints.ToList ().IndexOf (CGPoint.Empty);

            if (emptyIndex == -1)
                emptyIndex = loadedPoints.Count ();

            //Clear any existing paths or points.
            paths = new List<UIBezierPath> ();
            points = new List<CGPoint[]> ();

            do {
                //Create a new path and set the line options
                currentPath = UIBezierPath.Create ();
                currentPath.LineWidth = StrokeWidth;
                currentPath.LineJoinStyle = CGLineJoin.Round;

                currentPoints = new List<CGPoint> ();

                //Move to the first point and add that point to the current_points array.
                currentPath.MoveTo (loadedPoints [startIndex]);
                currentPoints.Add (loadedPoints [startIndex]);

                //Iterate through the array until an empty point (or the end of the array) is reached,
                //adding each point to the current_path and to the current_points array.
                for (var i = startIndex + 1; i < emptyIndex; i++) {
                    currentPath.AddLineTo (loadedPoints [i]);
                    currentPoints.Add (loadedPoints [i]);
                }

                //Add the current_path and current_points list to their respective Lists before
                //starting on the next line to be drawn.
                paths.Add (currentPath);
                points.Add (currentPoints.ToArray ());

                //Obtain the indices for the next line to be drawn.
                startIndex = emptyIndex + 1;
                if (startIndex < loadedPoints.Count () - 1) {
                    emptyIndex = loadedPoints.ToList ().IndexOf (CGPoint.Empty, startIndex);

                    if (emptyIndex == -1)
                        emptyIndex = loadedPoints.Count ();
                } else
                    emptyIndex = startIndex;
            } while (startIndex < emptyIndex);

            //Obtain the image for the imported signature and display it in the image view.
                    LoadNewImage();
            //Display the clear button.
            btnClear.Hidden = false;
            SetNeedsDisplay ();
        }
コード例 #42
0
        void Move(UIPanGestureRecognizer gesture)
        {
            if (CurrentMonkey == null)
                return;
            var point = gesture.TranslationInView (this);

            if (gesture.State == UIGestureRecognizerState.Began)
                initialPoint = CurrentMonkey.Center;

            point.X += initialPoint.X;
            point.Y += initialPoint.Y;

            CurrentMonkey.Center = point;
            if(gesture.State == UIGestureRecognizerState.Ended)
            {
                CurrentMonkey.UpdateMonkey(Bounds);
                Parent.UpdateMonkey(CurrentMonkey.Monkey);
            }
        }
コード例 #43
0
        /// <summary>
        /// Adds the mask.
        /// </summary>
        /// <param name="MaskBounds">Mask bounds.</param>
        private void AddMask(CGRect MaskBounds)
        {
            //clear old layers
            if (mBorderLayer != null)
            {
                mBorderLayer.RemoveFromSuperLayer();
            }

            this.Layer.Mask = null;

            switch (mStyle)
            {
                case Enums.GravatarViewStyle.Square:
                    {
                        if ((int)this.BorderWidth > 0)
                        {
							var point = new CGPoint(MaskBounds.Size.Width / 2, MaskBounds.Size.Height / 2);
							var maskPath = CGPath.FromRect(MaskBounds);
							mBorderLayer = (CAShapeLayer)CAShapeLayer.Create();
							mBorderLayer.Bounds = MaskBounds;
							mBorderLayer.Path = maskPath;
							mBorderLayer.LineWidth = this.BorderWidth * 2.0f;
							mBorderLayer.StrokeColor = BorderColor.CGColor;
							mBorderLayer.FillColor = UIColor.Clear.CGColor;
							mBorderLayer.Position = point;

							this.Layer.AddSublayer(mBorderLayer);
                        }
                    }
                    break;
                case Enums.GravatarViewStyle.Round:
                    {
                        mMaskLayer = new CAShapeLayer();

                        var maskPath = CGPath.EllipseFromRect(MaskBounds, CGAffineTransform.MakeIdentity());

                        mMaskLayer.Bounds = MaskBounds;
                        mMaskLayer.Path = maskPath;
                        mMaskLayer.FillColor = UIColor.Blue.CGColor;

                        var point = new CGPoint(MaskBounds.Size.Width / 2, MaskBounds.Size.Height / 2);
                        mMaskLayer.Position = point;

                        this.Layer.Mask = mMaskLayer;


                        if ((int)this.BorderWidth > 0)
                        {
                            mBorderLayer = (CAShapeLayer)CAShapeLayer.Create();
                            mBorderLayer.Bounds = MaskBounds;
                            mBorderLayer.Path = maskPath;
                            mBorderLayer.LineWidth = this.BorderWidth * 2.0f;
							mBorderLayer.StrokeColor = BorderColor.CGColor;
                            mBorderLayer.FillColor = UIColor.Clear.CGColor;
                            mBorderLayer.Position = point;

                            this.Layer.AddSublayer(mBorderLayer);
                        }
                    }
                    break;
            }


        }
コード例 #44
0
        void PositionHUD(NSNotification notification)
        {
            nfloat keyboardHeight    = 0;
            double animationDuration = 0;

            Frame = UIScreen.MainScreen.Bounds;

            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
            bool ignoreOrientation             = UIDevice.CurrentDevice.CheckSystemVersion(8, 0);

            if (notification != null)
            {
                var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                animationDuration = UIKeyboard.AnimationDurationFromNotification(notification);

                if (notification.Name == UIKeyboard.WillShowNotification || notification.Name == UIKeyboard.DidShowNotification)
                {
                    if (ignoreOrientation || IsPortrait(orientation))
                    {
                        keyboardHeight = keyboardFrame.Size.Height;
                    }
                    else
                    {
                        keyboardHeight = keyboardFrame.Size.Width;
                    }
                }
                else
                {
                    keyboardHeight = 0;
                }
            }
            else
            {
                keyboardHeight = VisibleKeyboardHeight;
            }

            CGRect orientationFrame = UIApplication.SharedApplication.GetKeyWindow().Bounds;

            CGRect statusBarFrame = UIApplication.SharedApplication.StatusBarFrame;

            if (!ignoreOrientation && IsLandscape(orientation))
            {
                orientationFrame.Size = new CGSize(orientationFrame.Size.Height, orientationFrame.Size.Width);
                statusBarFrame.Size   = new CGSize(statusBarFrame.Size.Height, statusBarFrame.Size.Width);
            }

            var activeHeight = orientationFrame.Size.Height;

            if (keyboardHeight > 0)
            {
                activeHeight += statusBarFrame.Size.Height;
            }

            activeHeight -= keyboardHeight;

            nfloat posY       = (float)Math.Floor(activeHeight * 0.45);
            nfloat posX       = orientationFrame.Size.Width / 2;
            nfloat textHeight = _stringLabel.Frame.Height / 2 + 40;

            switch (toastPosition)
            {
            case ToastPosition.Bottom:
                posY = activeHeight - textHeight;
                break;

            case ToastPosition.Center:
                // Already set above
                break;

            case ToastPosition.Top:
                posY = textHeight;
                break;

            default:
                break;
            }

            CGPoint newCenter;
            float   rotateAngle;

            if (ignoreOrientation)
            {
                rotateAngle = 0.0f;
                newCenter   = new CGPoint(posX, posY);
            }
            else
            {
                switch (orientation)
                {
                case UIInterfaceOrientation.PortraitUpsideDown:
                    rotateAngle = (float)Math.PI;
                    newCenter   = new CGPoint(posX, orientationFrame.Size.Height - posY);
                    break;

                case UIInterfaceOrientation.LandscapeLeft:
                    rotateAngle = (float)(-Math.PI / 2.0f);
                    newCenter   = new CGPoint(posY, posX);
                    break;

                case UIInterfaceOrientation.LandscapeRight:
                    rotateAngle = (float)(Math.PI / 2.0f);
                    newCenter   = new CGPoint(orientationFrame.Size.Height - posY, posX);
                    break;

                default:     // as UIInterfaceOrientationPortrait
                    rotateAngle = 0.0f;
                    newCenter   = new CGPoint(posX, posY);
                    break;
                }
            }

            if (notification != null)
            {
                UIView.Animate(animationDuration,
                               0, UIViewAnimationOptions.AllowUserInteraction, delegate
                {
                    MoveToPoint(newCenter, rotateAngle);
                }, null);
            }
            else
            {
                MoveToPoint(newCenter, rotateAngle);
            }
        }
コード例 #45
0
 public extern static global::System.IntPtr IntPtr_objc_msgSendSuper_GADAdSize_PointF(IntPtr receiver, IntPtr selector, global::GoogleAdMobAds.GADAdSize arg1, global::System.Drawing.PointF arg2);