예제 #1
0
		public override void DrawInContext (CGContext ctx)
		{
			UIGraphics.PushContext (ctx);
			CGRect bounds = this.Bounds;
			TKFill fill = this.LabelStyle.Fill;
			TKStroke stroke = new TKStroke (UIColor.Black);
			TKBalloonShape shape = new TKBalloonShape (TKBalloonShapeArrowPosition.Bottom ,new CGSize(bounds.Size.Width - stroke.Width, bounds.Size.Height - stroke.Width));
			CGRect textRect;
			if (this.IsOutsideBounds == true) {
				shape.ArrowPosition = TKBalloonShapeArrowPosition.Top;
				textRect = new CGRect (bounds.Left, bounds.Top - this.LabelStyle.Insets.Top + shape.ArrowSize.Height, bounds.Size.Width, bounds.Size.Height + this.LabelStyle.Insets.Bottom);
			} else {
				textRect = new CGRect (bounds.Left, bounds.Top - this.LabelStyle.Insets.Top, bounds.Size.Width, bounds.Size.Height + this.LabelStyle.Insets.Bottom);
			}

			shape.DrawInContext (ctx, new CGPoint (bounds.GetMidX (), bounds.GetMidY ()), new TKDrawing[]{ fill, stroke });
			NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle ();
			paragraphStyle.Alignment = this.LabelStyle.TextAlignment;
			NSDictionary attributes = new NSDictionary (UIStringAttributeKey.Font, UIFont.SystemFontOfSize (18),
				UIStringAttributeKey.ForegroundColor, this.LabelStyle.TextColor, 
				UIStringAttributeKey.ParagraphStyle, paragraphStyle);

			NSString text = new NSString (this.Text);
			text.WeakDrawString (textRect, NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null);
			UIGraphics.PopContext ();
		}
예제 #2
0
        public static CGSize DrawString(this NSString item, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment)
        {
            // Get paragraph style
            var labelStyle = new NSMutableParagraphStyle(NSParagraphStyle.DefaultParagraphStyle.MutableCopy() as AppKit.NSMutableParagraphStyle);

            // Adjust alignment
            labelStyle.Alignment = alignment;

            // Adjust line break mode
            labelStyle.LineBreakMode = mode;

            // Define attributes
            var attributes = new NSStringAttributes()
            {
                Font            = font.NSFont,
                ForegroundColor = UIStringDrawing.FillColor,
                ParagraphStyle  = labelStyle
            };

            // Preform drawing
            item.DrawInRect(rect, attributes);

            // Return new bounding size
            return(new CGSize(rect.Width, rect.Height));
        }
예제 #3
0
        public override void Draw(CGRect frame)
        {
            //// General Declarations
            var context = UIGraphics.GetCurrentContext();

            //// Rectangle Drawing
            var rectanglePath = UIBezierPath.FromRoundedRect(new CGRect(frame.GetMinX() + 14.0f, frame.GetMinY() + 2.0f, NMath.Floor((frame.Width - 14.0f) * 0.20776f + 0.5f), 21.0f), UIRectCorner.TopLeft | UIRectCorner.TopRight, new SizeF(4.0f, 4.0f));
            rectanglePath.ClosePath();
            Helpers.Colours.Green.SetFill();
            rectanglePath.Fill();


            //// Rectangle 2 Drawing
            var rectangle2Path = UIBezierPath.FromRect(new CGRect(frame.GetMinX(), frame.GetMinY() + 23.0f, 375.0f, 1.0f));
            Helpers.Colours.Green.SetFill();
            rectangle2Path.Fill();


            //// Text Drawing
            CGRect textRect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * 0.03733f + 0.5f), frame.GetMinY() + 3.0f, NMath.Floor(frame.Width * 0.23733f + 0.5f) - NMath.Floor(frame.Width * 0.03733f + 0.5f), 21.0f);
            UIColor.White.SetFill();
            var textStyle = new NSMutableParagraphStyle();
            textStyle.Alignment = UITextAlignment.Center;

            var textFontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Medium", UIFont.SmallSystemFontSize), ForegroundColor = UIColor.White, ParagraphStyle = textStyle };
            var textTextHeight = new NSString(header).GetBoundingRect(new CGSize(textRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, textFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(textRect);
            new NSString(header).DrawString(new CGRect(textRect.GetMinX(), textRect.GetMinY() + (textRect.Height - textTextHeight) / 2.0f, textRect.Width, textTextHeight), UIFont.FromName("Avenir-Medium", UIFont.SmallSystemFontSize), UILineBreakMode.WordWrap, UITextAlignment.Center);
            context.RestoreState();

        }
        public override void setData()
        {
            lblTitle.Text = "Beschrijving";

            //shows button depending on action
            add = _appController.ShowAdd;
            imgAction.Image = add ? UIImage.FromBundle ("SharedAssets/add_white") : UIImage.FromBundle ("SharedAssets/delete_white");

            if (hidden) {
                lblNumber.Text = "";
                lblHead.Text = "...";
                lblBody.Text = _appController.CurrentTotem.body.Replace (_appController.CurrentTotem.title, "...");
            } else {

                //styling for title (totem name)
                var paragraphStyleTitle = new NSMutableParagraphStyle ();
                paragraphStyleTitle.LineSpacing = 15;

                //styling for synonyms
                var paragraphStyleSyn = new NSMutableParagraphStyle ();
                paragraphStyleSyn.LineSpacing = 20;

                var titleAttributes = new UIStringAttributes {
                    Font = UIFont.FromName ("VerveineW01-Regular", 35f),
                    ParagraphStyle = paragraphStyleTitle
                };

                var synonymsAttributes = new UIStringAttributes {
                    Font = UIFont.FromName ("DIN-LightItalic", 17f),
                    ParagraphStyle = paragraphStyleSyn
                };

                var content = _appController.CurrentTotem.title;
                if (_appController.CurrentTotem.synonyms != null)
                    content += " - " + _appController.CurrentTotem.synonyms;

                //whitespace for UI purposes
                content += "\n";

                //applying attributes
                var title_synonyms = new NSMutableAttributedString (content);
                title_synonyms.SetAttributes (titleAttributes.Dictionary, new NSRange (0, _appController.CurrentTotem.title.Length));
                title_synonyms.SetAttributes (synonymsAttributes.Dictionary, new NSRange (_appController.CurrentTotem.title.Length, (title_synonyms.Length - _appController.CurrentTotem.title.Length)));

                lblNumber.Text = _appController.CurrentTotem.number + ". ";
                lblHead.AttributedText = title_synonyms;

                lblBody.Text = _appController.CurrentTotem.body;
            }

            imgLine.Image = UIImage.FromBundle ("SharedAssets/Lijn_bold");
            imgReturn.Image = UIImage.FromBundle ("SharedAssets/arrow_back_white");
            imgHidden.Image = hidden ? UIImage.FromBundle ("SharedAssets/visibility_white") : UIImage.FromBundle ("SharedAssets/visibility_off_white");
        }
예제 #5
0
		public override void ViewDidLayoutSubviews ()
		{
			base.ViewDidLayoutSubviews ();

			var paragraphStyle = new NSMutableParagraphStyle { HyphenationFactor = 1 };
			var attributedString = new NSMutableAttributedString(
				HomeViewModel?.FirstAppointment?.Description ?? string.Empty, 
				paragraphStyle: paragraphStyle);

			meetingDescriptionLabel.AttributedText = attributedString;
			meetingDescriptionLabel.SizeToFit ();
		}
예제 #6
0
        public override CGSize SizeThatFits(CGSize size)
        {
            NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle ();
            paragraphStyle.Alignment = this.Style.TextAlignment;
            NSDictionary attributes = new NSDictionary (UIStringAttributeKey.Font, UIFont.SystemFontOfSize (18),
                                          UIStringAttributeKey.ForegroundColor, this.Style.TextColor,
                                          UIStringAttributeKey.ParagraphStyle, paragraphStyle);

            CGSize textSize = (new NSString (this.Text)).WeakGetSizeUsingAttributes (attributes);
            CGSize labelSize = new SizeF ((float)(textSize.Width - 1.5 * (this.Style.Insets.Left + this.Style.Insets.Right) + Math.Abs (this.Style.ShadowOffset.Width)),
                                  (float)(textSize.Height - 1.5 * (this.Style.Insets.Top + this.Style.Insets.Bottom) + Math.Abs (this.Style.ShadowOffset.Height)));
            return labelSize;
        }
예제 #7
0
		public static NSAttributedString ParseStringForKeywords (ParseableString obj, string str)
		{

			if (String.IsNullOrEmpty (str)) {
				return new NSMutableAttributedString ("");
			}

			NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle ();
			paragraphStyle.LineSpacing = 2;

			NSMutableAttributedString attributedString = new NSMutableAttributedString (str);
			attributedString.BeginEditing ();
			attributedString.AddAttribute (UIStringAttributeKey.ForegroundColor, UIColor.FromRGB (129, 132, 136), new NSRange (0, attributedString.Value.Length));
			attributedString.AddAttribute (UIStringAttributeKey.Font, UIFont.FromName ("Arial", 16), new NSRange (0, attributedString.Value.Length));
			attributedString.AddAttribute (UIStringAttributeKey.ParagraphStyle, paragraphStyle, new NSRange (0, attributedString.Value.Length));

			if (obj.handles == null) {
				List<NSRange> handles = RangedOfStringInString (new NSString ("@"), str, str);
				obj.handles = new List<int> ();
				if (handles.Count > 0) {
					for (int i = 0; i < handles.Count; i++) {
						obj.handles.Add ((int)handles [i].Location);
						obj.handles.Add ((int)handles [i].Length);
					}
				} 
			}
			ChangeColorOfTextInRanges (obj.handles, attributedString);

			if (obj.hashes == null) {
				List<NSRange> hashes = RangedOfStringInString (new NSString ("#"), str, str);
				obj.hashes = new List<int> ();
				if (hashes.Count > 0) {
					for (int i = 0; i < hashes.Count; i++) {
						obj.hashes.Add ((int)hashes [i].Location);
						obj.hashes.Add ((int)hashes [i].Length);
					}
				}
			}
			ChangeColorOfTextInRanges (obj.hashes, attributedString);


			return attributedString;
		}
예제 #8
0
		public static CGSize DrawString (this NSString item, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment) {

			// Get paragraph style
			var labelStyle = new NSMutableParagraphStyle(NSParagraphStyle.DefaultParagraphStyle.MutableCopy() as AppKit.NSMutableParagraphStyle);

			// Adjust alignment
			labelStyle.Alignment = alignment;

			// Adjust line break mode
			labelStyle.LineBreakMode = mode;

			// Define attributes
			var attributes = new NSStringAttributes () {
				Font = font.NSFont,
				ForegroundColor = UIStringDrawing.FillColor,
				ParagraphStyle = labelStyle
			};

			// Preform drawing
			item.DrawInRect(rect, attributes);

			// Return new bounding size
			return new CGSize (rect.Width, rect.Height);
		}
        void DrawCanvas(CGRect frame)
        {
            //// General Declarations
            var context = UIGraphics.GetCurrentContext();

            //// Color Declarations
            var color = UIColor.FromRGBA(0.851f, 0.851f, 0.851f, 1.000f);
            var fillColor3 = UIColor.FromRGBA(0.333f, 0.333f, 0.333f, 1.000f);
            var fillColor4 = UIColor.FromRGBA(0.000f, 0.000f, 0.000f, 1.000f);
            var fillColor5 = UIColor.FromRGBA(0.867f, 0.867f, 0.863f, 1.000f);
            var fillColor6 = UIColor.FromRGBA(0.671f, 0.671f, 0.671f, 1.000f);
            var fillColor7 = UIColor.FromRGBA(0.467f, 0.467f, 0.467f, 1.000f);
            var fillColor8 = UIColor.FromRGBA(0.918f, 0.478f, 0.149f, 1.000f);
            var fillColor9 = UIColor.FromRGBA(0.529f, 0.529f, 0.529f, 1.000f);
            var fillColor10 = UIColor.FromRGBA(0.271f, 0.271f, 0.271f, 1.000f);
            var color2 = UIColor.FromRGBA(0.941f, 0.941f, 0.941f, 1.000f);
            var color5 = UIColor.FromRGBA(0.275f, 0.275f, 0.275f, 1.000f);

            //// Rectangle Drawing
            var rectanglePath = UIBezierPath.FromRoundedRect(new CGRect(frame.GetMinX(), frame.GetMinY() + NMath.Floor((frame.Height) * 0.00000f + 0.5f), frame.Width - 0.5f, frame.Height - NMath.Floor((frame.Height) * 0.00000f + 0.5f)), 4.0f);
            color2.SetFill();
            rectanglePath.Fill();
            color.SetStroke();
            rectanglePath.LineWidth = 1.0f;
            rectanglePath.Stroke();


            //// Group 2
            {
                context.SaveState();
                context.TranslateCTM(frame.GetMinX() + 0.43716f * frame.Width, frame.GetMinY() + 0.12195f * frame.Height);
                context.ScaleCTM(0.4f, 0.4f);



                //// Rectangle 2 Drawing
                var rectangle2Path = UIBezierPath.FromRect(new CGRect(0.0f, 36.0f, 112.0f, 36.0f));
                fillColor3.SetFill();
                rectangle2Path.Fill();


                //// Rectangle 3 Drawing
                var rectangle3Path = UIBezierPath.FromRect(new CGRect(0.0f, 72.0f, 112.0f, 8.0f));
                fillColor4.SetFill();
                rectangle3Path.Fill();


                //// Bezier Drawing
                UIBezierPath bezierPath = new UIBezierPath();
                bezierPath.MoveTo(new CGPoint(0.0f, 80.0f));
                bezierPath.AddCurveToPoint(new CGPoint(8.0f, 88.0f), new CGPoint(0.0f, 84.42f), new CGPoint(3.58f, 88.0f));
                bezierPath.AddLineTo(new CGPoint(104.0f, 88.0f));
                bezierPath.AddCurveToPoint(new CGPoint(112.0f, 80.0f), new CGPoint(108.42f, 88.0f), new CGPoint(112.0f, 84.42f));
                bezierPath.AddLineTo(new CGPoint(0.0f, 80.0f));
                bezierPath.AddLineTo(new CGPoint(0.0f, 80.0f));
                bezierPath.ClosePath();
                bezierPath.UsesEvenOddFillRule = true;

                fillColor5.SetFill();
                bezierPath.Fill();


                //// Bezier 2 Drawing
                UIBezierPath bezier2Path = new UIBezierPath();
                bezier2Path.MoveTo(new CGPoint(56.3f, 88.0f));
                bezier2Path.AddLineTo(new CGPoint(104.0f, 88.0f));
                bezier2Path.AddCurveToPoint(new CGPoint(112.0f, 80.0f), new CGPoint(108.42f, 88.0f), new CGPoint(112.0f, 84.42f));
                bezier2Path.AddLineTo(new CGPoint(48.3f, 80.0f));
                bezier2Path.AddLineTo(new CGPoint(56.3f, 88.0f));
                bezier2Path.AddLineTo(new CGPoint(56.3f, 88.0f));
                bezier2Path.ClosePath();
                bezier2Path.UsesEvenOddFillRule = true;

                fillColor6.SetFill();
                bezier2Path.Fill();


                //// Rectangle 4 Drawing
                var rectangle4Path = UIBezierPath.FromRect(new CGRect(0.0f, 28.0f, 112.0f, 8.0f));
                fillColor4.SetFill();
                rectangle4Path.Fill();


                //// Bezier 3 Drawing
                UIBezierPath bezier3Path = new UIBezierPath();
                bezier3Path.MoveTo(new CGPoint(104.0f, 8.0f));
                bezier3Path.AddLineTo(new CGPoint(76.0f, 8.0f));
                bezier3Path.AddLineTo(new CGPoint(68.0f, 0.0f));
                bezier3Path.AddLineTo(new CGPoint(44.0f, 0.0f));
                bezier3Path.AddLineTo(new CGPoint(36.0f, 8.0f));
                bezier3Path.AddLineTo(new CGPoint(8.0f, 8.0f));
                bezier3Path.AddCurveToPoint(new CGPoint(0.0f, 16.0f), new CGPoint(3.6f, 8.0f), new CGPoint(0.0f, 11.6f));
                bezier3Path.AddLineTo(new CGPoint(0.0f, 28.0f));
                bezier3Path.AddLineTo(new CGPoint(112.0f, 28.0f));
                bezier3Path.AddLineTo(new CGPoint(112.0f, 16.0f));
                bezier3Path.AddCurveToPoint(new CGPoint(104.0f, 8.0f), new CGPoint(112.0f, 11.58f), new CGPoint(108.42f, 8.0f));
                bezier3Path.AddLineTo(new CGPoint(104.0f, 8.0f));
                bezier3Path.ClosePath();
                bezier3Path.UsesEvenOddFillRule = true;

                fillColor5.SetFill();
                bezier3Path.Fill();


                //// Oval Drawing
                var ovalPath = UIBezierPath.FromOval(new CGRect(28.0f, 20.0f, 56.0f, 56.0f));
                fillColor7.SetFill();
                ovalPath.Fill();


                //// Oval 2 Drawing
                var oval2Path = UIBezierPath.FromOval(new CGRect(32.0f, 24.0f, 48.0f, 48.0f));
                fillColor4.SetFill();
                oval2Path.Fill();


                //// Oval 3 Drawing
                var oval3Path = UIBezierPath.FromOval(new CGRect(8.0f, 16.0f, 8.0f, 8.0f));
                fillColor8.SetFill();
                oval3Path.Fill();


                //// Group 3
                {
                    context.SaveState();
                    context.SetAlpha(0.4f);
                    context.BeginTransparencyLayer();


                    //// Bezier 4 Drawing
                    UIBezierPath bezier4Path = new UIBezierPath();
                    bezier4Path.MoveTo(new CGPoint(104.0f, 24.0f));
                    bezier4Path.AddLineTo(new CGPoint(96.0f, 24.0f));
                    bezier4Path.AddLineTo(new CGPoint(104.0f, 16.0f));
                    bezier4Path.AddLineTo(new CGPoint(104.0f, 24.0f));
                    bezier4Path.ClosePath();
                    bezier4Path.UsesEvenOddFillRule = true;

                    fillColor3.SetFill();
                    bezier4Path.Fill();


                    context.EndTransparencyLayer();
                    context.RestoreState();
                }


                //// Bezier 5 Drawing
                UIBezierPath bezier5Path = new UIBezierPath();
                bezier5Path.MoveTo(new CGPoint(96.0f, 24.0f));
                bezier5Path.AddLineTo(new CGPoint(96.0f, 16.0f));
                bezier5Path.AddLineTo(new CGPoint(104.0f, 16.0f));
                bezier5Path.AddLineTo(new CGPoint(96.0f, 24.0f));
                bezier5Path.ClosePath();
                bezier5Path.UsesEvenOddFillRule = true;

                fillColor9.SetFill();
                bezier5Path.Fill();


                //// Oval 4 Drawing
                var oval4Path = UIBezierPath.FromOval(new CGRect(40.0f, 32.0f, 32.0f, 32.0f));
                fillColor3.SetFill();
                oval4Path.Fill();


                //// Bezier 6 Drawing
                UIBezierPath bezier6Path = new UIBezierPath();
                bezier6Path.MoveTo(new CGPoint(60.0f, 36.0f));
                bezier6Path.AddCurveToPoint(new CGPoint(44.0f, 52.0f), new CGPoint(51.16f, 36.0f), new CGPoint(44.0f, 43.16f));
                bezier6Path.AddCurveToPoint(new CGPoint(46.88f, 61.12f), new CGPoint(44.0f, 55.4f), new CGPoint(45.07f, 58.53f));
                bezier6Path.AddCurveToPoint(new CGPoint(56.0f, 64.0f), new CGPoint(49.47f, 62.93f), new CGPoint(52.6f, 64.0f));
                bezier6Path.AddCurveToPoint(new CGPoint(72.0f, 48.0f), new CGPoint(64.84f, 64.0f), new CGPoint(72.0f, 56.84f));
                bezier6Path.AddCurveToPoint(new CGPoint(69.12f, 38.88f), new CGPoint(72.0f, 44.6f), new CGPoint(70.93f, 41.47f));
                bezier6Path.AddCurveToPoint(new CGPoint(60.0f, 36.0f), new CGPoint(66.53f, 37.07f), new CGPoint(63.4f, 36.0f));
                bezier6Path.AddLineTo(new CGPoint(60.0f, 36.0f));
                bezier6Path.ClosePath();
                bezier6Path.UsesEvenOddFillRule = true;

                fillColor7.SetFill();
                bezier6Path.Fill();


                //// Oval 5 Drawing
                var oval5Path = UIBezierPath.FromOval(new CGRect(48.0f, 40.0f, 12.0f, 12.0f));
                fillColor6.SetFill();
                oval5Path.Fill();


                //// Oval 6 Drawing
                var oval6Path = UIBezierPath.FromOval(new CGRect(60.0f, 48.0f, 8.0f, 8.0f));
                fillColor5.SetFill();
                oval6Path.Fill();


                //// Group 4
                {
                    context.SaveState();
                    context.SetAlpha(0.4f);
                    context.BeginTransparencyLayer();


                    //// Bezier 7 Drawing
                    UIBezierPath bezier7Path = new UIBezierPath();
                    bezier7Path.MoveTo(new CGPoint(41.65f, 72.0f));
                    bezier7Path.AddCurveToPoint(new CGPoint(35.96f, 67.54f), new CGPoint(39.57f, 70.75f), new CGPoint(37.65f, 69.26f));
                    bezier7Path.AddLineTo(new CGPoint(35.9f, 67.6f));
                    bezier7Path.AddLineTo(new CGPoint(40.3f, 72.0f));
                    bezier7Path.AddLineTo(new CGPoint(41.65f, 72.0f));
                    bezier7Path.AddLineTo(new CGPoint(41.65f, 72.0f));
                    bezier7Path.ClosePath();
                    bezier7Path.UsesEvenOddFillRule = true;

                    fillColor3.SetFill();
                    bezier7Path.Fill();


                    context.EndTransparencyLayer();
                    context.RestoreState();
                }


                //// Bezier 8 Drawing
                UIBezierPath bezier8Path = new UIBezierPath();
                bezier8Path.MoveTo(new CGPoint(81.26f, 36.0f));
                bezier8Path.AddCurveToPoint(new CGPoint(84.0f, 48.0f), new CGPoint(83.0f, 39.64f), new CGPoint(84.0f, 43.7f));
                bezier8Path.AddCurveToPoint(new CGPoint(70.36f, 72.0f), new CGPoint(84.0f, 58.2f), new CGPoint(78.52f, 67.1f));
                bezier8Path.AddLineTo(new CGPoint(112.0f, 72.0f));
                bezier8Path.AddLineTo(new CGPoint(112.0f, 64.5f));
                bezier8Path.AddLineTo(new CGPoint(83.5f, 36.0f));
                bezier8Path.AddLineTo(new CGPoint(81.26f, 36.0f));
                bezier8Path.AddLineTo(new CGPoint(81.26f, 36.0f));
                bezier8Path.ClosePath();
                bezier8Path.UsesEvenOddFillRule = true;

                fillColor10.SetFill();
                bezier8Path.Fill();



                context.RestoreState();
            }


            //// Text Drawing
            CGRect textRect = new CGRect(frame.GetMinX() + 7.0f, frame.GetMinY() + NMath.Floor((frame.Height - 8.0f) * 0.67568f + 0.5f), frame.Width - 14.0f, frame.Height - 8.0f - NMath.Floor((frame.Height - 8.0f) * 0.67568f + 0.5f));
            {
                var textContent = "Picture Search";
                color5.SetFill();
                var textStyle = new NSMutableParagraphStyle();
                textStyle.Alignment = UITextAlignment.Center;

                var textFontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Medium", UIFont.ButtonFontSize), ForegroundColor = color5, ParagraphStyle = textStyle };
                var textTextHeight = new NSString(textContent).GetBoundingRect(new CGSize(textRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, textFontAttributes, null).Height;
                context.SaveState();
                context.ClipToRect(textRect);
                new NSString(textContent).DrawString(new CGRect(textRect.GetMinX(), textRect.GetMinY() + (textRect.Height - textTextHeight) / 2.0f, textRect.Width, textTextHeight), UIFont.FromName("Avenir-Medium", UIFont.ButtonFontSize), UILineBreakMode.WordWrap, UITextAlignment.Center);
                context.RestoreState();
            }
        }
        //// Drawing Methods

        public static void DrawUISwitch(bool inFocus, bool switchOn)
        {
            //// General Declarations
            var context = UIGraphics.GetCurrentContext();


            //// Shadow Declarations
            var shadow = new NSShadow();
            shadow.ShadowColor = CustomControlsStyleKit.ShadowColor;
            shadow.ShadowOffset = new CGSize(0.1f, 5.1f);
            shadow.ShadowBlurRadius = 5.0f;

            //// Variable Declarations
            var thumbHeight = inFocus ? 85.0f : 65.0f;
            var thumbY = inFocus ? 6.0f : 16.0f;
            var thumbColor = inFocus ? CustomControlsStyleKit.InFocusThumbColor : CustomControlsStyleKit.UnFocusedThumbColor;
            var textColor = inFocus ? CustomControlsStyleKit.InFocusTextColor : CustomControlsStyleKit.UnFocusedTextColor;
            var gutterColor = switchOn ? (inFocus ? CustomControlsStyleKit.OnColor : CustomControlsStyleKit.OnColorUnFocused) : (inFocus ? CustomControlsStyleKit.OffColor : CustomControlsStyleKit.OffColorUnFocused);
            var thumbX = switchOn ? 147.0f : 11.0f;
            var switchOff = !switchOn;

            //// Gutter Drawing
            var gutterPath = UIBezierPath.FromRoundedRect(new CGRect(11.0f, 16.0f, 227.0f, 67.0f), 4.0f);
            gutterColor.SetFill();
            gutterPath.Fill();

            ////// Gutter Inner Shadow
            context.SaveState();
            context.ClipToRect(gutterPath.Bounds);
            context.SetShadow(new CGSize(0, 0), 0);
            context.SetAlpha(shadow.ShadowColor.CGColor.Alpha);
            context.BeginTransparencyLayer();
            {
                var opaqueShadow = new CGColor(shadow.ShadowColor.CGColor, 1.0f);
                context.SetShadow(shadow.ShadowOffset, shadow.ShadowBlurRadius, opaqueShadow);
                context.SetBlendMode(CGBlendMode.SourceOut);
                context.BeginTransparencyLayer();

                context.SetFillColor(opaqueShadow);
                gutterPath.Fill();

                context.EndTransparencyLayer();
            }
            context.EndTransparencyLayer();
            context.RestoreState();

            CustomControlsStyleKit.BorderColor.SetStroke();
            gutterPath.LineWidth = 2.0f;
            gutterPath.Stroke();


            //// Rectangle Drawing
            var rectanglePath = UIBezierPath.FromRoundedRect(new CGRect(thumbX, thumbY, 91.0f, thumbHeight), 4.0f);
            context.SaveState();
            context.SetShadow(shadow.ShadowOffset, shadow.ShadowBlurRadius, shadow.ShadowColor.CGColor);
            thumbColor.SetFill();
            rectanglePath.Fill();
            context.RestoreState();

            CustomControlsStyleKit.BorderColor.SetStroke();
            rectanglePath.LineWidth = 2.0f;
            rectanglePath.Stroke();


            if (switchOn)
            {
                //// OnText Drawing
                CGRect onTextRect = new CGRect(26.0f, 27.0f, 99.0f, 49.0f);
                {
                    var textContent = "ON";
                    textColor.SetFill();
                    var onTextStyle = new NSMutableParagraphStyle ();
                    onTextStyle.Alignment = UITextAlignment.Center;

                    var onTextFontAttributes = new UIStringAttributes () {Font = UIFont.BoldSystemFontOfSize(27.0f), ForegroundColor = textColor, ParagraphStyle = onTextStyle};
                    var onTextTextHeight = new NSString(textContent).GetBoundingRect(new CGSize(onTextRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, onTextFontAttributes, null).Height+10;
                    context.SaveState();
                    context.ClipToRect(onTextRect);
                    new NSString(textContent).DrawString(new CGRect(onTextRect.GetMinX(), onTextRect.GetMinY() + (onTextRect.Height - onTextTextHeight) / 2.0f, onTextRect.Width, onTextTextHeight), UIFont.BoldSystemFontOfSize(27.0f), UILineBreakMode.WordWrap, UITextAlignment.Center);
                    context.RestoreState();
                }
            }


            if (switchOff)
            {
                //// OffText Drawing
                CGRect offTextRect = new CGRect(123.0f, 27.0f, 99.0f, 49.0f);
                {
                    var textContent = "OFF";
                    textColor.SetFill();
                    var offTextStyle = new NSMutableParagraphStyle ();
                    offTextStyle.Alignment = UITextAlignment.Center;

                    var offTextFontAttributes = new UIStringAttributes () {Font = UIFont.BoldSystemFontOfSize(27.0f), ForegroundColor = textColor, ParagraphStyle = offTextStyle};
                    var offTextTextHeight = new NSString(textContent).GetBoundingRect(new CGSize(offTextRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, offTextFontAttributes, null).Height+10;
                    context.SaveState();
                    context.ClipToRect(offTextRect);
                    new NSString(textContent).DrawString(new CGRect(offTextRect.GetMinX(), offTextRect.GetMinY() + (offTextRect.Height - offTextTextHeight) / 2.0f, offTextRect.Width, offTextTextHeight), UIFont.BoldSystemFontOfSize(27.0f), UILineBreakMode.WordWrap, UITextAlignment.Center);
                    context.RestoreState();
                }
            }
        }
        public static void DrawUIControlWell(CGRect frame, bool inFocus, string title)
        {
            //// General Declarations
            var context = UIGraphics.GetCurrentContext();

            //// Color Declarations
            var wellColor = UIColor.FromRGBA(0.029f, 0.029f, 0.029f, 0.189f);

            //// Variable Declarations
            var textColor = inFocus ? CustomControlsStyleKit.InFocusTextColor : CustomControlsStyleKit.UnFocusedTextColor;

            //// Background Drawing
            var backgroundPath = UIBezierPath.FromRoundedRect(new CGRect(frame.GetMinX() + 1.0f, frame.GetMinY() + 1.0f, NMath.Floor((frame.Width - 1.0f) * 0.99749f + 0.5f), NMath.Floor((frame.Height - 1.0f) * 0.98990f + 0.5f)), 4.0f);
            wellColor.SetFill();
            backgroundPath.Fill();


            //// Text Drawing
            CGRect textRect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * 0.03250f + 0.5f), frame.GetMinY() + NMath.Floor(frame.Height * 0.19000f + 0.5f), NMath.Floor(frame.Width * 0.97250f + 0.5f) - NMath.Floor(frame.Width * 0.03250f + 0.5f), NMath.Floor(frame.Height * 0.80000f + 0.5f) - NMath.Floor(frame.Height * 0.19000f + 0.5f));
            textColor.SetFill();
            var textStyle = new NSMutableParagraphStyle ();
            textStyle.Alignment = UITextAlignment.Center;

            var textFontAttributes = new UIStringAttributes () {Font = UIFont.BoldSystemFontOfSize(27.0f), ForegroundColor = textColor, ParagraphStyle = textStyle};
            var textTextHeight = new NSString(title).GetBoundingRect(new CGSize(textRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, textFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(textRect);
            new NSString(title).DrawString(new CGRect(textRect.GetMinX(), textRect.GetMinY() + (textRect.Height - textTextHeight) / 2.0f, textRect.Width, textTextHeight), UIFont.BoldSystemFontOfSize(27.0f), UILineBreakMode.WordWrap, UITextAlignment.Center);
            context.RestoreState();
        }
        //// Drawing Methods

        public static void DrawLightMapPoint(float lightColorR, float lightColorG, float lightColorB, float lightColorA, string rank, float fontSize)
        {
            //// General Declarations
            var context = UIGraphics.GetCurrentContext();

            //// Color Declarations
            var lightBaseColor = UIColor.FromRGBA(0.009f, 0.471f, 0.009f, 1.000f);

            //// Shadow Declarations
            var shadow = new NSShadow();
            shadow.ShadowColor = UIColor.Black.ColorWithAlpha(0.62f);
            shadow.ShadowOffset = new CGSize(0.1f, -0.1f);
            shadow.ShadowBlurRadius = 5.0f;

            //// Variable Declarations
            var lightColor = UIColor.FromRGBA(lightColorR, lightColorG, lightColorB, lightColorA);

            //// LightIcon
            {
                //// Oval Drawing
                var ovalPath = UIBezierPath.FromOval(new CGRect(1.0f, 1.0f, 18.0f, 38.0f));
                lightColor.SetFill();
                ovalPath.Fill();

                ////// Oval Inner Shadow
                context.SaveState();
                context.ClipToRect(ovalPath.Bounds);
                context.SetShadow(new CGSize(0, 0), 0);
                context.SetAlpha(shadow.ShadowColor.CGColor.Alpha);
                context.BeginTransparencyLayer();
                {
                    var opaqueShadow = new CGColor(shadow.ShadowColor.CGColor, 1.0f);
                    context.SetShadow(shadow.ShadowOffset, shadow.ShadowBlurRadius, opaqueShadow);
                    context.SetBlendMode(CGBlendMode.SourceOut);
                    context.BeginTransparencyLayer();

                    context.SetFillColor(opaqueShadow);
                    ovalPath.Fill();

                    context.EndTransparencyLayer();
                }
                context.EndTransparencyLayer();
                context.RestoreState();



                //// Rectangle Drawing
                var rectanglePath = UIBezierPath.FromRect(new CGRect(3.0f, 34.0f, 14.0f, 12.0f));
                lightBaseColor.SetFill();
                rectanglePath.Fill();

                ////// Rectangle Inner Shadow
                context.SaveState();
                context.ClipToRect(rectanglePath.Bounds);
                context.SetShadow(new CGSize(0, 0), 0);
                context.SetAlpha(shadow.ShadowColor.CGColor.Alpha);
                context.BeginTransparencyLayer();
                {
                    var opaqueShadow = new CGColor(shadow.ShadowColor.CGColor, 1.0f);
                    context.SetShadow(shadow.ShadowOffset, shadow.ShadowBlurRadius, opaqueShadow);
                    context.SetBlendMode(CGBlendMode.SourceOut);
                    context.BeginTransparencyLayer();

                    context.SetFillColor(opaqueShadow);
                    rectanglePath.Fill();

                    context.EndTransparencyLayer();
                }
                context.EndTransparencyLayer();
                context.RestoreState();

            }


            //// Text Drawing
            CGRect textRect = new CGRect(0.0f, 8.0f, 20.0f, 23.0f);
            UIColor.White.SetFill();
            var textStyle = new NSMutableParagraphStyle ();
            textStyle.Alignment = UITextAlignment.Center;

            var textFontAttributes = new UIStringAttributes () {Font = UIFont.SystemFontOfSize(fontSize), ForegroundColor = UIColor.White, ParagraphStyle = textStyle};
            var textTextHeight = new NSString(rank).GetBoundingRect(new CGSize(textRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, textFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(textRect);
            new NSString(rank).DrawString(new CGRect(textRect.GetMinX(), textRect.GetMinY() + (textRect.Height - textTextHeight) / 2.0f, textRect.Width, textTextHeight), UIFont.SystemFontOfSize(fontSize), UILineBreakMode.WordWrap, UITextAlignment.Center);
            context.RestoreState();
        }
        private CGRect AutoCompleteRectForBounds(CGRect bounds) 
        {
            // get bounds for whole text area
            CGRect textRectBounds = this.TextRect(bounds);

            if (this.BeginningOfDocument == null)
                return CGRect.Empty;

            // get rect for actual text
            UITextRange textRange = this.GetTextRange(this.BeginningOfDocument, this.EndOfDocument);

            CGRect textRect = this.GetFirstRectForRange(textRange).Integral();

            NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle();
            paragraphStyle.LineBreakMode = UILineBreakMode.CharacterWrap;

            NSString text = new NSString(this.Text);

            UIStringAttributes attributes = new UIStringAttributes();
            attributes.Font = this.Font;
            attributes.ParagraphStyle = paragraphStyle;

            CGRect prefixTextRect  = text.GetBoundingRect(
                textRect.Size, 
                NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, 
                attributes, null
            );

            CGSize prefixTextSize = prefixTextRect.Size;

            NSString str = new NSString(autocompleteString);

            CGRect autocompleteTextRect = str.GetBoundingRect(
                new CGSize(textRectBounds.Size.Width - prefixTextSize.Width, textRectBounds.Size.Height),
                NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, 
                attributes, null
            );

            CGSize autocompleteTextSize = autocompleteTextRect.Size;

            return new CGRect(textRect.GetMaxX() + 6, //6 - correction
                textRectBounds.GetMinY() - 1, //1 - correction
                autocompleteTextSize.Width,
                textRectBounds.Size.Height);
        }
예제 #14
0
파일: MUtils.cs 프로젝트: borain89vn/demo2
		public static MTextAttributeDTO getSizeTextAttribute (string text, UIFont font, nfloat lineSpacing, CGSize sizeContainer)
		{
			if (text == null) {
				text = "";
			}

			NSMutableAttributedString attrString = new NSMutableAttributedString (text);
			NSMutableParagraphStyle style = new NSMutableParagraphStyle ();
			style.LineSpacing = lineSpacing;
			attrString.SetAttributes (new UIStringAttributes {
				ParagraphStyle = style,
				Font = font

			}.Dictionary, new NSRange (0, text.Length));

			CGSize size = attrString.GetBoundingRect (sizeContainer, NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, null).Size;

			return new MTextAttributeDTO (attrString, size);
		}
예제 #15
0
        public static UIImage UIImage(this FA fa, CGSize size, UIColor foreground, UIColor background)
        {
            var paragraph = new NSMutableParagraphStyle ();
            paragraph.Alignment = UITextAlignment.Center;

            // Taken from FontAwesome.io's Fixed Width Icon CSS
            nfloat fontAspectRatio = 1.28571429f;

            nfloat fontSize = (nfloat)Math.Min(size.Width / fontAspectRatio, size.Height);
            var attributes = new UIStringAttributes () {
                Font = fa.Font(fontSize),
                BackgroundColor = background,
                ForegroundColor = foreground,
                ParagraphStyle = paragraph
            };

            var attributedString = new NSMutableAttributedString(fa.String(), attributes);
            var point = new CGRect (0, (size.Height - fontSize) / 2, size.Width, fontSize);
            UIGraphics.BeginImageContextWithOptions(size, false, 0f);
            attributedString.DrawString (point);

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

            return image;
        }
		private void SetupTermsTextView()
		{
			NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle();
			paragraphStyle.Alignment = UITextAlignment.Center;

			NSMutableAttributedString attributedString = new NSMutableAttributedString(Strings.accept_terms_and_conditions_to_continue);
			attributedString.BeginEditing();
			attributedString.AddAttribute(UIStringAttributeKey.Font, UIFont.FromName("Arial", 11), new NSRange(0, attributedString.Value.Length));
			attributedString.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.White, new NSRange(0, attributedString.Value.Length));
			attributedString.AddAttribute(UIStringAttributeKey.ParagraphStyle, paragraphStyle, new NSRange(0, attributedString.Value.Length));
			attributedString.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Blue, new NSRange(Strings.accept_terms_and_conditions_to_continue.IndexOf("Privacy Policy.", StringComparison.Ordinal), 15));
			attributedString.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Blue, new NSRange(Strings.accept_terms_and_conditions_to_continue.IndexOf("Terms", StringComparison.Ordinal), 5));
			attributedString.EndEditing();
			TermsTextView.AttributedText = attributedString;

			TermsTextView.SizeToFit();

			UITapGestureRecognizer tapGesture = new UITapGestureRecognizer(delegate (UITapGestureRecognizer obj)
			{
				try
				{
					UITextRange textRange = TermsTextView.Tokenizer.GetRangeEnclosingPosition(TermsTextView.GetClosestPositionToPoint(obj.LocationInView(TermsTextView)), UITextGranularity.Word, UITextDirection.Forward);
					string clickedString = TermsTextView.Text.Substring((int)TermsTextView.GetOffsetFromPosition(TermsTextView.BeginningOfDocument, textRange.Start), 5);
					if (clickedString.Contains("Priva") || clickedString.Contains("Polic"))
					{
						WebViewController wvc = new WebViewController();
						wvc.URL = Strings.web_url_base + Strings.web_url_privacy_policy;
						this.NavigationController.PushViewController(wvc, true);
						return;
					}
					if (clickedString.Contains("Terms"))
					{
						WebViewController wvc = new WebViewController();
						wvc.URL = Strings.web_url_base + Strings.web_url_terms;
						this.NavigationController.PushViewController(wvc, true);
						return;
					}
				}
				catch (Exception)
				{
					return;
				}
			});
			TermsTextView.AddGestureRecognizer(tapGesture);

		}
예제 #17
0
		void drawLabel (CGContext ctx, CGRect rect, nfloat yCoord, nfloat xCoord, UITextAlignment alignment, string label, bool flipContext = true, bool centerVertical = false)
		{
			// Draw light the sunrise and Sunset labels at the ends of the light box
			using (UIColor fontColor = UIColor.White, shadowColor = UIColor.Black.ColorWithAlpha (0.1f)) {

				var fontAttributes = new UIFontAttributes (new UIFontFeature (CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

				using (var desc = UIFont.SystemFontOfSize (fontSize).FontDescriptor.CreateWithAttributes (fontAttributes)) {

					using (UIFont font = UIFont.FromDescriptor (desc, fontSize)) {

						// calculating the range of our attributed string
						var range = new NSRange (0, label.Length);

						// set justification for text block
						using (var alignStyle = new NSMutableParagraphStyle { Alignment = alignment }) {

							// add stylistic attributes to out attributed string
							var stringAttributes = new UIStringAttributes {
								ForegroundColor = fontColor,
								Font = font,
								ParagraphStyle = alignStyle
							};

							var target = new CGSize (float.MaxValue, float.MaxValue);

							NSRange fit;

							using (NSMutableAttributedString attrString = new NSMutableAttributedString (label, stringAttributes)) {

								//creating a container for out attributed string 
								using (CTFramesetter framesetter = new CTFramesetter (attrString)) {


									CGSize frameSize = framesetter.SuggestFrameSize (range, null, target, out fit);


									if (alignment == UITextAlignment.Center) xCoord -= (frameSize.Width / 2);

									if (alignment == UITextAlignment.Right) xCoord -= frameSize.Width;


									// subtract the frameSize so the flipped context behaves as expected
									yCoord -= frameSize.Height;

									if (centerVertical) yCoord += (frameSize.Height / 2);


									var textRect = new CGRect (xCoord, yCoord, frameSize.Width, frameSize.Height);

									using (CGPath path = new CGPath ()) {

										path.AddRect (textRect);

										ctx.SetShadow (new CGSize (0.0f, 1.0f), 0.0f, shadowColor.CGColor);

										using (CTFrame frame = framesetter.GetFrame (range, path, null)) {

											if (flipContext) {

												ctx.SaveState ();
												ctx.TranslateCTM (0, rect.Height);
												ctx.ScaleCTM (1, -1);

												frame.Draw (ctx);

												ctx.RestoreState ();

											} else {

												frame.Draw (ctx);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
예제 #18
0
		public nfloat GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
		{
			if (this.TableView == tableView) {
				var message = messages [indexPath.Row];
			
				var paragraphStyle = new NSMutableParagraphStyle ();
				paragraphStyle.LineBreakMode = UILineBreakMode.WordWrap;
				paragraphStyle.Alignment = UITextAlignment.Left;

				var pointSize = MessageTableViewCell.DefaultFontSize;
				var attributes = new UIStringAttributes {
					Font = UIFont.SystemFontOfSize (pointSize),
					ParagraphStyle = paragraphStyle
				};
			
				var width = tableView.Frame.Width - MessageTableViewCell.AvatarHeight;
				width -= 25.0f;
			
				var titleBounds = ((NSString)message.Username).GetBoundingRect (new CGSize (width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null);
				var bodyBounds = ((NSString)message.Text).GetBoundingRect (new CGSize (width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null);
			
				if (message.Text.Length == 0) {
					return 0.0f;
				}
			
				var height = titleBounds.Height;
				height += bodyBounds.Height;
				height += 40.0f;
			
				if (height < MessageTableViewCell.MinimumHeight) {
					height = MessageTableViewCell.MinimumHeight;
				}
			
				return height;
			} else {
				return MessageTableViewCell.MinimumHeight;
			}
		}
        internal CCTexture2D CreateTextSprite(string text, CCFontDefinition textDefinition)
        {
            if (string.IsNullOrEmpty(text))
                return new CCTexture2D();

            int imageWidth;
            int imageHeight;
            var textDef = textDefinition;
            var contentScaleFactorWidth = CCLabel.DefaultTexelToContentSizeRatios.Width;
            var contentScaleFactorHeight = CCLabel.DefaultTexelToContentSizeRatios.Height;
            textDef.FontSize *= contentScaleFactorWidth;
            textDef.Dimensions.Width *= contentScaleFactorWidth;
            textDef.Dimensions.Height *= contentScaleFactorHeight;

            //bool hasPremultipliedAlpha;

            // font
            NSFont font = null;

            var ext = System.IO.Path.GetExtension(textDef.FontName);
            if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
            {
                try 
                {
                    textDef.FontName = LoadFontFile(textDef.FontName);
                    font = NSFont.FromFontName(textDef.FontName, textDef.FontSize);
                }
                catch
                {
                    CCLog.Log(".ttf {0} file not found or can not be loaded.", textDef.FontName);
                }
            }
            else
            {
                // font
                font = NSFontManager.SharedFontManager.FontWithFamily(textDef.FontName, NSFontTraitMask.Unbold | NSFontTraitMask.Unitalic, 0, textDef.FontSize);
            }

            if (font == null) 
            {
                font = NSFontManager.SharedFontManager.FontWithFamily("Arial", NSFontTraitMask.Unbold | NSFontTraitMask.Unitalic, 0, textDef.FontSize);
                CCLog.Log("{0} not found.  Defaulting to Arial.", textDef.FontName);
            }

            // color
            var foregroundColor = NSColor.White;

            // alignment
            var horizontalAlignment = textDef.Alignment;
            var verticleAlignement = textDef.LineAlignment;

            var textAlign = (CCTextAlignment.Right == horizontalAlignment) ? NSTextAlignment.Right
                : (CCTextAlignment.Center == horizontalAlignment) ? NSTextAlignment.Center
                : NSTextAlignment.Left;

            // LineBreak
            var lineBreak = (CCLabelLineBreak.Character == textDef.LineBreak) ? NSLineBreakMode.CharWrapping 
                : (CCLabelLineBreak.Word == textDef.LineBreak) ? NSLineBreakMode.ByWordWrapping
                : NSLineBreakMode.Clipping;

            var nsparagraphStyle = new NSMutableParagraphStyle();
            nsparagraphStyle.SetParagraphStyle(NSMutableParagraphStyle.DefaultParagraphStyle);
            nsparagraphStyle.LineBreakMode = lineBreak;
            nsparagraphStyle.Alignment = textAlign;

            // Create a new attributed string definition
            var nsAttributes = new NSStringAttributes ();

            // Font attribute
            nsAttributes.Font = font;
            nsAttributes.ForegroundColor = foregroundColor;
            nsAttributes.ParagraphStyle = nsparagraphStyle;

            var stringWithAttributes = new NSAttributedString(text, nsAttributes);

            var realDimensions = stringWithAttributes.Size;

            // Mac crashes if the width or height is 0
            if (realDimensions == SizeF.Empty)
            {
                CCLog.Log("Native string:", "Dimensions of native NSAttributedString can not be 0,0");
                return new CCTexture2D();
            }

            var dimensions = new SizeF(textDef.Dimensions.Width, textDef.Dimensions.Height);

            var layoutAvailable = true;

            // 
            // * Note * This seems to only effect Mac because iOS works fine without this work around.
            // Right Alignment BoundingRectWithSize does not seem to be working correctly when the following conditions are set:
            //      1) Alignment Right
            //      2) No dimensions
            //      3) There are new line characters embedded in the string.
            //
            // So we set alignment to Left, calculate our bounds and then restore alignement afterwards before drawing.
            //
            if (dimensions.Width <= 0)
            {
                dimensions.Width = 8388608;
                layoutAvailable = false;

                // Set our alignment variables to left - see notes above.
                nsparagraphStyle.Alignment = NSTextAlignment.Left;
                stringWithAttributes.Dispose();
                stringWithAttributes = null;
                stringWithAttributes = new NSAttributedString(text, nsAttributes);
            }

            if (dimensions.Height <= 0)
            {
                dimensions.Height = 8388608;
                layoutAvailable = false;
            }

            // Calculate our bounding rectangle
            var boundingRect = stringWithAttributes.BoundingRectWithSize(new SizeF((int)dimensions.Width, (int)dimensions.Height), 
                NSStringDrawingOptions.UsesLineFragmentOrigin);

            if (!layoutAvailable)
            {
                if (dimensions.Width == 8388608)
                {
                    dimensions.Width = boundingRect.Width;

                    // Restore our alignment before drawing - see notes above.
                    nsparagraphStyle.Alignment = textAlign;
                    stringWithAttributes.Dispose();
                    stringWithAttributes = null;
                    stringWithAttributes = new NSAttributedString(text, nsAttributes);
                }
                if (dimensions.Height == 8388608)
                {
                    dimensions.Height = boundingRect.Height;
                }
            }

            imageWidth = (int)dimensions.Width;
            imageHeight = (int)dimensions.Height;

            // Alignment
            var xOffset = 0.0f;
            switch (textAlign) {
            case NSTextAlignment.Left:
                xOffset = 0; 
                break;
            case NSTextAlignment.Center: 
                xOffset = (dimensions.Width-boundingRect.Width)/2.0f; 
                break;
            case NSTextAlignment.Right: xOffset = dimensions.Width-boundingRect.Width; break;
            default: break;
            }

            // Line alignment
            var yOffset = (CCVerticalTextAlignment.Top == verticleAlignement 
                || boundingRect.Height >= dimensions.Height) ? (dimensions.Height - boundingRect.Height)  // align to top
                : (CCVerticalTextAlignment.Bottom == verticleAlignement) ? 0                    // align to bottom
                : (imageHeight - boundingRect.Height) / 2.0f;                                   // align to center

            //Find the rect that the string will draw into inside the dimensions 
            var drawRect = new RectangleF(xOffset
                , yOffset
                , boundingRect.Width 
                , boundingRect.Height);


            NSImage image = null;
            try
            {
                //Set antialias or not
                NSGraphicsContext.CurrentContext.ShouldAntialias = textDef.isShouldAntialias;

                image = new NSImage(new SizeF(imageWidth, imageHeight));

                image.LockFocus();

                // set a default transform
                var transform = new NSAffineTransform();
                transform.Set();

                stringWithAttributes.DrawInRect(drawRect);

                image.UnlockFocus();

                // We will use Texture2D from stream here instead of CCTexture2D stream.
                var tex = Texture2D.FromStream(CCDrawManager.SharedDrawManager.XnaGraphicsDevice, image);

                // Debugging purposes
//            var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//            var fileName = Path.Combine(path, "Label3.png");
//            using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
//            {
//                tex.SaveAsPng(stream, imageWidth, imageHeight);
//            }

                // Create our texture of the label string.
                var texture = new CCTexture2D(tex);

                return texture;
            }
            catch (Exception exc)
            {
                CCLog.Log ("CCLabel: Error creating native label:{0}\n{1}", exc.Message, exc.StackTrace);
            }
            finally
            {
                // clean up the resources
                if (image != null) 
                {
                    image.Dispose ();
                    image = null;
                }
                if (stringWithAttributes != null) 
                {
                    stringWithAttributes.Dispose ();
                    stringWithAttributes = null;
                }
            }
            return new CCTexture2D ();


        }
예제 #20
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);
		}
예제 #21
0
        void DrawControl(CGRect frame, string name, string country, string abv, string ibu, string srm)
        {
            BackgroundColor = UIColor.Clear;
            Layer.BackgroundColor = UIColor.Clear.CGColor;

            //// General Declarations
            var context = UIGraphics.GetCurrentContext();

            //// Color Declarations
            var fillColor = UIColor.FromRGBA(0.110f, 0.122f, 0.153f, 1.000f);
            var textForeground = UIColor.FromRGBA(1.000f, 1.000f, 1.000f, 1.000f);
            var fillColor2 = UIColor.FromRGBA(0.773f, 0.816f, 0.871f, 1.000f);
            var textForeground2 = UIColor.FromRGBA(0.773f, 0.816f, 0.871f, 1.000f);
            var fillColor3 = UIColor.FromRGBA(0.169f, 0.188f, 0.231f, 1.000f);

            //// Bezier Drawing
            UIBezierPath bezierPath = new UIBezierPath();
            bezierPath.MoveTo(new CGPoint(frame.GetMinX() + 0.00145f * frame.Width, frame.GetMinY() + 0.04170f * frame.Height));
            bezierPath.AddCurveToPoint(new CGPoint(frame.GetMinX() + 0.01299f * frame.Width, frame.GetMinY() + 0.00467f * frame.Height), new CGPoint(frame.GetMinX() + 0.00145f * frame.Width, frame.GetMinY() + 0.02125f * frame.Height), new CGPoint(frame.GetMinX() + 0.00664f * frame.Width, frame.GetMinY() + 0.00467f * frame.Height));
            bezierPath.AddLineTo(new CGPoint(frame.GetMinX() + 0.98701f * frame.Width, frame.GetMinY() + 0.00467f * frame.Height));
            bezierPath.AddCurveToPoint(new CGPoint(frame.GetMinX() + 0.99855f * frame.Width, frame.GetMinY() + 0.04170f * frame.Height), new CGPoint(frame.GetMinX() + 0.99338f * frame.Width, frame.GetMinY() + 0.00467f * frame.Height), new CGPoint(frame.GetMinX() + 0.99855f * frame.Width, frame.GetMinY() + 0.02125f * frame.Height));
            bezierPath.AddLineTo(new CGPoint(frame.GetMinX() + 0.99855f * frame.Width, frame.GetMinY() + 0.95830f * frame.Height));
            bezierPath.AddCurveToPoint(new CGPoint(frame.GetMinX() + 0.98701f * frame.Width, frame.GetMinY() + 0.99533f * frame.Height), new CGPoint(frame.GetMinX() + 0.99855f * frame.Width, frame.GetMinY() + 0.97875f * frame.Height), new CGPoint(frame.GetMinX() + 0.99336f * frame.Width, frame.GetMinY() + 0.99533f * frame.Height));
            bezierPath.AddLineTo(new CGPoint(frame.GetMinX() + 0.01299f * frame.Width, frame.GetMinY() + 0.99533f * frame.Height));
            bezierPath.AddCurveToPoint(new CGPoint(frame.GetMinX() + 0.00145f * frame.Width, frame.GetMinY() + 0.95830f * frame.Height), new CGPoint(frame.GetMinX() + 0.00662f * frame.Width, frame.GetMinY() + 0.99533f * frame.Height), new CGPoint(frame.GetMinX() + 0.00145f * frame.Width, frame.GetMinY() + 0.97875f * frame.Height));
            bezierPath.AddLineTo(new CGPoint(frame.GetMinX() + 0.00145f * frame.Width, frame.GetMinY() + 0.04170f * frame.Height));
            bezierPath.ClosePath();
            bezierPath.LineJoinStyle = CGLineJoin.Round;

            bezierPath.UsesEvenOddFillRule = true;

            fillColor.SetFill();
            bezierPath.Fill();
            fillColor3.SetStroke();
            bezierPath.LineWidth = 0.5f;
            bezierPath.Stroke();


            //// lblName Drawing
            CGRect lblNameRect = new CGRect(frame.GetMinX() + 13.25f, frame.GetMinY() + 9.45f, frame.Width - 23.25f, NMath.Floor((frame.Height - 9.45f) * 0.31777f + 9.39f) - 8.89f);
            textForeground.SetFill();
            var lblNameStyle = new NSMutableParagraphStyle();
            lblNameStyle.Alignment = UITextAlignment.Left;

            var lblNameFontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Heavy", 18.0f), ForegroundColor = textForeground, ParagraphStyle = lblNameStyle };
            var lblNameTextHeight = new NSString(name).GetBoundingRect(new CGSize(lblNameRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, lblNameFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(lblNameRect);
            new NSString(name).DrawString(new CGRect(lblNameRect.GetMinX(), lblNameRect.GetMinY() + (lblNameRect.Height - lblNameTextHeight) / 2.0f, lblNameRect.Width, lblNameTextHeight), UIFont.FromName("Avenir-Heavy", 18.0f), UILineBreakMode.WordWrap, UITextAlignment.Left);
            context.RestoreState();


            //// Bezier 2 Drawing
            UIBezierPath bezier2Path = new UIBezierPath();
            bezier2Path.MoveTo(new CGPoint(frame.GetMinX() + 18.25f, frame.GetMinY() + 39.0f));
            bezier2Path.AddCurveToPoint(new CGPoint(frame.GetMinX() + 15.0f, frame.GetMinY() + 42.08f), new CGPoint(frame.GetMinX() + 16.46f, frame.GetMinY() + 39.0f), new CGPoint(frame.GetMinX() + 15.0f, frame.GetMinY() + 40.38f));
            bezier2Path.AddCurveToPoint(new CGPoint(frame.GetMinX() + 18.26f, frame.GetMinY() + 46.96f), new CGPoint(frame.GetMinX() + 15.0f, frame.GetMinY() + 44.42f), new CGPoint(frame.GetMinX() + 17.63f, frame.GetMinY() + 46.96f));
            bezier2Path.AddCurveToPoint(new CGPoint(frame.GetMinX() + 21.5f, frame.GetMinY() + 42.08f), new CGPoint(frame.GetMinX() + 18.89f, frame.GetMinY() + 46.96f), new CGPoint(frame.GetMinX() + 21.5f, frame.GetMinY() + 44.42f));
            bezier2Path.AddCurveToPoint(new CGPoint(frame.GetMinX() + 18.25f, frame.GetMinY() + 39.0f), new CGPoint(frame.GetMinX() + 21.5f, frame.GetMinY() + 40.38f), new CGPoint(frame.GetMinX() + 20.05f, frame.GetMinY() + 39.0f));
            bezier2Path.ClosePath();
            bezier2Path.MoveTo(new CGPoint(frame.GetMinX() + 18.25f, frame.GetMinY() + 43.98f));
            bezier2Path.AddCurveToPoint(new CGPoint(frame.GetMinX() + 20.0f, frame.GetMinY() + 42.23f), new CGPoint(frame.GetMinX() + 19.22f, frame.GetMinY() + 43.98f), new CGPoint(frame.GetMinX() + 20.0f, frame.GetMinY() + 43.2f));
            bezier2Path.AddCurveToPoint(new CGPoint(frame.GetMinX() + 18.25f, frame.GetMinY() + 40.49f), new CGPoint(frame.GetMinX() + 20.0f, frame.GetMinY() + 41.27f), new CGPoint(frame.GetMinX() + 19.22f, frame.GetMinY() + 40.49f));
            bezier2Path.AddCurveToPoint(new CGPoint(frame.GetMinX() + 16.5f, frame.GetMinY() + 42.23f), new CGPoint(frame.GetMinX() + 17.28f, frame.GetMinY() + 40.49f), new CGPoint(frame.GetMinX() + 16.5f, frame.GetMinY() + 41.27f));
            bezier2Path.AddCurveToPoint(new CGPoint(frame.GetMinX() + 18.25f, frame.GetMinY() + 43.98f), new CGPoint(frame.GetMinX() + 16.5f, frame.GetMinY() + 43.2f), new CGPoint(frame.GetMinX() + 17.28f, frame.GetMinY() + 43.98f));
            bezier2Path.ClosePath();
            bezier2Path.UsesEvenOddFillRule = true;

            fillColor2.SetFill();
            bezier2Path.Fill();


            //// lblCountry Drawing
            CGRect lblCountryRect = new CGRect(frame.GetMinX() + 24.0f, frame.GetMinY() + 31.0f, frame.Width - 34.0f, NMath.Floor((frame.Height - 31.0f) * 0.30263f + 0.5f));
            textForeground2.SetFill();
            var lblCountryStyle = new NSMutableParagraphStyle();
            lblCountryStyle.Alignment = UITextAlignment.Left;

            var lblCountryFontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Medium", 13.0f), ForegroundColor = textForeground2, ParagraphStyle = lblCountryStyle };
            var lblCountryTextHeight = new NSString(country).GetBoundingRect(new CGSize(lblCountryRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, lblCountryFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(lblCountryRect);
            new NSString(country).DrawString(new CGRect(lblCountryRect.GetMinX(), lblCountryRect.GetMinY() + (lblCountryRect.Height - lblCountryTextHeight) / 2.0f, lblCountryRect.Width, lblCountryTextHeight), UIFont.FromName("Avenir-Medium", 13.0f), UILineBreakMode.WordWrap, UITextAlignment.Left);
            context.RestoreState();


            //// Rectangle 3 Drawing
            var rectangle3Path = UIBezierPath.FromRect(new CGRect(frame.GetMinX(), frame.GetMinY() + NMath.Floor((frame.Height - 40.0f) * 0.98507f + 0.5f), frame.Width, frame.Height - 40.0f - NMath.Floor((frame.Height - 40.0f) * 0.98507f + 0.5f)));
            fillColor3.SetFill();
            rectangle3Path.Fill();


            //// Rectangle 4 Drawing
            var rectangle4Path = UIBezierPath.FromRect(new CGRect(frame.GetMinX() + 114.3f, frame.GetMinY() + NMath.Floor((frame.Height) * 0.62804f + 0.5f), NMath.Floor((frame.Width - 114.3f) * 0.00433f + 0.5f), frame.Height - NMath.Floor((frame.Height) * 0.62804f + 0.5f)));
            fillColor3.SetFill();
            rectangle4Path.Fill();


            //// Rectangle 5 Drawing
            var rectangle5Path = UIBezierPath.FromRect(new CGRect(frame.GetMinX() + NMath.Floor((frame.Width - 114.25f) * 0.99567f - 0.25f) + 0.75f, frame.GetMinY() + NMath.Floor((frame.Height) * 0.62804f + 0.5f), frame.Width - 115.0f - NMath.Floor((frame.Width - 114.25f) * 0.99567f - 0.25f), frame.Height - NMath.Floor((frame.Height) * 0.62804f + 0.5f)));
            fillColor3.SetFill();
            rectangle5Path.Fill();


            //// lblAbv Drawing
            CGRect lblAbvRect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * -0.00000f - 0.5f) + 1.0f, frame.GetMinY() + NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f) + 0.81f, NMath.Floor(frame.Width * 0.16812f - 0.5f) - NMath.Floor(frame.Width * -0.00000f - 0.5f), frame.Height - 12.63f - NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f));
            textForeground2.SetFill();
            var lblAbvStyle = new NSMutableParagraphStyle();
            lblAbvStyle.Alignment = UITextAlignment.Right;

            var lblAbvFontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Heavy", 12.0f), ForegroundColor = textForeground2, ParagraphStyle = lblAbvStyle };
            var lblAbvTextHeight = new NSString(abv).GetBoundingRect(new CGSize(lblAbvRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, lblAbvFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(lblAbvRect);
            new NSString(abv).DrawString(new CGRect(lblAbvRect.GetMinX(), lblAbvRect.GetMinY() + (lblAbvRect.Height - lblAbvTextHeight) / 2.0f, lblAbvRect.Width, lblAbvTextHeight), UIFont.FromName("Avenir-Heavy", 12.0f), UILineBreakMode.WordWrap, UITextAlignment.Right);
            context.RestoreState();


            //// Label 4 Drawing
            CGRect label4Rect = new CGRect(frame.GetMinX() + NMath.Floor((frame.Width - 231.0f) * 0.52961f + 0.12f) + 0.38f, frame.GetMinY() + NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f) + 0.81f, frame.Width - 231.38f - NMath.Floor((frame.Width - 231.0f) * 0.52961f + 0.12f), frame.Height - 12.63f - NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f));
            {
                var textContent = "ABV";
                textForeground.SetFill();
                var label4Style = new NSMutableParagraphStyle();
                label4Style.Alignment = UITextAlignment.Left;

                var label4FontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Heavy", 12.0f), ForegroundColor = textForeground, ParagraphStyle = label4Style };
                var label4TextHeight = new NSString(textContent).GetBoundingRect(new CGSize(label4Rect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, label4FontAttributes, null).Height;
                context.SaveState();
                context.ClipToRect(label4Rect);
                new NSString(textContent).DrawString(new CGRect(label4Rect.GetMinX(), label4Rect.GetMinY() + (label4Rect.Height - label4TextHeight) / 2.0f, label4Rect.Width, label4TextHeight), UIFont.FromName("Avenir-Heavy", 12.0f), UILineBreakMode.WordWrap, UITextAlignment.Left);
                context.RestoreState();
            }


            //// lblIbu Drawing
            CGRect lblIbuRect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * 0.33623f + 0.5f), frame.GetMinY() + NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f) + 0.81f, NMath.Floor(frame.Width * 0.49855f + 0.5f) - NMath.Floor(frame.Width * 0.33623f + 0.5f), frame.Height - 12.63f - NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f));
            textForeground2.SetFill();
            var lblIbuStyle = new NSMutableParagraphStyle();
            lblIbuStyle.Alignment = UITextAlignment.Right;

            var lblIbuFontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Heavy", 12.0f), ForegroundColor = textForeground2, ParagraphStyle = lblIbuStyle };
            var lblIbuTextHeight = new NSString(ibu).GetBoundingRect(new CGSize(lblIbuRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, lblIbuFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(lblIbuRect);
            new NSString(ibu).DrawString(new CGRect(lblIbuRect.GetMinX(), lblIbuRect.GetMinY() + (lblIbuRect.Height - lblIbuTextHeight) / 2.0f, lblIbuRect.Width, lblIbuTextHeight), UIFont.FromName("Avenir-Heavy", 12.0f), UILineBreakMode.WordWrap, UITextAlignment.Right);
            context.RestoreState();


            //// Label 6 Drawing
            CGRect label6Rect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * 0.50435f + 0.5f), frame.GetMinY() + NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f) + 0.81f, NMath.Floor(frame.Width * 0.66667f + 0.5f) - NMath.Floor(frame.Width * 0.50435f + 0.5f), frame.Height - 12.63f - NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f));
            {
                var textContent = "IBU";
                textForeground.SetFill();
                var label6Style = new NSMutableParagraphStyle();
                label6Style.Alignment = UITextAlignment.Left;

                var label6FontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Heavy", 12.0f), ForegroundColor = textForeground, ParagraphStyle = label6Style };
                var label6TextHeight = new NSString(textContent).GetBoundingRect(new CGSize(label6Rect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, label6FontAttributes, null).Height;
                context.SaveState();
                context.ClipToRect(label6Rect);
                new NSString(textContent).DrawString(new CGRect(label6Rect.GetMinX(), label6Rect.GetMinY() + (label6Rect.Height - label6TextHeight) / 2.0f, label6Rect.Width, label6TextHeight), UIFont.FromName("Avenir-Heavy", 12.0f), UILineBreakMode.WordWrap, UITextAlignment.Left);
                context.RestoreState();
            }


            //// lblSrm Drawing
            CGRect lblSrmRect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * 0.66957f + 0.5f), frame.GetMinY() + NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f) + 0.81f, NMath.Floor(frame.Width * 0.83478f + 0.5f) - NMath.Floor(frame.Width * 0.66957f + 0.5f), frame.Height - 12.63f - NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f));
            textForeground2.SetFill();
            var lblSrmStyle = new NSMutableParagraphStyle();
            lblSrmStyle.Alignment = UITextAlignment.Right;

            var lblSrmFontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Heavy", 12.0f), ForegroundColor = textForeground2, ParagraphStyle = lblSrmStyle };
            var lblSrmTextHeight = new NSString(srm).GetBoundingRect(new CGSize(lblSrmRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, lblSrmFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(lblSrmRect);
            new NSString(srm).DrawString(new CGRect(lblSrmRect.GetMinX(), lblSrmRect.GetMinY() + (lblSrmRect.Height - lblSrmTextHeight) / 2.0f, lblSrmRect.Width, lblSrmTextHeight), UIFont.FromName("Avenir-Heavy", 12.0f), UILineBreakMode.WordWrap, UITextAlignment.Right);
            context.RestoreState();


            //// Label 8 Drawing
            CGRect label8Rect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * 0.83460f - 0.44f) + 0.94f, frame.GetMinY() + NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f) + 0.81f, NMath.Floor(frame.Width * 1.00000f - 0.5f) - NMath.Floor(frame.Width * 0.83460f - 0.44f) + 0.06f, frame.Height - 12.63f - NMath.Floor((frame.Height - 11.81f) * 0.78989f - 0.31f));
            {
                var textContent = "SRM";
                textForeground.SetFill();
                var label8Style = new NSMutableParagraphStyle();
                label8Style.Alignment = UITextAlignment.Left;

                var label8FontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Heavy", 12.0f), ForegroundColor = textForeground, ParagraphStyle = label8Style };
                var label8TextHeight = new NSString(textContent).GetBoundingRect(new CGSize(label8Rect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, label8FontAttributes, null).Height;
                context.SaveState();
                context.ClipToRect(label8Rect);
                new NSString(textContent).DrawString(new CGRect(label8Rect.GetMinX(), label8Rect.GetMinY() + (label8Rect.Height - label8TextHeight) / 2.0f, label8Rect.Width, label8TextHeight), UIFont.FromName("Avenir-Heavy", 12.0f), UILineBreakMode.WordWrap, UITextAlignment.Left);
                context.RestoreState();
            }
        }
		public override void Draw (CGRect rect)
		{
			base.Draw (rect);

			NSMutableParagraphStyle style = new NSMutableParagraphStyle ();
			style.Alignment = UITextAlignment.Center;

			int nummerOfBanners = GetNumberOfBanners ();
			int numRows = GetNumberOfRows ();

			float totalBannerHeight = nummerOfBanners * (BannerHeight + GapAfterRows);
			float rowHeight = IdealRowHeight;

			if (numRows > 0) {
				float maxRowHeight = (float)(rect.Size.Height - totalBannerHeight) / numRows;
				rowHeight = Math.Min (rowHeight, maxRowHeight);
			}

			float runningTop = (float)rect.Y;
			var bannerRect = rect;
			bannerRect.Height = BannerHeight;
			bannerRect.Y = runningTop;

			var rowRect = rect;
			rowRect.Height = rowHeight;

			rowRect.X += LeftInsetToMatchTimeSlider;
			rowRect.Width -= (LeftInsetToMatchTimeSlider + RightInsetToMatchTimeSlider);
			compositionRectWidth = (float)rowRect.Size.Width;

			if (duration.Seconds != 0)
				scaledDurationToWidth = compositionRectWidth / (float)duration.Seconds;
			else
				scaledDurationToWidth = 0;

			if (compositionTracks != null) {
				DrawCompositionTracks (bannerRect, rowRect, ref runningTop);
				DrawMarker (rowRect, (float)rect.Y);
			}

			if (videoCompositionStages != null)
				DrawVideoCompositionTracks (bannerRect, rowRect, ref runningTop);

			if (audioMixTracks != null)
				DrawAudioMixTracks (bannerRect, rowRect, ref runningTop);
		}
예제 #23
0
        private void DrawCanvas(CGRect frame, string beerName)
        {
            //// General Declarations
            var context = UIGraphics.GetCurrentContext();

            //// Color Declarations
            var fillColor = UIColor.FromRGBA(0.500f, 0.500f, 0.500f, 1.000f);
            var shadowTint = UIColor.FromRGBA(0.000f, 0.000f, 0.000f, 1.000f);
            var fillColor2 = UIColor.FromRGBA(1.000f, 1.000f, 1.000f, 1.000f);
            var strokeColor = UIColor.FromRGBA(0.531f, 0.531f, 0.531f, 1.000f);
            var textForeground2 = UIColor.FromRGBA(0.408f, 0.408f, 0.408f, 1.000f);

            //// Shadow Declarations
            var shadow2 = new NSShadow();
            shadow2.ShadowColor = shadowTint.ColorWithAlpha(shadowTint.CGColor.Alpha * 0.3f);
            shadow2.ShadowOffset = new CGSize(930.1f, -0.1f);
            shadow2.ShadowBlurRadius = 10.0f;

            //// Rectangle Drawing
            var rectanglePath = UIBezierPath.FromRoundedRect(new CGRect(-921.0f, 9.0f, 395.0f, 418.0f), 8.0f);
            context.SaveState();
            context.SetShadow(shadow2.ShadowOffset, shadow2.ShadowBlurRadius, shadow2.ShadowColor.CGColor);
            fillColor.SetFill();
            rectanglePath.Fill();
            context.RestoreState();



            //// Group
            {
                context.SaveState();
                context.BeginTransparencyLayer();

                //// Clip Clip 2
                UIBezierPath clip2Path = new UIBezierPath();
                clip2Path.MoveTo(new CGPoint(-11.5f, -11.5f));
                clip2Path.AddLineTo(new CGPoint(424.5f, -11.5f));
                clip2Path.AddLineTo(new CGPoint(424.5f, 447.5f));
                clip2Path.AddLineTo(new CGPoint(-11.5f, 447.5f));
                clip2Path.AddLineTo(new CGPoint(-11.5f, -11.5f));
                clip2Path.ClosePath();
                clip2Path.MoveTo(new CGPoint(9.5f, 17.0f));
                clip2Path.AddCurveToPoint(new CGPoint(17.0f, 9.5f), new CGPoint(9.5f, 12.86f), new CGPoint(12.86f, 9.5f));
                clip2Path.AddLineTo(new CGPoint(396.0f, 9.5f));
                clip2Path.AddCurveToPoint(new CGPoint(403.5f, 17.0f), new CGPoint(400.14f, 9.5f), new CGPoint(403.5f, 12.86f));
                clip2Path.AddLineTo(new CGPoint(403.5f, 419.0f));
                clip2Path.AddCurveToPoint(new CGPoint(396.0f, 426.5f), new CGPoint(403.5f, 423.14f), new CGPoint(400.14f, 426.5f));
                clip2Path.AddLineTo(new CGPoint(17.0f, 426.5f));
                clip2Path.AddCurveToPoint(new CGPoint(9.5f, 419.0f), new CGPoint(12.86f, 426.5f), new CGPoint(9.5f, 423.14f));
                clip2Path.AddLineTo(new CGPoint(9.5f, 17.0f));
                clip2Path.ClosePath();
                clip2Path.MoveTo(new CGPoint(8.5f, 17.0f));
                clip2Path.AddLineTo(new CGPoint(8.5f, 419.0f));
                clip2Path.AddCurveToPoint(new CGPoint(17.0f, 427.5f), new CGPoint(8.5f, 423.69f), new CGPoint(12.31f, 427.5f));
                clip2Path.AddLineTo(new CGPoint(396.0f, 427.5f));
                clip2Path.AddCurveToPoint(new CGPoint(404.5f, 419.0f), new CGPoint(400.69f, 427.5f), new CGPoint(404.5f, 423.69f));
                clip2Path.AddLineTo(new CGPoint(404.5f, 17.0f));
                clip2Path.AddCurveToPoint(new CGPoint(396.0f, 8.5f), new CGPoint(404.5f, 12.31f), new CGPoint(400.69f, 8.5f));
                clip2Path.AddLineTo(new CGPoint(17.0f, 8.5f));
                clip2Path.AddCurveToPoint(new CGPoint(8.5f, 17.0f), new CGPoint(12.31f, 8.5f), new CGPoint(8.5f, 12.31f));
                clip2Path.ClosePath();
                clip2Path.UsesEvenOddFillRule = true;

                clip2Path.AddClip();


                //// Group 2
                {
                    context.SaveState();
                    context.BeginTransparencyLayer();

                    //// Clip Clip
                    var clipPath = UIBezierPath.FromRoundedRect(new CGRect(9.0f, 9.0f, 395.0f, 418.0f), 8.0f);
                    clipPath.AddClip();


                    //// Rectangle 2 Drawing
                    var rectangle2Path = UIBezierPath.FromRoundedRect(new CGRect(9.0f, 9.0f, 395.0f, 418.0f), 8.0f);
                    fillColor2.SetFill();
                    rectangle2Path.Fill();


                    context.EndTransparencyLayer();
                    context.RestoreState();
                }


                context.EndTransparencyLayer();
                context.RestoreState();
            }


            //// background
            {
                context.SaveState();
                context.BeginTransparencyLayer();

                //// Clip Clip 3
                var clip3Path = UIBezierPath.FromRoundedRect(new CGRect(frame.GetMinX(), frame.GetMinY() + 9.0f, 395.0f, 418.0f), 8.0f);
                clip3Path.AddClip();


                //// Rectangle 4 Drawing
                var rectangle4Path = UIBezierPath.FromRoundedRect(new CGRect(frame.GetMinX(), frame.GetMinY() + 9.0f, 395.0f, 418.0f), 8.0f);
                strokeColor.SetStroke();
                rectangle4Path.LineWidth = 2.0f;
                rectangle4Path.Stroke();


                context.EndTransparencyLayer();
                context.RestoreState();
            }


            //// title Drawing
            CGRect titleRect = new CGRect(frame.GetMinX() + 0.38f, frame.GetMinY() + 19.0f, 394.62f, 41.0f);
            textForeground2.SetFill();
            var titleStyle = new NSMutableParagraphStyle ();
            titleStyle.Alignment = UITextAlignment.Center;

            var titleFontAttributes = new UIStringAttributes () {Font = UIFont.FromName("Avenir-Medium", 24.0f), ForegroundColor = textForeground2, ParagraphStyle = titleStyle};
            var titleTextHeight = new NSString(beerName).GetBoundingRect(new CGSize(titleRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, titleFontAttributes, null).Height;
            context.SaveState();
            context.ClipToRect(titleRect);
            new NSString(beerName).DrawString(new CGRect(titleRect.GetMinX(), titleRect.GetMinY() + (titleRect.Height - titleTextHeight) / 2.0f, titleRect.Width, titleTextHeight), UIFont.FromName("Avenir-Medium", 24.0f), UILineBreakMode.WordWrap, UITextAlignment.Center);
            context.RestoreState();
        }