Beispiel #1
0
            public override void Draw(RectangleF rect)
            {
                base.Draw(rect);

                if (!IsSelected)
                {
                    return;
                }

                CGContext context = UIGraphics.GetCurrentContext();

                context.SaveState();
                context.SetFillColorWithColor(new UIColor(0, 0, 0, 0.5f).CGColor);
                context.BeginPath();

                // top border
                context.AddRect(new RectangleF(0, 0, Frame.Width, 4));

                // left border
                context.AddRect(new RectangleF(0, 0, 4, Frame.Height));

                // right border
                context.AddRect(new RectangleF(Frame.Width - 4, 0, 4, Frame.Height));

                // bottom border
                context.AddRect(new RectangleF(0, Frame.Height - 4, Frame.Width, 4));

                context.ClosePath();
                context.FillPath();

                context.RestoreState();
                context.SetBlendMode(MonoTouch.CoreGraphics.CGBlendMode.Clear);
            }
Beispiel #2
0
        private void DrawShopping(CGContext context)
        {
            LearnerTemplateStyle shoppingStyle = this.FormsShimmer.ShoppingStyle;
            float lineSpacing = (float)shoppingStyle.LineSpacing;
            float lineHeight  = (float)shoppingStyle.LineHeight;
            float num1        = shoppingStyle.Width >= 0.0 ? (float)shoppingStyle.Width : this.templateWidth;
            float num2        = (shoppingStyle.Height >= 0.0 ? (float)shoppingStyle.Height : this.templateHeight) / 2f;

            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY - (double)num2, (double)num1, (double)num2 * 2.0 - (double)lineHeight * 0.6 * 2.0 - (double)lineSpacing * 0.6 * 2.0 * 1.5));
            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY + (double)num2 - (double)lineHeight * 0.6 * 2.0 - (double)lineSpacing * 0.6, (double)num1, (double)lineHeight * 0.6));
            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY + (double)num2 - (double)lineHeight * 0.6, (double)num1, (double)lineHeight * 0.6));
        }
Beispiel #3
0
        private void DrawVideo(CGContext context)
        {
            LearnerTemplateStyle videoStyle = this.FormsShimmer.VideoStyle;
            float circleRadius = (float)videoStyle.CircleRadius;
            float lineSpacing  = (float)videoStyle.LineSpacing;
            float lineHeight   = (float)videoStyle.LineHeight;
            float width        = videoStyle.Width >= 0.0 ? (float)videoStyle.Width : this.templateWidth;
            float num1         = (videoStyle.Height >= 0.0 ? (float)videoStyle.Height : this.templateHeight) / 2f;
            float num2         = this.templateX + circleRadius * 2f + this.columnSpacing;

            context.AddRect(new CGRect(this.templateX, this.centerY - num1, width, (float)((double)num1 * 2.0 - (double)circleRadius * 2.0) - lineSpacing));
            context.AddEllipseInRect(new CGRect(this.templateX, (float)((double)this.centerY + (double)num1 - (double)circleRadius * 2.0), circleRadius * 2f, circleRadius * 2f));
            context.AddRect(new CGRect((double)num2, (double)this.centerY + (double)num1 - (double)circleRadius * 2.0 + (double)lineSpacing * 0.5, (double)width - (double)this.columnSpacing - (double)circleRadius * 2.0, (double)lineHeight));
            context.AddRect(new CGRect((double)num2, (double)this.centerY + (double)num1 - (double)circleRadius * 2.0 + (double)lineSpacing * 1.5 + (double)lineHeight, (double)width - (double)this.columnSpacing - (double)circleRadius * 2.0, (double)lineHeight));
        }
Beispiel #4
0
        private void DrawPersona(CGContext context)
        {
            LearnerTemplateStyle personaStyle = this.FormsShimmer.PersonaStyle;
            float circleRadius = (float)personaStyle.CircleRadius;
            float lineSpacing  = (float)personaStyle.LineSpacing;
            float lineHeight   = (float)personaStyle.LineHeight;
            float num1         = personaStyle.Width >= 0.0 ? (float)personaStyle.Width : this.templateWidth;
            float num2         = (personaStyle.Height >= 0.0 ? (float)personaStyle.Height : this.templateHeight) / 2f;
            float num3         = (double)num2 > 0.0 ? ((double)circleRadius <= (double)num2 ? circleRadius : num2) : circleRadius;
            float num4         = this.templateX + num3 * 2f + this.columnSpacing;

            context.AddEllipseInRect(new CGRect(this.templateX, this.centerY - num3, num3 * 2f, num3 * 2f));
            context.AddRect(new CGRect((double)num4, (double)this.centerY - (double)num3 + (double)lineSpacing, ((double)num1 - (double)this.columnSpacing - (double)num3 * 2.0) * 0.8, (double)lineHeight));
            context.AddRect(new CGRect((double)num4, (double)this.centerY - (double)num3 + (double)lineSpacing + (double)lineHeight + (double)lineSpacing, ((double)num1 - (double)this.columnSpacing - (double)num3 * 2.0) * 0.5, (double)lineHeight));
        }
        public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect)
        {
            var       cb  = (CGContextBackend)backend;
            CGContext ctx = cb.Context;

            // Add the styles that have been globaly set to the context
            img.Styles = img.Styles.AddRange(cb.Styles);

            ctx.SaveState();
            ctx.SetAlpha((float)img.Alpha);

            double rx = destRect.Width / srcRect.Width;
            double ry = destRect.Height / srcRect.Height;

            ctx.AddRect(new CGRect((nfloat)destRect.X, (nfloat)destRect.Y, (nfloat)destRect.Width, (nfloat)destRect.Height));
            ctx.Clip();
            ctx.TranslateCTM((float)(destRect.X - (srcRect.X * rx)), (float)(destRect.Y - (srcRect.Y * ry)));
            ctx.ScaleCTM((float)rx, (float)ry);

            NSImage image = (NSImage)img.Backend;

            if (image is CustomImage)
            {
                ((CustomImage)image).DrawInContext((CGContextBackend)backend, img);
            }
            else
            {
                var size = new CGSize((nfloat)img.Size.Width, (nfloat)img.Size.Height);
                var rr   = new CGRect(0, 0, size.Width, size.Height);
                ctx.ScaleCTM(1f, -1f);
                ctx.DrawImage(new CGRect(0, -size.Height, size.Width, size.Height), image.AsCGImage(ref rr, NSGraphicsContext.CurrentContext, null));
            }

            ctx.RestoreState();
        }
Beispiel #6
0
        private void DrawArticle(CGContext context)
        {
            LearnerTemplateStyle articleStyle = this.FormsShimmer.ArticleStyle;
            float lineSpacing = (float)articleStyle.LineSpacing;
            float lineHeight  = (float)articleStyle.LineHeight;
            float squareSize  = (float)articleStyle.SquareSize;
            float num1        = articleStyle.Width >= 0.0 ? (float)articleStyle.Width : this.templateWidth;
            float num2        = (articleStyle.Height >= 0.0 ? (float)articleStyle.Height : this.templateHeight) / 2f;
            float x           = this.templateX + squareSize + this.columnSpacing;

            context.AddRect(new CGRect(this.templateX, this.centerY - num2, squareSize, num2 * 2f));
            context.AddRect(new CGRect(x, this.centerY - num2, num1 - this.columnSpacing - squareSize, lineHeight));
            context.AddRect(new CGRect((double)x, (double)this.centerY - (double)num2 + (double)lineHeight + (double)lineSpacing, ((double)num1 - (double)this.columnSpacing - (double)squareSize) * 0.8, (double)lineHeight));
            context.AddRect(new CGRect((double)x, (double)this.centerY + (double)lineSpacing, ((double)num1 - (double)this.columnSpacing - (double)squareSize) * 0.4, (double)lineHeight));
            context.AddRect(new CGRect((double)x, (double)this.centerY + (double)lineHeight + (double)lineSpacing * 2.0, ((double)num1 - (double)this.columnSpacing - (double)squareSize) * 0.3, (double)lineHeight));
        }
Beispiel #7
0
        protected virtual void HandleShapeDraw(CGContext currentContext, RectangleF rect)
        {
            // Only used for circles
            var centerX    = rect.X + (rect.Width / 2);
            var centerY    = rect.Y + (rect.Height / 2);
            var radius     = rect.Width / 2;
            var startAngle = 0;
            var endAngle   = (float)(Math.PI * 2);

            switch (Element.ShapeType)
            {
            case ShapeType.Box:
                HandleStandardDraw(currentContext, rect, () => {
                    if (Element.CornerRadius > 0)
                    {
                        var path = UIBezierPath.FromRoundedRect(rect, Element.CornerRadius);
                        currentContext.AddPath(path.CGPath);
                    }
                    else
                    {
                        currentContext.AddRect(rect);
                    }
                });
                break;

            case ShapeType.Circle:
                HandleStandardDraw(currentContext, rect, () => currentContext.AddArc(centerX, centerY, radius, startAngle, endAngle, true));
                break;

            case ShapeType.CircleIndicator:
                HandleStandardDraw(currentContext, rect, () => currentContext.AddArc(centerX, centerY, radius, startAngle, endAngle, true));
                HandleStandardDraw(currentContext, rect, () => currentContext.AddArc(centerX, centerY, radius, QuarterTurnCounterClockwise, (float)(Math.PI * 2 * (Element.IndicatorPercentage / 100)) + QuarterTurnCounterClockwise, false), Element.StrokeWidth + 3);
                break;
            }
        }
Beispiel #8
0
        public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect)
        {
            CGContext ctx   = ((CGContextBackend)backend).Context;
            NSImage   image = img.ToNSImage();

            ctx.SaveState();
            ctx.SetAlpha((float)img.Alpha);

            double rx = destRect.Width / srcRect.Width;
            double ry = destRect.Height / srcRect.Height;

            ctx.AddRect(new RectangleF((float)destRect.X, (float)destRect.Y, (float)destRect.Width, (float)destRect.Height));
            ctx.Clip();
            ctx.TranslateCTM((float)(destRect.X - (srcRect.X * rx)), (float)(destRect.Y - (srcRect.Y * ry)));
            ctx.ScaleCTM((float)rx, (float)ry);

            if (image is CustomImage)
            {
                ((CustomImage)image).DrawInContext((CGContextBackend)backend);
            }
            else
            {
                RectangleF rr = new RectangleF(0, 0, (float)image.Size.Width, image.Size.Height);
                ctx.ScaleCTM(1f, -1f);
                ctx.DrawImage(new RectangleF(0, -image.Size.Height, image.Size.Width, image.Size.Height), image.AsCGImage(ref rr, NSGraphicsContext.CurrentContext, null));
            }

            ctx.RestoreState();
        }
Beispiel #9
0
        private void DrawProfile(CGContext context)
        {
            LearnerTemplateStyle profileStyle = this.FormsShimmer.ProfileStyle;
            float  circleRadius = (float)profileStyle.CircleRadius;
            float  lineSpacing  = (float)profileStyle.LineSpacing;
            float  lineHeight   = (float)profileStyle.LineHeight;
            float  width        = profileStyle.Width >= 0.0 ? (float)profileStyle.Width : this.templateWidth;
            float  num1         = (profileStyle.Height >= 0.0 ? (float)profileStyle.Height : this.templateHeight) / 2f;
            double num2         = (double)width / 2.0;
            float  num3         = width / 2f;

            context.AddEllipseInRect(new CGRect(this.templateX + num3 - circleRadius, this.centerY - num1, circleRadius * 2f, circleRadius * 2f));
            context.AddRect(new CGRect((double)this.templateX + (double)num3 - (double)width * 0.2, (double)this.centerY + (double)lineSpacing, (double)width * 0.2 * 2.0, (double)lineHeight * 2.0));
            context.AddRect(new CGRect((double)this.templateX + (double)num3 - (double)width * 0.3, (double)this.centerY + (double)lineSpacing * 2.0 + (double)lineHeight * 2.0, (double)width * 0.3 * 2.0, (double)lineHeight * 2.0));
            context.AddRect(new CGRect(this.templateX, (float)((double)this.centerY + (double)num1 - (double)lineHeight * 2.0) - lineSpacing, width, lineHeight));
            context.AddRect(new CGRect(this.templateX, this.centerY + num1 - lineHeight, width, lineHeight));
        }
Beispiel #10
0
        private void DrawFeed(CGContext context)
        {
            LearnerTemplateStyle feedStyle = this.FormsShimmer.FeedStyle;
            float circleRadius             = (float)feedStyle.CircleRadius;
            float lineSpacing = (float)feedStyle.LineSpacing;
            float lineHeight  = (float)feedStyle.LineHeight;
            float num1        = feedStyle.Width >= 0.0 ? (float)feedStyle.Width : this.templateWidth;
            float num2        = (feedStyle.Height >= 0.0 ? (float)feedStyle.Height : this.templateHeight) / 2f;
            float num3        = this.templateX + circleRadius * 2f + this.columnSpacing;

            context.AddEllipseInRect(new CGRect(this.templateX, this.centerY - num2, circleRadius * 2f, circleRadius * 2f));
            context.AddRect(new CGRect((double)num3, (double)this.centerY - (double)num2 + (double)lineSpacing * 0.5, (double)num1 - (double)this.columnSpacing - (double)circleRadius * 2.0, (double)lineHeight));
            context.AddRect(new CGRect((double)num3, (double)this.centerY - (double)num2 + (double)lineSpacing * 1.5 + (double)lineHeight, ((double)num1 - (double)this.columnSpacing - (double)circleRadius * 2.0) * 0.5, (double)lineHeight));
            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY - (double)num2 + (double)circleRadius * 2.0 + (double)lineSpacing, (double)num1, (double)num2 * 2.0 - (double)lineHeight * 0.6 * 2.0 - (double)lineSpacing * 0.6 * 2.0 * 1.5 - (double)circleRadius * 2.0 - (double)lineSpacing));
            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY + (double)num2 - (double)lineHeight * 0.6 * 2.0 - (double)lineSpacing * 0.6, (double)num1, (double)lineHeight * 0.6));
            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY + (double)num2 - (double)lineHeight * 0.6, (double)num1, (double)lineHeight * 0.6));
        }
Beispiel #11
0
        //绘图
        private void DrawWave(CGRect rect)
        {
            //获取图片控件大小
            int width = (int)rect.Width;
            int height = (int)rect.Height;

            System.Diagnostics.Debug.Print($"{DateTime.Now}, DrawWave: width={width}, height={height}");

            MaxHeight = height;

            CGContext context = UIGraphics.GetCurrentContext();

            if (BioBuf.Length > 0)
            {
                //创建画笔
                context.SetLineWidth(1);//画笔线宽
                context.SetStrokeColor(UIColor.Blue.CGColor);//画笔颜色

                //画曲线
                int x = 0;
                int y1 = 0;
                int y2 = 0;
                context.MoveTo(x, y1);//起点

                for (int i = 0; i < BioBuf.Length; i++)
                {
                    x = i;
                    y1 = y2;
                    y2 = WaveHeight(BioBuf[i]);

                    context.AddLineToPoint(x + 1, y2);//终点
                }

                context.StrokePath();//画线

                //画基线
                if (BioBaselien > 0)
                {
                    //创建画笔
                    context.SetStrokeColor(UIColor.Red.CGColor);//画笔颜色

                    y2 = WaveHeight(BioBaselien);
                    context.MoveTo(0, y2);//起点
                    context.AddLineToPoint(BioBuf.Length, y2);//终点

                    context.StrokePath();//画线}
                }
            }

            //创建画笔
            context.SetStrokeColor(UIColor.Gray.CGColor);//画笔颜色

            //画边界
            context.AddRect(new CGRect(0, 0, width, height));
            context.StrokePath();//画线

            System.Diagnostics.Debug.Print($"{DateTime.Now}, DrawWave");
        }
        private void DrawAudioMixTracks(CGRect bannerRect, CGRect rowRect, ref float runningTop)
        {
            bannerRect.Y = runningTop;
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetFillColor(1.00f, 1.00f, 1.00f, 1.00f);              // white

            NSString compositionTitle = new NSString("AVAudioMix");

            compositionTitle.DrawString(bannerRect, UIFont.PreferredCaption1);
            runningTop += (float)bannerRect.Height;

            foreach (List <CGPoint> mixTrack in audioMixTracks)
            {
                rowRect.Y = runningTop;

                CGRect rampRect = rowRect;
                rampRect.Width = (float)duration.Seconds * scaledDurationToWidth;
                rampRect       = rampRect.Inset(3f, 3f);

                context.SetFillColor(0.55f, 0.02f, 0.02f, 1.00f);                  // darker red
                context.SetStrokeColor(0.87f, 0.10f, 0.10f, 1.00f);                // brighter red
                context.SetLineWidth(2f);
                context.AddRect(rampRect);
                context.DrawPath(CGPathDrawingMode.FillStroke);

                context.BeginPath();
                context.SetStrokeColor(0.95f, 0.68f, 0.09f, 1.00f);                  // yellow
                context.SetLineWidth(3f);
                bool firstPoint = true;

                foreach (CGPoint pointValue in mixTrack)
                {
                    CGPoint timeVolumePoint = pointValue;
                    CGPoint pointInRow      = new CGPoint();

                    pointInRow.X = rampRect.X + timeVolumePoint.X * scaledDurationToWidth;
                    pointInRow.Y = rampRect.Y + (0.9f - 0.8f * timeVolumePoint.Y) * rampRect.Height;

                    pointInRow.X = (float)Math.Max(pointInRow.X, rampRect.GetMinX());
                    pointInRow.X = (float)Math.Min(pointInRow.X, rampRect.GetMaxX());

                    if (firstPoint)
                    {
                        context.MoveTo(pointInRow.X, pointInRow.Y);
                        firstPoint = false;
                    }
                    else
                    {
                        context.AddLineToPoint(pointInRow.X, pointInRow.Y);
                    }
                }
                context.StrokePath();
                runningTop += (float)rowRect.Height;
            }

            runningTop += GapAfterRows;
        }
        //
        // Helper function to generate shadow
        //
        private void GenerateShapeShadow(CGContext context, UIBezierPath shapeObject, nfloat xOffset, nfloat yOffset, nfloat blurValue, CGBlendMode blendingMode, UIColor shadowColor, nfloat borderWidth, int borderPosition, nfloat iWidth, nfloat iHeight)
        {
            CGPoint basePoint;
            CGPoint offsetPoint;
            CGSize  calculatedShadowOffset;
            nfloat  calculatedShadowBlur;
            CGPoint constPointZero;

            constPointZero = new CGPoint(0, 0);

            basePoint              = baseTransform.TransformPoint(context.PointToDeviceSpace(constPointZero));
            offsetPoint            = baseTransform.TransformPoint(context.PointToDeviceSpace(new CGPoint(xOffset, yOffset)));
            calculatedShadowOffset = new CGSize(offsetPoint.X - basePoint.X, offsetPoint.Y - basePoint.Y);
            if (blurValue == 0)
            {
                calculatedShadowBlur = 0;
            }
            else
            {
                calculatedShadowBlur = Hypot(calculatedShadowOffset.Width, calculatedShadowOffset.Height) / blurValue;
            }
            context.SetShadow(calculatedShadowOffset, calculatedShadowBlur, shadowColor.CGColor);
            context.SetBlendMode(blendingMode);

            context.BeginTransparencyLayer(null);

            UIColor.Black.SetFill();
            shapeObject.Fill();

            if (borderWidth > 0)
            {
                if (borderPosition == 0)
                {
                    context.SaveState();
                    shapeObject.LineWidth = borderWidth;
                    UIColor.Black.SetStroke();
                    shapeObject.Stroke();
                    context.RestoreState();
                }

                if (borderPosition == 1)
                {
                    context.BeginPath();
                    context.AddPath(shapeObject.CGPath);
                    context.EOClip();
                }

                if (borderPosition == 2)
                {
                    context.BeginPath();
                    context.AddPath(shapeObject.CGPath);
                    context.AddRect(RectangleFExtensions.Inset(shapeObject.Bounds, iWidth, iHeight));
                    context.EOClip();
                }
            }

            context.EndTransparencyLayer();
        }
Beispiel #14
0
 public static void FillRect(CGContext context, RectangleF rect, CGColor color)
 {
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     context.SetFillColor(color);
     context.FillRect(rect);
     context.RestoreState();
 }
    public override void DrawInContext(CGContext context)
    {
        // Drawing with a white stroke color
        context.SetRGBStrokeColor(1, 1, 1, 1);
        // And drawing with a blue fill color
        context.SetRGBFillColor(0, 0, 1, 1);
        // Draw them with a 2 stroke width so they are a bit more visible.
        context.SetLineWidth(2);

        // Add Rect to the current path, then stroke it
        context.AddRect(new RectangleF(30, 30, 60, 60));
        context.StrokePath();

        // Stroke Rect convenience that is equivalent to above
        context.StrokeRect(new RectangleF(30, 120, 60, 60));

        // Stroke rect convenience equivalent to the above, plus a call to context.SetLineWidth ().
        context.StrokeRectWithWidth(new RectangleF(30, 210, 60, 60), 10);
        // Demonstate the stroke is on both sides of the path.
        context.SaveState();
        context.SetRGBStrokeColor(1, 0, 0, 1);
        context.StrokeRectWithWidth(new RectangleF(30, 210, 60, 60), 2);
        context.RestoreState();

        var rects = new RectangleF []
        {
            new RectangleF(120, 30, 60, 60),
            new RectangleF(120, 120, 60, 60),
            new RectangleF(120, 210, 60, 60),
        };

        // Bulk call to add rects to the current path.
        context.AddRects(rects);
        context.StrokePath();

        // Create filled rectangles via two different paths.
        // Add/Fill path
        context.AddRect(new RectangleF(210, 30, 60, 60));
        context.FillPath();
        // Fill convienience.
        context.FillRect(new RectangleF(210, 120, 60, 60));
    }
Beispiel #16
0
        /// <summary> 连线绘制图案(以设定颜色绘制)  将选中的圆形以color颜色链接起来
        /// </summary>
        /// <param name="rect">图形上下文</param>
        /// <param name="color">连线颜色</param>
        public void ConnectCirclesInRect(CGRect rect, UIColor color)
        {
            //获取上下文
            CGContext ctx = UIGraphics.GetCurrentContext();

            // 添加路径
            ctx.AddRect(rect);
            //是否剪裁
            ClipSubviewsWhenConnectInContext(ctx, Clip);
            //剪裁上下文
            ctx.EOClip();
            // 遍历数组中的circle
            for (int index = 0; index < CircleSet.Count; index++)
            {
                // 取出选中按钮
                PCCircle circle = CircleSet[index];
                // 起点按钮
                if (index == 0)
                {
                    ctx.MoveTo(circle.Center.X, circle.Center.Y);
                }
                else
                {
                    // 全部是连线
                    ctx.AddLineToPoint(circle.Center.X, circle.Center.Y);
                }
            }

            // 连接最后一个按钮到手指当前触摸得点
            if (!CurrentPoint.Equals(new CGPoint(0, 0)))
            {
                foreach (var item in Subviews)
                {
                    if (GetCircleState() == CircleState.CircleStateError || GetCircleState() == CircleState.CircleStateLastOneError)
                    {
                        // 如果是错误的状态下不连接到当前点
                    }
                    else
                    {
                        ctx.AddLineToPoint(CurrentPoint.X, CurrentPoint.Y);
                    }
                }
            }

            //线条转角样式
            ctx.SetLineCap(CGLineCap.Round);
            ctx.SetLineJoin(CGLineJoin.Round);
            // 设置绘图的属性
            ctx.SetLineWidth(PCCircleViewConst.CircleConnectLineWidth);
            // 线条颜色
            color.SetColor();
            //渲染路径
            ctx.StrokePath();
        }
        private void DrawCompositionTracks(CGRect bannerRect, CGRect rowRect, ref float runningTop)
        {
            bannerRect.Y = runningTop;
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetFillColor(1.00f, 1.00f, 1.00f, 1.00f);
            NSString compositionTitle = new NSString("AVComposition");

            compositionTitle.DrawString(bannerRect, UIFont.PreferredCaption1);

            runningTop += (float)bannerRect.Height;

            foreach (List <APLCompositionTrackSegmentInfo> track in compositionTracks)
            {
                rowRect.Y = runningTop;
                CGRect segmentRect = rowRect;
                foreach (APLCompositionTrackSegmentInfo segment in track)
                {
                    segmentRect.Width = (float)segment.TimeRange.Duration.Seconds * scaledDurationToWidth;

                    if (segment.Empty)
                    {
                        context.SetFillColor(0.00f, 0.00f, 0.00f, 1.00f);
                        DrawVerticallyCenteredInRect("empty", segmentRect);
                    }
                    else
                    {
                        if (segment.MediaType == AVMediaType.Video)
                        {
                            context.SetFillColor(0.00f, 0.36f, 0.36f, 1.00f);                              // blue-green
                            context.SetStrokeColor(0.00f, 0.50f, 0.50f, 1.00f);                            // brigher blue-green
                        }
                        else
                        {
                            context.SetFillColor(0.00f, 0.24f, 0.36f, 1.00f);                              // bluer-green
                            context.SetStrokeColor(0.00f, 0.33f, 0.60f, 1.00f);                            // brigher bluer-green
                        }

                        context.SetLineWidth(2f);
                        segmentRect = segmentRect.Inset(3f, 3f);
                        context.AddRect(segmentRect);
                        context.DrawPath(CGPathDrawingMode.FillStroke);

                        context.SetFillColor(0.00f, 0.00f, 0.00f, 1.00f);                          // white
                        DrawVerticallyCenteredInRect(segment.Description, segmentRect);
                    }

                    segmentRect.X += segmentRect.Width;
                }

                runningTop += (float)rowRect.Height;
            }
            runningTop += GapAfterRows;
        }
	public override void DrawInContext (CGContext context)
	{
		// Drawing with a white stroke color
		context.SetRGBStrokeColor (1, 1, 1, 1);
		// And drawing with a blue fill color
		context.SetRGBFillColor (0, 0, 1, 1);
		// Draw them with a 2 stroke width so they are a bit more visible.
		context.SetLineWidth (2);
		
		// Add Rect to the current path, then stroke it
		context.AddRect (new RectangleF (30, 30, 60, 60));
		context.StrokePath ();
		
		// Stroke Rect convenience that is equivalent to above
		context.StrokeRect (new RectangleF (30, 120, 60, 60));
		
		// Stroke rect convenience equivalent to the above, plus a call to context.SetLineWidth ().
		context.StrokeRectWithWidth (new RectangleF (30, 210, 60, 60), 10);
		// Demonstate the stroke is on both sides of the path.
		context.SaveState ();
		context.SetRGBStrokeColor (1, 0, 0, 1);
		context.StrokeRectWithWidth (new RectangleF (30, 210, 60, 60), 2);
		context.RestoreState ();
		
		var rects = new RectangleF []
		{
			new RectangleF (120, 30, 60, 60),
			new RectangleF (120, 120, 60, 60),
			new RectangleF (120, 210, 60, 60),
		};
		// Bulk call to add rects to the current path.
		context.AddRects (rects);
		context.StrokePath ();
		
		// Create filled rectangles via two different paths.
		// Add/Fill path
		context.AddRect (new RectangleF (210, 30, 60, 60));
		context.FillPath ();
		// Fill convienience.
		context.FillRect (new RectangleF (210, 120, 60, 60));
	}	
Beispiel #19
0
 public void FillRect(float x, float y, float width, float height)
 {
     if (_g != null)
     {
         _c.AddRect(new NativeRect(x, y, width, height));
         FillPath();
     }
     else
     {
         _c.FillRect(new NativeRect(x, y, width, height));
     }
 }
        public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            DrawElement(() => {
                context.AddRect(Conversions.GetCGRect(frame));
                return(frame);
            }, pen, brush);
        }
Beispiel #21
0
        public static UIImage ScaleToSize(UIImage image, int width, int height)
        {
            UIGraphics.BeginImageContext(new SizeF(width, height));
            CGContext ctx   = UIGraphics.GetCurrentContext();
            float     ratio = (float)width / (float)height;

            ctx.AddRect(new RectangleF(0.0f, 0.0f, width, height));
            ctx.Clip();

            var   cg = image.CGImage;
            float h  = cg.Height;
            float w  = cg.Width;
            float ar = w / h;

            if (ar != ratio)
            {
                // Image's aspect ratio is wrong so we'll need to crop
                float  scaleY = height / h;
                float  scaleX = width / w;
                PointF offset;
                SizeF  crop;
                float  size;

                if (scaleX >= scaleY)
                {
                    size   = h * (w / width);
                    offset = new PointF(0.0f, h / 2.0f - size / 2.0f);
                    crop   = new SizeF(w, size);
                }
                else
                {
                    size   = w * (h / height);
                    offset = new PointF(w / 2.0f - size / 2.0f, 0.0f);
                    crop   = new SizeF(size, h);
                }

                ctx.ScaleCTM(1.0f, -1.0f);
                using (var copy = cg.WithImageInRect(new RectangleF(offset, crop))) {
                    ctx.DrawImage(new RectangleF(0.0f, 0.0f, width, -height), copy);
                }
            }
            else
            {
                image.Draw(new RectangleF(0.0f, 0.0f, width, height));
            }

            UIImage scaled = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(scaled);
        }
Beispiel #22
0
        public override void DrawInteriorWithFrame(CGRect cellFrame, NSView inView)
        {
            CGContext ctx = NSGraphicsContext.CurrentContext.GraphicsPort;

            ctx.SaveState();
            ctx.AddRect(cellFrame);
            ctx.Clip();
            foreach (CellPos cp in GetCells(cellFrame))
            {
                cp.Cell.DrawInteriorWithFrame(cp.Frame, inView);
            }
            ctx.RestoreState();
        }
Beispiel #23
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            CGContext context = UIGraphics.GetCurrentContext();

            context.SaveState();
            context.SetFillColor(UIColor.Black.CGColor);
            context.SetLineWidth(1);
            context.SetFillColor(UIColor.Clear.CGColor);
            context.AddRect(this.Frame.Subtract(1, 1, 1, 1));
            context.RestoreState();
        }
Beispiel #24
0
 public override void DrawInteriorWithFrame(System.Drawing.RectangleF cellFrame, NSView inView)
 {
     if (DrawsBackground)
     {
         CGContext ctx = NSGraphicsContext.CurrentContext.GraphicsPort;
         ctx.AddRect(cellFrame);
         ctx.SetFillColorSpace(Util.DeviceRGBColorSpace);
         ctx.SetStrokeColorSpace(Util.DeviceRGBColorSpace);
         ctx.SetFillColor(bgColor);
         ctx.DrawPath(CGPathDrawingMode.Fill);
     }
     base.DrawInteriorWithFrame(TitleRectForBounds(cellFrame), inView);
 }
Beispiel #25
0
        private void _chart_OnDrawBar(object sender, Charting.Controls.Chart.DrawEventArgs <Events.DoubleDrawingData> e)
        {
            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                g.SetLineWidth(1);
                Colors[e.Data.SeriesNo].SetFill();
                Colors[e.Data.SeriesNo].SetStroke();

                RectangleF rect = new RectangleF((float)e.Data.XFrom, (float)e.Data.YFrom, (float)(e.Data.XTo - e.Data.XFrom), (float)(e.Data.YTo - e.Data.YFrom));
                g.AddRect(rect);

                g.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Beispiel #26
0
        protected virtual void DrawBox(CGContext context, float x, float y, float width, float height, float cornerRadius, bool fill, bool stroke)
        {
            var rect = new RectangleF(x, y, width, height);

            if (cornerRadius > 0)
            {
                context.AddPath(UIBezierPath.FromRoundedRect(rect, cornerRadius).CGPath);
            }
            else
            {
                context.AddRect(rect);
            }

            this.DrawPath(context, fill, stroke);
        }
Beispiel #27
0
            public override void Draw(CGRect rect)
            {
                base.Draw(rect);

                using (CGContext context = UIGraphics.GetCurrentContext())
                {
                    context.AddRect(new CGRect(0, 0, Frame.Width, 1));
                    context.Clip();

                    UIColor color = Rock.Mobile.UI.Util.GetUIColor(0x777777FF);

                    // probably should change this to not being a gradient
                    CGGradient gradiant = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor[] { color.CGColor, color.CGColor });
                    context.DrawLinearGradient(gradiant, new CGPoint(0, 0), new CGPoint(Frame.Width, 0), CGGradientDrawingOptions.DrawsBeforeStartLocation);
                }
            }
Beispiel #28
0
        public void DrawRectangle(Rect frame, Size corner, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            DrawElement(() => {
                if (corner.Width > 0 || corner.Height > 0)
                {
                    AddRoundedRect(Conversions.GetCGRect(frame), Conversions.GetCGSize(corner));
                }
                else
                {
                    context.AddRect(Conversions.GetCGRect(frame));
                }
                return(frame);
            }, pen, brush);
        }
Beispiel #29
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            if (!showQR)
            {
                return;
            }
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(String.Format("{0},{1}", cost, userId), QRGenerator.ECCLevel.M);

            //get graphics context
            UIGraphics.BeginImageContext(new CGSize(300, 300));
            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                var drawQuietZones  = true;
                var pixelsPerModule = 10;
                var size            = (qrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 8)) * pixelsPerModule;
                var offset          = drawQuietZones ? 0 : 4 * pixelsPerModule;
                UIColor.Black.SetFill();
                for (var x = 0; x < size + offset; x = x + pixelsPerModule)
                {
                    for (var y = 0; y < size + offset; y = y + pixelsPerModule)
                    {
                        var module = qrCodeData.ModuleMatrix[(y + pixelsPerModule) / pixelsPerModule - 1][(x + pixelsPerModule) / pixelsPerModule - 1];
                        if (module)
                        {
                            g.AddRect(new CGRect(x - offset, y - offset, pixelsPerModule, pixelsPerModule));
                        }
                    }
                }
                g.DrawPath(CGPathDrawingMode.Fill);
                g.SaveState();
                qrImage    = UIGraphics.GetImageFromCurrentImageContext();
                qrPainted  = true;
                view.Image = qrImage;
            }
            UIGraphics.EndImageContext();
            Console.WriteLine("qrImage");
            Console.WriteLine(qrImage);
        }
Beispiel #30
0
 private void DrawCustomView(CGContext context)
 {
     if (this.FormsShimmer == null || this.FormsShimmer.CustomView == null)
     {
         return;
     }
     context.SetStrokeColor(UIColor.Clear.CGColor);
     context.SetFillColor(this.FormsShimmer.Color.ToCGColor());
     foreach (ShimmerViewRenderer shimmerViewRenderer in this.GetShimmerViewRenderers(Xamarin.Forms.Platform.iOS.Platform.GetRenderer((VisualElement)this.FormsShimmer.CustomView) as UIView))
     {
         if (shimmerViewRenderer.Element == null || !(shimmerViewRenderer.Element is ShimmerView element))
         {
             return;
         }
         nfloat nfloat1 = (nfloat)element.CornerRadius;
         (double x2, double y2) = this.GetPosition((VisualElement)element);
         CGRect frame = shimmerViewRenderer.Frame;
         CGRect rect  = new CGRect(x2, y2, (double)frame.Width, (double)frame.Height);
         if (nfloat1 > (nfloat)0)
         {
             if (this.roundedPath == (CGPath)null)
             {
                 this.roundedPath = new CGPath();
             }
             nfloat nfloat2 = (nfloat)Math.Min((double)(frame.Width / (nfloat)2), (double)(frame.Height / (nfloat)2));
             if (nfloat1 > nfloat2)
             {
                 nfloat1 = nfloat2;
             }
             this.roundedPath.AddRoundedRect(rect, nfloat1, nfloat1);
             context.AddPath(this.roundedPath);
         }
         else
         {
             context.AddRect(rect);
         }
     }
     context.DrawPath(CGPathDrawingMode.FillStroke);
 }
Beispiel #31
0
        public override void DrawInteriorWithFrame(CGRect cellFrame, NSView inView)
        {
            // FIXME: although ObjectValue seems to be set and Fill called correctly,
            //        the table flickers without an additional Fill call, especially
            //        on expansion/collapsing with partially hidden cells (row wise).
            //        Cocoa seems to be resetting some NSCell bits, which may be
            //        related to the deprecated NSCell mode.
            if (tablePosition != null)
            {
                Fill();
            }
            CGContext ctx = NSGraphicsContext.CurrentContext.GraphicsPort;

            ctx.SaveState();
            ctx.AddRect(cellFrame);
            ctx.Clip();
            foreach (CellPos cp in GetCells(cellFrame))
            {
                cp.Cell.DrawInteriorWithFrame(cp.Frame, inView);
            }
            ctx.RestoreState();
        }
Beispiel #32
0
        public static void AddRoundedRectToPath(CGContext context, RectangleF rect, float ovalWidth, float ovalHeight)
        {
            float fw, fh;

            if (ovalWidth == 0 || ovalHeight == 0)
            {
                context.AddRect(rect);
                return;
            }
            context.SaveState();
            context.TranslateCTM(rect.GetMinX(), rect.GetMinY());
            context.ScaleCTM(ovalWidth, ovalHeight);
            fw = rect.Width / ovalWidth;
            fh = rect.Height / ovalHeight;
            context.MoveTo(fw, fh / 2);
            context.AddArcToPoint(fw, fh, fw / 2, fh, 1);
            context.AddArcToPoint(0, fh, 0, fh / 2, 1);
            context.AddArcToPoint(0, 0, fw / 2, 0, 1);
            context.AddArcToPoint(fw, 0, fw, fh / 2, 1);
            context.ClosePath();
            context.RestoreState();
        }
        private void DrawBackground(CGContext context)
        {
            context.SetFillDialogBorderColor();
            context.AddRect(
                new RectangleF(Frame.X - Border,
                               Frame.Y - Border,
                               Frame.Width + 2 * Border,
                               Frame.Height + 2 * Border));

            context.DrawPath(CGPathDrawingMode.Fill);

            context.SetFillDialogBackgroungColor();
            context.AddRect(Frame);
            context.DrawPath(CGPathDrawingMode.Fill);
        }
Beispiel #34
0
 public static void FillGradient(CGContext context, RectangleF rect, CGColor color1, CGColor color2)
 {
     CGGradient gradientBackground;
     CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
     
     float[] locationListBackground = new float[] { 1.0f, 0.0f };
     List<float> colorListBackground = new List<float>();
     colorListBackground.AddRange(color1.Components);
     colorListBackground.AddRange(color2.Components);
     gradientBackground = new CGGradient(colorSpace, colorListBackground.ToArray(), locationListBackground);
     
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     //context.ScaleCTM(1, -1);
     context.DrawLinearGradient(gradientBackground, new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     context.RestoreState();
 }       
Beispiel #35
0
		public static void AddRoundedRectToPath(CGContext context, RectangleF rect, float ovalWidth, float ovalHeight)
		{
			float fw, fh;
			if (ovalWidth == 0 || ovalHeight == 0)
			{
				context.AddRect(rect);
				return;
			}
			context.SaveState();
			context.TranslateCTM(rect.GetMinX(), rect.GetMinY());
			context.ScaleCTM(ovalWidth, ovalHeight);
			fw = rect.Width / ovalWidth;
			fh = rect.Height / ovalHeight;
			context.MoveTo(fw, fh / 2);
			context.AddArcToPoint(fw, fh, fw / 2, fh, 1);
			context.AddArcToPoint(0, fh, 0, fh / 2, 1);
			context.AddArcToPoint(0, 0, fw / 2, 0, 1);
			context.AddArcToPoint(fw, 0, fw, fh / 2, 1);
			context.ClosePath();
			context.RestoreState();
		}