예제 #1
0
        private void DrawText(string t, nfloat x, nfloat y, nfloat fontSize, CGContext gctx, int alignement, UIColor color, nfloat width, int position = PosCenter)
        {
            gctx.SaveState();
            UIGraphics.PushContext(gctx);
            gctx.SetFillColor(color.CGColor);

            var tfont = UIFont.FromName(FontName, fontSize);

            var nsstr = new NSString(t);
            var sz    = nsstr.StringSize(tfont, width, UILineBreakMode.WordWrap);

            while ((int)(sz.Width - width) == 0)
            {
                var temp = sz.Height;
                sz = nsstr.StringSize(tfont, new CGSize(width, sz.Height * 2.5f), UILineBreakMode.WordWrap);
                if (temp == sz.Height)
                {
                    break;
                }
            }
            var mitad = sz.Height / 2;

            switch (position)
            {
            case PosTop:
                mitad = 0;
                break;

            case PosCenter:
                mitad = sz.Height / 2;
                break;

            case PosBottom:
                mitad = sz.Height;
                break;
            }
            CGRect rect;

            switch (alignement)
            {
            case TextCenter:
                rect = new CGRect(x - sz.Width / 2, y - mitad, sz.Width, sz.Height * 2.5f);
                nsstr.DrawString(rect, tfont, UILineBreakMode.WordWrap, UITextAlignment.Center);
                break;

            case TextLeft:
                rect = new CGRect(x, y - mitad, sz.Width, sz.Height);
                nsstr.DrawString(rect, tfont, UILineBreakMode.WordWrap, UITextAlignment.Left);
                break;

            case TextRight:
                rect = new CGRect(x - sz.Width, y - mitad, sz.Width, sz.Height);
                nsstr.DrawString(rect, tfont, UILineBreakMode.WordWrap, UITextAlignment.Right);
                break;
            }

            UIGraphics.PopContext();
            gctx.RestoreState();
        }
예제 #2
0
        private void DrawStringOutline(string text, NSColor color, RectangleF rect, int align)
        {
            NSString nsString = new NSString(text);

            int halign = align % 3;
            int valign = align / 3;


            var objectsText    = new object[] { m_font, color };
            var keysText       = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
            var attributesText = NSDictionary.FromObjectsAndKeys(objectsText, keysText);

            var objectsOutline    = new object[] { m_font, NSColor.White };
            var keysOutline       = new object[] { NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName };
            var attributesOutline = NSDictionary.FromObjectsAndKeys(objectsOutline, keysOutline);


            SizeF size = nsString.StringSize(attributesText);

            if (halign == 0)
            {
            }
            else if (halign == 1)
            {
                rect.X = (rect.Left + rect.Right) / 2 - size.Width / 2;
            }
            else if (halign == 2)
            {
                rect.X = rect.Right - size.Width;
            }
            rect.Width = size.Width;

            if (valign == 0)
            {
            }
            else if (valign == 1)
            {
                rect.Y = (rect.Top + rect.Bottom) / 2 - size.Height / 2;
            }
            else if (valign == 2)
            {
                rect.Y = rect.Bottom - size.Height;
            }
            rect.Height = size.Height;

            NSColor.Black.Set();
            for (int ox = -1; ox <= 1; ox++)
            {
                for (int oy = -1; oy <= 1; oy++)
                {
                    RectangleF rectString = rect;
                    rectString.Offset(new PointF(ox, oy));
                    nsString.DrawString(Invert(rectString), attributesOutline);
                }
            }
            nsString.DrawString(Invert(rect), attributesText);
        }
예제 #3
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            var str = new NSString("Developers.IO");

            str.DrawString(new CGPoint(75, 60), UIFont.FromName("HiraKakuProN-W3", 24f));
        }
        public override void Draw(RectangleF rect)
        {
            base.Draw (rect);
            var ctx = UIGraphics.GetCurrentContext();

            var center = new PointF(Bounds.X + Bounds.Width / 2.0f, Bounds.Y + Bounds.Height / 2.0f);

            var maxRadius = distance(Bounds.Width, Bounds.Height) / 2.0f;

            ctx.SetLineWidth(10);
            CircleColor.SetStroke();

            for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20.0f) {
                ctx.AddArc(center.X, center.Y, currentRadius, 0.0f, (float)Math.PI * 2.0f, true);
                ctx.StrokePath();
            }

            var text = new NSString("You are getting sleepy.");
            var font = UIFont.BoldSystemFontOfSize(28.0f);
            var textSize = text.StringSize(font);

            UIColor.Black.SetFill();

            var offset = new SizeF(4.0f, 3.0f);
            ctx.SetShadowWithColor(offset, 2.0f, UIColor.DarkGray.CGColor);

            text.DrawString(new PointF(center.X - textSize.Width / 2.0f, center.Y - textSize.Height / 2.0f), font);
        }
예제 #5
0
        public override void Draw(CGRect rect)
        {
            var context = UIGraphics.GetCurrentContext();

            this.DrawRoundedRect(context, rect);

            if (!string.IsNullOrEmpty(_text))
            {
                _textColor.SetColor();
                var sizeOfFont = 13.5f * _scaleFactor;
                if (_text.Length < 2)
                {
                    sizeOfFont += sizeOfFont * 0.20f;
                }
                var font     = UIFont.BoldSystemFontOfSize(sizeOfFont);
                var text     = new NSString(this._text);
                var textSize = text.StringSize(font);
                var textPos  = new CGPoint(rect.Width / 2 - textSize.Width / 2, rect.Height / 2 - textSize.Height / 2);
                if (_text.Length < 2)
                {
                    textPos.X += 0.5f;
                }
                text.DrawString(textPos, font);
            }
        }
예제 #6
0
        private UIImage CreateImage (NSString title, float scale)
        {
            var titleAttrs = new UIStringAttributes () {
                Font = UIFont.FromName ("HelveticaNeue", 13f),
                ForegroundColor = Color.Gray,
            };

            var titleBounds = title.GetBoundingRect (
                                  new SizeF (Single.PositiveInfinity, Single.PositiveInfinity),
                                  NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesDeviceMetrics,
                                  titleAttrs,
                                  null);

            var image = Image.TagBackground;
            var imageBounds = new RectangleF (
                                  0, 0,
                                  (float)Math.Ceiling (titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f,
                                  (float)Math.Ceiling (titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom
                              );

            titleBounds.X = image.CapInsets.Left + 2f;
            titleBounds.Y = image.CapInsets.Top;

            UIGraphics.BeginImageContextWithOptions (imageBounds.Size, false, scale);

            try {
                image.Draw (imageBounds);
                title.DrawString (titleBounds, titleAttrs);
                return UIGraphics.GetImageFromCurrentImageContext ();
            } finally {
                UIGraphics.EndImageContext ();
            }
        }
        public static UIImage ImageFromFont(string text, UIColor iconColor, CGSize iconSize, string fontName)
        {
            UIGraphics.BeginImageContextWithOptions(iconSize, false, 0);

              var textRect = new CGRect(CGPoint.Empty, iconSize);
              var path = UIBezierPath.FromRect(textRect);
              UIColor.Clear.SetFill();
              path.Fill();

              var font = UIFont.FromName(fontName, iconSize.Width);
              using (var label = new UILabel() { Text = text, Font = font })
              {
            GetFontSize(label, iconSize, 500, 5);
            font = label.Font;
              }
              iconColor.SetFill();
              using (var nativeString = new NSString(text))
              {
            nativeString.DrawString(textRect, new UIStringAttributes
              {
            Font = font,
            ForegroundColor = iconColor,
            BackgroundColor = UIColor.Clear,
            ParagraphStyle = new NSMutableParagraphStyle
            {
              Alignment = UITextAlignment.Center
            }
              });
              }
              var image = UIGraphics.GetImageFromCurrentImageContext();
              UIGraphics.EndImageContext();
              image = image.ImageWithRenderingMode (UIImageRenderingMode.AlwaysOriginal);
              return image;
        }
예제 #8
0
        private UIImage CreateImage (NSString title, nfloat scale)
        {
            var titleAttrs = new UIStringAttributes () {
                Font = UIFont.FromName ("HelveticaNeue", 13f),
                ForegroundColor = Color.Gray,
            };

            var titleBounds = new CGRect (
                new CGPoint (0, 0),
                title.GetSizeUsingAttributes (titleAttrs)
            );

            var image = Image.TagBackground;
            var imageBounds = new CGRect (
                0, 0,
                (float)Math.Ceiling (titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f,
                (float)Math.Ceiling (titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom
            );

            titleBounds.X = image.CapInsets.Left + 2f;
            titleBounds.Y = image.CapInsets.Top;

            UIGraphics.BeginImageContextWithOptions (imageBounds.Size, false, scale);

            try {
                image.Draw (imageBounds);
                title.DrawString (titleBounds, titleAttrs);
                return UIGraphics.GetImageFromCurrentImageContext ();
            } finally {
                UIGraphics.EndImageContext ();
            }
        }
예제 #9
0
        public void DrawText(Font font, SolidBrush brush, float x, float y, string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            StartDrawing();
#if OSX
            var nsfont = FontHandler.GetControl(font);
            var str    = new NSString(text);
            var dic    = new NSMutableDictionary();
            dic.Add(NSAttributedString.ForegroundColorAttributeName, brush.Color.ToNS());
            dic.Add(NSAttributedString.FontAttributeName, nsfont);
            //context.SetShouldAntialias(true);
            if (!Flipped)
            {
                var size = str.StringSize(dic);
                Control.ConcatCTM(new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight));
                y = ViewHeight - y - size.Height;
            }
            str.DrawString(TranslateView(new SD.PointF(x, y)), dic);
            //context.SetShouldAntialias(antialias);
#elif IOS
            var uifont = font.ToUI();
            var str    = new NSString(text);
            var size   = str.StringSize(uifont);
            //context.SetShouldAntialias(true);
            Control.SetFillColor(brush.Color.ToCGColor());
            str.DrawString(TranslateView(new SD.PointF(x, y), elementHeight: size.Height), uifont);
#endif

            EndDrawing();
        }
        ////public override NSObject Annotation
        ////{
        ////    get
        ////    {
        ////        return base.Annotation;
        ////    }
        ////    set
        ////    {
        ////        base.Annotation = value;
        ////        this.Redraw();
        ////    }
        ////}

        ////private void Redraw()
        ////{
        ////    this.Draw(this.Frame);
        ////}

        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            var annotation = this.Annotation as ClusterMapAnnotation;

            if (annotation == null)
            {
                return;
            }

            using (var context = UIGraphics.GetCurrentContext())
            {
                context.SetLineWidth(1.0f);
                context.SetFillColor(this.color1);
                context.SetAlpha(0.5f);
                context.FillEllipseInRect(new RectangleF(0f, 0f, this.Diameter, this.Diameter));

                context.SetFillColor(this.color2);
                context.SetAlpha(1.0f);
                context.FillEllipseInRect(new RectangleF((this.Diameter - this.diameter2) / 2, (this.Diameter - this.diameter2) / 2, this.diameter2, this.diameter2));

                context.SetFillColor(this.Color.CGColor);
                context.SetAlpha(1.0f);
                context.FillEllipseInRect(new RectangleF((this.Diameter - this.diameter3) / 2, (this.Diameter - this.diameter3) / 2, this.diameter3, this.diameter3));

                NSString titleString = new NSString(annotation.Title);
                UIColor.White.SetColor();
                UIFont font = UIFont.BoldSystemFontOfSize(10.0f);
                titleString.DrawString(new RectangleF(((float)this.CenterOffset.X) / 2, ((float)this.CenterOffset.Y) / 2, this.diameter3, this.diameter3), font);
                titleString.Dispose();
            }
        }
예제 #11
0
        private void DrawString(string str, NSDictionary fontInfo, NSColor color, int xpos, int ypos)
        {
            color.Set();
            NSString tmp = new NSString(str);

            tmp.DrawString(new CGPoint(xpos, ypos), fontInfo);
        }
예제 #12
0
        public override void DrawFooterForPage(int index, RectangleF footerRect)
        {
            NSString footer = new NSString(string.Format("Page {0} of {1}", index - pageRange.Location + 1, pageRange.Length));

            footer.DrawString(footerRect, SystemFont, UILineBreakMode.Clip, UITextAlignment.Center);
            footer.Dispose();
        }
        public void GenView(MKClusterAnnotation cluster)
        {
            AnnotationViewSize annotationSize = MapSettings.AnnotationSize;

            if (cluster != null)
            {
                var renderer = new UIGraphicsImageRenderer(new CGSize(annotationSize.Width,
                                                                      annotationSize.Height));
                var count = cluster.MemberAnnotations.Length;

                Image = renderer.CreateImage((context) => {
                    //circle
                    UIColor.FromRGB(230, 141, 119).SetFill();
                    UIBezierPath.FromOval(new CGRect(0,
                                                     0,
                                                     annotationSize.Width,
                                                     annotationSize.Height)).Fill();

                    //text
                    var attributes = new UIStringAttributes()
                    {
                        ForegroundColor = UIColor.Black,
                        Font            = UIFont.BoldSystemFontOfSize(20)
                    };
                    var text = new NSString($"{count}");
                    var size = text.GetSizeUsingAttributes(attributes);
                    var rect = new CGRect(20 - size.Width / 2, 20 - size.Height / 2, size.Width, size.Height);
                    text.DrawString(rect, attributes);
                });
            }
        }
        public override void DrawFooterForPage(nint index, CGRect footerRect)
        {
            base.DrawFooterForPage(index, footerRect);

            UIFont footerFont = UIFont.SystemFontOfSize(FOOTER_FONT_SIZE);

            //Draw Print date
            NSString dateStr  = new NSString(PAGE_FOOTER_DATE_STR + DateTime.Now.ToString("dd MMM yyyy "));
            CGSize   dateSize = dateStr.StringSize(footerFont);
            CGPoint  point    = new CGPoint(CONTENT_LEFT_RIGHT_MARGIN, footerRect.GetMaxY() - dateSize.Height - FOOTER_BOTTOM_PADDING);

            dateStr.DrawString(point, footerFont);

            //Draw "© 2015 LexisNexis" in the horizontal center of footer
            NSString copyrightStr  = new NSString(PAGE_FOOTER_COPYRIGHT);
            CGSize   copyrightSize = copyrightStr.StringSize(footerFont);

            point = new CGPoint(footerRect.GetMaxX() / 2 - copyrightSize.Width / 2, footerRect.GetMaxY() - copyrightSize.Height - FOOTER_BOTTOM_PADDING);
            copyrightStr.DrawString(point, footerFont);

            //Draw page num in the footer
            NSString pageNumStr  = new NSString(PAGE_FOOTER_PAGE_INFO + (index + 1));
            CGSize   pageNumSize = pageNumStr.StringSize(footerFont);

            point = new CGPoint(footerRect.GetMaxX() - pageNumSize.Width - CONTENT_LEFT_RIGHT_MARGIN, footerRect.GetMaxY() - pageNumSize.Height - FOOTER_BOTTOM_PADDING);
            pageNumStr.DrawString(point, footerFont);
        }
예제 #15
0
        private UIImage CreateImage(NSString title, float scale)
        {
            var titleAttrs = new UIStringAttributes()
            {
                Font            = UIFont.FromName("HelveticaNeue", 13f),
                ForegroundColor = Color.Gray,
            };

            var titleBounds = new RectangleF(
                new PointF(0, 0),
                title.GetSizeUsingAttributes(titleAttrs)
                );

            var image       = Image.TagBackground;
            var imageBounds = new RectangleF(
                0, 0,
                (float)Math.Ceiling(titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f,
                (float)Math.Ceiling(titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom
                );

            titleBounds.X = image.CapInsets.Left + 2f;
            titleBounds.Y = image.CapInsets.Top;

            UIGraphics.BeginImageContextWithOptions(imageBounds.Size, false, scale);

            try {
                image.Draw(imageBounds);
                title.DrawString(titleBounds, titleAttrs);
                return(UIGraphics.GetImageFromCurrentImageContext());
            } finally {
                UIGraphics.EndImageContext();
            }
        }
예제 #16
0
        public static UIImage GenerateImage(nfloat width, nfloat height, string name = "ME")
        {
            Random rnd = new Random();

            CGColor color = colors[rnd.Next(colors.Length - 1)];

            UIFont font = UIFont.FromName("Helvetica Light", 14);

            UIGraphics.BeginImageContextWithOptions(new CGSize(width, height), false, 0);

            var context = UIGraphics.GetCurrentContext();

            context.SetFillColor(color);
            context.AddArc(width / 2, height / 2, width / 2, 0, (nfloat)(2 * Math.PI), true);
            context.FillPath();

            var textAttributes = new UIStringAttributes
            {
                ForegroundColor = UIColor.White,
                BackgroundColor = UIColor.Clear,
                Font            = font,
                ParagraphStyle  = new NSMutableParagraphStyle {
                    Alignment = UITextAlignment.Center
                },
            };

            string text;

            string[] splitFrom = name.Split(' ');
            if (splitFrom[0] == "ME")
            {
                text = "ME";
            }
            else if (splitFrom.Length > 1)
            {
                text = splitFrom[0][0].ToString() + splitFrom[1][0];
            }
            else if (splitFrom.Length > 0)
            {
                text = splitFrom[0][0].ToString();
            }
            else
            {
                text = "?";
            }

            NSString str = new NSString(text);

            var textSize = str.GetSizeUsingAttributes(textAttributes);

            str.DrawString(new CGRect(0, height / 2 - textSize.Height / 2,
                                      width, height), textAttributes);

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
예제 #17
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            var  mainText   = new NSString(node.ToString());
            var  bounds     = this.Bounds.ToRectangleF();
            bool isSelected = node.IsSelected;

            var mainTextAttrs = new NSMutableDictionary();
            var mainTextPara  = new NSMutableParagraphStyle();

            mainTextPara.LineBreakMode = NSLineBreakMode.TruncatingTail;
            mainTextPara.TighteningFactorForTruncation = 0;
            mainTextAttrs.Add(NSStringAttributeKey.ParagraphStyle, mainTextPara);
            if (isSelected)
            {
                mainTextAttrs.Add(NSStringAttributeKey.ForegroundColor, NSColor.SelectedMenuItemText);
            }
            else
            {
                mainTextAttrs.Add(NSStringAttributeKey.ForegroundColor, NSColor.Text);
            }

            var   mainTextSz = mainText.StringSize(mainTextAttrs).ToSizeF();
            float nodeTextAndPrimaryPropHorzSpacing = 8;
            float spaceAvailableForDefaultPropValue =
                bounds.Width - mainTextSz.Width - nodeTextAndPrimaryPropHorzSpacing;

            var paintInfo = owner.ViewModel.PaintNode(node, spaceAvailableForDefaultPropValue > 30);

            if (paintInfo.PrimaryPropValue != null)
            {
                var r = new RectangleF(
                    bounds.Right - spaceAvailableForDefaultPropValue,
                    bounds.Y,
                    spaceAvailableForDefaultPropValue,
                    bounds.Height);

                // todo: move dict to a static field
                var dict = new NSMutableDictionary();
                var para = new NSMutableParagraphStyle();
                para.Alignment     = NSTextAlignment.Right;
                para.LineBreakMode = NSLineBreakMode.TruncatingTail;
                para.TighteningFactorForTruncation = 0;
                dict.Add(NSStringAttributeKey.ParagraphStyle, para);
                if (isSelected)
                {
                    dict.Add(NSStringAttributeKey.ForegroundColor, NSColor.FromDeviceRgba(0.9f, 0.9f, 0.9f, 1f));
                }
                else
                {
                    dict.Add(NSStringAttributeKey.ForegroundColor, NSColor.Gray);
                }

                new NSString(paintInfo.PrimaryPropValue).DrawString(r.ToCGRect(), dict);
            }

            mainText.DrawString(bounds.ToCGRect(), mainTextAttrs);
        }
예제 #18
0
        public override void DrawFooterForPage(nint index, CGRect footerRect)
        {
            var      item   = printItem [index].First();
            NSString footer = new NSString(item.Key.ToString());

            footer.DrawString(footerRect, eBriefingAppearance.ThemeRegularFont(10f), UILineBreakMode.Clip, UITextAlignment.Center);
            footer.Dispose();
        }
        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();
        }
예제 #20
0
        public override void Draw(CGRect rect)
        {
            UIImage img;
            UIColor color;

            if (!Active)
            {
                color = UIColor.FromRGBA(0.576f, 0.608f, 0.647f, 1f);
                img   = Images.dateCell;
            }
            else if (Today && Selected)
            {
                color = UIColor.White;
                img   = Images.todayselected;
            }
            else if (Today)
            {
                color = UIColor.White;
                img   = Images.today;
            }
            else if (Selected)
            {
                color = UIColor.White;
                img   = Images.datecellselected;
            }
            else
            {
                //color = UIColor.DarkTextColor;
                color = UIColor.FromRGBA(0.275f, 0.341f, 0.412f, 1f);
                img   = Images.dateCell;
            }
            //img.Draw (new CGPoint (0, 0));
            img.Draw(rect);
            color.SetColor();
            var s1 = new NSString(Text);

            s1.DrawString(CGRect.Inflate(Bounds, 4, -8), UIFont.BoldSystemFontOfSize(22), UILineBreakMode.WordWrap, UITextAlignment.Center);

            if (Marked)
            {
                var context = UIGraphics.GetCurrentContext();
                if (Selected || Today)
                {
                    context.SetFillColor(1, 1, 1, 1);
                }
                else if (!Active)
                {
                    UIColor.LightGray.SetColor();
                }
                else
                {
                    context.SetFillColor(75 / 255f, 92 / 255f, 111 / 255f, 1);
                }
                context.SetLineWidth(0);
                context.AddEllipseInRect(new CGRect(Frame.Size.Width / 2 - 2, 45 - 10, 4, 4));
                context.FillPath();
            }
        }
        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;
        }
예제 #22
0
        public override void Draw(CoreGraphics.CGRect rect)
        {
            UIColor.Black.SetColor();
            var text = new NSString($"Drop {Name}");
            var b    = Bounds;

            b.Inflate(-22, -22);
            text.DrawString(b, UIFont.BoldSystemFontOfSize(24));
        }
        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;
        }
예제 #24
0
        public void DrawText(Font font, Color color, int x, int y, string text)
        {
            UIGraphics.PushContext(this.context);

            var str  = new NSString(text);
            var size = str.StringSize(font.ControlObject as UIFont);

            //context.SetShouldAntialias(true);
            str.DrawString(new SD.PointF(x, height - y - size.Height), font.ControlObject as UIFont);
            UIGraphics.PopContext();
        }
예제 #25
0
        private void DrawMonthLabel(CGRect rect)
        {
            var r = new CGRect(new CGPoint(0, 5), new CGSize {
                Width = CurrentWidth, Height = 42
            });

            UIColor.DarkGray.SetColor();
            var s = new NSString(CurrentMonthYear.ToString("MMMM yyyy"));

            s.DrawString(r, UIFont.BoldSystemFontOfSize(20), UILineBreakMode.WordWrap, UITextAlignment.Center);
        }
        private void DrawVerticallyCenteredInRect(string text, CGRect rect)
        {
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetFillColor(1.00f, 1.00f, 1.00f, 1.00f);
            NSString title = new NSString(text);

            rect.Y += rect.Height / 2f - UIFont.PreferredCaption1.xHeight;
            title.DrawString(rect, UIFont.PreferredCaption1,
                             UILineBreakMode.CharacterWrap,
                             UITextAlignment.Center);
        }
            private UIImage GetIconForText(string text, nuint bucketIndex)
            {
                var nsText = new NSString(text);
                var icon   = _iconCache.ObjectForKey(nsText);

                if (icon != null)
                {
                    return((UIImage)icon);
                }

                var font           = UIFont.BoldSystemFontOfSize(14);
                var paragraphStyle = NSParagraphStyle.Default;
                var dict           = NSDictionary.FromObjectsAndKeys(
                    objects: new NSObject[] { font, paragraphStyle, this._options.RendererTextColor.ToUIColor() },
                    keys: new NSObject[] { UIStringAttributeKey.Font, UIStringAttributeKey.ParagraphStyle, UIStringAttributeKey.ForegroundColor }
                    );
                var attributes = new UIStringAttributes(dict);


                var textSize      = nsText.GetSizeUsingAttributes(attributes);
                var rectDimension = Math.Max(20, Math.Max(textSize.Width, textSize.Height)) + 3 * bucketIndex + 6;
                var rect          = new CGRect(0.0f, 0.0f, rectDimension, rectDimension);

                UIGraphics.BeginImageContext(rect.Size);
                UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0);

                // Background circle
                var ctx = UIGraphics.GetCurrentContext();

                ctx.SaveState();

                bucketIndex = (nuint)Math.Min((int)bucketIndex, this._options.BucketColors.Length - 1);
                var backColor = this._options.BucketColors[bucketIndex];

                ctx.SetFillColor(backColor.ToCGColor());
                ctx.FillEllipseInRect(rect);
                ctx.RestoreState();

                // Draw the text
                UIColor.White.SetColor();
                var textRect = RectangleFExtensions.Inset(rect, (rect.Size.Width - textSize.Width) / 2,
                                                          (rect.Size.Height - textSize.Height) / 2);

                nsText.DrawString(RectangleFExtensions.Integral(textRect), attributes);

                var newImage = UIGraphics.GetImageFromCurrentImageContext();

                UIGraphics.EndImageContext();

                this._iconCache.SetObjectforKey(newImage, nsText);

                return(newImage);
            }
예제 #28
0
        public override void Draw(CoreGraphics.CGRect rect)
        {
            UIColor.FromHSB(80.0f / 360.0f, 0.1f, 0.9f).SetFill();
            UIGraphics.RectFill(rect);

            UIColor.Black.SetColor();
            var text = new NSString($"Drag {Name}");
            var b    = Bounds;

            b.Inflate(-22, -22);
            text.DrawString(b, UIFont.BoldSystemFontOfSize(24));
        }
예제 #29
0
		public override void Draw(CGRect rect)
		{
			if (SelectionColor == null)
				SelectionColor = UIColor.Red;

			UIImage img = UIImage.FromFile(FMCalendar.BasePath + "datecell.png");
			UIColor color = UIColor.Black;

			if (!Active || !Available)
			{
				color = UIColor.FromRGBA(0.576f, 0.608f, 0.647f, 1f);
				if(Selected)
					color = SelectionColor;
			} else if (Today && Selected)
			{
				color = UIColor.White;
                img = UIImage.FromFile(FMCalendar.BasePath + "today.png");
			} else if (Today)
			{
				color = UIColor.White;
                img = UIImage.FromFile(FMCalendar.BasePath + "today.png");
			} else if (Selected)
			{
				color = SelectionColor;
			}

			img.Draw(new CGPoint(0, 0));
			color.SetColor();

            NSString nativeText = new NSString(Text);
		    nativeText.DrawString(CGRect.Inflate(Bounds, 4, -8),
		        UIFont.SystemFontOfSize(20),
		        UILineBreakMode.WordWrap, UITextAlignment.Center);

			if (Marked)
			{
				var context = UIGraphics.GetCurrentContext();
				if (Selected && !Today)
					SelectionColor.SetColor ();
				else if (Today)
					UIColor.White.SetColor ();
				else if (!Active || !Available)
					UIColor.LightGray.SetColor ();
				else
					UIColor.Black.SetColor ();

				context.SetLineWidth(0);
				context.AddEllipseInRect(new CGRect(Frame.Size.Width/2 - 2, 45-10, 4, 4));
				context.FillPath();

			}
		}
예제 #30
0
        // Custom UIPrintPageRenderer's may override this class to draw a custom print page header.
        // To illustrate that, this class sets the date in the header.
        public override void DrawHeaderForPage(int index, RectangleF headerRect)
        {
            NSDateFormatter dateFormatter = new NSDateFormatter();

            dateFormatter.DateFormat = "MMMM d, yyyy 'at' h:mm a";

            NSString dateString = new NSString(dateFormatter.ToString(NSDate.Now));

            dateFormatter.Dispose();

            dateString.DrawString(headerRect, SystemFont, UILineBreakMode.Clip, UITextAlignment.Right);
            dateString.Dispose();
        }
예제 #31
0
        public static UIImage ImageFromFont(UIFont font, char character, UIColor fillColor)
        {
            var s    = new NSString("" + character);
            var size = s.StringSize(font);

            UIGraphics.BeginImageContextWithOptions(size, false, 0f);
            fillColor.SetFill();
            s.DrawString(new CGPoint(0, 0), font);
            var img = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(img);
        }
예제 #32
0
		static UIImage Render (string value)
		{
			NSString text = new NSString (string.IsNullOrEmpty (value) ? " " : value);
			UIFont font = UIFont.SystemFontOfSize (20);
			SizeF size = text.StringSize (font);
			UIGraphics.BeginImageContextWithOptions (size, false, 0.0f);
			UIColor.Red.SetColor ();
			text.DrawString (new PointF (0, 0), font);
			UIImage image = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();
			
			return image;
		}
예제 #33
0
        // Custom drawing code to put the recipe recipe description, and prep time
        // in the title section of the recipe presentation's header.
        void DrawRecipeInfo(string info, RectangleF rect)
        {
            RectangleF infoRect = RectangleF.Empty;

            infoRect.X      = rect.Left + RecipeInfoHeight;
            infoRect.Y      = rect.Top + TitleSize * 2;
            infoRect.Width  = rect.Width - RecipeInfoHeight;
            infoRect.Height = RecipeInfoHeight - TitleSize * 2;

            UIColor.DarkGray.SetColor();
            using (NSString str = new NSString(info)) {
                str.DrawString(infoRect, SystemFont, UILineBreakMode.Clip, UITextAlignment.Left);
            }
        }
예제 #34
0
        // Custom drawing code to put the recipe name in the title section of the recipe presentation's header.
        void DrawRecipeName(string name, RectangleF rect)
        {
            RectangleF nameRect = RectangleF.Empty;

            nameRect.X      = rect.Left + RecipeInfoHeight;
            nameRect.Y      = rect.Top + Padding;
            nameRect.Width  = rect.Width - RecipeInfoHeight;
            nameRect.Height = RecipeInfoHeight;

            using (UIFont font = UIFont.BoldSystemFontOfSize(TitleSize)) {
                using (NSString str = new NSString(name)) {
                    str.DrawString(nameRect, font, UILineBreakMode.Clip, UITextAlignment.Left);
                }
            }
        }
예제 #35
0
        public static UIImage Text2Image(String text, CGSize imageSize)
        {
            NSString ns           = new NSString(text);
            CGSize   size         = new CGSize(500, imageSize.Height);
            CGSize   expectedSize = ns.StringSize(eBriefingAppearance.ThemeRegularFont(13), size, UILineBreakMode.WordWrap);

            UIGraphics.BeginImageContext(expectedSize);
            ns.DrawString(new CGRect(0, 0, expectedSize.Width, expectedSize.Height), eBriefingAppearance.ThemeRegularFont(13), UILineBreakMode.WordWrap);

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
예제 #36
0
        static UIImage Render(string value)
        {
            NSString text = new NSString(string.IsNullOrEmpty(value) ? " " : value);
            UIFont   font = UIFont.SystemFontOfSize(20);
            SizeF    size = text.StringSize(font);

            UIGraphics.BeginImageContextWithOptions(size, false, 0.0f);
            UIColor.Red.SetColor();
            text.DrawString(new PointF(0, 0), font);
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(image);
        }
예제 #37
0
파일: Graphics.cs 프로젝트: jianwoo/CodeHub
        public static UIImage ImageFromFont(UIFont font, char character, UIColor fillColor)
        {
            var s = new NSString("" + character);
            var stringSize = s.StringSize(font);
            var maxSize = (nfloat)Math.Max(stringSize.Height, stringSize.Width);
            var size = new CGSize(maxSize, maxSize);

            UIGraphics.BeginImageContextWithOptions(size, false, 0f);
            fillColor.SetFill();

            var drawPoint = new CGPoint((size.Width / 2f) - (stringSize.Width / 2f),
                                (size.Height / 2f) - (stringSize.Height / 2f));
            s.DrawString(drawPoint, font);

            var img = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();
            return img;
        }
예제 #38
0
		static NSImage Render (string value)
		{
			NSImage image = null;

			NSApplication.SharedApplication.InvokeOnMainThread (() =>
			{
				NSString text = new NSString (string.IsNullOrEmpty (value) ? " " : value);
				NSFont font = NSFont.FromFontName ("Arial", 20);
				var fontDictionary = NSDictionary.FromObjectsAndKeys (new NSObject[] { font, NSColor.Red }, new NSObject[] { NSStringAttributeKey.Font, NSStringAttributeKey.ForegroundColor });
				CGSize size = text.StringSize (fontDictionary);

				image = new NSImage (new CGSize (size));

				image.LockFocus ();
				text.DrawString (new CGPoint (0, 0), fontDictionary);
				image.UnlockFocus ();
			});

			return image;
		}
예제 #39
0
        public Size GetCharData(char c,out  UInt32[] cdata)
        {
            NSString str =new NSString(c.ToString());
            var size=str.StringSize(font);
            UIGraphics.BeginImageContextWithOptions(size,false,1.0f);
            UIGraphics.GetCurrentContext().SetFillColor(1.0f,1.0f,1.0f,1.0f);
            str.DrawString(new System.Drawing.PointF(0,0),font);
            UIImage img =UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();

            //
            int width=(int)size.Width;
            int height=(int)size.Height;
            cdata=new UInt32[width*height];
            var gdata=new byte[width*height*4];
            var colorSpace = CGColorSpace.CreateDeviceRGB();
            var gbmp = new CGBitmapContext(gdata, width, height,
                                       8, width * 4, colorSpace, CGBitmapFlags.PremultipliedLast);
            //gbmp.ClearRect(new RectangleF(0,0,width,height));
            gbmp.DrawImage(new System.Drawing.RectangleF(0,0,width,height),img.CGImage);
            gbmp.Dispose();
            colorSpace.Dispose();
            unsafe
            {
                fixed(byte* srcb = gdata)
                    fixed (UInt32* dest=cdata)
                {
                    UInt32* src=(UInt32*)srcb;
                    for(int y=0;y<height;y++)
                    {
                        for(int x=0;x<width;x++)
                        {
                            dest[y*width+x]=src[y*width+x];
                        }
                    }
                }
            }

            return new Size(width,height);
        }
 /// <summary>
 /// Draws the centered string.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="color">The color.</param>
 /// <param name="rect">The rect.</param>
 /// <param name="font">The font.</param>
 private static void DrawCenteredString(NSString text, UIColor color, CGRect rect, UIFont font)
 {
     var paragraphStyle = (NSMutableParagraphStyle)NSParagraphStyle.Default.MutableCopy();
     paragraphStyle.LineBreakMode = UILineBreakMode.TailTruncation;
     paragraphStyle.Alignment = UITextAlignment.Center;
     var attrs = new UIStringAttributes { Font = font, ForegroundColor = color, ParagraphStyle = paragraphStyle };
     var size = text.GetSizeUsingAttributes(attrs);
     var targetRect = new CGRect(
         rect.X + (float)Math.Floor((rect.Width - size.Width) / 2f),
         rect.Y + (float)Math.Floor((rect.Height - size.Height) / 2f),
         size.Width,
         size.Height);
     text.DrawString(targetRect, attrs);
 }
 void DrawString(ref NSString s, ref PointF p)
 {
     s.DrawString(p, UIFont.FromName("Helvetica", _size));
 }
		public void DrawTextWithUTF8Fonts (CGContext mBmpContext, string text, float x, float y, string font_family, double text_size)
		{
			/*
			The problem is that CoreGraphics APIs for CGContext do not support rendering UTF8 code, and then ShowTextAtPoint() is limited to the text encoding in MacRoman.
			The fix is to use the UIKit function DrawString() instead.
			 */

			UIGraphics.PushContext (mBmpContext);
			mBmpContext.SetRGBFillColor(1f,1f,1f,1f);

			UIFont tfont = UIFont.FromName (font_family,(float)text_size);

			NSString nsstr = new NSString(text);
			SizeF sz = nsstr.StringSize(tfont);
			RectangleF rect = new RectangleF(x,y,sz.Width,sz.Height);
			nsstr.DrawString( rect, tfont);


			UIGraphics.PopContext ();
		}
예제 #43
0
        public override void Draw(RectangleF rect)
        {
            var context = UIGraphics.GetCurrentContext ();
            this.DrawRoundedRect (context, rect);

            if (this.shining)
                DrawShine (context, rect);

            if (this.border)
                DrawBorder (context, rect);

            if (this.text.Length > 0) {
                textColor.SetColor ();
                var sizeOfFont = 13.5f * scaleFactor;
                if (this.text.Length < 2) {
                    sizeOfFont += sizeOfFont * 0.20f;
                }
                var font = UIFont.BoldSystemFontOfSize (sizeOfFont);
                var text = new NSString (this.text);
                var textSize = text.StringSize (font);
                var textPos = new PointF (rect.Width / 2 - textSize.Width / 2, rect.Height / 2 - textSize.Height / 2);
                if (this.text.Length < 2)
                    textPos.X += 0.5f;
                text.DrawString (textPos, font);
            }
        }
예제 #44
0
 private void _chart_OnDrawText(object sender, Charting.Controls.Chart.DrawEventArgs<Events.TextDrawingData> e)
 {
     NSString str = new NSString(e.Data.Text);
     str.DrawString(new PointF((float)e.Data.X, (float)e.Data.Y), UIFont.SystemFontOfSize(12));
 }
예제 #45
0
 // simple icon showing "tv", override Image property to show your own image
 static UIImage GetIcon()
 {
     // http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIActivity_Class/Reference/Reference.html
     // iPhone / iPod Touch: 43x43 (86x86 retina)
     // iPad: 55x55 (110x110 retina)
     float size = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 55f : 43f;
     // http://tirania.org/blog/archive/2010/Jul-20-2.html
     UIGraphics.BeginImageContextWithOptions (new CGSize (size, size), false, 0.0f);
     using (var c = UIGraphics.GetCurrentContext ()) {
         c.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
         c.SetStrokeColor (1.0f, 1.0f, 1.0f, 1.0f);
         UIFont font = UIFont.BoldSystemFontOfSize (size - 8);
         using (var s = new NSString ("tv"))
             s.DrawString (new CGPoint (7.5f, 0.0f), font);
     }
     UIImage img = UIGraphics.GetImageFromCurrentImageContext ();
     UIGraphics.EndImageContext ();
     return img;
 }
		private void DrawVerticallyCenteredInRect (string text, CGRect rect)
		{
			CGContext context = UIGraphics.GetCurrentContext ();
			context.SetFillColor (1.00f, 1.00f, 1.00f, 1.00f);
			NSString title = new NSString (text);
			rect.Y += rect.Height / 2f - UIFont.PreferredCaption1.xHeight;
			title.DrawString (rect, UIFont.PreferredCaption1,
				UILineBreakMode.CharacterWrap,
				UITextAlignment.Center);
		}
		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;
		}
        public void ShowFrame(FrameInfo frameItem)
        {
            UIGraphics.BeginImageContextWithOptions (this.Bounds.Size, false, UIScreen.MainScreen.Scale);

            using (CGContext context = UIGraphics.GetCurrentContext()) {

                context.SetLineJoin (CGLineJoin.Round);
                context.SetLineCap (CGLineCap.Round);
                context.SetShouldAntialias (true);

                foreach (LayerInfo eachLayerInfo in frameItem.Layers.Values.OrderBy(s => s.ID)) {

                    if (eachLayerInfo.DrawingItems.Count > 0) {

                        foreach (KeyValuePair<int, DrawingInfo> eachItem in eachLayerInfo.DrawingItems) {

                            if (eachItem.Value.DrawingType == DrawingLayerType.Drawing) {

                                if (eachItem.Value.Brush.BrushType == BrushType.Normal) {

                                    context.SetStrokeColor (eachLayerInfo.IsCanvasActive ?
                                                           eachItem.Value.LineColor :
                                                           this.inactiveColor);

                                    context.SetLineWidth (eachItem.Value.Brush.Thickness);

                                    for (int i = 0; i < eachItem.Value.PathPoints.Count; i++) {

                                        PointF eachPoint = eachItem.Value.PathPoints [i];
                                        if (i == 0) {
                                            context.MoveTo (eachPoint.X, eachPoint.Y);
                                            context.AddLineToPoint (eachPoint.X, eachPoint.Y);
                                        } else {
                                            PointF prevPoint = eachItem.Value.PathPoints [i - 1];
                                            PointF midPoint = new PointF ((prevPoint.X + eachPoint.X) / 2f, (prevPoint.Y + eachPoint.Y) / 2f);
                                            context.MoveTo (prevPoint.X, prevPoint.Y);
                                            context.AddCurveToPoint (prevPoint.X, prevPoint.Y, midPoint.X, midPoint.Y, eachPoint.X, eachPoint.Y);
                                        }//end if else

                                    }//end for

                                    context.DrawPath (CGPathDrawingMode.Stroke);

                                } else {

                                    SizeF brushImageSize = eachItem.Value.Brush.BrushImage.Size;
                                    if (eachItem.Value.Brush.IsSprayBrushActive !=
                                        eachLayerInfo.IsCanvasActive) {
                                        eachItem.Value.Brush.SetBrushActive (eachLayerInfo.IsCanvasActive);
                                    }//end if

                                    for (int i = 0; i < eachItem.Value.PathPoints.Count; i++) {

                                        PointF eachPoint = eachItem.Value.PathPoints [i];
                                        RectangleF rect = new RectangleF (eachPoint.X - (brushImageSize.Width / 2f),
                                                                         eachPoint.Y - (brushImageSize.Height / 2f),
                                                                         brushImageSize.Width,
                                                                         brushImageSize.Height);

                                        eachItem.Value.Brush.BrushImage.Draw (rect.Location);

            //										context.SaveState();
            //
            //										context.SetBlendMode(eachLayerInfo.IsCanvasActive ?
            //										                     CGBlendMode.SourceIn :
            //										                     CGBlendMode.SourceAtop);
            //										context.SetFillColor(eachLayerInfo.IsCanvasActive ?
            //										                     eachItem.Value.LineColor :
            //										                     this.inactiveColor);
            //										context.FillRect(rect);
            //
            //										context.RestoreState();

                                    }//end for

                                }//end if else

                            } else if (eachItem.Value.DrawingType == DrawingLayerType.Image ||
                                eachItem.Value.DrawingType == DrawingLayerType.Comix ||
                                eachItem.Value.DrawingType == DrawingLayerType.Stamp ||
                                eachItem.Value.DrawingType == DrawingLayerType.Callout) {

                                if (eachItem.Value.RotationAngle == 0) {

                                    if (!eachLayerInfo.IsCanvasActive) {

                                        UIImage imgToDraw = eachItem.Value.GetInactiveImage (this.inactiveColor);
                                        imgToDraw.Draw (eachItem.Value.ImageFrame);
                                        imgToDraw.Dispose ();

                                    } else {

                                        eachItem.Value.Image.Draw (eachItem.Value.ImageFrame);

                                    }//end if else

                                    if (eachItem.Value.DrawingType == DrawingLayerType.Callout &&
                                        !string.IsNullOrEmpty (eachItem.Value.CalloutText)) {

                                        Pair<UIFont, SizeF> calloutTextParams =
                                            AnimationUtils.GetTextParamsForCallout (eachItem.Value.CalloutTextRect, eachItem.Value.CalloutText);

                                        context.SaveState ();

                                        context.SetFillColor (eachLayerInfo.IsCanvasActive ?
                                                             eachItem.Value.LineColor :
                                                             this.inactiveTextColor);
                                        context.SetTextDrawingMode (CGTextDrawingMode.Fill);
                                        context.SetShouldSmoothFonts (true);
                                        context.SetAllowsFontSmoothing (true);
                                        context.SetShouldAntialias (true);

                                        using (NSString nsText = new NSString(eachItem.Value.CalloutText)) {

                                            nsText.DrawString (eachItem.Value.CalloutTextRect.CenterInRect (calloutTextParams.ItemB),
                                                              calloutTextParams.ItemA,
                                                              UILineBreakMode.WordWrap,
                                                              UITextAlignment.Center);
                                        }//end using nsText

                                        context.RestoreState ();

                                    }//end if

                                } else {

                                    using (UIImage rotatedImage =
                                           AnimationUtils.RotateImage(eachLayerInfo.IsCanvasActive ?
                                                               eachItem.Value.Image :
                                                               eachItem.Value.GetInactiveImage(this.inactiveColor),
                                                               eachItem.Value.ImageFrame,
                                                               eachItem.Value.RotatedImageBox,
                                                               eachItem.Value.RotationAngle, !eachLayerInfo.IsCanvasActive)) {
                                        rotatedImage.Draw (eachItem.Value.RotatedImageBox);
                                    }//end using rotatedImage

                                    if (eachItem.Value.DrawingType == DrawingLayerType.Callout &&
                                        !string.IsNullOrEmpty (eachItem.Value.CalloutText)) {

                                        Pair<UIFont, SizeF> textParams =
                                            AnimationUtils.GetTextParamsForCallout (eachItem.Value.CalloutTextRect, eachItem.Value.CalloutText);

                                        context.SaveState ();

                                        context.SetFillColor (eachLayerInfo.IsCanvasActive ?
                                                             eachItem.Value.LineColor :
                                                             this.inactiveTextColor);
                                        context.SetTextDrawingMode (CGTextDrawingMode.Fill);
                                        context.SetShouldSmoothFonts (true);
                                        context.SetAllowsFontSmoothing (true);
                                        context.SetShouldAntialias (true);

                                        List<PointF> calloutTextCorners =
                                            eachItem.Value.CalloutTextRect.CenterInRect (textParams.ItemB).GetCorners ();
                                        List<PointF> rotatedCalloutTextCorners =
                                            calloutTextCorners.RotatePoints (eachItem.Value.RotationAngle,
                                                                            new PointF (eachItem.Value.RotatedImageBox.GetMidX (), eachItem.Value.RotatedImageBox.GetMidY ()));

                                        context.TranslateCTM (rotatedCalloutTextCorners [0].X, rotatedCalloutTextCorners [0].Y);
                                        context.RotateCTM (((float)eachItem.Value.RotationAngle * (float)LOLConstants.DegToRad));
                                        context.TranslateCTM (-rotatedCalloutTextCorners [0].X, -rotatedCalloutTextCorners [0].Y);

                                        using (NSString nsText = new NSString(eachItem.Value.CalloutText)) {

                                            nsText.DrawString (new RectangleF (rotatedCalloutTextCorners [0].X,
                                                                             rotatedCalloutTextCorners [0].Y,
                                                                             textParams.ItemB.Width,
                                                                             textParams.ItemB.Height),
                                                              textParams.ItemA,
                                                              UILineBreakMode.WordWrap,
                                                              UITextAlignment.Center);

                                        }//end using nsText

                                        context.RestoreState ();

                                    }//end if

                                }//end if else

                            }//end if else if

                        }//end foreach

                    }//end if

                }//end foreach

                if (null != this.imgDrawDisplay.Image) {
                    this.imgDrawDisplay.Image.Dispose ();
                    this.imgDrawDisplay.Image = null;
                }//end if
                this.imgDrawDisplay.Image = UIGraphics.GetImageFromCurrentImageContext ();

            }//end using context

            UIGraphics.EndImageContext ();
        }
		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;
		}
예제 #50
0
		/// <summary>
		/// Draws the date string.
		/// </summary>
		/// <param name="dateString">The date string.</param>
		/// <param name="color">The color.</param>
		/// <param name="rect">The rect.</param>
		private void DrawDateString(NSString dateString, UIColor color, CGRect rect)
		{
			if (paragraphStyle == null)
			{
				paragraphStyle = (NSMutableParagraphStyle)NSParagraphStyle.Default.MutableCopy();
				paragraphStyle.LineBreakMode = UILineBreakMode.TailTruncation;
				paragraphStyle.Alignment = UITextAlignment.Center;

			}
			var attrs = new UIStringAttributes()
			{
				Font = _mv.StyleDescriptor.DateLabelFont,
				ForegroundColor = color,
				ParagraphStyle = paragraphStyle
			};
			var size = dateString.GetSizeUsingAttributes(attrs);
			var targetRect = new CGRect(
				rect.X + (float)Math.Floor((rect.Width - size.Width) / 2f),
				rect.Y + (float)Math.Floor((rect.Height - size.Height) / 2f),
										size.Width,
										size.Height
									);
			dateString.DrawString(targetRect, attrs);
		}
		private void DrawVideoCompositionTracks (CGRect bannerRect, CGRect rowRect, ref float runningTop)
		{
			bannerRect.Y = runningTop;
			var context = UIGraphics.GetCurrentContext ();
			context.SetFillColor (1.00f, 1.00f, 1.00f, 1.00f);
			var compositionTitle = new NSString ("AVComposition");
			compositionTitle.DrawString (bannerRect, UIFont.PreferredCaption1);

			runningTop += (float)bannerRect.Height;
			rowRect.Y = runningTop;
			CGRect stageRect = rowRect;

			foreach (APLVideoCompositionStageInfo stage in videoCompositionStages) {
				stageRect.Width = (float)stage.TimeRange.Duration.Seconds * scaledDurationToWidth;
				int layerCount = stage.LayerNames.Count;
				CGRect layerRect = stageRect;

				if (layerCount > 0)
					layerRect.Height /= layerCount;

				foreach (string layerName in stage.LayerNames) {
					CGRect bufferRect = layerRect;
					int intValueOfName;
					Int32.TryParse (layerName, out intValueOfName);
					if (intValueOfName % 2 == 1) {
						context.SetFillColor (0.55f, 0.02f, 0.02f, 1.00f); // darker red
						context.SetStrokeColor (0.87f, 0.10f, 0.10f, 1.00f); // brighter red
					} else {
						context.SetFillColor (0.00f, 0.40f, 0.76f, 1.00f); // darker blue
						context.SetStrokeColor (0.00f, 0.67f, 1.00f, 1.00f); // brighter blue
					}

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

					context.SetFillColor (0.00f, 0.00f, 0.00f, 1.00f); // white
					DrawVerticallyCenteredInRect (layerName, bufferRect);

					// Draw the opacity ramps for each layer as per the layerInstructions
					List<CGPoint> rampArray = new List<CGPoint> ();

					if (stage.OpacityRamps != null)
						rampArray = stage.OpacityRamps [layerName];

					if (rampArray.Count > 0) {
						CGRect rampRect = bufferRect;
						rampRect.Width = (float)duration.Seconds * scaledDurationToWidth;
						rampRect = rampRect.Inset (3f, 3f);

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

						foreach (CGPoint point in rampArray) {
							CGPoint timeVolumePoint = point;
							CGPoint pointInRow = new CGPoint ();

							pointInRow.X = (float)HorizontalPositionForTime (CMTime.FromSeconds (timeVolumePoint.X, 1)) - 9.0f;
							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 ();
					}
					layerRect.Y += layerRect.Height;
				}
				stageRect.X += stageRect.Width;
			}
			runningTop += (float)rowRect.Height;
			runningTop += GapAfterRows;
		}
		// Custom UIPrintPageRenderer's may override this class to draw a custom print page header. 
		// To illustrate that, this class sets the date in the header.
		public override void DrawHeaderForPage (int index, RectangleF headerRect)
		{
			NSDateFormatter dateFormatter = new NSDateFormatter ();
			dateFormatter.DateFormat = "MMMM d, yyyy 'at' h:mm a";
			
			NSString dateString = new NSString (dateFormatter.ToString (NSDate.Now));
			dateFormatter.Dispose ();
			
			dateString.DrawString (headerRect, SystemFont, UILineBreakMode.Clip, UITextAlignment.Right);
			dateString.Dispose ();
		}
예제 #53
0
 void DrawStringCenteredInRectangle(string str, CGRect rect)
 {
     NSString drawLetter = new NSString(str);
     CGSize strSize = drawLetter.StringSize(mTextAttributes);
     CGPoint strOrigin = new CGPoint();
     strOrigin.X = rect.Location.X + (rect.Size.Width - strSize.Width)/2;
     strOrigin.Y = rect.Location.Y + (rect.Size.Height - strSize.Height)/2;
     if (LetterShadow) {
         NSShadow shadow = new NSShadow();
         shadow.ShadowBlurRadius = 8.0f;
         shadow.ShadowOffset = new CGSize(5.0f, 5.0f);
         shadow.ShadowColor = NSColor.Gray;
         shadow.Set();
     }
     drawLetter.DrawString(strOrigin, mTextAttributes);
 }
		public override void DrawFooterForPage (int index, RectangleF footerRect)
		{
			NSString footer = new NSString (string.Format ("Page {0} of {1}", index - pageRange.Location + 1, pageRange.Length));
			footer.DrawString (footerRect, SystemFont, UILineBreakMode.Clip, UITextAlignment.Center);
			footer.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 ();
			}
		}
		// Custom drawing code to put the recipe name in the title section of the recipe presentation's header.
		void DrawRecipeName (string name, RectangleF rect)
		{
			RectangleF nameRect = RectangleF.Empty;
			nameRect.X = rect.Left + RecipeInfoHeight;
			nameRect.Y = rect.Top + Padding;
			nameRect.Width = rect.Width - RecipeInfoHeight;
			nameRect.Height = RecipeInfoHeight;
			
			using (UIFont font = UIFont.BoldSystemFontOfSize (TitleSize)) {
				using (NSString str = new NSString (name)) {
					str.DrawString (nameRect, font, UILineBreakMode.Clip, UITextAlignment.Left);
				}
			}
		}
		public override void DrawText (ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, HorizontalTextAlign halign, VerticalTextAlign valign, OxySize? maxSize)
		{


			//This method needs work not 100% around vertical alignment.
			if(string.IsNullOrEmpty(text))
			{
				return;
			}

			fontFamily = GetDefaultFont(fontFamily);

			if (fontWeight >= 700)
            {
                //fs = FontStyle.Bold;
            }

			//var textSize = MeasureText(text, fontFamily, fontSize, fontWeight);

			if (maxSize != null)
            {
//                if (size.Width > maxSize.Value.Width)
//                {
//                    size.Width = (float)maxSize.Value.Width;
//                }
//
//                if (size.Height > maxSize.Value.Height)
//                {
//                    size.Height = (float)maxSize.Value.Height;
//                }
            }

			gctx.SaveState();

			gctx.SelectFont(fontFamily, (float)fontSize, CGTextEncoding.MacRoman);
			ToColor(fill).SetFill();

			gctx.SetTextDrawingMode(CGTextDrawingMode.Fill);

			var tfont = UIFont.FromName (fontFamily,(float)fontSize);
			NSString nsstr = new NSString(text);
			SizeF sz = nsstr.StringSize(tfont);

			float y = (float)(p.Y);
			float x = (float)(p.X);

			switch(halign)
			{
			case HorizontalTextAlign.Left:
				x = (float)(p.X);
				break;
			case HorizontalTextAlign.Right:
				x = (float)(p.X - sz.Width);
				break;
			case HorizontalTextAlign.Center:
				x = (float)(p.X - (sz.Width / 2));
				break;
			}

			switch(valign)
			{
			case VerticalTextAlign.Bottom:
				y -= (float)fontSize;
				break;
			case VerticalTextAlign.Top:
//				y += (float)fontSize;
				break;
			case VerticalTextAlign.Middle:
				y -= (float)(fontSize / 2);
				break;
			}


			RectangleF rect = new RectangleF(x,y,sz.Width,sz.Height);
			nsstr.DrawString( rect, tfont);

			gctx.RestoreState();
			//Console.WriteLine("X:{0:###} Y:{1:###} HA:{2}:{3:###} VA:{4}:{5:###} TW:{6:###} - {7}", p.X, p.Y, halign, x, valign, y, textSize.Width, text);
		}
		// Custom drawing code to put the recipe recipe description, and prep time 
		// in the title section of the recipe presentation's header.
		void DrawRecipeInfo (string info, RectangleF rect)
		{
			RectangleF infoRect = RectangleF.Empty;
			infoRect.X = rect.Left + RecipeInfoHeight;
			infoRect.Y = rect.Top + TitleSize * 2;
			infoRect.Width = rect.Width - RecipeInfoHeight;
			infoRect.Height = RecipeInfoHeight - TitleSize * 2;
			
			UIColor.DarkGray.SetColor ();
			using (NSString str = new NSString (info)) {
				str.DrawString (infoRect, SystemFont, UILineBreakMode.Clip, UITextAlignment.Left);
			}
		}
        public UIImage GetImage()
        {
            nfloat width = 32;
            nfloat height = 32;

            CGColor color = colors[DataGenerator.RNG.Next(colors.Length - 1)];

            UIFont font = UIFont.FromName("Helvetica Light", 14);
            UIGraphics.BeginImageContextWithOptions(new CGSize(width,height), false, 0);

            var context = UIGraphics.GetCurrentContext();
            context.SetFillColor(color);
            context.AddArc(width / 2, height / 2, width / 2, 0, (nfloat)(2 * Math.PI), true);
            context.FillPath();

            var textAttributes = new UIStringAttributes {
                ForegroundColor = UIColor.White,
                BackgroundColor = UIColor.Clear,
                Font = font,
                ParagraphStyle = new NSMutableParagraphStyle { Alignment = UITextAlignment.Center },
            };

            string text;
            string[] splitFrom = From.Split(' ');
            if (splitFrom.Length > 1) {
                text = splitFrom[0][0].ToString() + splitFrom[1][0];
            } else if (splitFrom.Length > 0) {
                text = splitFrom[0][0].ToString();
            } else {
                text = "?";
            }

            NSString str = new NSString(text);

            var textSize = str.GetSizeUsingAttributes(textAttributes);
            str.DrawString(new CGRect(0, height/2 - textSize.Height/2, 
                width, height), textAttributes);

            UIImage image = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();

            return image;
        }
            public override void Draw(RectangleF rect)
            {
                var fontSize = BadgeView.fontSize;
                var text = new NSString (Text);
                var numberSize = text.StringSize (UIFont.BoldSystemFontOfSize (fontSize));
                var radius = Radius;

                var bounds = new RectangleF (PointF.Empty, new SizeF (numberSize.Width + 12f, 18f));
                UIColor color;
                if (Parent.SelectionStyle != UITableViewCellSelectionStyle.None && (Parent.Highlighted || Parent.Selected)) {
                    color = HighlightColor;
                } else {
                    color = Color;
                }

                bounds.X = (bounds.Width - numberSize.Width) / 2f + .5f;
                bounds.Y += 2f;

                CALayer badge = new CALayer ();
                badge.Frame = rect;

                var imageSize = badge.Frame.Size;

                // Render the image @x2 for retina people
                if (UIScreen.MainScreen.Scale == 2) {
                    imageSize = new SizeF (imageSize.Width * 2, imageSize.Height * 2);
                    badge.Frame = new RectangleF (badge.Frame.Location, new SizeF (
                        badge.Frame.Width * 2, badge.Frame.Height * 2));

                    fontSize *= 2;
                    bounds.X = ((bounds.Width * 2) - (numberSize.Width * 2)) / 2f + 1;
                    bounds.Y += 3;
                    bounds.Width *= 2;
                    radius *= 2;
                }

                badge.BackgroundColor = color.CGColor;
                badge.CornerRadius = radius;

                UIGraphics.BeginImageContext (imageSize);
                var context = UIGraphics.GetCurrentContext ();

                context.SaveState ();
                badge.RenderInContext (context);
                context.RestoreState ();

                context.SetBlendMode (CGBlendMode.Clear);
                text.DrawString (bounds, UIFont.BoldSystemFontOfSize (fontSize), UILineBreakMode.Clip);
                context.SetBlendMode (CGBlendMode.Normal);

                var outputImage = UIGraphics.GetImageFromCurrentImageContext ();
                UIGraphics.EndImageContext ();

                outputImage.Draw (rect);
                if (Parent.SelectionStyle == UITableViewCellSelectionStyle.None && (Parent.Highlighted || Parent.Selected) && Shadow) {
                    Layer.CornerRadius = radius;
                    Layer.ShadowOffset = new SizeF (0f, 1f);
                    Layer.ShadowRadius = 1f;
                    Layer.ShadowOpacity = .8f;
                } else {
                    Layer.CornerRadius = radius;
                    Layer.ShadowOffset = SizeF.Empty;
                    Layer.ShadowRadius = 0f;
                    Layer.ShadowOpacity = 0f;
                }
            }