예제 #1
0
        protected override void DrawBackground(UIntPtr hdc, string image, background_repeat repeat, ref web_color color, ref position pos, ref border_radiuses br, ref position borderBox, bool isRoot)
        {
            var cgColor = color.ToCGColor();
            var rect    = pos.ToRect();

            if (string.IsNullOrEmpty(image))
            {
                CGPath path = new CGPath();
                path.MoveToPoint(rect.Left + br.top_left_x, rect.Top);
                path.AddLineToPoint(rect.Right - br.top_right_x, rect.Top);
                path.AddQuadCurveToPoint(rect.Right, rect.Top, rect.Right, rect.Top + br.top_right_y);
                path.AddLineToPoint(rect.Right, rect.Bottom - br.bottom_right_y);
                path.AddQuadCurveToPoint(rect.Right, rect.Bottom, rect.Right - br.bottom_right_x, rect.Bottom);
                path.AddLineToPoint(rect.Left + br.bottom_left_x, rect.Bottom);
                path.AddQuadCurveToPoint(rect.Left, rect.Bottom, rect.Left, rect.Bottom - br.bottom_left_y);
                path.AddLineToPoint(rect.Left, rect.Top + br.top_left_y);
                path.AddQuadCurveToPoint(rect.Left, rect.Top, rect.Left + br.top_left_x, rect.Top);

                Context.SetFillColor(cgColor);
                Context.AddPath(path);
                Context.FillPath();
            }
            else
            {
                DrawImage(image, rect);
            }
        }
예제 #2
0
        private static CGPath RoundedRect(nfloat left, nfloat top, nfloat right, nfloat bottom, nfloat r)
        {
            var path = new CGPath();

            if (r < 0)
            {
                r = 0;
            }
            var width  = right - left;
            var height = bottom - top;

            if (r > width / 2)
            {
                r = width / 2;
            }
            if (r > height / 2)
            {
                r = height / 2;
            }

            path.MoveToPoint(left, bottom);
            path.AddLineToPoint(left, top - r);
            path.AddArc(left + r, top + r, r, (float)Math.PI, (float)Math.PI * 3 / 2, false);
            path.AddLineToPoint(right - r, top);
            path.AddArc(right - r, top + r, r, (float)Math.PI / 2, 0, false);
            path.AddLineToPoint(right, bottom);
            path.CloseSubpath();

            return(path);
        }
예제 #3
0
        private void DrawMark(CGContext canvas, nfloat startY, nfloat restY, nfloat startX, nfloat restX)
        {
            nfloat pixelPerTicks = restX / (days * TimeSpan.TicksPerDay);
            nfloat realValue     = (float)((weigths[selected].Value - minWeight) / (maxWeight - minWeight) * restY);
            var    pos           = startX + (weigths[selected].Date.Ticks - initDate.Ticks) * pixelPerTicks;
            String valor         = weigths[selected].Value.ToString("0.#");
            String unidades      = weigths[selected].Unit;
            var    tfont         = UIFont.FromName(FontName, 12);
            var    nsstr         = new NSString(valor);
            var    sz            = nsstr.StringSize(tfont, Frame.Width, UILineBreakMode.WordWrap);

            tfont = UIFont.FromName(FontName, 10);
            nsstr = new NSString(unidades);
            var    sz2  = nsstr.StringSize(tfont, Frame.Width, UILineBreakMode.WordWrap);
            String date = " - " + weigths[selected].Date.ToString("dd/MM/yy");

            tfont = UIFont.FromName(FontName, 10);
            nsstr = new NSString(date);
            var    sz3   = nsstr.StringSize(tfont, Frame.Width, UILineBreakMode.WordWrap);
            nfloat width = sz.Width + sz2.Width + sz3.Width;

            if (pos - width / 2 < startX)
            {
                pos = 0 + width / 2 + 3;
            }
            if (pos + width / 2 > startX + restX)
            {
                pos = startX + restX - width / 2 - 3;
            }
            DrawAxis(canvas, pos - width / 2 - 3, width + 6, startY + restY - realValue - 10, startY + restY - realValue - 10 - sz.Height - 6, UIColor.Red);
            DrawText(valor, pos - width / 2, startY + restY - realValue - 13, 12, canvas, TextLeft, UIColor.White, sz.Width, PosBottom);
            DrawText(unidades, pos - width / 2 + sz.Width, startY + restY - realValue - 13, 10, canvas, TextLeft, UIColor.White, sz2.Width, PosBottom);
            DrawText(date, pos - width / 2 + sz.Width + sz2.Width, startY + restY - realValue - 13, 10, canvas, TextLeft, UIColor.White, sz3.Width, PosBottom);

            /*nfloat maxWidth = width;
             * if (sz3.Width > width)
             *  maxWidth = sz3.Width;
             * if (pos - maxWidth / 2 < startX)
             *  pos = 0+maxWidth/2+3;
             * if (pos + maxWidth / 2 > startX+restX)
             *  pos = startX+restX- maxWidth / 2-3;
             * DrawAxis(canvas, pos-maxWidth/2-3, maxWidth+6, startY+ restY - realValue - 10, startY+restY - realValue - 10-sz.Height-sz3.Height-6, UIColor.Red);
             * DrawText(valor,pos-width/2,startY+restY - realValue-13-sz3.Height,12,canvas,TextLeft,UIColor.White,width,PosBottom);
             * DrawText(unidades, pos + width / 2, startY+restY - realValue - 13-sz3.Height, 10, canvas, TextRight, UIColor.White, width, PosBottom);
             * DrawText(date, pos , startY + restY - realValue - 13, 10, canvas, TextCenter, UIColor.White, sz3.Width, PosBottom);*/
            pos = startX + (weigths[selected].Date.Ticks - initDate.Ticks) * pixelPerTicks;//Pintar triangulo en su sitio
            canvas.SaveState();
            UIColor.Red.SetFill();
            UIColor.Red.SetStroke();
            canvas.SetLineWidth(0);
            var path = new CGPath();

            path.MoveToPoint(pos - 4f, startY + restY - realValue - 10f);
            path.AddLineToPoint(pos + 4f, startY + restY - realValue - 10f);
            path.AddLineToPoint(pos, startY + restY - realValue - 6);
            path.CloseSubpath();
            canvas.AddPath(path);
            canvas.DrawPath(CGPathDrawingMode.Fill);
            canvas.RestoreState();
        }
예제 #4
0
        private void Win()
        {
            state = State.Win;
            ShowMines(-1);
            var background = new SKShapeNode();
            var p          = new CGPath();

            p.MoveToPoint(0, 0);
            p.AddLineToPoint(40 * 19, 0);
            p.AddLineToPoint(40 * 19, 40 * 13);
            p.AddLineToPoint(0, 40 * 13);
            p.AddLineToPoint(0, 0);
            background.Path      = p;
            background.FillColor = NSColor.FromCalibratedRgba(1.0f, 1.0f, 1.0f, 0.7f);
            AddChild(background);

            var label = new SKLabelNode("Arial");

            label.Text                    = "Win";
            label.FontColor               = NSColor.FromCalibratedRgb(0.0f, 0.502f, 0.0f);
            label.FontSize                = 40;
            label.Position                = new CGPoint(40 * 19 / 2, 40 * 13 / 2);
            label.VerticalAlignmentMode   = SKLabelVerticalAlignmentMode.Center;
            label.HorizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center;
            AddChild(label);
        }
예제 #5
0
        private void DrawFlag()
        {
            var s1 = new SKShapeNode();
            var p1 = new CGPath();

            p1.MoveToPoint(size / 3.0f, size / 2.0f);
            p1.AddLineToPoint(size / 3.0f * 2, size / 3.0f);
            p1.AddLineToPoint(size / 3.0f * 2, size / 3.0f * 2);
            s1.Path        = p1.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size));
            s1.StrokeColor = NSColor.Red;
            s1.FillColor   = NSColor.Red;
            AddChild(s1);

            var s2 = new SKShapeNode();
            var p2 = new CGPath();

            p2.MoveToPoint(size / 3.0f * 2, size - size / 3.0f);
            p2.AddLineToPoint(size / 3.0f * 2, size / 4.0f);
            p2.AddLineToPoint(size / 2.0f, size / 4.0f);
            p2.AddLineToPoint(size - size / 5.0f, size / 4.0f);
            s2.Path        = p2.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size));
            s2.StrokeColor = NSColor.Black;
            s2.FillColor   = NSColor.FromCalibratedRgba(0.0f, 0.0f, 0.0f, 0.0f);
            s2.LineWidth   = size / 20;
            AddChild(s2);
        }
예제 #6
0
        private CGPath CreateCornerPath(double topLeft, double topRight, double bottomRight, double bottomLeft, CGRect insetBounds)
        {
            var cornerPath = new CGPath();

            // Start of our path is where the top left horizontal starts.
            cornerPath.MoveToPoint(new CGPoint(topLeft + insetBounds.X, insetBounds.Y));

            // Top line + top right corner
            cornerPath.AddLineToPoint(new CGPoint(insetBounds.Width - topRight, insetBounds.Y));
            cornerPath.AddArc((float)(insetBounds.X + insetBounds.Width - topRight), (float)(insetBounds.Y + topRight), (float)topRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, false);

            // Right side + bottom right corner
            cornerPath.AddLineToPoint(insetBounds.Width + insetBounds.X, (float)(insetBounds.Height - bottomRight));
            cornerPath.AddArc((float)(insetBounds.X + insetBounds.Width - bottomRight), (float)(insetBounds.Y + insetBounds.Height - bottomRight), (float)bottomRight, 0, (float)(Math.PI * .5), false);

            // Bottom side + bottom left corner
            cornerPath.AddLineToPoint((float)(insetBounds.X + bottomLeft), insetBounds.Height + insetBounds.Y);
            cornerPath.AddArc((float)(insetBounds.X + bottomLeft), (float)(insetBounds.Y + insetBounds.Height - bottomLeft), (float)bottomLeft, (float)(Math.PI * .5), (float)Math.PI, false);

            // Left side + top left corner
            cornerPath.AddLineToPoint(insetBounds.X, (float)(insetBounds.Y + topLeft));
            cornerPath.AddArc((float)(insetBounds.X + topLeft), (float)(insetBounds.Y + topLeft), (float)topLeft, (float)Math.PI, (float)(Math.PI * 1.5), false);

            return(cornerPath);
        }
예제 #7
0
        private CGPath NewBadgePathForTextSize(CGSize size)
        {
            nfloat arcRadius = (nfloat)Math.Ceiling((size.Height + Pad) / 2.0f);

            nfloat badgeWidthAdjustment = size.Width - (size.Height / 2.0f);
            nfloat badgeWidth           = 2.0f * arcRadius;
            var    m_pi_2 = (float)(Math.PI / 2);

            if (badgeWidthAdjustment > 0.0)
            {
                badgeWidth += badgeWidthAdjustment;
            }

            CGPath badgePath = new CGPath();

            //Add main circle
            badgePath.MoveToPoint(arcRadius, 0.0f);
            badgePath.AddArc(arcRadius, arcRadius, arcRadius, 3.0f * m_pi_2, m_pi_2, true);
            badgePath.AddLineToPoint(badgeWidth - arcRadius, 2.0f * arcRadius);
            badgePath.AddArc(badgeWidth - arcRadius, arcRadius, arcRadius, m_pi_2, 3.0f * m_pi_2, true);
            badgePath.AddLineToPoint(arcRadius, 0.0f);

            //Add sub circle
            badgePath.MoveToPoint(arcRadius, 0.0f);
            badgePath.AddArc(arcRadius, arcRadius, arcRadius / 2, m_pi_2, 3.0f * m_pi_2, false);
            badgePath.AddLineToPoint(badgeWidth - arcRadius, 2.0f * arcRadius);
            badgePath.AddArc(badgeWidth - arcRadius, arcRadius, arcRadius / 2, 3.0f * m_pi_2, m_pi_2, false);
            badgePath.AddLineToPoint(arcRadius, 0.0f);

            return(badgePath);
        }
예제 #8
0
        public static XIR.Image RemoteRepresentation(this CGLineJoin obj)
        {
            // Customize the line cap style for the new object.
            var aPath       = new CGPath();
            var lineWidth   = 10;
            var sampleWidth = 50;

            // First we draw the presentation line
            aPath.MoveToPoint(new CGPoint(lineWidth, lineWidth));
            aPath.AddLineToPoint(new CGPoint(lineWidth + sampleWidth / 2, sampleWidth));
            aPath.AddLineToPoint(new CGPoint(lineWidth + sampleWidth, lineWidth));

            // let's make sure we leave a little room for the line width drawing as well by adding the lineWidth as well
            var width  = (int)aPath.PathBoundingBox.Right + lineWidth;
            var height = (int)aPath.PathBoundingBox.Bottom + lineWidth;

            var bytesPerRow = width * 4;

            using (var context = new CGBitmapContext(
                       IntPtr.Zero, width, height,
                       8, bytesPerRow, CGColorSpace.CreateDeviceRGB(),
                       CGImageAlphaInfo.PremultipliedFirst)) {
                context.SaveState();
                context.SetStrokeColor(NSColor.Black.CGColor);
                context.SetLineWidth(lineWidth);
                context.AddPath(aPath);
                switch ((CGLineJoin)obj)
                {
                case CGLineJoin.Bevel:
                    context.SetLineJoin(CGLineJoin.Bevel);
                    break;

                case CGLineJoin.Miter:
                    context.SetLineJoin(CGLineJoin.Miter);
                    break;

                case CGLineJoin.Round:
                    context.SetLineJoin(CGLineJoin.Round);
                    break;
                }

                context.DrawPath(CGPathDrawingMode.Stroke);

                context.RestoreState();

                aPath = new CGPath();

                aPath.MoveToPoint(new CGPoint(lineWidth, lineWidth));
                aPath.AddLineToPoint(new CGPoint(lineWidth + sampleWidth / 2, sampleWidth));
                aPath.AddLineToPoint(new CGPoint(lineWidth + sampleWidth, lineWidth));

                context.SetStrokeColor(NSColor.White.CGColor);
                context.SetLineWidth(2);
                context.AddPath(aPath);

                context.DrawPath(CGPathDrawingMode.Stroke);

                return(context.RemoteRepresentation());
            }
        }
예제 #9
0
 public /*interface ChartPainter*/ void DrawCourseRange(List <KChartEntry> list, int seriesIndex, SKColor color, Swipe pinchPan)
 {
     if (list.Count == 1)
     {
         DrawCircle(list[0].Ypoint[seriesIndex], pinchPan % 8, FillPaint(color));
     }
     if (list.Count > 1)
     {
         canvas.SetFillColor(CG.Color(color));
         var         path       = new CGPath();
         KChartEntry entry0     = list[0];
         SKPoint     meanPoint0 = entry0.Ypoint[seriesIndex];
         float       range0     = entry0.YpointRange[seriesIndex];
         path.MoveToPoint(CG.Point(pinchPan % new SKPoint(meanPoint0.X, meanPoint0.Y + range0)));
         path.AddLineToPoint(CG.Point(pinchPan % new SKPoint(meanPoint0.X, meanPoint0.Y - range0)));
         for (int i = 0; i < list.Count; i++)
         {
             KChartEntry entry     = list[i];
             SKPoint     meanPoint = entry.Ypoint[seriesIndex];
             float       range     = entry.YpointRange[seriesIndex];
             path.AddLineToPoint(CG.Point(pinchPan % new SKPoint(meanPoint.X, meanPoint.Y - range)));
         }
         for (int i = list.Count - 1; i >= 0; i--)
         {
             KChartEntry entry     = list[i];
             SKPoint     meanPoint = entry.Ypoint[seriesIndex];
             float       range     = entry.YpointRange[seriesIndex];
             path.AddLineToPoint(CG.Point(pinchPan % new SKPoint(meanPoint.X, meanPoint.Y + range)));
         }
         path.CloseSubpath();
         canvas.AddPath(path);
         canvas.FillPath();
     }
 }
        private UIImage CreatePieSegment(CGSize size, nfloat endAngle)
        {
            // Add the arc
            var arc = new CGPath();

            arc.MoveToPoint(size.Width / 2.0f, size.Height / 2.0f);
            arc.AddLineToPoint(size.Width / 2.0f, 0);
            arc.AddArc(size.Width / 2.0f, size.Height / 2.0f, size.Width / 2.0f, _startAngle, endAngle, false);
            arc.AddLineToPoint(size.Width / 2.0f, size.Height / 2.0f);

            // Stroke the arc
            UIGraphics.BeginImageContextWithOptions(size, false, 0);

            var context = UIGraphics.GetCurrentContext();

            context.AddPath(arc);
            context.SetFillColor(UIColor.FromRGBA(0f, 0f, 0f, 1f).CGColor);
            context.FillPath();

            // Get the mask image
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return image;
        }
예제 #11
0
        protected override void OnElementChanged(ElementChangedEventArgs <Issue11132Control> e)
        {
            base.OnElementChanged(e);

            var layer = Layer;

            if (layer != null)
            {
                layer.BorderWidth     = 10;
                layer.BorderColor     = Colors.Red.ToCGColor();
                layer.BackgroundColor = Colors.Orange.ToCGColor();

                var width  = 100;
                var height = 25;

                var clipPath = new CGPath();
                clipPath.MoveToPoint(width, height);
                clipPath.AddLineToPoint(width * 2, height);
                clipPath.AddLineToPoint(width * 2, height * 2);
                clipPath.AddLineToPoint(width, height * 2);
                clipPath.CloseSubpath();

                var clipShapeLayer = new CAShapeLayer
                {
                    Path = clipPath
                };
                layer.Mask      = clipShapeLayer;
                layer.Mask.Name = null;

                Debug.WriteLine($"_11132CustomRenderer Layer Name { layer.Mask.Name}");
            }
        }
        private static CGPath GetRoundedPath(CornerRadius cornerRadius, CGRect area, CGPath path = null, bool clockwise = true)
        {
            path ??= new CGPath();
            // How AddArcToPoint works:
            // http://www.twistedape.me.uk/blog/2013/09/23/what-arctopointdoes/

            if (clockwise)
            {
                path.MoveToPoint(area.GetMidX(), area.Y);
                path.AddArcToPoint(area.Right, area.Top, area.Right, area.GetMidY(), (float)cornerRadius.TopRight);
                path.AddArcToPoint(area.Right, area.Bottom, area.GetMidX(), area.Bottom, (float)cornerRadius.BottomRight);
                path.AddArcToPoint(area.Left, area.Bottom, area.Left, area.GetMidY(), (float)cornerRadius.BottomLeft);
                path.AddArcToPoint(area.Left, area.Top, area.GetMidX(), area.Top, (float)cornerRadius.TopLeft);
                path.AddLineToPoint(area.GetMidX(), area.Y);
            }
            else
            {
                path.MoveToPoint(area.GetMidX(), area.Y);
                path.AddArcToPoint(area.Left, area.Top, area.Left, area.GetMidY(), (float)cornerRadius.TopLeft);
                path.AddArcToPoint(area.Left, area.Bottom, area.GetMidX(), area.Bottom, (float)cornerRadius.BottomLeft);
                path.AddArcToPoint(area.Right, area.Bottom, area.Right, area.GetMidY(), (float)cornerRadius.BottomRight);
                path.AddArcToPoint(area.Right, area.Top, area.GetMidX(), area.Top, (float)cornerRadius.TopRight);
                path.AddLineToPoint(area.GetMidX(), area.Y);
            }

            return(path);
        }
예제 #13
0
        private void AppendLineTo(bool relative)
        {
            if (_operands.Count % 2 != 0)
            {
                throw new Exception("Invalid parameter count in L style token");
            }

            for (int i = 0; i < _operands.Count; i += 2)
            {
                float x = _operands[i];
                float y = _operands[i + 1];

                if (relative)
                {
                    x += _posx;
                    y += _posy;
                }
                _spath.LineTo(x, y);
#if OSX
                _cgpath.AddLineToPoint(x, y);
#endif

                _posx = x;
                _posy = y;
                _scaler.AddXYOperands(x, y);
            }
            _scaler.AddOperator('L');
        }
예제 #14
0
        private UIImage CreatePieSegment(CGSize size, nfloat endAngle)
        {
            // Add the arc
            var arc = new CGPath();

            arc.MoveToPoint(size.Width / 2.0f, size.Height / 2.0f);
            arc.AddLineToPoint(size.Width / 2.0f, 0);
            arc.AddArc(size.Width / 2.0f, size.Height / 2.0f, size.Width / 2.0f, _startAngle, endAngle, false);
            arc.AddLineToPoint(size.Width / 2.0f, size.Height / 2.0f);

            // Stroke the arc
            UIGraphics.BeginImageContextWithOptions(size, false, 0);

            var context = UIGraphics.GetCurrentContext();

            context.AddPath(arc);
            context.SetFillColor(UIColor.FromRGBA(0f, 0f, 0f, 1f).CGColor);
            context.FillPath();

            // Get the mask image
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
예제 #15
0
        public void RenderExplodedMine()
        {
            RemoveAllChildren();
            var s    = new SKShapeNode();
            var path = new CGPath();

            path.MoveToPoint(0, 0);
            path.AddLineToPoint(size, 0);
            path.AddLineToPoint(size, size);
            path.AddLineToPoint(0, size);
            path.AddLineToPoint(0, 0);
            s.Path        = path.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size));
            s.StrokeColor = NSColor.FromCalibratedRgb(0.502f, 0.502f, 0.502f);
            s.FillColor   = NSColor.FromCalibratedRgb(0.8f, 0.8f, 0.8f);
            AddChild(s);

            var s1 = new SKShapeNode();
            var p1 = new CGPath();

            p1.AddArc(x * size + size / 2, y * size + size / 2, size / 4, 0, 2 * (float)Math.PI, true);
            s1.Path        = p1;
            s1.StrokeColor = NSColor.FromCalibratedRgb(0.2f, 0.2f, 0.2f);
            s1.FillColor   = NSColor.FromCalibratedRgb(0.8f, 0.0f, 0.0f);
            AddChild(s1);
        }
        public override void Draw(RectangleF rect)
        {
            WeatherForecastAnnotation annotation;
            CGPath path;

            base.Draw(rect);

            annotation = Annotation as WeatherForecastAnnotation;
            if (annotation == null)
            {
                return;
            }

            // Get the current graphics context
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetLineWidth(1.0f);

            // Draw the gray pointed shape:
            path = new CGPath();
            path.MoveToPoint(14.0f, 0.0f);
            path.AddLineToPoint(0.0f, 0.0f);
            path.AddLineToPoint(55.0f, 50.0f);
            context.AddPath(path);

            context.SetFillColor(UIColor.LightGray.CGColor);
            context.SetStrokeColor(UIColor.Gray.CGColor);
            context.DrawPath(CGPathDrawingMode.FillStroke);

            // Draw the cyan rounded box
            path = new CGPath();
            path.MoveToPoint(15.0f, 0.5f);
            path.AddArcToPoint(59.5f, 00.5f, 59.5f, 05.0f, 5.0f);
            path.AddArcToPoint(59.5f, 69.5f, 55.5f, 69.5f, 5.0f);
            path.AddArcToPoint(10.5f, 69.5f, 10.5f, 64.0f, 5.0f);
            path.AddArcToPoint(10.5f, 00.5f, 15.5f, 00.5f, 5.0f);
            context.AddPath(path);

            context.SetFillColor(UIColor.Cyan.CGColor);
            context.SetStrokeColor(UIColor.Blue.CGColor);
            context.DrawPath(CGPathDrawingMode.FillStroke);

            // Create the location & temperature string
            WeatherForecast forecast    = annotation.Forecast;
            NSString        temperature = new NSString(string.Format("{0}\n{1} / {2}", forecast.Place, forecast.High, forecast.Low));

            // Draw the text in black
            UIColor.Black.SetColor();
            temperature.DrawString(new RectangleF(15.0f, 5.0f, 50.0f, 40.0f), UIFont.SystemFontOfSize(11.0f));
            temperature.Dispose();

            // Draw the icon for the weather condition
            string  imageName = string.Format("WeatherMap.WeatherIcons.{0}.png", forecast.Condition);
            UIImage image     = UIImage.FromResource(typeof(WeatherAnnotationView).Assembly, imageName);

            image.Draw(new RectangleF(12.5f, 28.0f, 45.0f, 45.0f));
            image.Dispose();
        }
		public override void Draw (CGRect rect)
		{
			WeatherForecastAnnotation annotation;
			CGPath path;

			base.Draw (rect);

			annotation = Annotation as WeatherForecastAnnotation;
			if (annotation == null)
				return;

			// Get the current graphics context
			using (var context = UIGraphics.GetCurrentContext ()) {

				context.SetLineWidth (1.0f);

				// Draw the gray pointed shape:
				path = new CGPath ();
				path.MoveToPoint (14.0f, 0.0f);
				path.AddLineToPoint (0.0f, 0.0f);
				path.AddLineToPoint (55.0f, 50.0f);
				context.AddPath (path);

				context.SetFillColor (UIColor.LightGray.CGColor);
				context.SetStrokeColor (UIColor.Gray.CGColor);
				context.DrawPath (CGPathDrawingMode.FillStroke);

				// Draw the cyan rounded box
				path = new CGPath ();
				path.MoveToPoint (15.0f, 0.5f);
				path.AddArcToPoint (59.5f, 00.5f, 59.5f, 05.0f, 5.0f);
				path.AddArcToPoint (59.5f, 69.5f, 55.5f, 69.5f, 5.0f);
				path.AddArcToPoint (10.5f, 69.5f, 10.5f, 64.0f, 5.0f);
				path.AddArcToPoint (10.5f, 00.5f, 15.5f, 00.5f, 5.0f);
				context.AddPath (path);

				context.SetFillColor (UIColor.Cyan.CGColor);
				context.SetStrokeColor (UIColor.Blue.CGColor);
				context.DrawPath (CGPathDrawingMode.FillStroke);

				// Create the location & temperature string
				WeatherForecast forecast = annotation.Forecast;
				NSString temperature = new NSString (string.Format ("{0}\n{1} / {2}", forecast.Place, forecast.High, forecast.Low));

				// Draw the text in black
				UIColor.Black.SetColor ();
				temperature.DrawString (new CGRect (15.0f, 5.0f, 50.0f, 40.0f), UIFont.SystemFontOfSize (11.0f));
				temperature.Dispose ();

				// Draw the icon for the weather condition
				string imageName = string.Format ("WeatherMap.WeatherIcons.{0}.png", forecast.Condition);
				UIImage image = UIImage.FromResource (typeof(WeatherAnnotationView).Assembly, imageName);
				image.Draw (new CGRect (12.5f, 28.0f, 45.0f, 45.0f));
				image.Dispose ();
			}
		}
예제 #18
0
        /// <summary>画三角形
        /// </summary>
        /// <param name="ctx">图形上下文</param>
        /// <param name="point">顶点</param>
        /// <param name="length">边长</param>
        /// <param name="color">绘制颜色</param>
        void DrawTrangleWithContext(CGContext ctx, CGPoint point, nfloat length, UIColor color)
        {
            CGPath trianglePathM = new CGPath();

            trianglePathM.MoveToPoint(point.X, point.Y);
            trianglePathM.AddLineToPoint(point.X - length / 2, point.Y + length / 2);
            trianglePathM.AddLineToPoint(point.X + length / 2, point.Y + length / 2);
            ctx.AddPath(trianglePathM);
            color.SetColor();
            ctx.FillPath();
            trianglePathM.Dispose();
        }
예제 #19
0
파일: Menu.cs 프로젝트: tilemapjp/MonoKit
        private void Close()
        {
            if (flag == -1)
            {
                this.isAnimating = false;
                this.timer.Invalidate();
                this.timer = null;
                return;
            }

            int      tag  = 1000 + flag;
            MenuItem item = this.GetByTag(tag);

            item.Selected -= this.ItemSelected;

            var rotateAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");

            rotateAnimation.Values   = new NSNumber[] { 0f, this.CloseRotation, 0f };
            rotateAnimation.Duration = 0.5f;
            rotateAnimation.KeyTimes = new NSNumber[] { 0f, 0.4f, 0.5f };

            var positionAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");

            positionAnimation.Duration = 0.5f;

            var path = new CGPath();

            path.MoveToPoint(item.EndPoint.X, item.EndPoint.Y);
            path.AddLineToPoint(item.FarPoint.X, item.FarPoint.Y);
            path.AddLineToPoint(item.StartPoint.X, item.StartPoint.Y);
            positionAnimation.Path = path;

            var alphaAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("opacity");

            alphaAnimation.Values   = new NSNumber[] { 1f, 1f, 0f };
            alphaAnimation.Duration = 0.5f;
            alphaAnimation.KeyTimes = new NSNumber[] { 0f, 0.8f, 1f };

            var animationGroup = new CAAnimationGroup();

            animationGroup.Animations     = new[] { positionAnimation, rotateAnimation, alphaAnimation };
            animationGroup.Duration       = 0.5f;
            animationGroup.FillMode       = CAFillMode.Forwards;
            animationGroup.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);

            item.Layer.AddAnimation(animationGroup, "Close");

            item.Alpha  = 0f;
            item.Center = item.StartPoint;
            flag--;
        }
        private void Setup()
        {
            // set up events
            TouchUpInside += OnTapped;

            // create the check path
            var path = new CGPath();

            path.MoveToPoint(5.07473346f, 20.2956615f);
            path.AddCurveToPoint(3.1031115f, 24.4497281f, 2f, 29.0960413f, 2f, 34f);
            path.AddCurveToPoint(2f, 51.673112f, 16.326888f, 66f, 34f, 66f);
            path.AddCurveToPoint(51.673112f, 66f, 66f, 51.673112f, 66f, 34f);
            path.AddCurveToPoint(66f, 16.326888f, 51.673112f, 2f, 34f, 2f);
            path.AddCurveToPoint(21.3077047f, 2f, 10.3412842f, 9.38934836f, 5.16807419f, 20.1007094f);
            path.AddLineToPoint(29.9939289f, 43.1625671f);
            path.AddLineToPoint(56.7161293f, 17.3530369f);

            shape.Path  = path;
            circle.Path = path;
            check.Path  = path;

            shape.StrokeColor  = color.CGColor;
            circle.StrokeColor = skeletonColor.CGColor;
            check.StrokeColor  = skeletonColor.CGColor;

            shape.StrokeStart  = circleStrokeStart;
            shape.StrokeEnd    = circleStrokeEnd;
            circle.StrokeStart = circleStrokeStart;
            circle.StrokeEnd   = circleStrokeEnd;
            check.StrokeStart  = checkStrokeStart;
            check.StrokeEnd    = checkStrokeEnd;

            shape.LineWidth  = lineWidth;
            circle.LineWidth = lineWidth;
            check.LineWidth  = lineWidthBold;

            foreach (var layer in new[] { circle, check, shape })
            {
                layer.FillColor     = null;
                layer.MiterLimit    = 4;
                layer.LineCap       = CAShapeLayer.CapRound;
                layer.MasksToBounds = true;

                var strokingPath = layer.Path.CopyByStrokingPath(4f, CGLineCap.Round, CGLineJoin.Miter, 4f);
                layer.Bounds  = strokingPath.BoundingBox;
                layer.Actions = NSDictionary.FromObjectsAndKeys(
                    new[] { NSNull.Null, NSNull.Null, NSNull.Null },
                    new[] { "strokeStart", "strokeEnd", "transform" });
                Layer.AddSublayer(layer);
            }
        }
예제 #21
0
        CGPath iOSCreatePath(GraphicsPath p)
        {
            CGPath path = new CGPath();

            for (int i = 0; i < p._segments.Count; i++)
            {
                {
                    var ln = p._segments[i] as GraphicsPath._LineSegment;
                    if (ln != null)
                    {
                        if (i == 0)
                        {
                            path.MoveToPoint(ln.x1, ln.y1);
                        }
                        else
                        {
                            path.AddLineToPoint(ln.x1, ln.y1);
                        }
                        path.AddLineToPoint(ln.x2, ln.y2);
                        continue;
                    }
                }
                {
                    var bz = p._segments[i] as GraphicsPath._BezierSegment;
                    if (bz != null)
                    {
                        if (i == 0)
                        {
                            path.MoveToPoint(bz.x1, bz.y1);
                        }
                        else
                        {
                            path.AddLineToPoint(bz.x1, bz.y1);
                        }

                        path.AddCurveToPoint(
                            bz.x2, bz.y2,
                            bz.x3, bz.y3,
                            bz.x4, bz.y4);
                        continue;
                    }
                }
            }
            if (p._closed)
            {
                path.CloseSubpath();
            }

            return(path);
        }
예제 #22
0
        internal static CGPath CreateClippingPath(CGRect rect, float radius)
        {
            var path = new CGPath();

            path.MoveToPoint(rect.GetMinX(), rect.GetMinY());
            path.AddLineToPoint(rect.GetMinX(), rect.GetMaxY() - radius);
            path.AddArcToPoint(rect.GetMinX(), rect.GetMaxY(), rect.GetMinX() + radius, rect.GetMaxY(), radius);
            path.AddLineToPoint(rect.GetMaxX() - radius, rect.GetMaxY());
            path.AddArcToPoint(rect.GetMaxX(), rect.GetMaxY(), rect.GetMaxX(), rect.GetMaxY() - radius, radius);
            path.AddLineToPoint(rect.GetMaxX(), rect.GetMinY());
            path.CloseSubpath();

            return(path);
        }
        protected virtual void DrawTriangle(CGContext context, CGRect rect, bool fill, bool stroke)
        {
            var trianglePath = new CGPath();

            trianglePath.MoveToPoint(rect.Width / 2, 0);
            trianglePath.AddLineToPoint(rect.Size.Width, rect.Size.Height);
            trianglePath.AddLineToPoint(0, rect.Size.Height);
            trianglePath.AddLineToPoint(rect.Width / 2, 0);

            context.AddPath(trianglePath);
            context.Clip();
            context.AddPath(trianglePath);

            DrawPath(context, fill, stroke);
        }
예제 #24
0
        public Region(RectangleF rect)
        {
            regionObject = rect;
            var path = RectangleToPath(rect);

            solution.Add(path);
            regionList.Add(new RegionEntry(RegionType.Rectangle, rect, path));
            regionPath = new CGPath();
            regionPath.MoveToPoint(rect.Left, rect.Top);
            regionPath.AddLineToPoint(rect.Right, rect.Top);
            regionPath.AddLineToPoint(rect.Right, rect.Bottom);
            regionPath.AddLineToPoint(rect.Left, rect.Bottom);

            regionBounds = rect;
        }
예제 #25
0
        public static void DrawRoundRect(CGContext canvas, SKRect rect, float padding, SKPaint paint)
        {
            var path = new CGPath();

            path.MoveToPoint(rect.Left + padding, rect.Top);
            path.AddLineToPoint(rect.Right - padding, rect.Top);
            path.AddQuadCurveToPoint(rect.Right, rect.Top, rect.Right, rect.Top + padding);
            path.AddLineToPoint(rect.Right, rect.Bottom - padding);
            path.AddQuadCurveToPoint(rect.Right, rect.Bottom, rect.Right - padding, rect.Bottom);
            path.AddLineToPoint(rect.Left + padding, rect.Bottom);
            path.AddQuadCurveToPoint(rect.Left, rect.Bottom, rect.Left, rect.Bottom - padding);
            path.AddLineToPoint(rect.Left, rect.Top + padding);
            path.AddQuadCurveToPoint(rect.Left, rect.Top, rect.Left + padding, rect.Top);
            PaintPath(canvas, path, paint);
        }
예제 #26
0
        private void DrawCross()
        {
            var s3 = new SKShapeNode();
            var p3 = new CGPath();

            p3.MoveToPoint(size / 5.0f, size / 5.0f);
            p3.AddLineToPoint(size - size / 5.0f, size - size / 5.0f);
            p3.MoveToPoint(size / 5.0f, size - size / 5.0f);
            p3.AddLineToPoint(size - size / 5.0f, size / 5.0f);
            s3.Path        = p3.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size));
            s3.StrokeColor = NSColor.Black;
            s3.FillColor   = NSColor.FromCalibratedRgba(0.0f, 0.0f, 0.0f, 0.0f);
            s3.LineWidth   = size / 20;
            AddChild(s3);
        }
예제 #27
0
        private void DrawTile()
        {
            var s    = new SKShapeNode();
            var path = new CGPath();

            path.MoveToPoint(0, 0);
            path.AddLineToPoint(size, 0);
            path.AddLineToPoint(size, size);
            path.AddLineToPoint(0, size);
            path.AddLineToPoint(0, 0);
            s.Path        = path.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size));
            s.StrokeColor = NSColor.FromCalibratedRgb(0.502f, 0.502f, 0.502f);
            s.FillColor   = NSColor.FromCalibratedRgb(0.8f, 0.8f, 0.8f);
            AddChild(s);
        }
예제 #28
0
파일: Menu.cs 프로젝트: tilemapjp/MonoKit
        private void Expand()
        {
            if (flag == this.MenuItems.Count)
            {
                this.isAnimating = false;
                this.timer.Invalidate();
                this.timer = null;
                return;
            }

            int tag = 1000 + this.flag;

            MenuItem item = this.GetByTag(tag);

            item.Selected -= this.ItemSelected;
            item.Selected += this.ItemSelected;

            var rotateAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");

            rotateAnimation.Values   = new NSNumber[] { this.ExpandRotation, 0.0f };
            rotateAnimation.Duration = 0.5f;
            rotateAnimation.KeyTimes = new NSNumber[] { 0.3f, 0.4f };

            var positionAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");

            positionAnimation.Duration = 0.5f;

            var path = new CGPath();

            path.MoveToPoint(item.StartPoint.X, item.StartPoint.Y);
            path.AddLineToPoint(item.FarPoint.X, item.FarPoint.Y);
            path.AddLineToPoint(item.NearPoint.X, item.NearPoint.Y);
            path.AddLineToPoint(item.EndPoint.X, item.EndPoint.Y);
            positionAnimation.Path = path;

            var animationGroup = new CAAnimationGroup();

            animationGroup.Animations     = new[] { positionAnimation, rotateAnimation };
            animationGroup.Duration       = 0.5f;
            animationGroup.FillMode       = CAFillMode.Forwards;
            animationGroup.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);

            item.Layer.AddAnimation(animationGroup, "Expand");

            item.Alpha  = 1f;
            item.Center = item.EndPoint;
            this.flag++;
        }
예제 #29
0
        public override void RelLineTo(object backend, double dx, double dy)
        {
            CGPath path = (CGPath)backend;
            PointF p    = path.CurrentPoint;

            path.AddLineToPoint((float)(p.X + dx), (float)(p.Y + dy));
        }
예제 #30
0
    CGPath GetCurrentWavePath ()
    {
      var path = new CGPath ();
      path.MoveToPoint (0, waterWaveHeight);
      nfloat y = 0.0f;
      for (float x = 0.0f; x <= waterWaveWidth; x++) {
        y = WaveAmplitude * (float)Math.Sin ((360 / waterWaveWidth) * (x * Math.PI / 180) - offsetX * Math.PI / 180) + waterWaveHeight;
        path.AddLineToPoint (x, y);
      }

      path.AddLineToPoint (waterWaveWidth, Frame.Height);
      path.AddLineToPoint (0, Frame.Height);
      path.CloseSubpath ();

      return path;
    }
        public static CGPath ToCGPath(this NSBezierPath bezierPath)
        {
            var path = new CGPath();

            for (var i = 0; i < bezierPath.ElementCount; i++)
            {
                var type = bezierPath.ElementAt(i, out var points);

                switch (type)
                {
                case NSBezierPathElement.MoveTo:
                    path.MoveToPoint(points[0]);
                    break;

                case NSBezierPathElement.LineTo:
                    path.AddLineToPoint(points[0]);
                    break;

                case NSBezierPathElement.CurveTo:
                    path.AddCurveToPoint(points[0], points[1], points[2]);
                    break;

                case NSBezierPathElement.ClosePath:
                    path.CloseSubpath();
                    break;
                }
            }

            return(path);
        }
        public static CGPath ToCGPath(this NSBezierPath nsPath)
        {
            var cgPath = new CGPath();
            var points = null as CGPoint[];

            for (int i = 0; i < nsPath.ElementCount; i++)
            {
                var type = nsPath.ElementAt(i, out points);

                switch (type)
                {
                case NSBezierPathElement.MoveTo:
                    cgPath.MoveToPoint(points[0]);
                    break;

                case NSBezierPathElement.LineTo:
                    cgPath.AddLineToPoint(points[0]);
                    break;

                case NSBezierPathElement.CurveTo:
                    cgPath.AddCurveToPoint(cp1: points[0], cp2: points[1], point: points[2]);
                    break;

                case NSBezierPathElement.ClosePath:
                    cgPath.CloseSubpath();
                    break;
                }
            }

            return(cgPath);
        }
예제 #33
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            if (!initialPoint.IsEmpty)
            {
                //get graphics context
                using (CGContext g = UIGraphics.GetCurrentContext()){
                    //set up drawing attributes
                    g.SetLineWidth(2);
                    UIColor.Red.SetStroke();

                    //add lines to the touch points
                    if (path.IsEmpty)
                    {
                        path.AddLines(new CGPoint[] { initialPoint, latestPoint });
                    }
                    else
                    {
                        path.AddLineToPoint(latestPoint);
                    }

                    //use a dashed line
                    g.SetLineDash(0, new nfloat[] { 5, 2 });

                    //add geometry to graphics context and draw it
                    g.AddPath(path);
                    g.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
        }
예제 #34
0
        public ShipSprite(PointF initialPosition)
            : base(NSBundle.MainBundle.PathForResource ("spaceship", "png"))
        {
            CGPath boundingPath = new CGPath ();
            boundingPath.MoveToPoint (-12f, -38f);
            boundingPath.AddLineToPoint (12f, -38f);
            boundingPath.AddLineToPoint (9f, 18f);
            boundingPath.AddLineToPoint (2f, 38f);
            boundingPath.AddLineToPoint (-2f, 38f);
            boundingPath.AddLineToPoint (-9f, 18f);
            boundingPath.AddLineToPoint (-12f, -38f);
            #if false
            // Debug overlay
            SKShapeNode shipOverlayShape = new SKShapeNode () {
                Path = boundingPath,
                StrokeColor = UIColor.Clear,
                FillColor = UIColor.FromRGBA (0f, 1f, 0f, 0.5f)
            };
            ship.AddChild (shipOverlayShape);
            #endif
            var body = SKPhysicsBody.BodyWithPolygonFromPath (boundingPath);
            body.CategoryBitMask = Category.Ship;
            body.CollisionBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge;
            body.ContactTestBitMask = body.CollisionBitMask;
            body.LinearDamping = 0;
            body.AngularDamping = 0.5f;

            PhysicsBody = body;
            Position = initialPosition;
        }
예제 #35
0
        public override void Draw(RectangleF rect)
        {
            base.Draw (rect);
            float midY = this.Bounds.Height / 2f;
            float right = this.Bounds.Width;
            float bottom = this.Bounds.Height;

            var ctx = UIGraphics.GetCurrentContext();
            ctx.SaveState();
            CGPath path = new CGPath();
            path.MoveToPoint(new PointF(right, 0f));
            path.AddLineToPoint(2f, midY);
            path.AddLineToPoint(right, bottom);
            ctx.AddPath(path);
            ctx.SetStrokeColor(UIColor.Black.CGColor);
            ctx.SetLineWidth(2f);
            ctx.SetLineCap(CGLineCap.Round);
            ctx.StrokePath();
            ctx.RestoreState();
            ctx.Dispose();
            path.Dispose();
        }
예제 #36
0
		public ClockView ()
		{
			// Set background to pink.
			this.BackgroundColor = UIColor.FromRGB (1.0f, 0.8f, 0.8f);

			// All paths are based on 100-unit clock radius
			//		centered at (0, 0)

			// Define circle for tick marks.
			tickMarks = new CGPath ();
			tickMarks.AddEllipseInRect(new CGRect(-90, -90, 180, 180));

			// Hour, minute, second hands defined to point straight up.

			// Define hour hand.
			hourHand = new CGPath ();
			hourHand.MoveToPoint (0, -60);
			hourHand.AddCurveToPoint (0, -30, 20, -30, 5, - 20);
			hourHand.AddLineToPoint (5, 0);
			hourHand.AddCurveToPoint (5, 7.5f, -5, 7.5f, -5, 0);
			hourHand.AddLineToPoint (-5, -20);
			hourHand.AddCurveToPoint (-20, -30, 0, -30, 0, -60);
			hourHand.CloseSubpath ();

			// Define minute hand.
			minuteHand = new CGPath ();
			minuteHand.MoveToPoint (0, -80);
			minuteHand.AddCurveToPoint (0, -75, 0, -70, 2.5f, -60);
			minuteHand.AddLineToPoint (2.5f, 0);
			minuteHand.AddCurveToPoint (2.5f, 5, -2.5f, 5, -2.5f, 0);
			minuteHand.AddLineToPoint (-2.5f, -60);
			minuteHand.AddCurveToPoint (0, -70, 0, -75, 0, -80);
			minuteHand.CloseSubpath ();

			// Define second hand.
			secondHand = new CGPath ();
			secondHand.MoveToPoint (0, 10);
			secondHand.AddLineToPoint(0, -80);
		}
		CGPath createPathForPoints (NSDictionary[] points)
		{
			CGPath path = new CGPath ();
			PointF point;

			if (points.Length > 0) {
				points [0].ToPoint (out point);
				path.MoveToPoint (point);

				int i = 1;
				while (i < points.Length) {
					points [i].ToPoint (out point);
					path.AddLineToPoint (point);
					i++;
				}

				path.CloseSubpath ();
			}

			return path;
		}
		CGPath createPathForPoints (CGPoint[] points)
		{
			CGPath path = new CGPath ();
			CGPoint point;

			if (points.Length > 0) {
				point = points [0];
				path.MoveToPoint (point);

				int i = 1;
				while (i < points.Length) {
					point = points [i];
					path.AddLineToPoint (point);
					i++;
				}

				path.CloseSubpath ();
			}

			return path;
		}
예제 #39
0
        public CGPath polyPath(MKPolyline polyline,MKMapRect mapRect, float zoomScale, CGContext context)
        {
            MKMapPoint[] points = polyline.Points;
            Int32 pointCount = polyline.PointCount;
            Int32 i;

            if (pointCount < 3)
                return null;

            CGPath path = new CGPath ();

            PointF relativePoint = this.PointForMapPoint (points[0]);
            path.MoveToPoint (relativePoint.X, relativePoint.Y);
            for (i = 1; i < pointCount; i++)
            {
                relativePoint = this.PointForMapPoint (points[i]);
                path.AddLineToPoint(relativePoint);
            }

            return path;
        }
예제 #40
0
		public ShipSprite (CGPoint initialPosition)
			: base (NSBundle.MainBundle.PathForResource ("spaceship", "png"))
		{
			health = startingShipHealth;

			using (CGPath boundingPath = new CGPath ()) {
				boundingPath.MoveToPoint (-12f, -38f);
				boundingPath.AddLineToPoint (12f, -38f);
				boundingPath.AddLineToPoint (9f, 18f);
				boundingPath.AddLineToPoint (2f, 38f);
				boundingPath.AddLineToPoint (-2f, 38f);
				boundingPath.AddLineToPoint (-9f, 18f);
				boundingPath.AddLineToPoint (-12f, -38f);
#if false
			// Debug overlay
			SKShapeNode shipOverlayShape = new SKShapeNode () {
				Path = boundingPath,
				StrokeColor = UIColor.Clear,
				FillColor = UIColor.FromRGBA (0f, 1f, 0f, 0.5f)
			};
			ship.AddChild (shipOverlayShape);
#endif
				var body = SKPhysicsBody.CreateBodyFromPath (boundingPath);
				body.CategoryBitMask = Category.Ship;
				body.CollisionBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge;
				body.ContactTestBitMask = body.CollisionBitMask;

				// The ship doesn't slow down when it moves forward, but it does slow its angular rotation. In practice,
				// this feels better for a game.
				body.LinearDamping = 0;
				body.AngularDamping = 0.5f;

				PhysicsBody = body;
			}
			Position = initialPosition;
		}
                    public PersonEntry( Rock.Client.Person personModel, bool isChild, OnPersonEntryClicked personClickedDelegate )
                    {
                        View = new UIView( );
                        View.Layer.AnchorPoint = CGPoint.Empty;
                        View.Layer.CornerRadius = 4;
                        View.Bounds = new CGRect( 0, 0, PersonEntrySize, PersonEntrySize );

                        Button = UIButton.FromType( UIButtonType.System );
                        Button.Layer.AnchorPoint = CGPoint.Empty;
                        Button.Bounds = View.Bounds;
                        View.AddSubview( Button );

                        ImageView = new UIImageView( );
                        ImageView.Layer.AnchorPoint = CGPoint.Empty;
                        View.AddSubview( ImageView );

                        PersonModel = personModel;
                        IsChild = isChild;

                        // set the profile image mask so it's circular
                        CALayer maskLayer = new CALayer();
                        maskLayer.AnchorPoint = new CGPoint( 0, 0 );
                        maskLayer.BackgroundColor = UIColor.Black.CGColor;
                        ImageView.Layer.Mask = maskLayer;
                        ImageView.BackgroundColor = UIColor.Black;

                        // we can't position these until we know their length
                        Name = new UILabel( );
                        Name.Layer.AnchorPoint = CGPoint.Empty;
                        Name.Font = FontManager.GetFont( Settings.General_LightFont, Config.Instance.VisualSettings.SmallFontSize );
                        Name.TextAlignment = UITextAlignment.Center;
                        View.AddSubview( Name );

                        // procedurally create the little fancy mask that goes under the age.
                        AgeShapeLayer = new CAShapeLayer( );
                        CGPath path = new CGPath( );

                        // render as a triangle
                        path.MoveToPoint( 0, 0 );
                        path.AddLineToPoint( AgeMaskSize, 0 );
                        path.AddLineToPoint( AgeMaskSize, AgeMaskSize );
                        path.AddLineToPoint( 0, 0 );
                        path.CloseSubpath( );

                        AgeShapeLayer.Path = path;
                        AgeShapeLayer.FillColor = UIColor.Black.CGColor;
                        AgeShapeLayer.Position = new CGPoint( View.Bounds.Width - AgeMaskSize, 0 );
                        AgeShapeLayer.Opacity = .10f;
                        View.Layer.AddSublayer( AgeShapeLayer );

                        // setup the age value
                        Age = new UILabel( );
                        Age.Layer.AnchorPoint = CGPoint.Empty;
                        Age.Font = FontManager.GetFont( Settings.General_RegularFont, Config.Instance.VisualSettings.SmallFontSize );
                        View.AddSubview( Age );

                        Name.TextColor = Theme.GetColor( Config.Instance.VisualSettings.FamilyCellStyle.EntryTextColor );
                        Age.TextColor = Theme.GetColor( Config.Instance.VisualSettings.FamilyCellStyle.EntryTextColor );
                        View.BackgroundColor = Theme.GetColor( Config.Instance.VisualSettings.FamilyCellStyle.EntryBGColor );

                        Button.TouchUpInside += (object sender, EventArgs e) =>
                            {
                                personClickedDelegate( PersonModel, ImageBuffer );
                            };
                    }
예제 #42
0
        public Region(RectangleF rect)
        {
            regionObject = rect;
            var path = RectangleToPath (rect);
            solution.Add (path);
            regionList.Add (new RegionEntry (RegionType.Rectangle, rect, path));
            regionPath = new CGPath ();
            regionPath.MoveToPoint (rect.Left, rect.Top);
            regionPath.AddLineToPoint (rect.Right, rect.Top);
            regionPath.AddLineToPoint (rect.Right, rect.Bottom);
            regionPath.AddLineToPoint (rect.Left, rect.Bottom);

            regionBounds = rect;
        }
예제 #43
0
        //        public bool IsInfinite(Graphics g)
        //        {
        //        }
        public void MakeInfinite()
        {
            regionObject = infinite;

            var path = RectangleToPath (infinite);

            // clear out our containers.
            regionList.Clear ();
            solution.Clear ();

            solution.Add (path);
            regionList.Add (new RegionEntry (RegionType.Infinity, infinite, path));

            regionPath = new CGPath ();
            regionPath.MoveToPoint (infinite.Left, infinite.Top);
            regionPath.AddLineToPoint (infinite.Right, infinite.Top);
            regionPath.AddLineToPoint (infinite.Right, infinite.Bottom);
            regionPath.AddLineToPoint (infinite.Left, infinite.Bottom);

            regionBounds = regionPath.BoundingBox.ToRectangleF ();
        }
예제 #44
0
        protected virtual CGPath CreateDisclosureIndicatorPath(PointF arrowPointFront, float height, float thickness, out float width)
        {
            float out_width = 0; // fix for method wrapping
            CGPath result = Wrap.Function("CreateDisclosureIndicatorPath", delegate()
            {
                thickness /= (float)Math.Cos(Math.PI / 4);
                CGPath path = new CGPath(); //CGPathCreateMutable();
                path.MoveToPoint(arrowPointFront.X, arrowPointFront.Y);

                PointF bottomPointFront = new PointF(arrowPointFront.X - (float)(height / (2 * Math.Tan(Math.PI / 4))), arrowPointFront.Y - height / 2);
                path.AddLineToPoint(bottomPointFront.X, bottomPointFront.Y);


                PointF bottomPointBack = new PointF(bottomPointFront.X - thickness * (float)Math.Cos(Math.PI / 4), bottomPointFront.Y + thickness * (float)Math.Sin(Math.PI / 4));
                path.AddLineToPoint(bottomPointBack.X, bottomPointBack.Y);

                PointF arrowPointBack = new PointF(arrowPointFront.X - thickness / (float)Math.Cos(Math.PI / 4), arrowPointFront.Y);
                path.AddLineToPoint(arrowPointBack.X, arrowPointBack.Y);

                PointF topPointFront = new PointF(bottomPointFront.X, arrowPointFront.Y + height / 2);
                PointF topPointBack = new PointF(bottomPointBack.X, topPointFront.Y - thickness * (float)Math.Sin(Math.PI / 4));

                path.AddLineToPoint(topPointBack.X, topPointBack.Y);
                path.AddLineToPoint(topPointFront.X, topPointFront.Y);
                path.AddLineToPoint(arrowPointFront.X, arrowPointFront.Y);

                out_width = (arrowPointFront.X - topPointBack.X);
                return path;
            });
            width = out_width;
            return result;
        }
예제 #45
0
        /// <summary>
        /// Gets the poly path for a polygon.
        /// </summary>
        /// <returns>The path.</returns>
        /// <param name="polygon">Polygon to get the path for.</param>
        public CGPath PolyPath(MKPolygon polygon)
        {
            var path = new CGPath();

            foreach (var item in polygon.InteriorPolygons)
            {
                var interiorPath = this.PolyPath(item);
                path.AddPath(interiorPath);
            }

            var relativePoint = PointForMapPoint(polygon.Points[0]);
            path.MoveToPoint(relativePoint);
            foreach (var point in polygon.Points)
            {
                path.AddLineToPoint(this.PointForMapPoint(point));
            }

            return path;
        }
예제 #46
0
        private void CreateLayers(UIImage image)
        {
            if (image == null)
                return;

            Layer.Sublayers = new CALayer[0];

            var imageFrame = new CGRect(
                Frame.Width / 2f - Frame.Width / 4f,
                Frame.Height / 2f - Frame.Height / 4f,
                Frame.Width / 2f,
                Frame.Height / 2f);
            var imgCenterPoint = new CGPoint(imageFrame.GetMidX(), imageFrame.GetMidY());
            var lineFrame = new CGRect(
                imageFrame.X - imageFrame.Width / 4f,
                imageFrame.Y - imageFrame.Height / 4f,
                imageFrame.Width * 1.5f,
                imageFrame.Height * 1.5f);

            //===============
            // circle layer
            //===============
            circleShape = new CAShapeLayer();
            circleShape.Bounds = imageFrame;
            circleShape.Position = imgCenterPoint;
            circleShape.Path = UIBezierPath.FromOval(imageFrame).CGPath;
            circleShape.FillColor = circleColor.CGColor;
            circleShape.Transform = CATransform3D.MakeScale(0.0f, 0.0f, 1.0f);
            Layer.AddSublayer(circleShape);

            circleMaskShape = new CAShapeLayer();
            circleMaskShape.Bounds = imageFrame;
            circleMaskShape.Position = imgCenterPoint;
            circleMaskShape.FillRule = CAShapeLayer.FillRuleEvenOdd;
            circleShape.Mask = circleMaskShape;

            var maskPath = UIBezierPath.FromRect(imageFrame);
            maskPath.AddArc(imgCenterPoint, 0.1f, 0.0f, fPI * 2f, true);
            circleMaskShape.Path = maskPath.CGPath;

            //===============
            // line layer
            //===============
            lineShapes = new CAShapeLayer[5];
            for (int i = 0; i < 5; i++)
            {
                var line = new CAShapeLayer();
                line.Bounds = lineFrame;
                line.Position = imgCenterPoint;
                line.MasksToBounds = true;
                line.Actions = NSDictionary.FromObjectsAndKeys(
                    new[] { NSNull.Null, NSNull.Null },
                    new[] { (NSString)"strokeStart", (NSString)"strokeEnd" });
                line.StrokeColor = linesColor.CGColor;
                line.LineWidth = 1.25f;
                line.MiterLimit = 1.25f;
                var path = new CGPath();
                path.MoveToPoint(lineFrame.GetMidX(), lineFrame.GetMidY());
                path.AddLineToPoint(lineFrame.X + lineFrame.Width / 2f, lineFrame.Y);
                line.Path = path;
                line.LineCap = CAShapeLayer.CapRound;
                line.LineJoin = CAShapeLayer.JoinRound;
                line.StrokeStart = 0.0f;
                line.StrokeEnd = 0.0f;
                line.Opacity = 0.0f;
                line.Transform = CATransform3D.MakeRotation(fPI / 5f * (i * 2f + 1f), 0.0f, 0.0f, 1.0f);
                Layer.AddSublayer(line);
                lineShapes[i] = line;
            }

            //===============
            // image layer
            //===============
            imageShape = new CAShapeLayer();
            imageShape.Bounds = imageFrame;
            imageShape.Position = imgCenterPoint;
            imageShape.Path = UIBezierPath.FromRect(imageFrame).CGPath;
            imageShape.FillColor = Checked ? Color.CGColor : SkeletonColor.CGColor;
            imageShape.Actions = NSDictionary.FromObjectAndKey(NSNull.Null, (NSString)"fillColor");
            Layer.AddSublayer(imageShape);

            imageShape.Mask = new CALayer();
            imageShape.Mask.Contents = image.CGImage;
            imageShape.Mask.Bounds = imageFrame;
            imageShape.Mask.Position = imgCenterPoint;

            //==============================
            // circle transform animation
            //==============================
            circleTransform.Values = new[]
            {
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.0f,  0.0f,  1.0f)),    //  0/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.5f,  0.5f,  1.0f)),    //  1/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.0f,  1.0f,  1.0f)),    //  2/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.2f,  1.2f,  1.0f)),    //  3/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.3f,  1.3f,  1.0f)),    //  4/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.37f, 1.37f, 1.0f)),    //  5/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.4f,  1.4f,  1.0f)),    //  6/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.4f,  1.4f,  1.0f))     // 10/10
            };
            circleTransform.KeyTimes = new[]
            {
                NSNumber.FromDouble(0.0),    //  0/10
                NSNumber.FromDouble(0.1),    //  1/10
                NSNumber.FromDouble(0.2),    //  2/10
                NSNumber.FromDouble(0.3),    //  3/10
                NSNumber.FromDouble(0.4),    //  4/10
                NSNumber.FromDouble(0.5),    //  5/10
                NSNumber.FromDouble(0.6),    //  6/10
                NSNumber.FromDouble(1.0)     // 10/10
            };

            circleMaskTransform.Values = new[]
            {
                NSValue.FromCATransform3D(CATransform3D.Identity),                                                                 //  0/10
                NSValue.FromCATransform3D(CATransform3D.Identity),                                                                 //  2/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 1.25f,  imageFrame.Height * 1.25f,  1.0f)),   //  3/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 2.688f, imageFrame.Height * 2.688f, 1.0f)),   //  4/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 3.923f, imageFrame.Height * 3.923f, 1.0f)),   //  5/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 4.375f, imageFrame.Height * 4.375f, 1.0f)),   //  6/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 4.731f, imageFrame.Height * 4.731f, 1.0f)),   //  7/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 5.0f,   imageFrame.Height * 5.0f,   1.0f)),   //  9/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 5.0f,   imageFrame.Height * 5.0f,   1.0f))    // 10/10
            };
            circleMaskTransform.KeyTimes = new[]
            {
                NSNumber.FromDouble(0.0),    //  0/10
                NSNumber.FromDouble(0.2),    //  2/10
                NSNumber.FromDouble(0.3),    //  3/10
                NSNumber.FromDouble(0.4),    //  4/10
                NSNumber.FromDouble(0.5),    //  5/10
                NSNumber.FromDouble(0.6),    //  6/10
                NSNumber.FromDouble(0.7),    //  7/10
                NSNumber.FromDouble(0.9),    //  9/10
                NSNumber.FromDouble(1.0)     // 10/10
            };

            //==============================
            // line stroke animation
            //==============================
            lineStrokeStart.Values = new[]
            {
                NSNumber.FromDouble(0.0),    //  0/18
                NSNumber.FromDouble(0.0),    //  1/18
                NSNumber.FromDouble(0.18),   //  2/18
                NSNumber.FromDouble(0.2),    //  3/18
                NSNumber.FromDouble(0.26),   //  4/18
                NSNumber.FromDouble(0.32),   //  5/18
                NSNumber.FromDouble(0.4),    //  6/18
                NSNumber.FromDouble(0.6),    //  7/18
                NSNumber.FromDouble(0.71),   //  8/18
                NSNumber.FromDouble(0.89),   // 17/18
                NSNumber.FromDouble(0.92)    // 18/18
            };
            lineStrokeStart.KeyTimes = new[]
            {
                NSNumber.FromDouble(0.0),    //  0/18
                NSNumber.FromDouble(0.056),  //  1/18
                NSNumber.FromDouble(0.111),  //  2/18
                NSNumber.FromDouble(0.167),  //  3/18
                NSNumber.FromDouble(0.222),  //  4/18
                NSNumber.FromDouble(0.278),  //  5/18
                NSNumber.FromDouble(0.333),  //  6/18
                NSNumber.FromDouble(0.389),  //  7/18
                NSNumber.FromDouble(0.444),  //  8/18
                NSNumber.FromDouble(0.944),  // 17/18
                NSNumber.FromDouble(1.0),    // 18/18
            };

            lineStrokeEnd.Values = new[]
            {
                NSNumber.FromDouble(0.0),    //  0/18
                NSNumber.FromDouble(0.0),    //  1/18
                NSNumber.FromDouble(0.32),   //  2/18
                NSNumber.FromDouble(0.48),   //  3/18
                NSNumber.FromDouble(0.64),   //  4/18
                NSNumber.FromDouble(0.68),   //  5/18
                NSNumber.FromDouble(0.92),   // 17/18
                NSNumber.FromDouble(0.92)    // 18/18
            };
            lineStrokeEnd.KeyTimes = new[]
            {
                NSNumber.FromDouble(0.0),    //  0/18
                NSNumber.FromDouble(0.056),  //  1/18
                NSNumber.FromDouble(0.111),  //  2/18
                NSNumber.FromDouble(0.167),  //  3/18
                NSNumber.FromDouble(0.222),  //  4/18
                NSNumber.FromDouble(0.278),  //  5/18
                NSNumber.FromDouble(0.944),  // 17/18
                NSNumber.FromDouble(1.0),    // 18/18
            };

            lineOpacity.Values = new[]
            {
                NSNumber.FromDouble(1.0),    //  0/30
                NSNumber.FromDouble(1.0),    // 12/30
                NSNumber.FromDouble(0.0)     // 17/30
            };
            lineOpacity.KeyTimes = new[]
            {
                NSNumber.FromDouble(0.0),    //  0/30
                NSNumber.FromDouble(0.4),    // 12/30
                NSNumber.FromDouble(0.567)   // 17/30
            };

            //==============================
            // image transform animation
            //==============================
            imageTransform.Values = new[]
            {
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.0f,   0.0f,   1.0f)),  //  0/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.0f,   0.0f,   1.0f)),  //  3/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.2f,   1.2f,   1.0f)),  //  9/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.25f,  1.25f,  1.0f)),  // 10/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.2f,   1.2f,   1.0f)),  // 11/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.9f,   0.9f,   1.0f)),  // 14/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.875f, 0.875f, 1.0f)),  // 15/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.875f, 0.875f, 1.0f)),  // 16/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.9f,   0.9f,   1.0f)),  // 17/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.013f, 1.013f, 1.0f)),  // 20/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.025f, 1.025f, 1.0f)),  // 21/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.013f, 1.013f, 1.0f)),  // 22/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.96f,  0.96f,  1.0f)),  // 25/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.95f,  0.95f,  1.0f)),  // 26/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.96f,  0.96f,  1.0f)),  // 27/30
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.99f,  0.99f,  1.0f)),  // 29/30
                NSValue.FromCATransform3D(CATransform3D.Identity)                          // 30/30
            };
            imageTransform.KeyTimes = new[]
            {
                NSNumber.FromDouble(0.0),    //  0/30
                NSNumber.FromDouble(0.1),    //  3/30
                NSNumber.FromDouble(0.3),    //  9/30
                NSNumber.FromDouble(0.333),  // 10/30
                NSNumber.FromDouble(0.367),  // 11/30
                NSNumber.FromDouble(0.467),  // 14/30
                NSNumber.FromDouble(0.5),    // 15/30
                NSNumber.FromDouble(0.533),  // 16/30
                NSNumber.FromDouble(0.567),  // 17/30
                NSNumber.FromDouble(0.667),  // 20/30
                NSNumber.FromDouble(0.7),    // 21/30
                NSNumber.FromDouble(0.733),  // 22/30
                NSNumber.FromDouble(0.833),  // 25/30
                NSNumber.FromDouble(0.867),  // 26/30
                NSNumber.FromDouble(0.9),    // 27/30
                NSNumber.FromDouble(0.967),  // 29/30
                NSNumber.FromDouble(1.0)     // 30/30
            };

            // re-set the durations
            Duration = duration;
        }
예제 #47
0
		void RenderReticleImage ()
		{
			var imageRadius = NMath.Ceiling (radius * 1.2f);
			var imageSize = new CGSize (imageRadius * 2f, imageRadius * 2f);
			UIGraphics.BeginImageContextWithOptions (imageSize, false, ContentScaleFactor);

			var ctx = UIGraphics.GetCurrentContext ();
			ctx.TranslateCTM (imageRadius, imageRadius);
			ctx.SetLineWidth (2f);

			ctx.SetStrokeColor (reticleColor.CGColor);
			ctx.AddEllipseInRect (new CGRect (-radius, -radius, radius * 2, radius * 2));

			// Draw targeting lines.
			var path = new CGPath ();
			var transform = CGAffineTransform.MakeIdentity ();

			for (int i = 0; i < 4; i++) {
				path.MoveToPoint (transform, radius * .5f, 0f);
				path.AddLineToPoint (transform, radius * 1.15f, 0);
				transform.Rotate (NMath.PI / 2f);
			}

			ctx.AddPath (path);
			ctx.StrokePath ();

			reticleImage = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();

			reticleLayer.Contents = reticleImage.CGImage;
			reticleLayer.Bounds = new CGRect (0f, 0f, imageRadius * 2f, imageRadius * 2f);
			reticleLayer.ContentsScale = ContentScaleFactor;
		}
예제 #48
0
파일: Menu.cs 프로젝트: nagyist/MonoKit
        private void Close()
        {
            if (flag == -1) 
            {
                this.isAnimating = false;
                this.timer.Invalidate();
                this.timer = null;
                return;
            }

            int tag = 1000 + flag;
            MenuItem item = this.GetByTag(tag);

            item.Selected -= this.ItemSelected;

            var rotateAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");
            rotateAnimation.Values = new NSNumber[] {0f, this.CloseRotation, 0f};
            rotateAnimation.Duration = 0.5f;
            rotateAnimation.KeyTimes = new NSNumber[] {0f, 0.4f, 0.5f}; 

            var positionAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");
            positionAnimation.Duration = 0.5f;

            var path = new CGPath();
            path.MoveToPoint(item.EndPoint.X, item.EndPoint.Y);
            path.AddLineToPoint(item.FarPoint.X, item.FarPoint.Y);
            path.AddLineToPoint(item.StartPoint.X, item.StartPoint.Y);
            positionAnimation.Path = path;

            var alphaAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("opacity");
            alphaAnimation.Values = new NSNumber[] {1f, 1f, 0f};
            alphaAnimation.Duration = 0.5f;
            alphaAnimation.KeyTimes = new NSNumber[] {0f, 0.8f, 1f};

            var animationGroup = new CAAnimationGroup();
            animationGroup.Animations = new[] { positionAnimation, rotateAnimation, alphaAnimation };
            animationGroup.Duration = 0.5f;
            animationGroup.FillMode = CAFillMode.Forwards;
            animationGroup.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);

            item.Layer.AddAnimation(animationGroup, "Close");

            item.Alpha = 0f;
            item.Center = item.StartPoint;
            flag--;
        }
예제 #49
0
파일: Menu.cs 프로젝트: nagyist/MonoKit
        private void Expand()
        {
            if (flag == this.MenuItems.Count) 
            {
                this.isAnimating = false;
                this.timer.Invalidate();
                this.timer = null;
                return;
            }

            int tag = 1000 + this.flag;

            MenuItem item = this.GetByTag(tag);

            item.Selected -= this.ItemSelected;
            item.Selected += this.ItemSelected;

            var rotateAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");
            rotateAnimation.Values = new NSNumber[] {this.ExpandRotation, 0.0f};
            rotateAnimation.Duration = 0.5f;
            rotateAnimation.KeyTimes = new NSNumber[] {0.3f, 0.4f}; 

            var positionAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");
            positionAnimation.Duration = 0.5f;

            var path = new CGPath();
            path.MoveToPoint(item.StartPoint.X, item.StartPoint.Y);
            path.AddLineToPoint(item.FarPoint.X, item.FarPoint.Y);
            path.AddLineToPoint(item.NearPoint.X, item.NearPoint.Y);
            path.AddLineToPoint(item.EndPoint.X, item.EndPoint.Y);
            positionAnimation.Path = path;

            var animationGroup = new CAAnimationGroup();
            animationGroup.Animations = new[] {positionAnimation, rotateAnimation};
            animationGroup.Duration = 0.5f;
            animationGroup.FillMode = CAFillMode.Forwards;
            animationGroup.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);

            item.Layer.AddAnimation(animationGroup, "Expand");

            item.Alpha = 1f;
            item.Center = item.EndPoint;
            this.flag++;
        }
예제 #50
0
		public override void Draw (RectangleF rect)
		{
			//base.Draw (rect);
			
			float radius = 7.0f;
			float stroke = 1.0f;
						
			var context = UIGraphics.GetCurrentContext ();
			
			rect.Size.Width -= stroke + 14f;
			rect.Size.Height -= stroke + CalloutMapAnnotationViewHeightAboveParent
				- offsetFromParent.Y + CalloutMapAnnotationViewBottomShadowBufferSize;
			
			rect.Location.X += stroke / 2.0f + 7.0f;
			rect.Location.Y += stroke / 2.0f;
			
			SizeF size = new SizeF(rect.Size);
			size.Height -= 8;			

			var path = new CGPath ();
			path.MoveToPoint (rect.Location.X, rect.Location.Y + radius);
			path.AddLineToPoint(rect.Location.X, rect.Location.Y + size.Height - radius);									
			
			path.AddArc (rect.Location.X + radius, rect.Location.Y + size.Height - radius, 
			                    radius, (float)Math.PI, (float)Math.PI / 2.0f, true);
			/*
			 * 
			 * 
			 * 
			 */
			 
			path.AddArc(rect.Location.X + rect.Size.Width - radius, rect.Location.Y + size.Height - radius,
			            radius, (float)Math.PI / 2.0f, 0.0f, true);
						
			path.AddLineToPoint(rect.Location.X + size.Width, rect.Location.Y + radius);			
			path.AddArc(rect.Location.X + size.Width - radius, rect.Location.Y + radius,
			            radius, 0.0f, - (float)Math.PI / 2.0f, true);					
			
			path.AddLineToPoint(rect.Location.X + radius, rect.Location.Y);			
			
			path.AddArc(rect.Location.X + radius, rect.Location.Y + radius, radius,
			            - (float)Math.PI / 2.0f, (float)Math.PI, true);
			
			path.CloseSubpath ();
			
			float red, green, blue, alpha;
			UIColor.Black.GetRGBA(out red, out green, out blue, out alpha);
			UIColor color = UIColor.FromRGBA(red, green, blue, .6f);
			color.SetFill();
						
			var bounds = Bounds;
			var b = new SizeF(16, 8);
			context.MoveTo ((bounds.Width - b.Width) / 2 - 8, bounds.Height - 2 - b.Height);
			context.AddLineToPoint (bounds.Width/2 - 8, bounds.Height - 2);
			context.AddLineToPoint ((bounds.Width + b.Width) / 2 - 8, bounds.Height - b.Height - 2);
			context.ClosePath ();			
			
			context.AddPath(path);
			context.SaveState();
			context.SetShadowWithColor (new SizeF (0, yShadowOffset), 6, UIColor.FromWhiteAlpha(0.0f, 0.5f).CGColor);
			context.FillPath();
			context.RestoreState();					
			
			if (Annotation is CalloutMapAnnotation)
			{
				var annotation = (Annotation as CalloutMapAnnotation);
				blocks = new List<Block>();
				GetSize(annotation, blocks, bounds);
				
				foreach (Block block in blocks)
				{
					if (block.Type == BlockType.Text)
					{
						block.TextColor.SetColor();
						if (block.LineBreakMode.HasValue)
							DrawString (block.Value, block.Bounds, block.Font, block.LineBreakMode.Value, UITextAlignment.Left);
						else
							DrawString (block.Value, block.Bounds, block.Font);
					}
				}
			}			
		}
		public CGPath GetCellBorderPath(RectangleF rect)
		{
			var cornerRadius = 10;
			
			float minx = rect.GetMinX(), midx = rect.GetMidX(), maxx = rect.GetMaxX();
			float miny = rect.GetMinY(), midy = rect.GetMidY(), maxy = rect.GetMaxY();
			
			CGPath path = new CGPath();
			
			var cellPosition = CellPosition;

			if (cellPosition == CellPosition.Top)
			{
				minx = minx + 1;
				miny = miny + 1;
				
				maxx = maxx - 1;
				
				path.MoveToPoint(minx, maxy);
				path.AddArcToPoint(minx, miny, midx, miny, cornerRadius);
				path.AddArcToPoint(maxx, miny, maxx, maxy, cornerRadius);
				path.AddLineToPoint(maxx, maxy);
			}
			else if (cellPosition == CellPosition.Bottom)
			{
				minx = minx + 1;
				
				maxx = maxx - 1;
				maxy = maxy - 1;
				
				path.MoveToPoint(minx, miny);
				path.AddArcToPoint(minx, maxy, midx, maxy, cornerRadius);
				path.AddArcToPoint(maxx, maxy, maxx, miny, cornerRadius);
				path.AddLineToPoint(maxx, miny);
			}
			else if (cellPosition == CellPosition.Middle)
			{
				minx = minx + 1;
				maxx = maxx - 1;
				
				path.MoveToPoint(minx, miny);
				path.AddLineToPoint(maxx, miny);
				path.AddLineToPoint(maxx, maxy);
				path.AddLineToPoint(minx, maxy);
			}
			else if (cellPosition == CellPosition.Single)
			{
				minx = minx + 1;
				miny = miny + 1;
				
				maxx = maxx - 1;
				maxy = maxy - 1;
				
				path.MoveToPoint(minx, midy);
				path.AddArcToPoint(minx, miny, midx, miny, cornerRadius);
				path.AddArcToPoint(maxx, miny, maxx, midy, cornerRadius);
				path.AddArcToPoint(maxx, maxy, midx, maxy, cornerRadius);
				path.AddArcToPoint(minx, maxy, minx, midy, cornerRadius);
				
			}

			path.CloseSubpath();
			return path;
		}
예제 #52
0
        void PathsToInternalPath(Paths paths)
        {
            regionPath = new CGPath ();

            foreach (var poly in solution)
            {
                regionPath.MoveToPoint(IntPointToPointF(poly[0]).ToCGPoint ());

                for (var p =1; p < poly.Count; p++)
                {
                    regionPath.AddLineToPoint (IntPointToPointF (poly [p]).ToCGPoint ());
                }
            }
        }
예제 #53
0
		void drawLines ()
		{
			layer.RemoveAllAnimations ();

			var dot = new CGRect (0, 0, lineWidth, lineWidth);

			nfloat x, y;

			CGPoint start = CGPoint.Empty;
			CGPoint end = CGPoint.Empty;


			// Draw curved graph line
			using (UIColor color = UIColor.White.ColorWithAlpha (0.25f), dotColor = UIColor.White.ColorWithAlpha (0.70f)) {

				//color.SetStroke ();

				//dotColor.SetFill ();

				//ctx.SetLineWidth (lineWidth);

				using (CGPath path = new CGPath ()) {


					var count = hourly ? HourlyTemps.Count : (Forecasts.Count * 2);

					for (int i = 0; i < count; i++) {

						// adjusted index
						var ai = i;

						double temp;

						if (hourly) {

							temp = HourlyTemps [ai];

						} else {

							// reset start when switching from highs to lows
							if (i == Forecasts.Count) start = CGPoint.Empty;

							var highs = i < Forecasts.Count;

							ai = highs ? i : i - Forecasts.Count;

							temp = highs ? HighTemps [ai] : LowTemps [ai];
						}

						var percent = ((nfloat)temp - scaleLow) / scaleRange;


						x = padding + inset + (ai * scaleX);

						y = graphRect.GetMaxY () - (graphRect.Height * percent);

						end = new CGPoint (x, y);


						if (!hourly) {

							dot.X = end.X - (lineWidth / 2);
							dot.Y = end.Y - (lineWidth / 2);

							path.AddEllipseInRect (dot);

							//ctx.AddEllipseInRect (dot);
						}


						if (start == CGPoint.Empty) {

							path.MoveToPoint (end);

						} else {

							path.MoveToPoint (start);

							if (hourly) {

								path.AddLineToPoint (end);

							} else {

								var diff = (end.X - start.X) / 2;

								path.AddCurveToPoint (end.X - diff, start.Y, start.X + diff, end.Y, end.X, end.Y);
							}
						}

						start = end;
					}

					// draw all dots to context
					//if (!hourly) ctx.DrawPath (CGPathDrawingMode.Fill);

					// add line path to context
					layer.Path = path;
					//ctx.AddPath (path);

					// draw lines
					//ctx.DrawPath (CGPathDrawingMode.Stroke);

					layer.LineWidth = lineWidth;
					layer.StrokeColor = color.CGColor;
					layer.FillColor = dotColor.CGColor;

					CABasicAnimation pathAnimation = new CABasicAnimation { KeyPath = "strokeEnd" };
					pathAnimation.Duration = 1.0;
					pathAnimation.From = NSNumber.FromNFloat (0);
					pathAnimation.To = NSNumber.FromNFloat (1);
					layer.AddAnimation (pathAnimation, "strokeEndAnimation");

				}
			}
		}
예제 #54
0
		public void SetMagnitudes (double [] magnitudeData)
		{
			if (curveLayer == null) {
				curveLayer = new CAShapeLayer ();
				curveLayer.FillColor = UIColor.FromRGBA (0.31f, 0.37f, 0.73f, 0.8f).CGColor;
				graphLayer.AddSublayer (curveLayer);
			}

			var bezierPath = new CGPath ();
			var width = graphLayer.Bounds.Width;
			bezierPath.MoveToPoint (leftMargin, graphLayer.Frame.Height + bottomMargin);

			float lastDbPos = 0f;
			float location = leftMargin;
			var frequencyCount = frequencies?.Count ?? 0;
			var pixelRatio = (int)(Math.Ceiling (width / frequencyCount));

			for (int i = 0; i < frequencyCount; i++) {
				var dbValue = 20 * Math.Log10 (magnitudeData [i]);
				float dbPos;

				if (dbValue < -defaultGain)
					dbPos = GetLocationForDbValue (-defaultGain);
				else if (dbValue > defaultGain)
					dbPos = GetLocationForDbValue (defaultGain);
				else
					dbPos = GetLocationForDbValue ((float)dbValue);

				if (Math.Abs (lastDbPos - dbPos) >= 0.1)
					bezierPath.AddLineToPoint (location, dbPos);

				lastDbPos = dbPos;
				location += pixelRatio;

				if (location > width + graphLayer.Frame.X) {
					location = (float)width + (float)graphLayer.Frame.X;
					break;
				}
			}

			bezierPath.AddLineToPoint (location, graphLayer.Frame.Y + graphLayer.Frame.Height + bottomMargin);
			bezierPath.CloseSubpath ();

			CATransaction.Begin ();
			CATransaction.DisableActions = true;
			curveLayer.Path = bezierPath;
			CATransaction.Commit ();

			UpdateControls (true);
		}
        private CGPath NewBadgePathForTextSize(SizeF size)
        {
            float arcRadius = (float)Math.Ceiling((size.Height + this.Pad) / 2.0f);

            float badgeWidthAdjustment = size.Width - (size.Height / 2.0f);
            float badgeWidth = 2.0f * arcRadius;

            if (badgeWidthAdjustment > 0.0)
            {
                badgeWidth += badgeWidthAdjustment;
            }

            CGPath badgePath = new CGPath();

            var m_pi_2 = (float)(Math.PI / 2);

            badgePath.MoveToPoint(arcRadius, 0.0f);
            badgePath.AddArc(arcRadius, arcRadius, arcRadius, 3.0f * m_pi_2, m_pi_2, true);
            badgePath.AddLineToPoint(badgeWidth - arcRadius, 2.0f * arcRadius);
            badgePath.AddArc(badgeWidth - arcRadius, arcRadius, arcRadius, m_pi_2, 3.0f * m_pi_2, true);
            badgePath.AddLineToPoint(arcRadius, 0.0f);

            return badgePath;
        }
예제 #56
0
        void SetBackground(UIInterfaceOrientation interfaceOrientation)
        {
            var sunImg = new UIImage ("Images/sun.png");
            sunImageView = new UIImageView (sunImg);
            sunImageView.Alpha = 0;
            var imageViews = ParentViewController.View.Subviews.Where (v=> v.GetType() == typeof(UIImageView));
            foreach (var view in imageViews){
                if (((UIImageView)view).Image.Size == sunImg.Size){
                    view.RemoveFromSuperview();
                    Console.WriteLine("View removed");
                }
            }
            ParentViewController.View.AddSubview (sunImageView);
            ParentViewController.View.SendSubviewToBack (sunImageView);
            Console.WriteLine("View added");

            var alpha = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath ("opacity");
            alpha.Values = new NSNumber[]{
                                   NSNumber.FromFloat (0),
                                   NSNumber.FromFloat (1),
                                 };

            var rotation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath ("transform.rotation");
            rotation.Values = new NSNumber[]{
                                   NSNumber.FromFloat (-3),
                                   NSNumber.FromFloat (0),
                                 };

            var posAnim = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath ("position");
            var posPath = new CGPath ();
            posPath.MoveToPoint (SunPath.CurrentSunPosition);
            var toPoint = SunPath.GetPointForControllerIndex (GetCurrentControllerViewIndex (), interfaceOrientation == UIInterfaceOrientation.Portrait || interfaceOrientation == UIInterfaceOrientation.PortraitUpsideDown);
            posPath.AddLineToPoint (toPoint);

            posAnim.Path = posPath;

            var anGroup = CAAnimationGroup.CreateAnimation ();
            anGroup.Animations = new CAAnimation [] { alpha, rotation, posAnim };
            anGroup.Duration = 0.5;
            anGroup.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseOut.ToString ());
            anGroup.AnimationStopped += delegate {
                sunImageView.Layer.Position = toPoint;
                SunPath.CurrentSunPosition = sunImageView.Layer.Position;
                sunImageView.Alpha = 1;
            };

            sunImageView.Layer.AddAnimation (anGroup, "sun");
        }
예제 #57
0
        private static float scale = 10000; //or 1 or 10 or 10000 etc for lesser or greater precision.

        #endregion Fields

        #region Constructors

        // An infinite region would cover the entire device region which is the same as
        // not having a clipping region. Note that this is not the same as having an
        // empty region, which when clipping to it has the effect of excluding the entire
        // device region.
        public Region()
        {
            // We set the default region to a very large
            regionObject = infinite;

            var path = RectangleToPath (infinite);
            solution.Add (path);

            regionList.Add (new RegionEntry (RegionType.Infinity, infinite, path));

            regionPath = new CGPath ();
            regionPath.MoveToPoint (infinite.Left, infinite.Top);
            regionPath.AddLineToPoint (infinite.Right, infinite.Top);
            regionPath.AddLineToPoint (infinite.Right, infinite.Bottom);
            regionPath.AddLineToPoint (infinite.Left, infinite.Bottom);

            regionBounds = infinite;
        }
    public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
    {
        if (keyPath == "contentInset") {
            if (!_ignoreInset && !_ignoreInsetBlock) {
                OriginalContentInset = ((NSValue) change ["new"]).UIEdgeInsetsValue;

                Frame = (_vertical)
                    ? new RectangleF (0, - (TotalViewHeight + ScrollView.ContentInset.Top), ScrollView.Bounds.Size.Width, TotalViewHeight)
                    : new RectangleF (- (TotalViewHeight + ScrollView.ContentInset.Left), 0, TotalViewHeight, ScrollView.Bounds.Size.Height);
            }
            
            return;
        }
        
        if (!Enabled || _ignoreOffset)
            return;
        
        var newContentOffset = ((NSValue) change ["new"]).PointFValue;
        float offset;
        
        if (_vertical) {
            offset = newContentOffset.Y + OriginalContentInset.Top;
        } else {
            offset = newContentOffset.X + OriginalContentInset.Left;
        }
        
        if (_refreshing) {
            if (offset != 0) {
                // Keep thing pinned at the top
                
                CATransaction.Begin ();
                CATransaction.DisableActions = true;
                
                _shapeLayer.Position = (_vertical)
                    ? new PointF (0, MaxDistance + offset + OpenedViewHeight)
                        : new PointF (MaxDistance + offset + OpenedViewHeight, 0);
                
                CATransaction.Commit ();
                
                if (_vertical) {
                    _activity.Center = new PointF (
                        (float) Math.Floor (Bounds.Width / 2.0f),
                        Math.Min (
                        offset + Bounds.Height + (float) Math.Floor (OpenedViewHeight / 2.0f),
                        Bounds.Height - OpenedViewHeight / 2.0f
                        )
                        );
                } else {
                    _activity.Center = new PointF (
                        Math.Min (
                        offset + Bounds.Width + (float) Math.Floor (OpenedViewHeight / 2.0f),
                        Bounds.Width - OpenedViewHeight / 2.0f
                        ),
                        (float) Math.Floor (Bounds.Height / 2.0f)
                        );
                }
                
                _ignoreInset = true;
                _ignoreOffset = true;
                
                if (offset < 0) {
                    // Set the inset depending on the situation
                    if (offset >= -OpenedViewHeight) {
                        if (!ScrollView.Dragging) {
                            if (!_didSetInset) {
                                _didSetInset = true;
                                _hasSectionHeaders = false;
                                
                                if (ScrollView is UITableView) {
                                    var tableView = (UITableView) ScrollView;
                                    for (var i = 0; i < tableView.NumberOfSections (); i++) {
                                        if (tableView.RectForHeaderInSection (i).Size.Height > 0) {
                                            _hasSectionHeaders = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            
                            if (_hasSectionHeaders) {
                                ScrollView.ContentInset = (_vertical)
                                    ? new UIEdgeInsets (Math.Min (-offset, OpenedViewHeight) + OriginalContentInset.Top, OriginalContentInset.Left, OriginalContentInset.Bottom, OriginalContentInset.Right)
                                    : new UIEdgeInsets (OriginalContentInset.Top, Math.Min (-offset, OpenedViewHeight) + OriginalContentInset.Left, OriginalContentInset.Bottom, OriginalContentInset.Right);
                            } else {
                                ScrollView.ContentInset = (_vertical)
                                    ? new UIEdgeInsets (OpenedViewHeight + OriginalContentInset.Top, OriginalContentInset.Left, OriginalContentInset.Bottom, OriginalContentInset.Right)
                                    : new UIEdgeInsets (OriginalContentInset.Top, OriginalContentInset.Left + OpenedViewHeight, OriginalContentInset.Bottom, OriginalContentInset.Right);
                            }
                        } else if (_didSetInset && _hasSectionHeaders) {
                            ScrollView.ContentInset = (_vertical)
                                ? new UIEdgeInsets (-offset + OriginalContentInset.Top, OriginalContentInset.Left, OriginalContentInset.Bottom, OriginalContentInset.Right)
                                : new UIEdgeInsets (OriginalContentInset.Top, -offset + OriginalContentInset.Left, OriginalContentInset.Bottom, OriginalContentInset.Right);
                        }
                        
                    }
                } else if (_hasSectionHeaders) {
                    ScrollView.ContentInset = OriginalContentInset;
                }
                
                _ignoreInset = false;
                _ignoreOffset = false;
            }
            
            return;
        } else {
            // Check if we can trigger a new refresh and if we can draw the control
            bool dontDraw = false;
            
            if (!_canRefresh) {
                if (offset >= 0) {
                    // We can refresh again after the control is scrolled out of view
                    _canRefresh = true;
                    _didSetInset = false;
                } else {
                    dontDraw = true;
                }
            } else {
                if (offset >= 0) {
                    // Don't draw if the control is not visible
                    dontDraw = true;
                }
            }
            
            if (offset > 0 && _lastOffset > offset && !ScrollView.Tracking) {
                // If we are scrolling too fast, don't draw, and don't trigger unless the scrollView bounced back
                _canRefresh = false;
                dontDraw = true;
            }
            
            if (dontDraw) {
                _shapeLayer.Path = null;
                _shapeLayer.ShadowPath = new CGPath (IntPtr.Zero);
                _arrowLayer.Path = null;
                _highlightLayer.Path = null;
                _lastOffset = offset;
                return;
            }
        }
        
        _lastOffset = offset;
        bool triggered = false;
        
        CGPath path = new CGPath ();
        
        //Calculate some useful points and values
        var verticalShift = Math.Max (0, -((MaxTopRadius + MaxBottomRadius + MaxTopPadding + MaxBottomPadding) + offset));
        var distance = Math.Min (MaxDistance, Math.Abs (verticalShift));
        var percentage = 1 - (distance / MaxDistance);
        
        PointF headOrigin;
        float headRadius;
        
        if (_vertical) {
            float currentTopPadding = lerp (MinTopPadding, MaxTopPadding, percentage);
            float currentTopRadius = lerp (MinTopRadius, MaxTopRadius, percentage);
            float currentBottomRadius = lerp (MinBottomRadius, MaxBottomRadius, percentage);
            float currentBottomPadding = lerp (MinBottomPadding, MaxBottomPadding, percentage);
            
            var bottomOrigin = new PointF ((float) Math.Floor (Bounds.Width / 2.0f), Bounds.Height - currentBottomPadding - currentBottomRadius);
            var topOrigin = PointF.Empty;
            
            if (distance == 0) {
                topOrigin = new PointF ((float) Math.Floor (Bounds.Width / 2.0f), bottomOrigin.Y);
            } else {
                topOrigin = new PointF ((float) Math.Floor (Bounds.Width / 2.0f), Bounds.Height + offset + currentTopPadding + currentTopRadius);
                
                if (percentage == 0) {
                    bottomOrigin.Y -= ((Math.Abs (verticalShift) - MaxDistance));
                    triggered = true;
                }
            }
            
            //Top semicircle
            path.AddArc (topOrigin.X, topOrigin.Y, currentTopRadius, 0, (float) Math.PI, true);
            
            //Left curve
            var leftCp1 = new PointF (lerp ((topOrigin.X - currentTopRadius), (bottomOrigin.X - currentBottomRadius), 0.1f), lerp (topOrigin.Y, bottomOrigin.Y, .2f));
            var leftCp2 = new PointF (lerp ((topOrigin.X - currentTopRadius), (bottomOrigin.X - currentBottomRadius), 0.9f), lerp (topOrigin.Y, bottomOrigin.Y, .2f));
            var leftDestination = new PointF (bottomOrigin.X - currentBottomRadius, bottomOrigin.Y);
            
            path.AddCurveToPoint (leftCp1, leftCp2, leftDestination);
            
            //Bottom semicircle
            path.AddArc (bottomOrigin.X, bottomOrigin.Y, currentBottomRadius, (float) Math.PI, 0, true);
            
            //Right curve
            var rightCp2 = new PointF (lerp ((topOrigin.X + currentTopRadius), (bottomOrigin.X + currentBottomRadius), 0.1f), lerp (topOrigin.Y, bottomOrigin.Y, .2f));
            var rightCp1 = new PointF (lerp ((topOrigin.X + currentTopRadius), (bottomOrigin.X + currentBottomRadius), 0.9f), lerp (topOrigin.Y, bottomOrigin.Y, .2f));
            var rightDestination = new PointF (bottomOrigin.X + currentTopRadius, topOrigin.Y);
            
            path.AddCurveToPoint (rightCp1, rightCp2, rightDestination);
            
            headOrigin = topOrigin;
            headRadius = currentTopRadius;
        } else {
            float currentLeftPadding = lerp (MinTopPadding, MaxTopPadding, percentage);
            float currentLeftRadius = lerp (MinTopRadius, MaxTopRadius, percentage);
            float currentRightRadius = lerp (MinBottomRadius, MaxBottomRadius, percentage);
            float currentRightPadding = lerp (MinBottomPadding, MaxBottomPadding, percentage);
            
            var rightOrigin = new PointF (Bounds.Width - currentRightPadding - currentRightRadius, (float) Math.Floor (Bounds.Height / 2.0f));
            var leftOrigin = PointF.Empty;
            
            if (distance == 0) {
                leftOrigin = new PointF (rightOrigin.X, (float) Math.Floor (Bounds.Size.Height / 2.0f));
            } else {
                leftOrigin = new PointF (Bounds.Size.Width + offset + currentLeftPadding + currentLeftRadius, (float) Math.Floor (Bounds.Height / 2.0f));
                
                if (percentage == 0) {
                    rightOrigin.X -= ((Math.Abs (verticalShift) - MaxDistance));
                    triggered = true;
                }
            }
            
            //Left cemicircle
            path.AddArc (leftOrigin.X, leftOrigin.Y, currentLeftRadius, (float) -Math.PI / 2.0f, (float) Math.PI / 2.0f, true);
            
            // Bottom curve
            var bottomCp1 = new PointF (lerp (leftOrigin.X, rightOrigin.X, .2f), lerp ((leftOrigin.Y + currentLeftRadius), (rightOrigin.Y + currentRightRadius), .1f));
            var bottomCp2 = new PointF (lerp (leftOrigin.X, rightOrigin.X, .2f), lerp ((leftOrigin.Y + currentLeftRadius), (rightOrigin.Y + currentRightRadius), .9f));
            var bottomDestination = new PointF (rightOrigin.X, rightOrigin.Y + currentRightRadius);
            
            path.AddCurveToPoint (bottomCp1, bottomCp2, bottomDestination);
            
            //Right semicircle
            path.AddArc (rightOrigin.X, rightOrigin.Y, currentRightRadius, (float) Math.PI / 2.0f, 3 * (float) Math.PI / 2.0f, true);
            
            //Top curve
            var topCp2 = new PointF (lerp (leftOrigin.X, rightOrigin.X, .2f), lerp ((leftOrigin.Y - currentLeftRadius), (rightOrigin.Y - currentRightRadius), .1f));
            var topCp1 = new PointF (lerp (leftOrigin.X, rightOrigin.X, .2f), lerp ((leftOrigin.Y - currentLeftRadius), (rightOrigin.Y - currentRightRadius), .9f));
            var topDestination = new PointF (leftOrigin.X, leftOrigin.Y - currentLeftRadius);
            
            path.AddCurveToPoint (topCp1, topCp2, topDestination);
            
            headOrigin = leftOrigin;
            headRadius = currentLeftRadius;
        }
        
        path.CloseSubpath ();
        
        if (!triggered) {
            // Set paths
            
            _shapeLayer.Path = path;
            _shapeLayer.ShadowPath = path;
            
            // Add the arrow shape
            
            var currentArrowSize = lerp (MinArrowSize, MaxArrowSize, percentage);
            var currentArrowRadius = lerp (MinArrowRadius, MaxArrowRadius, percentage);
            
            var arrowBigRadius = currentArrowRadius + (currentArrowSize / 2.0f);
            var arrowSmallRadius = currentArrowRadius - (currentArrowSize / 2.0f);
            
            var arrowPath = new CGPath ();
            arrowPath.AddArc (headOrigin.X, headOrigin.Y, arrowBigRadius, 0, 3 * (float) Math.PI / 2.0f, false);
            arrowPath.AddLineToPoint (headOrigin.X, headOrigin.Y - arrowBigRadius - currentArrowSize);
            arrowPath.AddLineToPoint (headOrigin.X + (2 * currentArrowSize), headOrigin.Y - arrowBigRadius + (currentArrowSize / 2.0f));
            arrowPath.AddLineToPoint (headOrigin.X, headOrigin.Y - arrowBigRadius + (2 * currentArrowSize));
            arrowPath.AddLineToPoint (headOrigin.X, headOrigin.Y - arrowBigRadius + currentArrowSize);
            arrowPath.AddArc (headOrigin.X, headOrigin.Y, arrowSmallRadius, 3 * (float) Math.PI / 2.0f, 0, true);
            arrowPath.CloseSubpath ();
            
            _arrowLayer.Path = arrowPath;
            _arrowLayer.FillRule =  CAShapeLayer.FillRuleEvenOdd;
            arrowPath.Dispose ();
            
            // Add the highlight shape
            
            var highlightPath = new CGPath ();
            if (_vertical) {
                highlightPath.AddArc (headOrigin.X, headOrigin.Y, headRadius, 0, (float) Math.PI, true);
                highlightPath.AddArc (headOrigin.X, headOrigin.Y + 1.25f, headRadius, (float) Math.PI, 0, false);
            } else {
                highlightPath.AddArc (headOrigin.X, headOrigin.Y, headRadius, - (float) Math.PI / 2.0f, (float) Math.PI / 2.0f, true);
                highlightPath.AddArc (headOrigin.X + 1.25f, headOrigin.Y, headRadius, (float) Math.PI / 2.0f, - (float) Math.PI / 2.0f, false);
            }
            
            _highlightLayer.Path = highlightPath;
            _highlightLayer.FillRule = CAShapeLayer.FillRuleNonZero;
            highlightPath.Dispose ();
        } else {
            // Start the shape disappearance animation
            var radius = lerp (MinBottomRadius, MaxBottomRadius, .2f);
            var pathMorph = CABasicAnimation.FromKeyPath ("path");
            
            pathMorph.Duration = .15f;
            pathMorph.FillMode = CAFillMode.Forwards;
            pathMorph.RemovedOnCompletion = false;
            
            var toPath = new CGPath ();
            
            if (_vertical) {
                toPath.AddArc (headOrigin.X, headOrigin.Y, radius, 0, (float)Math.PI, true);
                toPath.AddCurveToPoint (headOrigin.X - radius, headOrigin.Y, headOrigin.X - radius, headOrigin.Y, headOrigin.X - radius, headOrigin.Y);
                toPath.AddArc (headOrigin.X, headOrigin.Y, radius, (float) Math.PI, 0, true);
                toPath.AddCurveToPoint (headOrigin.X + radius, headOrigin.Y, headOrigin.X + radius, headOrigin.Y, headOrigin.X + radius, headOrigin.Y);
            } else {
                toPath.AddArc (headOrigin.X, headOrigin.Y, radius, - (float) Math.PI / 2.0f, (float) Math.PI / 2.0f, true);
                toPath.AddCurveToPoint (headOrigin.X, headOrigin.Y + radius, headOrigin.X, headOrigin.Y + radius, headOrigin.X, headOrigin.Y + radius);
                toPath.AddArc (headOrigin.X, headOrigin.Y, radius, (float) Math.PI / 2.0f, - (float) Math.PI / 2.0f, true);
                toPath.AddCurveToPoint (headOrigin.X, headOrigin.Y - radius, headOrigin.X, headOrigin.Y - radius, headOrigin.X, headOrigin.Y - radius);
            }
            
            toPath.CloseSubpath ();
            
            pathMorph.To = new NSValue (toPath.Handle);
            _shapeLayer.AddAnimation (pathMorph, null);
            
            var shadowPathMorph = CABasicAnimation.FromKeyPath ("shadowPath");
            shadowPathMorph.Duration = .15f;
            shadowPathMorph.FillMode = CAFillMode.Forwards;
            shadowPathMorph.RemovedOnCompletion = false;
            shadowPathMorph.To = new NSValue (toPath.Handle);
            
            _shapeLayer.AddAnimation (shadowPathMorph, null);
            toPath.Dispose ();
            
            var shapeAlphaAnimation = CABasicAnimation.FromKeyPath ("opacity");
            shapeAlphaAnimation.Duration = .1f;
            shapeAlphaAnimation.BeginTime = CABasicAnimation.CurrentMediaTime () + .1;
            shapeAlphaAnimation.To = new NSNumber (0);
            shapeAlphaAnimation.FillMode = CAFillMode.Forwards;
            shapeAlphaAnimation.RemovedOnCompletion = false;
            _shapeLayer.AddAnimation (shapeAlphaAnimation, null);
            
            var alphaAnimation = CABasicAnimation.FromKeyPath ("opacity");
            alphaAnimation.Duration = .1f;
            alphaAnimation.To = new NSNumber (0);
            alphaAnimation.FillMode = CAFillMode.Forwards;
            alphaAnimation.RemovedOnCompletion = false;
            
            _arrowLayer.AddAnimation (alphaAnimation, null);
            _highlightLayer.AddAnimation (alphaAnimation, null);
            
            CATransaction.Begin ();
            CATransaction.DisableActions = true;
            _activity.Layer.Transform = CATransform3D.MakeScale (.1f, .1f, 1);
            CATransaction.Commit ();
            
            UIView.Animate (.2f, .15f, UIViewAnimationOptions.CurveLinear, () => {
                _activity.Alpha = 1;
                _activity.Layer.Transform = CATransform3D.MakeScale (1, 1, 1);
            }, null);
            
            _refreshing = true;
            _canRefresh = false;
            
            SendActionForControlEvents (UIControlEvent.ValueChanged);
        }
        
        path.Dispose ();
    }
        public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
        {
            //base.ObserveValue(keyPath, ofObject, change, context);
            if (keyPath.ToString().ToLower() == "contentInset".ToLower())
            {
                if (!_ignoreInset)
                {
                    this.originalContentInset = (change["new"] as NSValue).UIEdgeInsetsValue;
                    this.Frame = new RectangleF(0, -1 * (kTotalViewHeight + this.scrollView.ContentInset.Top), this.scrollView.Frame.Size.Width, kTotalViewHeight);
                }
                return;
            }

            if (!this.Enabled || this._ignoreOffset)
                return;

            float offset = (change["new"] as NSValue).PointFValue.Y + this.originalContentInset.Top;

            if (_refreshing)
            {
                if (offset != 0)
                {
                    // keep thing pinned at the top
                    CATransaction.Begin();
                    CATransaction.SetValueForKey(NSNumber.FromBoolean(true), CATransaction.DisableActionsKey);
                    _shapeLayer.Position = new PointF(0, kMaxDistance + offset + kOpenedViewHeight);
                    CATransaction.Commit();

                    this.activity.Center = new PointF((float)Math.Floor(this.Frame.Size.Width / 2), (float)Math.Min(offset + this.Frame.Size.Height + Math.Floor(kOpenedViewHeight / 2), this.Frame.Size.Height - kOpenedViewHeight / 2));

                    _ignoreInset = true;
                    _ignoreOffset = true;

                    if (offset < 0)
                    {
                        // set the inset depending on the situation
                        if (offset >= kOpenedViewHeight * -1)
                        {
                            if (!this.scrollView.Dragging)
                            {
                                if (!_didSetInset)
                                {
                                    _didSetInset = true;
                                    _hasSectionHeaders = false;
                                    if (this.scrollView is UITableView)
                                    {
                                        for (int i = 0; i < (this.scrollView as UITableView).NumberOfSections(); ++i)
                                        {
                                            if ((this.scrollView as UITableView).RectForHeaderInSection(i).Size.Height != 0)
                                            {
                                                _hasSectionHeaders = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (_hasSectionHeaders)
                                    this.scrollView.ContentInset = new UIEdgeInsets(Math.Min(offset * -1, kOpenedViewHeight) + this.originalContentInset.Top, this.originalContentInset.Left, this.originalContentInset.Bottom, this.originalContentInset.Right);
                                else
                                    this.scrollView.ContentInset = new UIEdgeInsets(kOpenedViewHeight + this.originalContentInset.Top, this.originalContentInset.Left, this.originalContentInset.Bottom, this.originalContentInset.Right);
                            }
                            else if(_didSetInset && _hasSectionHeaders)
                            {
                                this.scrollView.ContentInset = new UIEdgeInsets(-1 * offset + this.originalContentInset.Top, this.originalContentInset.Left, this.originalContentInset.Bottom, this.originalContentInset.Right);
                            }
                        }
                    }
                    else if (_hasSectionHeaders)
                    {
                        this.scrollView.ContentInset = this.originalContentInset;
                    }
                    _ignoreInset = false;
                    _ignoreOffset = false;
                }
                return;
            }
            else
            {
                // check if we can trigger a new refresh and if we can draw the control
                bool dontDraw = false;  // line 230
                if (!_canRefresh)
                {
                    if (offset >= 0)
                    {
                        // we can refresh again after the control is scrolled out of view
                        _canRefresh = true;
                        _didSetInset = false;
                    }
                    else
                    {
                        dontDraw = true;
                    }
                }
                else
                {
                    if (offset >= 0)
                    {
                        // don't draw if the control is not visible
                        dontDraw = true;
                    }
                }
                if (offset > 0 && _lastOffset > offset  && !this.scrollView.Tracking)
                {
                    // if we are scrolling too fast, don't draw, and don't trigger unless the scrollView bounced back

                    // removed behavior Heath
                    //_canRefresh = false;
                    //dontDraw = true;
                }
                if (dontDraw)
                {
                    _shapeLayer.Path = null;
                    _shapeLayer.ShadowPath = new CGPath(IntPtr.Zero);
                    _arrowLayer.Path = null;
                    _highlightLayer.Path = null;
                    _lastOffset = offset;
                    return;
                }
            }

            _lastOffset = offset;  // line 260

            bool triggered = false;

            CGPath path = new CGPath();

            // calculate some useful points and values
            float verticalShift = (float)Math.Max(0, -1 * ((kMaxTopRadius + kMaxBottomRadius + kMaxTopPadding + kMaxBottomPadding) + offset));
            float distance = (float)Math.Min(kMaxDistance, (float)Math.Abs(verticalShift));
            float percentage = 1 - (distance / kMaxDistance);

            float currentTopPadding = lerp(kMinTopPadding, kMaxTopPadding, percentage);
            float currentTopRadius = lerp(kMinTopRadius, kMaxTopRadius, percentage);
            float currentBottomRadius = lerp(kMinBottomRadius, kMaxBottomRadius, percentage);
            float currentBottomPadding = lerp(kMinBottomPadding, kMaxBottomPadding, percentage);

            PointF bottomOrigin = new PointF((float)Math.Floor(this.Bounds.Size.Width / 2), this.Bounds.Size.Height - currentBottomPadding - currentBottomRadius);
            PointF topOrigin = PointF.Empty;
            if (distance == 0)
            {
                topOrigin = new PointF((float)Math.Floor(this.Bounds.Size.Width / 2), bottomOrigin.Y);
            }
            else
            {
                topOrigin = new PointF((float)Math.Floor(this.Bounds.Size.Width / 2), this.Bounds.Size.Height + offset + currentTopPadding + currentTopRadius);
                if (percentage == 0)
                {
                    bottomOrigin.Y -= (float)Math.Abs(verticalShift) - kMaxDistance;
                    triggered = true;
                }
            }

            // top semicircle
            path.AddArc(topOrigin.X, topOrigin.Y, currentTopRadius, 0, (float)Math.PI, true);

            // left curve
            PointF leftCp1 = new PointF(lerp((topOrigin.X - currentTopRadius), (bottomOrigin.X - currentBottomRadius), 0.1f), lerp(topOrigin.Y, bottomOrigin.Y, 0.2f));
            PointF leftCp2 = new PointF(lerp((topOrigin.X - currentTopRadius), (bottomOrigin.X - currentBottomRadius), 0.9f), lerp(topOrigin.Y, bottomOrigin.Y, 0.2f));
            PointF leftDestination = new PointF(bottomOrigin.X - currentBottomRadius, bottomOrigin.Y);

            path.AddCurveToPoint(leftCp1, leftCp2, leftDestination);

            // bottom semicircle
            path.AddArc(bottomOrigin.X, bottomOrigin.Y, currentBottomRadius, (float)Math.PI, 0, true);

            // right curve
            PointF rightCp2 = new PointF(lerp((topOrigin.X + currentTopRadius), (bottomOrigin.X + currentBottomRadius), 0.1f), lerp(topOrigin.Y, bottomOrigin.Y, 0.2f));
            PointF rightCp1 = new PointF(lerp((topOrigin.X + currentTopRadius), (bottomOrigin.X + currentBottomRadius), 0.9f), lerp(topOrigin.Y, bottomOrigin.Y, 0.2f));
            PointF rightDestination = new PointF(bottomOrigin.X + currentTopRadius, topOrigin.Y);

            path.AddCurveToPoint (rightCp1, rightCp2, rightDestination);
            path.CloseSubpath();

            if (!triggered) // line 309
            {
                // set paths
                _shapeLayer.Path = path;
                _shapeLayer.ShadowPath = path;

                // add the arrow shape
                float currentArrowSize = lerp(kMinArrowSize, kMaxArrowSize, percentage);
                float currentArrowRadius = lerp(kMinArrowRadius, kMaxArrowRadius, percentage);
                float arrowBigRadius = currentArrowRadius + (currentArrowSize / 2);
                float arrowSmallRadius = currentArrowRadius - (currentArrowSize / 2);
                CGPath arrowPath = new CGPath();
                /*
                arrowPath.AddArc(topOrigin.X, topOrigin.Y, arrowBigRadius, 0, 3 * (float)Math.PI, false);
                arrowPath.AddLineToPoint(topOrigin.X, topOrigin.Y - arrowBigRadius - currentArrowSize);
                arrowPath.AddLineToPoint(topOrigin.X + (2 * currentArrowSize), topOrigin.Y - arrowBigRadius + (currentArrowSize / 2));
                arrowPath.AddLineToPoint(topOrigin.X, topOrigin.Y - arrowBigRadius + (2 * currentArrowSize));
                arrowPath.AddLineToPoint(topOrigin.X, topOrigin.Y - arrowBigRadius + currentArrowSize);
                arrowPath.AddArc(topOrigin.X, topOrigin.Y, arrowSmallRadius, 3 * (float)Math.PI, 0, true);
                */
                arrowPath.AddArc (topOrigin.X, topOrigin.Y, arrowBigRadius, 0, 3 * (float) Math.PI / 2.0f, false);
                arrowPath.AddLineToPoint (topOrigin.X, topOrigin.Y - arrowBigRadius - currentArrowSize);
                arrowPath.AddLineToPoint (topOrigin.X + (2 * currentArrowSize), topOrigin.Y - arrowBigRadius + (currentArrowSize / 2.0f));
                arrowPath.AddLineToPoint (topOrigin.X, topOrigin.Y - arrowBigRadius + (2 * currentArrowSize));
                arrowPath.AddLineToPoint (topOrigin.X, topOrigin.Y - arrowBigRadius + currentArrowSize);
                arrowPath.AddArc (topOrigin.X, topOrigin.Y, arrowSmallRadius, 3 * (float) Math.PI / 2.0f, 0, true);

                arrowPath.CloseSubpath();
                _arrowLayer.Path = arrowPath;
                _arrowLayer.FillRule = CAShapeLayer.FillRuleEvenOdd;
                arrowPath.Dispose();

                // add the highlight shape
                CGPath highlightPath = new CGPath();
                highlightPath.AddArc(topOrigin.X, topOrigin.Y, currentTopRadius, 0, (float)Math.PI, true);
                highlightPath.AddArc(topOrigin.X, topOrigin.Y + 1.25f, currentTopRadius, (float)Math.PI, 0, false);

                _highlightLayer.Path = highlightPath;
                _highlightLayer.FillRule = CAShapeLayer.FillRuleNonZero;
                highlightPath.Dispose();
            }
            else
            {
                // start the shape disappearance animation
                float radius = lerp(kMinBottomRadius, kMaxBottomRadius, 0.2f);
                CABasicAnimation pathMorph = CABasicAnimation.FromKeyPath("path");
                pathMorph.Duration = 0.15f;
                pathMorph.FillMode = CAFillMode.Forwards;
                pathMorph.RemovedOnCompletion = false;

                CGPath toPath = new CGPath();
                toPath.AddArc(topOrigin.X, topOrigin.Y, radius, 0, (float)Math.PI, true);
                toPath.AddCurveToPoint(topOrigin.X - radius, topOrigin.Y, topOrigin.X - radius, topOrigin.Y, topOrigin.X - radius, topOrigin.Y);
                toPath.AddArc(topOrigin.X, topOrigin.Y, radius, (float)Math.PI, 0, true);
                toPath.AddCurveToPoint(topOrigin.X + radius, topOrigin.Y, topOrigin.X + radius, topOrigin.Y, topOrigin.X + radius, topOrigin.Y);
                toPath.CloseSubpath();

                pathMorph.To = new NSValue(toPath.Handle);
                _shapeLayer.AddAnimation(pathMorph, null);

                CABasicAnimation shadowPathMorph = CABasicAnimation.FromKeyPath("shadowPath");
                shadowPathMorph.Duration = 0.15f;
                shadowPathMorph.FillMode = CAFillMode.Forwards;
                shadowPathMorph.RemovedOnCompletion = false;
                shadowPathMorph.To = new NSValue(toPath.Handle);

                _shapeLayer.AddAnimation(shadowPathMorph, null);
                toPath.Dispose();

                CABasicAnimation shapeAlphaAnimation = CABasicAnimation.FromKeyPath("opacity");
                shapeAlphaAnimation.Duration = 0.1f;
                shapeAlphaAnimation.BeginTime = CAAnimation.CurrentMediaTime() + 0.1f;
                shapeAlphaAnimation.To = new NSNumber(0);
                shapeAlphaAnimation.FillMode = CAFillMode.Forwards;
                shapeAlphaAnimation.RemovedOnCompletion = false;
                _shapeLayer.AddAnimation(shapeAlphaAnimation, null);

                CABasicAnimation alphaAnimation = CABasicAnimation.FromKeyPath("opacity");
                alphaAnimation.Duration = 0.1f;
                alphaAnimation.To = new NSNumber (0);
                alphaAnimation.FillMode = CAFillMode.Forwards;
                alphaAnimation.RemovedOnCompletion = false;

                _arrowLayer.AddAnimation(alphaAnimation, null);
                _highlightLayer.AddAnimation(alphaAnimation, null);

                CATransaction.Begin();
                CATransaction.DisableActions = true;
                activity.Layer.Transform = CATransform3D.MakeScale(0.1f, 0.1f, 1f);
                CATransaction.Commit();

                UIView.Animate (0.2f, 0.15f, UIViewAnimationOptions.CurveLinear, () => {
                    activity.Alpha = 1;
                    activity.Layer.Transform = CATransform3D.MakeScale(1, 1, 1);
                }, null);

                _refreshing = true;
                _canRefresh = false;
                this.SendActionForControlEvents(UIControlEvent.ValueChanged);

                if (this.Action != null)
                    this.Action();
            }
            path.Dispose();
        }
예제 #60
0
        /// <summary>
        /// Helper method that creates the grid shown in the background of the scene.
        /// </summary>
        /// <returns>The background node.</returns>
        /// <param name="size">Size of the scene.</param>
        /// <param name="height">Height of the scene.</param>
        static SKNode CreateBackgroundNode(SizeF size)
        {
            // Use a SKShapeNode. This can display any arbitrary CG content.
            var shapeNode = new SKShapeNode ();
            var path = new CGPath();
            shapeNode.StrokeColor = UIColor.FromRGB (112, 80, 160);
            float cellSize = 32f;

            // Draw vertical lines.
            float x = 0f;
            do
            {
                path.MoveToPoint (x, 0);
                path.AddLineToPoint (x, size.Height);
                x += cellSize;
            } while(x < size.Width);

            // Draw horizontal lines.
            float y = 0f;
            do
            {
                path.MoveToPoint (0, y);
                path.AddLineToPoint (size.Width, y);
                y += cellSize;
            } while(y < size.Height);

            shapeNode.Path = path;

            return shapeNode;
        }