public static CATextLayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IFeature feature, IViewport viewport, string text) { // Offset stackOffset, Mapsui.Geometries.Point p = viewport.WorldToScreen(point); //var pointF = new xPointF((float)p.X, (float)p.Y); var label = new CATextLayer (); var aString = new Foundation.NSAttributedString (text, new CoreText.CTStringAttributes(){ Font = new CoreText.CTFont("ArialMT", 10) }); var frame = new CGRect(new CoreGraphics.CGPoint((int)p.X, (int)p.Y), GetSizeForText(0, aString)); //label.Frame = frame; //frame.Width = (float)(p2.X - p1.X);// + margin); //frame.Height = (float)(p1.Y - p2.Y); label.FontSize = 10; label.ForegroundColor = new CoreGraphics.CGColor (0, 0, 255, 150); label.BackgroundColor = new CoreGraphics.CGColor (255, 0, 2, 150); label.String = text; label.Frame = frame; Console.WriteLine ("Pos " + label.Frame.X + ":" + label.Frame.Y + " w " + label.Frame.Width + " h " + label.Frame.Height); // = MonoTouch.UIKit.UIScreen.MainScreen.Scale; // label.ContentsScale = scale; return label; }
public ValuePopUpView(CGRect frame) : base(frame) { shouldAnimate = false; Layer.AnchorPoint = new CGPoint(0.5, 1); UserInteractionEnabled = false; pathLayer = (CAShapeLayer)this.Layer; cornerRadius = 4.0f; ArrowLength = 13.0f; WidthPaddingFactor = 1.15f; HeightPaddingFactor = 1.1f; textLayer = new CATextLayer(); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.AnchorPoint = new CGPoint(0, 0); textLayer.ContentsScale = UIScreen.MainScreen.Scale; textLayer.Actions = NSDictionary.FromObjectAndKey(NSNull.Null, new NSString("contents")); colorAnimLayer = new CAShapeLayer(); Layer.AddSublayer(colorAnimLayer); Layer.AddSublayer(textLayer); attributedString = new NSMutableAttributedString(" ", new NSDictionary()); }
public UIImage GetThumbImage(CGRect rect, int value) { var mainThumb = new CALayer(); var iconName = (control.ThumbImageSource as FileImageSource).File; var myImage = new UIImage(iconName); mainThumb.Contents = myImage.CGImage; mainThumb.Frame = rect; var textlayer = new CATextLayer(); textlayer.FontSize = (nfloat)control.ThumbTextFontSize; textlayer.TextAlignmentMode = CATextLayerAlignmentMode.Center; textlayer.String = String.Format(control.ThumbTextFormat, value); textlayer.Wrapped = true; textlayer.TextTruncationMode = CATextLayerTruncationMode.End; //textlayer.BackgroundColor = UIColor.White.CGColor; textlayer.ForegroundColor = UIColor.White.CGColor; var yCenter = (rect.Height - textlayer.FontSize) / 2 - textlayer.FontSize / 10; textlayer.Frame = new CGRect(rect.X, yCenter, rect.Width, rect.Height); mainThumb.AddSublayer(textlayer); UIGraphics.BeginImageContextWithOptions(rect.Size, mainThumb.Opaque, 0.0f); var context = UIGraphics.GetCurrentContext(); mainThumb.RenderInContext(context); var image = UIGraphics.GetImageFromCurrentImageContext().CreateResizableImage(new UIEdgeInsets(top: 0, left: rect.Size.Height, bottom: 0, right: rect.Size.Height)); UIGraphics.EndImageContext(); return(image); }
void CreateDbLabelsAndLines() { int value; var scale = Layer.ContentsScale; for (int index = -numDBLines; index <= numDBLines; index++) { value = index * (defaultGain / numDBLines); if (index >= -numDBLines && index <= numDBLines) { var labelLayer = new CATextLayer { String = string.Format("{0} db", value), Name = index.ToString(), FontSize = 14, ContentsScale = scale, ForegroundColor = UIColor.FromWhiteAlpha(0.1f, 1f).CGColor, AlignmentMode = CATextLayer.AlignmentRight }; labelLayer.SetFont(UIFont.SystemFontOfSize(14).Name); dbLabels.Add(labelLayer); containerLayer.AddSublayer(labelLayer); var lineLayer = new CALayer { BackgroundColor = index == 0 ? UIColor.FromWhiteAlpha(0.65f, 1f).CGColor : UIColor.FromWhiteAlpha(0.8f, 1f).CGColor }; dbLines.Add(lineLayer); graphLayer.AddSublayer(lineLayer); } } }
void DrawTextInCorner(CVPixelBuffer pixelBuffer) { var textLayer = new CATextLayer(); const float textLayerWidth = 100f; const float textLayerHeight = 50f; if (AffineTransform.xx == -1.0f && AffineTransform.yy == -1.0f) { textLayer.AffineTransform = AffineTransform; } else if (AffineTransform.xy == 1.0f && AffineTransform.yx == -1f) { textLayer.AffineTransform = new CGAffineTransform( AffineTransform.xx * -1f, AffineTransform.xy * -1f, AffineTransform.yx * -1f, AffineTransform.yy * -1f, AffineTransform.x0, AffineTransform.y0 ); } textLayer.Frame = new CGRect(Bounds.Size.Width - textLayerWidth, 0f, textLayerWidth, textLayerHeight); textLayer.String = TimeCode; textLayer.BackgroundColor = UIColor.Black.CGColor; AddSublayer(textLayer); }
public static CATextLayer ToShape(this TextPath element) { var text = new CATextLayer(); text.FontSize = element.FontSize; return(text); }
public override void AwakeFromNib() { base.AwakeFromNib(); View.Layer = new CALayer(); View.WantsLayer = true; textContainer = new CALayer(); textContainer.AnchorPoint = CGPoint.Empty; textContainer.Position = new CGPoint(10, 10); textContainer.ZPosition = 100; textContainer.BackgroundColor = NSColor.Black.CGColor; textContainer.BorderColor = NSColor.White.CGColor; textContainer.BorderWidth = 2; textContainer.CornerRadius = 15; textContainer.ShadowOpacity = 0.5f; View.Layer.AddSublayer(textContainer); textLayer = new CATextLayer(); textLayer.AnchorPoint = CGPoint.Empty; textLayer.Position = new CGPoint(10, 6); textLayer.ZPosition = 100; textLayer.FontSize = 24; textLayer.ForegroundColor = NSColor.White.CGColor; textContainer.AddSublayer(textLayer); // Rely on setText: to set the above layers' bounds: [self setText:@"Loading..."]; SetText("Loading...", textLayer); var dirs = NSSearchPath.GetDirectories(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.Local); foreach (string dir in dirs) { Console.WriteLine("Dir: {0}", dir); } string libDir = dirs[0]; string desktopPicturesDir = Path.Combine(libDir, "Desktop Pictures"); Console.WriteLine("DP Dir: {0}", desktopPicturesDir); // Launch loading of images on background thread Task.Run(async() => { await AddImagesFromFolderUrlAsync(desktopPicturesDir); }); repositionButton.Layer.ZPosition = 100; durationTextField.Layer.ZPosition = 100; lastWindowSize = Window.Frame.Size; Window.DidResize += (sender, e) => { if (Math.Abs(lastWindowSize.Width - Window.Frame.Width) > 25 || Math.Abs(lastWindowSize.Height - Window.Frame.Height) > 25) { windowIsResizing = true; repositionImages(repositionButton); lastWindowSize = Window.Frame.Size; windowIsResizing = false; } }; }
public void AddItem(string identifier, string title) { var layer = new CATextLayer(); layer.String = title; layer.SetFont("SF UI Text Bold"); layer.FontSize = 12; layer.ForegroundColor = NSColor.FromRgb(80, 80, 80).CGColor; layer.ContentsScale = NSScreen.MainScreen.BackingScaleFactor; var attrs = new NSStringAttributes(); attrs.Font = NSFont.FromFontName("SF UI Text Bold", 12); var stringSize = NSStringDrawing.StringSize(layer.String, attrs); var frame = new CGRect(new CGPoint(0, 0), stringSize); layer.Frame = frame; layer.AnchorPoint = new CGPoint(0, 0.5f); items.Add(new BreadcrumbViewItem { Identifier = identifier, Title = title, Layer = layer }); Layer.AddSublayer(layer); NeedsDisplay = true; }
public static CATextLayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IFeature feature, IViewport viewport, string text) { // Offset stackOffset, Mapsui.Geometries.Point p = viewport.WorldToScreen(point); //var pointF = new xPointF((float)p.X, (float)p.Y); var label = new CATextLayer(); var aString = new MonoTouch.Foundation.NSAttributedString(text, new MonoTouch.CoreText.CTStringAttributes() { Font = new MonoTouch.CoreText.CTFont("ArialMT", 10) }); var frame = new RectangleF(new System.Drawing.Point((int)p.X, (int)p.Y), GetSizeForText(0, aString)); //label.Frame = frame; //frame.Width = (float)(p2.X - p1.X);// + margin); //frame.Height = (float)(p1.Y - p2.Y); label.FontSize = 10; label.ForegroundColor = new MonoTouch.CoreGraphics.CGColor(0, 0, 255, 150); label.BackgroundColor = new MonoTouch.CoreGraphics.CGColor(255, 0, 2, 150); label.String = text; label.Frame = frame; Console.WriteLine("Pos " + label.Frame.X + ":" + label.Frame.Y + " w " + label.Frame.Width + " h " + label.Frame.Height); // = MonoTouch.UIKit.UIScreen.MainScreen.Scale; // label.ContentsScale = scale; return(label); }
private static CATextLayer CreateCATextLayer(LabelStyle style, string text) { var label = new CATextLayer(); var ctFont = new CoreText.CTFont(style.Font.FontFamily, (float)style.Font.Size); var aString = new Foundation.NSAttributedString(text, new CoreText.CTStringAttributes() { Font = ctFont }); label.SetFont(ctFont); label.FontSize = (float)style.Font.Size; label.ForegroundColor = ToCGColor(style.ForeColor); label.BackgroundColor = TransparentColor; label.ShadowOpacity = 0; label.BorderWidth = 0; label.String = text; var size = GetSizeForText(0, aString); label.Frame = new CGRect(0, 0, size.Width, size.Height); return(label); }
public override void AwakeFromNib() { base.AwakeFromNib(); View.Layer = new CALayer(); View.WantsLayer = true; textContainer = new CALayer(); textContainer.AnchorPoint = CGPoint.Empty; textContainer.Position = new CGPoint(10, 10); textContainer.ZPosition = 100; textContainer.BackgroundColor = NSColor.Black.CGColor; textContainer.BorderColor = NSColor.White.CGColor; textContainer.BorderWidth = 2; textContainer.CornerRadius = 15; textContainer.ShadowOpacity = 0.5f; View.Layer.AddSublayer(textContainer); textLayer = new CATextLayer(); textLayer.AnchorPoint = CGPoint.Empty; textLayer.Position = new CGPoint(10, 6); textLayer.ZPosition = 100; textLayer.FontSize = 24; textLayer.ForegroundColor = NSColor.White.CGColor; textContainer.AddSublayer(textLayer); // Rely on setText: to set the above layers' bounds: [self setText:@"Loading..."]; SetText("Loading...", textLayer); var dirs = NSSearchPath.GetDirectories(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.Local); foreach (string dir in dirs) { Console.WriteLine("Dir: {0}", dir); } string libDir = dirs[0]; string desktopPicturesDir = Path.Combine(libDir, "Desktop Pictures"); Console.WriteLine("DP Dir: {0}", desktopPicturesDir); // Launch loading of images on background thread Task.Run(async () => { await AddImagesFromFolderUrlAsync(desktopPicturesDir); }); repositionButton.Layer.ZPosition = 100; durationTextField.Layer.ZPosition = 100; lastWindowSize = Window.Frame.Size; Window.DidResize += (sender, e) => { if (Math.Abs(lastWindowSize.Width - Window.Frame.Width) > 25 || Math.Abs(lastWindowSize.Height - Window.Frame.Height) > 25) { windowIsResizing = true; repositionImages(repositionButton); lastWindowSize = Window.Frame.Size; windowIsResizing = false; } }; }
// An AutoResetEvent instance is used for drawing metadata object overlays so that // only one group of metadata object overlays is drawn at a time. MetadataObjectLayer CreateMetadataOverlay(AVMetadataObject metadataObject) { // Transform the metadata object so the bounds are updated to reflect those of the video preview layer. var transformedMetadataObject = PreviewView.VideoPreviewLayer.GetTransformedMetadataObject(metadataObject); // Create the initial metadata object overlay layer that can be used for either machine readable codes or faces. var metadataObjectOverlayLayer = new MetadataObjectLayer { MetadataObject = transformedMetadataObject, LineJoin = CAShapeLayer.JoinRound, LineWidth = 7, StrokeColor = View.TintColor.ColorWithAlpha(0.7f).CGColor, FillColor = View.TintColor.ColorWithAlpha(0.3f).CGColor }; var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject; if (barcodeMetadataObject != null) { var barcodeOverlayPath = BarcodeOverlayPathWithCorners(barcodeMetadataObject.Corners); metadataObjectOverlayLayer.Path = barcodeOverlayPath; // If the metadata object has a string value, display it. if (barcodeMetadataObject.StringValue.Length > 0) { var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox; var font = UIFont.BoldSystemFontOfSize(19).ToCTFont(); var textLayer = new CATextLayer { AlignmentMode = CATextLayer.AlignmentCenter, Bounds = new CGRect(0, 0, barcodeOverlayBoundingBox.Size.Width, barcodeOverlayBoundingBox.Size.Height), ContentsScale = UIScreen.MainScreen.Scale, Position = new CGPoint(barcodeOverlayBoundingBox.GetMidX(), barcodeOverlayBoundingBox.GetMidY()), Wrapped = true, // Invert the effect of transform of the video preview so the text is orientated with the interface orientation. Transform = CATransform3D.MakeFromAffine(PreviewView.Transform).Invert(default(CATransform3D)), AttributedString = new NSAttributedString(barcodeMetadataObject.StringValue, new CTStringAttributes { Font = font, ForegroundColor = UIColor.White.CGColor, StrokeWidth = -5, StrokeColor = UIColor.Black.CGColor }) }; textLayer.SetFont(font); metadataObjectOverlayLayer.AddSublayer(textLayer); } } else if (transformedMetadataObject is AVMetadataFaceObject) { metadataObjectOverlayLayer.Path = CGPath.FromRect(transformedMetadataObject.Bounds); } return(metadataObjectOverlayLayer); }
CATextLayer SetupTextLayer() { _textLayer = new CATextLayer { AlignmentMode = CATextLayer.AlignmentCenter, ShadowOpacity = ProgressButtonFloats.TextLayerShadowOpacity.AsResourceFloat(), }; _textLayer.Bind("foregroundColor", _progressButtonLayer, "curForegroundColor", null); _textLayer.Bind("Frame", _progressButtonLayer, "curFrame", null); _textLayer.Bind("string", _progressButtonLayer, "curText", null); _textLayer.Bind("FontSize", _progressButtonLayer, "curFontSize", null); return(_textLayer); }
void CreateFrequencyLabelsAndLines() { float value; bool firstK = true; var scale = Layer.ContentsScale; for (int index = 0; index <= gridLineCount; index++) { value = GetValue((float)index); var labelLayer = new CATextLayer { ForegroundColor = UIColor.FromWhiteAlpha(0.1f, 1f).CGColor, FontSize = 14, AlignmentMode = CATextLayer.AlignmentCenter, ContentsScale = scale, AnchorPoint = CGPoint.Empty }; labelLayer.SetFont(UIFont.SystemFontOfSize(14).Name); frequencyLabels.Add(labelLayer); if (index > 0 && index < gridLineCount) { var lineLayer = new CALayer { BackgroundColor = UIColor.FromWhiteAlpha(0.8f, 1f).CGColor }; freqLines.Add(lineLayer); graphLayer.AddSublayer(lineLayer); var s = GetString(value); if (value >= 1000 && firstK) { s += "K"; firstK = false; } labelLayer.String = s; } else if (index == 0) { labelLayer.String = string.Format("{0} Hz", GetString(value)); } else { labelLayer.String = string.Format("{0} K", GetString(DefaultMaxHertz)); } containerLayer.AddSublayer(labelLayer); } }
public void CATextLayerAlignmentModeTest() { var textLayer = new CATextLayer { String = "Hello", TextAlignmentMode = CATextLayerAlignmentMode.Justified }; Assert.AreEqual(CATextLayerAlignmentMode.Justified, textLayer.TextAlignmentMode, "TextAlignmentMode"); Assert.AreEqual(textLayer.AlignmentMode, (string)textLayer.TextAlignmentMode.GetConstant(), "AlignmentMode"); textLayer.AlignmentMode = CATextLayer.AlignmentNatural; Assert.AreEqual(CATextLayerAlignmentMode.Natural, textLayer.TextAlignmentMode, "TextAlignmentMode 2"); Assert.Throws <ArgumentNullException> (() => textLayer.AlignmentMode = null); }
public void CATextLayerTruncationModeTest() { var textLayer = new CATextLayer { String = "Hello", TextTruncationMode = CATextLayerTruncationMode.Middle }; Assert.AreEqual(CATextLayerTruncationMode.Middle, textLayer.TextTruncationMode, "TextTruncationMode"); Assert.AreEqual(textLayer.TruncationMode, (string)textLayer.TextTruncationMode.GetConstant(), "TruncationMode"); textLayer.TruncationMode = CATextLayer.TruncantionEnd; Assert.AreEqual(CATextLayerTruncationMode.End, textLayer.TextTruncationMode, "TextTruncationMode 2"); Assert.Throws <ArgumentNullException> (() => textLayer.TruncationMode = null); }
public override void Draw(RectangleF rect) { base.Draw(rect); using (var context = UIGraphics.GetCurrentContext()) { UIBezierPath mainAxis = UIBezierPath.FromRoundedRect(new RectangleF(xAxisMargin, 0.0f, 2.0f, rect.Height), 2.0f); UIColor.FromRGB(203, 203, 203).SetFill(); mainAxis.Fill(); float sepInterval = Convert.ToSingle(Math.Floor((rect.Width - xAxisMargin - xTextMargin) / 5)); for (int i = 1; i < 6; i++) { var separatorAxis = new UIBezierPath(); separatorAxis.MoveTo(new PointF(xAxisMargin + sepInterval * i, 0)); separatorAxis.AddLineTo(new PointF(xAxisMargin + sepInterval * i, rect.Height - yAxisMargin)); UIColor.FromRGB(203, 203, 203).SetStroke(); separatorAxis.LineWidth = 1.0f; separatorAxis.SetLineDash(new [] { 1.0f, 1.0f }, 1); separatorAxis.Stroke(); var textLayer = new CATextLayer(); textLayer.ContentsScale = UIScreen.MainScreen.Scale; CGFont font = CGFont.CreateWithFontName(LabelFont.Name); if (font != null) { textLayer.SetFont(font); font.Dispose(); } textLayer.FontSize = LabelFont.PointSize; textLayer.AnchorPoint = new PointF(0.5f, 0.0f); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.BackgroundColor = UIColor.Clear.CGColor; textLayer.ForegroundColor = LabelColor.CGColor; SizeF size = ((NSString)"0000 h").StringSize(LabelFont); textLayer.String = "00 h"; textLayer.Bounds = new RectangleF(0, 0, size.Width, size.Height); textLayer.Position = new PointF(xAxisMargin + sepInterval * i, rect.Height - yAxisMargin + 5.0f); Layer.AddSublayer(textLayer); xAxisText [i - 1] = textLayer; } } }
private SliceLayer createSliceLayer() { var pieLayer = new SliceLayer(); pieLayer.Frame = _pieView.Frame; var arcLayer = new CAShapeLayer(); arcLayer.ZPosition = 0; arcLayer.StrokeColor = null; pieLayer.AddSublayer(arcLayer); var textLayer = new CATextLayer(); textLayer.ContentsScale = UIScreen.MainScreen.Scale; CGFont font = CGFont.CreateWithFontName(LabelFont.Name); if (font != null) { textLayer.SetFont(font); font.Dispose(); } textLayer.FontSize = LabelFont.PointSize; textLayer.AnchorPoint = new CGPoint(0.5f, 0.5f); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.BackgroundColor = UIColor.Clear.CGColor; textLayer.ForegroundColor = LabelColor.CGColor; if (LabelShadowColor != null) { textLayer.ShadowColor = LabelShadowColor.CGColor; textLayer.ShadowOffset = CGSize.Empty; textLayer.ShadowOpacity = 1.0f; textLayer.ShadowRadius = 2.0f; } CGSize size = ((NSString)"0").StringSize(LabelFont); textLayer.Frame = new CGRect(new CGPoint(0, 0), size); textLayer.Position = new CGPoint(_pieCenter.X + LabelRadius * (nfloat)Math.Cos(0), _pieCenter.Y + LabelRadius * (nfloat)Math.Sin(0)); pieLayer.AddSublayer(textLayer); layerPool.Add(pieLayer); return(pieLayer); }
//- (void)setText:(NSString *)text; void SetText(string text, CATextLayer tl) { NSFont font = NSFont.SystemFontOfSize(tl.FontSize); NSDictionary attrs = NSDictionary.FromObjectsAndKeys(new NSObject[] { font }, new NSObject[] { NSStringAttributeKey.Font }); CGSize size = text.StringSize(attrs); // Ensure that the size is in whole numbers: size.Width = (nfloat)Math.Ceiling(size.Width); size.Height = (nfloat)Math.Ceiling(size.Height); CGRect bounds = new CGRect(0, 0, size.Width, size.Height); tl.Bounds = bounds; if (tl.SuperLayer == textContainer) { tl.SuperLayer.Bounds = new CGRect(0, 0, size.Width + 16, size.Height + 20); } tl.String = text; }
public void DidStop(CAAnimation theAnimation, bool finished) { finishedAnimationCount++; if (finishedAnimationCount != animationList.Count) { return; } nfloat nextPos = StartXPos; foreach (var result in Results.OrderByDescending(c => c.ExecutionDate)) { nfloat graphPoint = this.Frame.Height - EndYPos(result.Score); string scoreText = result.Score.ToString(); var scorePath = new CGPath(); scorePath.AddEllipseInRect(new CGRect(new CGPoint(nextPos - ScoreBubleSize.Width / 2, graphPoint), ScoreBubleSize)); var pointLayer = new CAShapeLayer(); pointLayer.Path = scorePath; pointLayer.StrokeColor = graphColor; pointLayer.FillColor = UIColor.Clear.CGColor; this.Layer.AddSublayer(pointLayer); var scoreLayer = new CATextLayer(); scoreLayer.SetFont("System"); scoreLayer.FontSize = 10; scoreLayer.Frame = new CGRect(nextPos - ScoreSize.Width / 2, graphPoint + ScoreBubleSize.Height / 2 - ScoreSize.Height / 2, ScoreSize.Width, ScoreSize.Height); scoreLayer.AlignmentMode = CATextLayer.AlignmentCenter; scoreLayer.String = scoreText; scoreLayer.ForegroundColor = graphColor; this.Layer.AddSublayer(scoreLayer); nextPos -= Offset; } }
CALayer SetupClockFaceLayer() { clockFaceLayer = new CATextLayer() { FontSize = 60, ShadowOpacity = .9f }; clockFaceLayer.Bind("string", clockTimer, "outputString", null); clockFaceLayer.SetFont("Menlo"); // Constrain the text layer in the middle var constraint = CAConstraint.Create(CAConstraintAttribute.MidX, "superlayer", CAConstraintAttribute.MidX); clockFaceLayer.AddConstraint(constraint); constraint = CAConstraint.Create(CAConstraintAttribute.MidY, "superlayer", CAConstraintAttribute.MidY); clockFaceLayer.AddConstraint(constraint); return(clockFaceLayer); }
private static CATextLayer CreateCATextLayer(LabelStyle style, string text) { var label = new CATextLayer (); var ctFont = new CoreText.CTFont (style.Font.FontFamily, (float)style.Font.Size); var aString = new Foundation.NSAttributedString (text, new CoreText.CTStringAttributes() { Font = ctFont }); label.SetFont(ctFont); label.FontSize = (float)style.Font.Size; label.ForegroundColor = ToCGColor(style.ForeColor); label.BackgroundColor = TransparentColor; label.ShadowOpacity = 0; label.BorderWidth = 0; label.String = text; var size = GetSizeForText (0, aString); label.Frame = new CGRect (0, 0, size.Width, size.Height); return label; }
CATextLayer SetupTextLayer() { _textLayer = new CATextLayer { ForegroundColor = ProgressPieColors.TextLayerForegroundColor.AsResourceCgColor(), AlignmentMode = CATextLayer.AlignmentCenter, }; _textLayer.SetFont(ProgressPieFonts.TextFont.AsResourceNsFont()); var attrs = new NSMutableDictionary { { NSAttributedString.FontAttributeName, NSFont.FromFontName(ProgressPieFonts.TextFont.AsResourceNsFont().FontName, ProgressPieFonts.TextFont.AsResourceNsFont().PointSize) }, }; var applicationName = new NSAttributedString("100%", attrs); var textSize = applicationName.Size; _textLayer.Frame = new RectangleF(ProgressPieFloats.Radius.AsResourceFloat() - textSize.Width / 2 + ProgressPieFloats.TextLayerMargin.AsFloat(), ProgressPieFloats.Radius.AsResourceFloat() - textSize.Height / 2, textSize.Width, textSize.Height); return(_textLayer); }
void DrawTextLine(RTRTextLine textLine, CALayer layer, RTRResultStabilityStatus progress) { var topLeft = ScaledPoint(textLine.Quadrangle[0] as NSValue); var bottomLeft = ScaledPoint(textLine.Quadrangle[1] as NSValue); var bottomRight = ScaledPoint(textLine.Quadrangle[2] as NSValue); var topRight = ScaledPoint(textLine.Quadrangle[3] as NSValue); DrawQuadrangle(topLeft, bottomLeft, bottomRight, topRight, layer, progress); var recognizedString = textLine.Text; var textLayer = new CATextLayer(); var textWidth = DistanceBetween(topLeft, topRight); var textHeight = DistanceBetween(topLeft, bottomLeft); var rectForTextLayer = new CGRect(bottomLeft.X, bottomLeft.Y, textWidth, textHeight); // Selecting the initial font size by rectangle var textFont = GetFont(recognizedString, rectForTextLayer); textLayer.SetFont(CGFont.CreateWithFontName(textFont.FontDescriptor.Name)); textLayer.FontSize = textFont.PointSize; textLayer.ForegroundColor = ProgressColor(progress).CGColor; textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.String = recognizedString; textLayer.Frame = rectForTextLayer; // Rotate the text layer var angle = (float)Math.Asin((bottomRight.Y - bottomLeft.Y) / DistanceBetween(bottomLeft, bottomRight)); textLayer.AnchorPoint = new CGPoint(0, 0); textLayer.Position = bottomLeft; //textLayer.Transform = new CATransform3DRotate(CATransform3DIdentity, angle, 0, 0, 1); textLayer.Transform = CATransform3D.MakeRotation(angle, 0, 0, 1); layer.AddSublayer(textLayer); }
void CreateFrequencyLabelsAndLines () { float value; bool firstK = true; var scale = Layer.ContentsScale; for (int index = 0; index <= gridLineCount; index++) { value = GetValue ((float)index); var labelLayer = new CATextLayer { ForegroundColor = UIColor.FromWhiteAlpha (0.1f, 1f).CGColor, FontSize = 14, AlignmentMode = CATextLayer.AlignmentCenter, ContentsScale = scale, AnchorPoint = CGPoint.Empty }; labelLayer.SetFont (UIFont.SystemFontOfSize (14).Name); frequencyLabels.Add (labelLayer); if (index > 0 && index < gridLineCount) { var lineLayer = new CALayer { BackgroundColor = UIColor.FromWhiteAlpha (0.8f, 1f).CGColor }; freqLines.Add (lineLayer); graphLayer.AddSublayer (lineLayer); var s = GetString (value); if (value >= 1000 && firstK) { s += "K"; firstK = false; } labelLayer.String = s; } else if (index == 0) labelLayer.String = string.Format ("{0} Hz", GetString (value)); else labelLayer.String = string.Format ("{0} K", GetString (DefaultMaxHertz)); containerLayer.AddSublayer (labelLayer); } }
void CreateDbLabelsAndLines () { int value; var scale = Layer.ContentsScale; for (int index = -numDBLines; index <= numDBLines; index++) { value = index * (defaultGain / numDBLines); if (index >= -numDBLines && index <= numDBLines) { var labelLayer = new CATextLayer { String = string.Format ("{0} db", value), Name = index.ToString (), FontSize = 14, ContentsScale = scale, ForegroundColor = UIColor.FromWhiteAlpha (0.1f, 1f).CGColor, AlignmentMode = CATextLayer.AlignmentRight }; labelLayer.SetFont (UIFont.SystemFontOfSize (14).Name); dbLabels.Add (labelLayer); containerLayer.AddSublayer (labelLayer); var lineLayer = new CALayer { BackgroundColor = index == 0 ? UIColor.FromWhiteAlpha (0.65f, 1f).CGColor : UIColor.FromWhiteAlpha (0.8f, 1f).CGColor }; dbLines.Add (lineLayer); graphLayer.AddSublayer (lineLayer); } } }
public static void AddBadge(this UIBarButtonItem barButtonItem, string text, UIColor backgroundColor, UIColor textColor, bool filled = true, float fontSize = 11.0f) { if (string.IsNullOrEmpty(text)) { return; } CGPoint offset = CGPoint.Empty; if (backgroundColor == null) { backgroundColor = UIColor.Red; } var font = UIFont.SystemFontOfSize(fontSize); if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { font = UIFont.MonospacedDigitSystemFontOfSize(fontSize, UIFontWeight.Regular); } var view = barButtonItem.ValueForKey(new NSString(@"view")) as UIView; var bLayer = GetBadgeLayer(barButtonItem); bLayer?.RemoveFromSuperLayer(); var badgeSize = text.StringSize(font); var height = badgeSize.Height; var width = badgeSize.Width + 2; /* padding */ //make sure we have at least a circle if (width < height) { width = height; } //x position is offset from right-hand side var x = view.Frame.Width - width + offset.X; var badgeFrame = new CGRect(new CGPoint(x: x, y: offset.Y), size: new CGSize(width: width, height: height)); bLayer = new CAShapeLayer(); DrawRoundedRect(bLayer, badgeFrame, 7.0f, backgroundColor, filled); view.Layer.AddSublayer(bLayer); // Initialiaze Badge's label var label = new CATextLayer { String = text, TextAlignmentMode = CATextLayerAlignmentMode.Center, FontSize = font.PointSize, Frame = badgeFrame, ForegroundColor = filled ? textColor.CGColor : UIColor.White.CGColor, BackgroundColor = UIColor.Clear.CGColor, ContentsScale = UIScreen.MainScreen.Scale }; label.SetFont(CGFont.CreateWithFontName(font.Name)); bLayer.AddSublayer(label); // Save Badge as UIBarButtonItem property objc_setAssociatedObject(barButtonItem.Handle, BadgeKey.Handle, bLayer.Handle, AssociationPolicy.RETAIN_NONATOMIC); }
public override void Draw (CGRect rect) { base.Draw (rect); using (var context = UIGraphics.GetCurrentContext ()) { UIBezierPath mainAxis = UIBezierPath.FromRoundedRect ( new CGRect (xAxisMargin, 0.0f, 2.0f, rect.Height), 2.0f); UIColor.FromRGB ( 203, 203, 203).SetFill(); mainAxis.Fill(); nfloat sepInterval = (nfloat)Math.Floor ((rect.Width - xAxisMargin - xTextMargin)/ 5); for (int i = 1; i < 6; i++) { var separatorAxis = new UIBezierPath(); separatorAxis.MoveTo (new CGPoint (xAxisMargin + sepInterval * i, 0)); separatorAxis.AddLineTo (new CGPoint ( xAxisMargin + sepInterval * i, rect.Height - yAxisMargin)); UIColor.FromRGB ( 203, 203, 203).SetStroke(); separatorAxis.LineWidth = 1.0f; separatorAxis.SetLineDash ( new nfloat[] {1.0f,1.0f}, 1); separatorAxis.Stroke (); var textLayer = new CATextLayer (); textLayer.ContentsScale = UIScreen.MainScreen.Scale; CGFont font = CGFont.CreateWithFontName (LabelFont.Name); if (font != null) { textLayer.SetFont (font); font.Dispose (); } textLayer.FontSize = LabelFont.PointSize; textLayer.AnchorPoint = new CGPoint ( 0.5f, 0.0f); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.BackgroundColor = UIColor.Clear.CGColor; textLayer.ForegroundColor = LabelColor.CGColor; CGSize size = ((NSString)"0000 h").StringSize (LabelFont); textLayer.String = "00 h"; textLayer.Bounds = new CGRect (0, 0, size.Width, size.Height); textLayer.Position = new CGPoint ( xAxisMargin + sepInterval * i, rect.Height - yAxisMargin + 5.0f); Layer.AddSublayer (textLayer); xAxisText [i - 1] = textLayer; } } }
//partial void SelectMetadataObjectTypes(UIButton sender) //{ // var controller = new ItemSelectionViewController<AVMetadataObjectType>(this, // MetadataObjectTypeItemSelectionIdentifier, // this.metadataOutput.AvailableMetadataObjectTypes.GetFlags().ToList(), // this.metadataOutput.MetadataObjectTypes.GetFlags().ToList(), // true); // this.PresentItemSelectionViewController(controller); //} /// <summary> /// 2.스캔결과값 /// </summary> /// <param name="metadataObject"></param> /// <returns></returns> private MetadataObjectLayer CreateMetadataOverlay(AVMetadataObject metadataObject) { // Transform the metadata object so the bounds are updated to reflect those of the video preview layer. var transformedMetadataObject = this.PreviewView.VideoPreviewLayer.GetTransformedMetadataObject(metadataObject); // Create the initial metadata object overlay layer that can be used for either machine readable codes or faces. //빔 컬러 var metadataObjectOverlayLayer = new MetadataObjectLayer { LineWidth = 3, LineJoin = CAShapeLayer.JoinRound, MetadataObject = transformedMetadataObject, FillColor = UIColor.Red.CGColor, StrokeColor = UIColor.Red.CGColor //FillColor = this.View.TintColor.ColorWithAlpha(0.3f).CGColor, //StrokeColor = this.View.TintColor.ColorWithAlpha(0.7f).CGColor }; var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject; if (barcodeMetadataObject != null) { var barcodeOverlayPath = this.BarcodeOverlayPathWithCorners(barcodeMetadataObject.Corners); metadataObjectOverlayLayer.Path = barcodeOverlayPath; // If the metadata object has a string value, display it. string textLayerString = null; //스캔된 바코드 값 //바코드 타입 : barcodeMetadataObject.Type if (!string.IsNullOrEmpty(barcodeMetadataObject.StringValue)) { textLayerString = barcodeMetadataObject.StringValue; } else { // TODO: add Descriptor (line 618 in original iOS sample) } //스캔된 바코드 값 if (!string.IsNullOrEmpty(textLayerString)) { Console.WriteLine("========Result========"); Console.WriteLine(barcodeMetadataObject.Type + ", " + barcodeMetadataObject.StringValue); //this.PreviewView.customOverlay.tableSource.tableItems.Add(new TableItem { Heading = "heading", SubHeading = "subheading", ImageName = "barcode36x36.png" }); //this.InvokeOnMainThread(() => { this.PreviewView.customOverlay.RowAdd("aa", "bb"); }); var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox; var font = UIFont.BoldSystemFontOfSize(16).ToCTFont(); var textLayer = new CATextLayer(); textLayer.TextAlignmentMode = CATextLayerAlignmentMode.Center; //글자표시 박스, 높이가 작아서 글자 안보임 +50추가 textLayer.Bounds = new CGRect(0, 0, barcodeOverlayBoundingBox.Size.Width + 20, barcodeOverlayBoundingBox.Size.Height + 50); //textLayer.Bounds = new CGRect(0, 0, 300, 100); textLayer.ContentsScale = UIScreen.MainScreen.Scale; textLayer.Position = new CGPoint(barcodeOverlayBoundingBox.GetMidX(), barcodeOverlayBoundingBox.GetMidY()); textLayer.Wrapped = true; textLayer.Transform = CATransform3D.MakeFromAffine(this.PreviewView.Transform).Invert(); //------------------------------------- //스캔된 바코드 biz logic //------------------------------------- //연속 스캔 if (this.IsContinue) { if (this.IsFixed) { if (this.AllScanBarcode.Contains(textLayerString)) { //1. 저장 했는지? if (this.SaveCompletedBarcode.Contains(textLayerString)) { //저장 완료 //Color.Green textLayer.String = "저장 완료\n" + textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.Green.CGColor }); //경고 audioCautionPlayer.Play(); doubleVibrator.PlaySystemSoundAsync(); } //2. Scan 완료 했는지? else if (this.ScanCompletedBarcode.Contains(textLayerString)) { //스캔 완료 //Color.Yellow textLayer.String = "스캔 완료\n" + textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.Yellow.CGColor }); //경고 audioCautionPlayer.Play(); doubleVibrator.PlaySystemSoundAsync(); } else { //------------ //정상처리 작업 //------------ OnScanCompleted?.Invoke(barcodeMetadataObject.Type.ToString(), textLayerString); textLayer.String = textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.White.CGColor }); //정상 audioPlayer.Play(); SystemSound.Vibrate.PlaySystemSoundAsync(); if (!this.ScanCompletedBarcode.Contains(textLayerString)) { this.ScanCompletedBarcode.Add(textLayerString); } if (this.AllScanBarcode.Count == this.SaveCompletedBarcode.Count + this.ScanCompletedBarcode.Count) { this.session.StopRunning(); OnScanCompleted?.Invoke(string.Empty, "EXIT"); DismissViewController(true, null); //화면 종료 } else { //연속스캔 사이의 간격 지정 //이 함수 호출하는 부분에서 처리 } } } else { //스캔 대상X //Color.Red textLayer.String = "스캔 대상X\n" + textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.Red.CGColor }); //경고 audioCautionPlayer.Play(); doubleVibrator.PlaySystemSoundAsync(); } } //비고정(스캔 대상 없음) else { //현재로서는 biz로직 없음 } } //단일 스캔 else { this.session.StopRunning(); textLayer.String = textLayerString; textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes { Font = font, StrokeWidth = 0, StrokeColor = UIColor.Black.CGColor, ForegroundColor = UIColor.White.CGColor }); //정상 audioPlayer.Play(); SystemSound.Vibrate.PlaySystemSoundAsync(); OnScanCompleted?.Invoke(barcodeMetadataObject.Type.ToString(), textLayerString); DismissViewController(true, null); //화면 종료 } //화면에 표시 textLayer.SetFont(font); metadataObjectOverlayLayer.AddSublayer(textLayer); } } else if (transformedMetadataObject is AVMetadataFaceObject) { metadataObjectOverlayLayer.Path = CGPath.FromRect(transformedMetadataObject.Bounds); } return(metadataObjectOverlayLayer); }
public static CATextLayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IFeature feature, IViewport viewport, string text) { // Offset stackOffset, Mapsui.Geometries.Point p = viewport.WorldToScreen(point); //var pointF = new xPointF((float)p.X, (float)p.Y); var label = new CATextLayer(); var aString = new MonoTouch.Foundation.NSAttributedString(text, new MonoTouch.CoreText.CTStringAttributes() { Font = new MonoTouch.CoreText.CTFont("ArialMT", 10) }); var frame = new RectangleF(new System.Drawing.Point((int)p.X, (int)p.Y), GetSizeForText(0, aString)); //label.Frame = frame; //frame.Width = (float)(p2.X - p1.X);// + margin); //frame.Height = (float)(p1.Y - p2.Y); label.FontSize = 10; label.ForegroundColor = new MonoTouch.CoreGraphics.CGColor(0, 0, 255, 150); label.BackgroundColor = new MonoTouch.CoreGraphics.CGColor(255, 0, 2, 150); label.String = text; label.Frame = frame; Console.WriteLine("Pos " + label.Frame.X + ":" + label.Frame.Y + " w " + label.Frame.Width + " h " + label.Frame.Height); // = MonoTouch.UIKit.UIScreen.MainScreen.Scale; // label.ContentsScale = scale; return(label); //var border = new Border(); //var textblock = new TextBlock(); //Text //textblock.Text = text; //Colors //textblock.Foreground = new SolidColorBrush(style.ForeColor.ToXaml()); //border.Background = new SolidColorBrush(style.BackColor.Color.ToXaml()); //Font //textblock.FontFamily = new FontFamily(style.Font.FontFamily); //textblock.FontSize = style.Font.Size; //set some defaults which should be configurable someday const double witdhMargin = 3.0; const double heightMargin = 0.0; //textblock.Margin = new Thickness(witdhMargin, heightMargin, witdhMargin, heightMargin); //border.CornerRadius = new CornerRadius(4); //border.Child = textblock; //Offset //var textWidth = textblock.ActualWidth; //var textHeight = textblock.ActualHeight; #if !SILVERLIGHT && !NETFX_CORE // in WPF the width and height is not calculated at this point. So we use FormattedText //getTextWidthAndHeight(ref textWidth, ref textHeight, style, text); #endif //border.SetValue(Canvas.LeftProperty, windowsPoint.X + style.Offset.X + stackOffset.X - (textWidth + 2 * witdhMargin) * (short)style.HorizontalAlignment * 0.5f); //border.SetValue(Canvas.TopProperty, windowsPoint.Y + style.Offset.Y + stackOffset.Y - (textHeight + 2 * heightMargin) * (short)style.VerticalAlignment * 0.5f); //return border; //return null; }
private SliceLayer createSliceLayer () { var pieLayer = new SliceLayer (); pieLayer.Frame = _pieView.Frame; var arcLayer = new CAShapeLayer (); arcLayer.ZPosition = 0; arcLayer.StrokeColor = null; pieLayer.AddSublayer (arcLayer); var textLayer = new CATextLayer (); textLayer.ContentsScale = UIScreen.MainScreen.Scale; CGFont font = CGFont.CreateWithFontName (LabelFont.Name); if (font != null) { textLayer.SetFont (font); font.Dispose (); } textLayer.FontSize = LabelFont.PointSize; textLayer.AnchorPoint = new CGPoint (0.5f, 0.5f); textLayer.AlignmentMode = CATextLayer.AlignmentCenter; textLayer.BackgroundColor = UIColor.Clear.CGColor; textLayer.ForegroundColor = LabelColor.CGColor; if (LabelShadowColor != null) { textLayer.ShadowColor = LabelShadowColor.CGColor; textLayer.ShadowOffset = CGSize.Empty; textLayer.ShadowOpacity = 1.0f; textLayer.ShadowRadius = 2.0f; } CGSize size = ((NSString)"0").StringSize (LabelFont); textLayer.Frame = new CGRect (new CGPoint (0, 0), size); textLayer.Position = new CGPoint (_pieCenter.X + LabelRadius * (nfloat)Math.Cos (0), _pieCenter.Y + LabelRadius * (nfloat)Math.Sin (0)); pieLayer.AddSublayer (textLayer); layerPool.Add (pieLayer); return pieLayer; }
public ActivityArcView(IntPtr ptr) : base(ptr) { _shadowStrokeColor = UIColor.FromRGB(0xe0, 0xe0, 0xe0); _arcStrokeColor = UIColor.Black; _arcLayer = new CAShapeLayer() { StrokeColor = _arcStrokeColor.CGColor }; _shadowLayer = new CAShapeLayer() { StrokeColor = _shadowStrokeColor.CGColor, FillColor = _arcLayer.FillColor = null, StrokeStart = _arcLayer.StrokeStart = 0f, LineWidth = _arcLayer.LineWidth = 4f, LineCap = _arcLayer.LineCap = CAShapeLayer.CapRound, }; _textLayer = new CATextLayer() { Hidden = true, TextAlignmentMode = CATextLayerAlignmentMode.Center, ForegroundColor = UIColor.DarkTextColor.CGColor }; _textLayer.ContentsScale = _textLayer.RasterizationScale = _shadowLayer.RasterizationScale = _arcLayer.RasterizationScale = UIScreen.MainScreen.Scale; Layer.AddSublayer(_shadowLayer); Layer.AddSublayer(_arcLayer); Layer.AddSublayer(_textLayer); SetupRotationAnimation(); SetupStrokeAnimation(); SetupColorAnimation(); var path = CreateArcPath(5f); _pathGrowAnimation = CABasicAnimation.FromKeyPath("path"); _pathGrowAnimation.Duration = 0.5f; _pathGrowAnimation.RemovedOnCompletion = false; _pathGrowAnimation.FillMode = CAFillMode.Forwards; _pathGrowAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut); _pathGrowAnimation.AnimationStopped += (x, y) => { _shadowLayer.Path = _pathGrowAnimation.GetToAs <CGPath>(); UpdateLayers(); }; _pathShrinkAnimation = CABasicAnimation.FromKeyPath("path"); _pathShrinkAnimation.Duration = 0.5f; _pathShrinkAnimation.RemovedOnCompletion = false; _pathShrinkAnimation.FillMode = CAFillMode.Forwards; _pathShrinkAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn); _pathShrinkAnimation.AnimationStopped += (x, y) => { _shadowLayer.Path = _pathShrinkAnimation.GetToAs <CGPath>(); UpdateLayers(); }; _pathOpacityUpAnimation = CABasicAnimation.FromKeyPath("opacity"); _pathOpacityUpAnimation.From = NSNumber.FromNFloat(0f); _pathOpacityUpAnimation.To = NSNumber.FromNFloat(1f); _pathOpacityUpAnimation.Duration = 0.5f; _pathOpacityUpAnimation.FillMode = CAFillMode.Forwards; _pathOpacityUpAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut); _pathOpacityUpAnimation.RemovedOnCompletion = false; _pathOpacityUpAnimation.AnimationStopped += (x, y) => { _shadowLayer.Opacity = _arcLayer.Opacity = _pathOpacityUpAnimation.GetToAs <NSNumber>().FloatValue; }; _pathOpacityDownAnimation = CABasicAnimation.FromKeyPath("opacity"); _pathOpacityDownAnimation.From = NSNumber.FromNFloat(1f); _pathOpacityDownAnimation.To = NSNumber.FromNFloat(0f); _pathOpacityDownAnimation.Duration = 0.5f; _pathOpacityDownAnimation.FillMode = CAFillMode.Forwards; _pathOpacityDownAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn); _pathOpacityDownAnimation.RemovedOnCompletion = false; _pathOpacityDownAnimation.AnimationStopped += (x, y) => { _shadowLayer.Opacity = _arcLayer.Opacity = _pathOpacityDownAnimation.GetToAs <NSNumber>().FloatValue; }; }
/// <summary> /// Initializes a new instance of the <see cref="JZMultiChoice.JZMultiChoicesCircleButton"/> class. /// </summary> /// <param name="point">Center Point.</param> /// <param name="icon">Center Icon</param> /// <param name="sRadius">Small radius.</param> /// <param name="bRadius">Big radius.</param> /// <param name="mMenuItems">Choice items</param> /// <param name="isParallex">If set to <c>true</c> is parallex.</param> /// <param name="parallex">Parallex amount</param> /// <param name="vc">ViewContoller.</param> public JZMultiChoicesCircleButton(CGPoint point, UIImage icon , float sRadius, float bRadius, ChoiceItemCollection mMenuItems, bool isParallex , float parallex, UIViewController vc) : this(UIScreen.MainScreen.Bounds) { this.SmallRadius = sRadius; this.BigRadius = bRadius; this.isTouchDown = false; this.CenterPoint = point; this.IconImage = icon; this.ParallexParameter = parallex; this.Parallex = isParallex; this.ResponderUIVC = vc; BackgroundView = new UIView(new CGRect(point.X - sRadius, point.Y - sRadius, sRadius * 2, sRadius * 2)); BackgroundView.BackgroundColor = new UIColor(0f, 0f, 0f, 0.7f); BackgroundView.Layer.CornerRadius = sRadius; this.Add(BackgroundView); SmallButton = new UIButton(new CGRect(point.X - sRadius, point.Y - sRadius, sRadius * 2, sRadius * 2)); SmallButton.Layer.CornerRadius = sRadius; SmallButton.Layer.BackgroundColor = UIColor.FromRGBA(252.0f / 255.0f, 81.0f / 255.0f, 106.0f / 255.0f, 1.0f).CGColor; SmallButton.Layer.ShadowColor = UIColor.Black.CGColor; SmallButton.Layer.ShadowOffset = new CGSize(0.0f, 6.0f); SmallButton.Layer.ShadowOpacity = 0.3f; SmallButton.Layer.ShadowRadius = 4.0f; SmallButton.Layer.ZPosition = bRadius; SmallButton.SetImage(IconImage, UIControlState.Normal); SmallButton.AddTarget(TouchDown, UIControlEvent.TouchDown); SmallButton.AddTarget(this, new Selector("TouchDrag:withEvent:"), UIControlEvent.TouchDragInside); SmallButton.AddTarget(this, new Selector("TouchDrag:withEvent:"), UIControlEvent.TouchDragOutside); SmallButton.AddTarget(this, new Selector("TouchUpInside:withEvent:"), UIControlEvent.TouchUpInside); SmallButton.AddTarget(TouchUpOutside, UIControlEvent.TouchUpOutside); this.Add(SmallButton); label = new CATextLayer(); label.FontSize = 9.0f; label.String = @"Choose:"; label.FontSize = 40; label.SetFont(@"ArialMT"); label.AlignmentMode = CATextLayer.AlignmentCenter; label.ForegroundColor = UIColor.FromWhiteAlpha(1.0f, 0.0f).CGColor; label.Frame = new CGRect(-SmallRadius * 3, -52, SmallRadius * 8, 100); var UnScaleFactor = SmallRadius / BigRadius; label.Transform = CATransform3D.MakeScale(UnScaleFactor, UnScaleFactor, 1.0f); SmallButton.Layer.AddSublayer(label); var TransformPara = BigRadius / SmallRadius; var MultiChoiceRadius = (BigRadius + SmallRadius) / 8 / TransformPara; this.mItems = mMenuItems; IconArray = new List <UIImageView> (); var number = mMenuItems.Count; foreach (var aItem in this.mItems) { var i = mItems.IndexOf(aItem); var XOffest = 4 * MultiChoiceRadius * Math.Cos(2 * Math.PI * i / number); var YOffest = 4 * MultiChoiceRadius * Math.Sin(2 * Math.PI * i / number); var IconImageView = new UIImageView(new CGRect(sRadius + XOffest - MultiChoiceRadius, sRadius + YOffest - MultiChoiceRadius, MultiChoiceRadius * 2, MultiChoiceRadius * 2)); IconImageView.Image = aItem.Icon; IconImageView.Alpha = 0.0f; IconImageView.Hidden = true; SmallButton.Add(IconImageView); SmallButton.BringSubviewToFront(IconImageView); IconImageView.Layer.ContentsScale = UIScreen.MainScreen.Scale * BigRadius / SmallRadius; IconArray.Add(IconImageView); } var UnFullFactor = SmallRadius / this.Frame.Size.Height; CallbackIcon = new UIImageView(new CGRect((SmallButton.Frame.Size.Width - BigRadius) / 2, (SmallButton.Frame.Size.Height - BigRadius) / 2, BigRadius, BigRadius)); CallbackIcon.Layer.Transform = CATransform3D.MakeScale(UnFullFactor, UnFullFactor, 1.0f); CallbackIcon.Image = UIImage.FromBundle("CallbackSuccess"); CallbackIcon.Alpha = 0.0f; SmallButton.Add(CallbackIcon); CallbackMessage = new UILabel(); CallbackMessage.Text = @""; CallbackMessage.Alpha = 0.0f; CallbackMessage.Font = UIFont.SystemFontOfSize(20.0f); CallbackMessage.Layer.Transform = CATransform3D.MakeScale(UnFullFactor, UnFullFactor, 1.0f); CallbackMessage.TextColor = UIColor.White; //[UIColor whiteColor]; CallbackMessage.TextAlignment = UITextAlignment.Center; CallbackMessage.Frame = new CGRect((SmallButton.Frame.Size.Width - SmallRadius / 2) / 2, (SmallButton.Frame.Size.Height - SmallRadius / 4) / 2 + 6, SmallRadius / 2, SmallRadius / 4); SmallButton.Add(CallbackMessage); // FullPara = this.Frame.Size.Height / SmallRadius; var thning = SmallButton.Layer.ValueForKey(new NSString(@"transform.scale")); if (thning != null) { var val = (NSNumber)NSNumber.FromObject(thning); MidiumPara = val.DoubleValue; } else { MidiumPara = 1.0f; } SmallPara = 1.0f; }
private BarLayer CreateBarLayer(float barHeight) { var barLayer = new BarLayer() { ZPosition = 0, BorderColor = UIColor.White.CGColor, AnchorPoint = new PointF(0.0f, 0.5f), Frame = new RectangleF(0, 0, Bounds.Width, barHeight) }; var mainBar = new CALayer(); mainBar.AnchorPoint = new PointF(0.0f, 0.0f); mainBar.Bounds = new RectangleF(0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); mainBar.Position = new PointF(xAxisMargin, 0); mainBar.BackgroundColor = MainBarColor.CGColor; mainBar.SetValueForKeyPath(new NSNumber(minBarScale), new NSString("transform.scale.x")); barLayer.AddSublayer(mainBar); var secondaryBar = new CALayer(); secondaryBar.AnchorPoint = new PointF(0.0f, 0.0f); secondaryBar.Bounds = new RectangleF(0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); secondaryBar.Position = new PointF(xAxisMargin, 0); secondaryBar.BackgroundColor = SecondaryBarColor.CGColor; secondaryBar.SetValueForKeyPath(new NSNumber(minBarScale), new NSString("transform.scale.x")); barLayer.AddSublayer(secondaryBar); var emptyBar = new CALayer(); emptyBar.AnchorPoint = new PointF(0.0f, 0.0f); emptyBar.Bounds = new RectangleF(0, 0, 2.0f, barHeight); emptyBar.Position = new PointF(xAxisMargin, 0); emptyBar.BackgroundColor = UIColor.Gray.CGColor; barLayer.AddSublayer(emptyBar); CGFont font = CGFont.CreateWithFontName(LabelFont.Name); SizeF size = ((NSString)"00.00:00").StringSize(LabelFont); var textLayer = new CATextLayer() { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new PointF(0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = LabelColor.CGColor }; barLayer.AddSublayer(textLayer); var timeTextLayer = new CATextLayer() { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new PointF(0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = SecondaryBarColor.CGColor }; barLayer.AddSublayer(timeTextLayer); if (font != null) { textLayer.SetFont(font); timeTextLayer.SetFont(font); font.Dispose(); } CATransaction.DisableActions = true; textLayer.Bounds = new RectangleF(new PointF(0, 0), size); textLayer.Position = mainBar.Position; timeTextLayer.Bounds = new RectangleF(new PointF(0, 0), size); timeTextLayer.Position = new PointF(mainBar.Position.X + 5.0f, mainBar.Position.Y); CATransaction.DisableActions = false; return(barLayer); }
//- (void)presentImage:(NSImage *)image; void PresentImage(NSImage image, string filename) { int animationSpeed = 3; CGRect superLayerBounds = View.Layer.Bounds; CGPoint center = new CGPoint(superLayerBounds.GetMidX(), superLayerBounds.GetMidY()); CGRect imageBounds = new CGRect(0, 0, image.Size.Width, image.Size.Height); nfloat X = (nfloat)random.Next((int)Math.Floor(imageBounds.Width / 2), (int)Math.Floor(superLayerBounds.GetMaxX() - imageBounds.Width / 2)); //(superLayerBounds.GetMaxX() - imageBounds.Width/2) * random.NextDouble(); nfloat Y = (nfloat)random.Next((int)Math.Floor(imageBounds.Height / 2), (int)Math.Floor(superLayerBounds.GetMaxY() - imageBounds.Height / 2)); //(superLayerBounds.GetMaxY() - imageBounds.Height/2) * random.NextDouble(); CGPoint randomPoint = new CGPoint(X, Y); CAMediaTimingFunction tf = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); // Animations for image layer CABasicAnimation posAnim = CABasicAnimation.FromKeyPath("position"); posAnim.From = NSValue.FromCGPoint(center); posAnim.Duration = animationSpeed; posAnim.TimingFunction = tf; CABasicAnimation bdsAnim = CABasicAnimation.FromKeyPath("bounds"); bdsAnim.From = NSValue.FromCGRect(CGRect.Empty); bdsAnim.Duration = animationSpeed; bdsAnim.TimingFunction = tf; // Image layer CALayer layer = new CALayer(); layer.Contents = image.CGImage; layer.Position = center; layer.ZPosition = random.Next(-100, 99); layer.Actions = NSDictionary.FromObjectsAndKeys(new NSObject[] { posAnim, bdsAnim }, new NSObject[] { new NSString("position"), new NSString("bounds") }); // Animation for text layer CATransform3D scale = CATransform3D.MakeScale(0.0f, 0.0f, 0.0f); CABasicAnimation tScaleAnim = CABasicAnimation.FromKeyPath("transform"); tScaleAnim.From = NSValue.FromCATransform3D(scale); tScaleAnim.Duration = animationSpeed; tScaleAnim.TimingFunction = tf; // text layer CATextLayer fileNameLayer = new CATextLayer(); fileNameLayer.FontSize = 24; fileNameLayer.ForegroundColor = NSColor.White.CGColor; SetText(" " + filename + " ", fileNameLayer); fileNameLayer.Transform = scale; fileNameLayer.Position = CGPoint.Empty; fileNameLayer.AnchorPoint = CGPoint.Empty; fileNameLayer.ShadowColor = NSColor.Black.CGColor; fileNameLayer.ShadowOffset = new CGSize(5, 5); fileNameLayer.ShadowOpacity = 1.0f; fileNameLayer.ShadowRadius = 0.0f; fileNameLayer.BorderColor = NSColor.White.CGColor; fileNameLayer.BorderWidth = 1.0f; fileNameLayer.Actions = NSDictionary.FromObjectsAndKeys(new NSObject[] { tScaleAnim }, new NSObject[] { new NSString("transform") }); layer.AddSublayer(fileNameLayer); View.Layer.AddSublayer(layer); CATransaction.Begin(); layer.Position = randomPoint; layer.Bounds = imageBounds; fileNameLayer.Transform = CATransform3D.Identity; CATransaction.Commit(); }
CALayer SetupClockFaceLayer() { clockFaceLayer = new CATextLayer (){ FontSize = 60, ShadowOpacity = .9f }; clockFaceLayer.Bind ("string", clockTimer, "outputString", null); clockFaceLayer.SetFont ("Menlo-Regular"); // Constrain the text layer in the middle var constraint = CAConstraint.Create (CAConstraintAttribute.MidX, "superlayer", CAConstraintAttribute.MidX); clockFaceLayer.AddConstraint (constraint); constraint = CAConstraint.Create (CAConstraintAttribute.MidY, "superlayer", CAConstraintAttribute.MidY); clockFaceLayer.AddConstraint (constraint); return clockFaceLayer; }
private BarLayer CreateBarLayer ( nfloat barHeight) { var barLayer = new BarLayer () { ZPosition = 0, BorderColor = UIColor.White.CGColor, AnchorPoint = new CGPoint ( 0.0f, 0.5f), Frame = new CGRect ( 0, 0, Bounds.Width, barHeight) }; var mainBar = new CALayer (); mainBar.AnchorPoint = new CGPoint (0.0f, 0.0f); mainBar.Bounds = new CGRect ( 0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); mainBar.Position = new CGPoint ( xAxisMargin, 0); mainBar.BackgroundColor = MainBarColor.CGColor; mainBar.SetValueForKeyPath ( new NSNumber ( minBarScale), new NSString ( "transform.scale.x")); barLayer.AddSublayer (mainBar); var secondaryBar = new CALayer (); secondaryBar.AnchorPoint = new CGPoint (0.0f, 0.0f); secondaryBar.Bounds = new CGRect ( 0, 0, Bounds.Width - xAxisMargin - xTextMargin, barHeight); secondaryBar.Position = new CGPoint ( xAxisMargin, 0); secondaryBar.BackgroundColor = SecondaryBarColor.CGColor; secondaryBar.SetValueForKeyPath ( new NSNumber ( minBarScale), new NSString ( "transform.scale.x")); barLayer.AddSublayer (secondaryBar); var emptyBar = new CALayer (); emptyBar.AnchorPoint = new CGPoint (0.0f, 0.0f); emptyBar.Bounds = new CGRect ( 0, 0, 2.0f, barHeight); emptyBar.Position = new CGPoint ( xAxisMargin, 0); emptyBar.BackgroundColor = UIColor.Gray.CGColor; barLayer.AddSublayer (emptyBar); CGFont font = CGFont.CreateWithFontName (LabelFont.Name); CGSize size = ((NSString)"00.00:00").StringSize (LabelFont); var textLayer = new CATextLayer () { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new CGPoint (0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = LabelColor.CGColor }; barLayer.AddSublayer (textLayer); var timeTextLayer = new CATextLayer () { ContentsScale = UIScreen.MainScreen.Scale, FontSize = 10.0f, AnchorPoint = new CGPoint (0.0f, 0.5f), AlignmentMode = CATextLayer.AlignmentLeft, BackgroundColor = UIColor.Clear.CGColor, ForegroundColor = SecondaryBarColor.CGColor }; barLayer.AddSublayer (timeTextLayer); if (font != null) { textLayer.SetFont (font); timeTextLayer.SetFont (font); font.Dispose (); } CATransaction.DisableActions = true; textLayer.Bounds = new CGRect (new CGPoint (0, 0), size); textLayer.Position = mainBar.Position; timeTextLayer.Bounds = new CGRect (new CGPoint (0, 0), size); timeTextLayer.Position = new CGPoint ( mainBar.Position.X + 5.0f, mainBar.Position.Y); CATransaction.DisableActions = false; return barLayer; }
void DrawTextInCorner (CVPixelBuffer pixelBuffer) { var textLayer = new CATextLayer (); const float textLayerWidth = 100f; const float textLayerHeight = 50f; if (AffineTransform.xx == -1.0f && AffineTransform.yy == -1.0f) { textLayer.AffineTransform = AffineTransform; } else if (AffineTransform.xy == 1.0f && AffineTransform.yx == -1f) { textLayer.AffineTransform = new CGAffineTransform ( AffineTransform.xx * -1f, AffineTransform.xy * -1f, AffineTransform.yx * -1f, AffineTransform.yy * -1f, AffineTransform.x0, AffineTransform.y0 ); } textLayer.Frame = new CGRect (Bounds.Size.Width - textLayerWidth, 0f, textLayerWidth, textLayerHeight); textLayer.String = TimeCode; textLayer.BackgroundColor = UIColor.Black.CGColor; AddSublayer (textLayer); }
// An AutoResetEvent instance is used for drawing metadata object overlays so that // only one group of metadata object overlays is drawn at a time. MetadataObjectLayer CreateMetadataOverlay (AVMetadataObject metadataObject) { // Transform the metadata object so the bounds are updated to reflect those of the video preview layer. var transformedMetadataObject = PreviewView.VideoPreviewLayer.GetTransformedMetadataObject (metadataObject); // Create the initial metadata object overlay layer that can be used for either machine readable codes or faces. var metadataObjectOverlayLayer = new MetadataObjectLayer { MetadataObject = transformedMetadataObject, LineJoin = CAShapeLayer.JoinRound, LineWidth = 7, StrokeColor = View.TintColor.ColorWithAlpha (0.7f).CGColor, FillColor = View.TintColor.ColorWithAlpha (0.3f).CGColor }; var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject; if (barcodeMetadataObject != null) { var barcodeOverlayPath = BarcodeOverlayPathWithCorners (barcodeMetadataObject.Corners); metadataObjectOverlayLayer.Path = barcodeOverlayPath; // If the metadata object has a string value, display it. if (barcodeMetadataObject.StringValue.Length > 0) { var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox; var font = UIFont.BoldSystemFontOfSize (19).ToCTFont (); var textLayer = new CATextLayer { AlignmentMode = CATextLayer.AlignmentCenter, Bounds = new CGRect (0, 0, barcodeOverlayBoundingBox.Size.Width, barcodeOverlayBoundingBox.Size.Height), ContentsScale = UIScreen.MainScreen.Scale, Position = new CGPoint (barcodeOverlayBoundingBox.GetMidX (), barcodeOverlayBoundingBox.GetMidY ()), Wrapped = true, // Invert the effect of transform of the video preview so the text is orientated with the interface orientation. Transform = CATransform3D.MakeFromAffine (PreviewView.Transform).Invert (default (CATransform3D)), AttributedString = new NSAttributedString (barcodeMetadataObject.StringValue, new CTStringAttributes { Font = font, ForegroundColor = UIColor.White.CGColor, StrokeWidth = -5, StrokeColor = UIColor.Black.CGColor }) }; textLayer.SetFont (font); metadataObjectOverlayLayer.AddSublayer (textLayer); } } else if (transformedMetadataObject is AVMetadataFaceObject) { metadataObjectOverlayLayer.Path = CGPath.FromRect (transformedMetadataObject.Bounds); } return metadataObjectOverlayLayer; }
//- (void)setText:(NSString *)text; void SetText(string text, CATextLayer tl) { NSFont font = NSFont.SystemFontOfSize(tl.FontSize); NSDictionary attrs = NSDictionary.FromObjectsAndKeys(new NSObject[]{font}, new NSObject[]{NSStringAttributeKey.Font}); CGSize size = text.StringSize(attrs); // Ensure that the size is in whole numbers: size.Width = (nfloat)Math.Ceiling(size.Width); size.Height = (nfloat)Math.Ceiling(size.Height); CGRect bounds = new CGRect(0, 0, size.Width, size.Height); tl.Bounds = bounds; if (tl.SuperLayer == textContainer ) { tl.SuperLayer.Bounds = new CGRect(0, 0, size.Width + 16, size.Height + 20); } tl.String = text; }
//- (void)presentImage:(NSImage *)image; void PresentImage(NSImage image, string filename) { int animationSpeed = 3; CGRect superLayerBounds = View.Layer.Bounds; CGPoint center = new CGPoint(superLayerBounds.GetMidX(), superLayerBounds.GetMidY()); CGRect imageBounds = new CGRect(0, 0, image.Size.Width, image.Size.Height); nfloat X = (nfloat)random.Next((int)Math.Floor(imageBounds.Width/2), (int)Math.Floor(superLayerBounds.GetMaxX() - imageBounds.Width/2));//(superLayerBounds.GetMaxX() - imageBounds.Width/2) * random.NextDouble(); nfloat Y = (nfloat)random.Next((int)Math.Floor(imageBounds.Height/2), (int)Math.Floor(superLayerBounds.GetMaxY() - imageBounds.Height/2)); //(superLayerBounds.GetMaxY() - imageBounds.Height/2) * random.NextDouble(); CGPoint randomPoint = new CGPoint(X, Y); CAMediaTimingFunction tf = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); // Animations for image layer CABasicAnimation posAnim = CABasicAnimation.FromKeyPath("position"); posAnim.From = NSValue.FromCGPoint(center); posAnim.Duration = animationSpeed; posAnim.TimingFunction = tf; CABasicAnimation bdsAnim = CABasicAnimation.FromKeyPath("bounds"); bdsAnim.From = NSValue.FromCGRect(CGRect.Empty); bdsAnim.Duration = animationSpeed; bdsAnim.TimingFunction = tf; // Image layer CALayer layer = new CALayer(); layer.Contents = image.CGImage; layer.Position = center; layer.ZPosition = random.Next(-100, 99); layer.Actions = NSDictionary.FromObjectsAndKeys(new NSObject[]{posAnim, bdsAnim}, new NSObject[]{new NSString("position"), new NSString("bounds")}); // Animation for text layer CATransform3D scale = CATransform3D.MakeScale(0.0f, 0.0f, 0.0f); CABasicAnimation tScaleAnim = CABasicAnimation.FromKeyPath("transform"); tScaleAnim.From = NSValue.FromCATransform3D(scale); tScaleAnim.Duration = animationSpeed; tScaleAnim.TimingFunction = tf; // text layer CATextLayer fileNameLayer = new CATextLayer(); fileNameLayer.FontSize = 24; fileNameLayer.ForegroundColor = NSColor.White.CGColor; SetText(" " + filename + " ", fileNameLayer); fileNameLayer.Transform = scale; fileNameLayer.Position = CGPoint.Empty; fileNameLayer.AnchorPoint = CGPoint.Empty; fileNameLayer.ShadowColor = NSColor.Black.CGColor; fileNameLayer.ShadowOffset = new CGSize(5, 5); fileNameLayer.ShadowOpacity = 1.0f; fileNameLayer.ShadowRadius = 0.0f; fileNameLayer.BorderColor = NSColor.White.CGColor; fileNameLayer.BorderWidth = 1.0f; fileNameLayer.Actions = NSDictionary.FromObjectsAndKeys(new NSObject[]{tScaleAnim}, new NSObject[]{new NSString("transform")}); layer.AddSublayer(fileNameLayer); View.Layer.AddSublayer(layer); CATransaction.Begin(); layer.Position = randomPoint; layer.Bounds = imageBounds; fileNameLayer.Transform = CATransform3D.Identity; CATransaction.Commit(); }