/*** * Expand `rect' to the smallest standardized rect containing it with pixel-aligned origin and size. * If @c scale is zero, then a scale of 1 will be used instead. * * @param rect the rectangle to align. * @param scale the scale factor to use for pixel alignment. * * @return the input rectangle aligned to the nearest pixels using the provided scale factor. * * @see CGRectIntegral */ public static CGRect MDCRectAlignToScale(CGRect rect, nfloat scale) { if (rect.IsNull()) { return(CGRect.Null); } if (MDCCGFloatEqual(scale, 0)) { scale = 1; } if (MDCCGFloatEqual(scale, 1)) { return(rect.Integral()); } CGPoint originalMinimumPoint = new CGPoint(rect.GetMinX(), rect.GetMinY()); CGPoint newOrigin = new CGPoint(MDCFloor(originalMinimumPoint.X * scale) / scale, MDCFloor(originalMinimumPoint.Y * scale) / scale); CGSize adjustWidthHeight = new CGSize(originalMinimumPoint.X - newOrigin.X, originalMinimumPoint.Y - newOrigin.Y); return(new CGRect(newOrigin.X, newOrigin.Y, MDCCeil((rect.Width + adjustWidthHeight.Width) * scale) / scale, MDCCeil((rect.Height + adjustWidthHeight.Height) * scale) / scale)); }
public HelpView(CGRect frame) : base(frame) { BackgroundColor = UIColor.White; Layer.CornerRadius = 8; var closeFrame = new CGRect(10, frame.Size.Height - 140, 80, 80); var closeView = new SymbolMarkView(closeFrame); closeView.TouchUpInside += async(s, e) => await Hide(); AddSubview(closeView); closeView.Symbol = "X"; closeView.AccessibilityLabel = "Close"; var label = new UILabel(new CGRect(0, 20, frame.Size.Width, 40)); label.Font = UIFont.FromName("HelveticaNeue-Italic", 82); label.Text = "NSZombieApocalypse"; label.BackgroundColor = UIColor.Clear; label.TextAlignment = UITextAlignment.Center; label.SizeToFit(); var labelFrame = label.Frame; labelFrame.X = (frame.Size.Width - labelFrame.Size.Width) / 2; label.Frame = labelFrame; AddSubview(label); label.AccessibilityTraits = UIAccessibilityTrait.Header; var nextFrame = new CGRect(frame.Size.Width - 90, frame.Size.Height - 140, 80, 80); nextButton = new SymbolMarkView(nextFrame); nextButton.TouchUpInside += (s, e) => NextSlide(); AddSubview(nextButton); nextButton.Symbol = "->"; nextButton.AccessibilityLabel = "Next"; float width = (float)frame.Size.Width * 0.6f; var textViewFrame = new CGRect( 200 + ((frame.Size.Width - 200) - width) / 2, label.Frame.GetMaxY() + 30, width, frame.Size.Height * 0.6f ); textView = new UITextView(textViewFrame.Integral()); AddSubview(textView); textView.Editable = false; textView.Font = UIFont.FromName("HelveticaNeue", 36); textView.Text = NSBundle.MainBundle.LocalizedString("helpText1", null, "Strings"); var imageView = new UIImageView(UIImage.FromBundle("smaller-zombie1.png")); var imageFrame = new CGRect(label.Frame.X - 20, textViewFrame.Y, imageView.Frame.Width, imageView.Frame.Height); imageView.Frame = imageFrame; AddSubview(imageView); imageView.IsAccessibilityElement = true; imageView.AccessibilityLabel = "Poorly drawn, yet oddly menancing, zombie"; }
void slideViewWithPercentage(nfloat percentage, UIView view, bool isDragging) { if (view == null) { return; } var position = new CGPoint(0.0F, 0.0F); position.Y = cell.Bounds.Height / 2.0F; var hft = ShortTrigger / 2.0F; // half first trigger var width = cell.Bounds.Width; if (isDragging) { if (percentage >= 0 && percentage < ShortTrigger) { position.X = offsetWithPercentage(hft, width); } else if (percentage >= ShortTrigger) { position.X = offsetWithPercentage(percentage - hft, width); } else if (percentage < 0 && percentage >= ShortTrigger.Neg()) { position.X = width - offsetWithPercentage(hft, width); } else if (percentage < ShortTrigger.Neg()) { position.X = width + offsetWithPercentage(percentage + hft, width); } } else { if (direction == SwipeTableViewCellDirection.Right) { position.X = offsetWithPercentage(hft, width); } else if (direction == SwipeTableViewCellDirection.Left) { position.X = width - offsetWithPercentage(hft, width); } else { return; } } var activeViewSize = view.Bounds.Size; var activeViewFrame = new CGRect( position.X - (activeViewSize.Width / 2.0F), position.Y - (activeViewSize.Height / 2.0F), activeViewSize.Width, activeViewSize.Height); slidingView.Frame = activeViewFrame.Integral(); }
public override void LayoutSubviews() { CGRect frame = Bounds; var newFrame = new CGRect(Bounds.X, frame.Size.Height - 20, Bounds.Width, 20); labelView.Frame = newFrame.Integral(); CGRect imageFrame = imageView.Frame; imageFrame.X = (newFrame.Size.Width - imageFrame.Size.Width) / 2; imageView.Frame = imageFrame.Integral(); }
public HelpView (CGRect frame): base(frame) { BackgroundColor = UIColor.White; Layer.CornerRadius = 8; var closeFrame = new CGRect (10, frame.Size.Height - 140, 80, 80); var closeView = new SymbolMarkView (closeFrame); closeView.TouchUpInside += async (s, e) => await Hide (); AddSubview (closeView); closeView.Symbol = "X"; closeView.AccessibilityLabel = "Close"; var label = new UILabel (new CGRect (0, 20, frame.Size.Width, 40)) { Font = UIFont.FromName ("HelveticaNeue-Italic", 82), Text = "NSZombieApocalypse", BackgroundColor = UIColor.Clear, TextAlignment = UITextAlignment.Center, }; label.SizeToFit (); var labelFrame = label.Frame; labelFrame.X = (frame.Size.Width - labelFrame.Size.Width) / 2; label.Frame = labelFrame; AddSubview (label); label.AccessibilityTraits = UIAccessibilityTrait.Header; var nextFrame = new CGRect (frame.Size.Width - 90, frame.Size.Height - 140, 80, 80); nextButton = new SymbolMarkView (nextFrame); nextButton.TouchUpInside += (s, e) => NextSlide (); AddSubview (nextButton); nextButton.Symbol = "->"; nextButton.AccessibilityLabel = "Next"; float width = (float) frame.Size.Width * 0.6f; var textViewFrame = new CGRect ( 200 + ((frame.Size.Width - 200) - width) / 2, label.Frame.GetMaxY () + 30, width, frame.Size.Height * 0.6f ); textView = new UITextView (textViewFrame.Integral ()); AddSubview (textView); textView.Editable = false; textView.Font = UIFont.FromName ("HelveticaNeue", 36); textView.Text = NSBundle.MainBundle.LocalizedString ("helpText1", null, "Strings"); var imageView = new UIImageView (UIImage.FromBundle ("smaller-zombie1.png")); var imageFrame = new CGRect (label.Frame.X - 20, textViewFrame.Y, imageView.Frame.Width, imageView.Frame.Height); imageView.Frame = imageFrame; AddSubview (imageView); imageView.IsAccessibilityElement = true; imageView.AccessibilityLabel = "Poorly drawn, yet oddly menancing, zombie"; }
public override void LayoutSubviews() { base.LayoutSubviews(); nfloat textHeight = attributedString.Size.Height; CGRect textRect = new CGRect(this.Bounds.X, (this.Bounds.Size.Height - ArrowLength - textHeight) / 2.0f, this.Bounds.Size.Width, textHeight); textLayer.Frame = textRect.Integral(); }
/// <summary> /// returms the rect of the tumb image for a given track rect and value /// </summary> private CGRect HandleLabelRect(UILabel label, CGRect handleFrame) { var thumbRect = new CGRect { Size = GetTextAboveThumbSize(label) }; var xValue = handleFrame.X + handleFrame.Size.Width / 2 - thumbRect.Size.Width / 2; thumbRect.X = (float)Math.Round(xValue); thumbRect.Y = SpaceAboveThumbs / 2.0f - thumbRect.Size.Height / 2.0f; return(Normalise(thumbRect.Integral())); }
public static UIImage DrawTextInImage1(UIImage uiImage, NSString text, NSString text1, CGPoint point) { nfloat fWidth = uiImage.Size.Width; nfloat fHeight = uiImage.Size.Height; nfloat afHeight = uiImage.Size.Height / 5; UIFont font = UIFont.BoldSystemFontOfSize(50); UIFont authorfont = UIFont.SystemFontOfSize(45); var imagesize = new CGSize(fWidth, fHeight + afHeight); UIGraphics.BeginImageContext(imagesize); UIImage background = new UIImage(); background.Draw(new CGRect(0, 0, fWidth, fHeight + afHeight)); uiImage.Draw(new CGRect(0, 0, fWidth, fHeight)); var style = new NSMutableParagraphStyle(); style.Alignment = UITextAlignment.Center; var att = new NSAttributedString(text, font: font, paragraphStyle: style, foregroundColor: UIColor.White ); var author = new NSAttributedString(text1, font: authorfont, paragraphStyle: style, foregroundColor: UIColor.Black ); CGRect stringrect = att.GetBoundingRect(new CGSize(fWidth - 100, fHeight + afHeight), NSStringDrawingOptions.UsesLineFragmentOrigin, null); System.Diagnostics.Debug.WriteLine("width:" + stringrect.Size.Width + " height:" + stringrect.Size.Height); nfloat yOffset = (fHeight - stringrect.Size.Height) / 2; nfloat heightsize = stringrect.Size.Height + yOffset; System.Diagnostics.Debug.WriteLine("yOffset + height:" + heightsize); CGRect rect = new CGRect(point.X + 50, yOffset, fWidth - 100, fHeight + afHeight); att.DrawString(rect.Integral()); CGRect rect1 = new CGRect(point.X, fHeight + (afHeight - authorfont.LineHeight) / 2, fWidth, 50); author.DrawString(rect1.Integral()); UIImage resultImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return(resultImage); }
/// <summary> /// returms the rect of the tumb image for a given track rect and value /// </summary> private CGRect ThumbRectForValue(float value, UIImage thumbImage) { var thumbRect = new CGRect(); var insets = thumbImage.CapInsets; thumbRect.Size = new CGSize(thumbImage.Size.Width, thumbImage.Size.Height); var xValue = ((float)Bounds.Size.Width - (float)thumbRect.Size.Width) * ((value - MinimumValue) / (MaximumValue - MinimumValue)); thumbRect.X = (float)Math.Round(xValue); thumbRect.Y = Bounds.Size.Height / 2.0f - thumbRect.Size.Height / 2.0f; return(thumbRect.Integral()); }
private static UIImage ResizeImage(UIImage image, int maxSize) { var newSize = MediaHelper.Crop((int)image.Size.Width, (int)image.Size.Height, maxSize); var rect = new CGRect(0, 0, newSize.Item1, newSize.Item2); rect = rect.Integral(); UIGraphics.BeginImageContextWithOptions(new CGSize(rect.Width, rect.Height), false, image.CurrentScale); image.Draw(rect); var resizedImage = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return(resizedImage); }
/// <summary> /// returms the rect of the tumb image for a given track rect and value /// </summary> private CGRect ThumbRectForValue(float value, UIImage thumbImage) { var thumbRect = new CGRect(); var insets = thumbImage.CapInsets; thumbRect.Size = new CGSize(thumbImage.Size.Width, thumbImage.Size.Height); var height = Bounds.Size.Height - SpaceAboveThumbs; if (Math.Abs(insets.Top) > float.Epsilon || Math.Abs(insets.Bottom) > float.Epsilon) { thumbRect.Height = height; } var xValue = ((float)Bounds.Size.Width - (float)thumbRect.Size.Width) * ((value - MinimumValue) / (MaximumValue - MinimumValue)); thumbRect.X = (float)Math.Round(xValue); thumbRect.Y = SpaceAboveThumbs + height / 2.0f - thumbRect.Size.Height / 2.0f; return(Normalise(thumbRect.Integral())); }
public override void LayoutSubviews() { UIView[] subviews = Subviews; int count = 0; CGRect bounds = Bounds; CGSize buttonSize = ButtonView.ButtonSize; float xPad = (float)(bounds.Size.Width - (buttonSize.Width * 3)) / 4; float yPad = (float)(bounds.Size.Height - (buttonSize.Height * 2)) / 3; float x = xPad, y = 5; foreach (var subview in subviews) { if (count > 0 && count % 3 == 0) { x = xPad; y += (float)buttonSize.Height + yPad; } count++; var frame = new CGRect(x, y, buttonSize.Width, buttonSize.Height); subview.Frame = frame.Integral(); x += (float)buttonSize.Width + xPad; } }
// Create the set of display lists for the bitmaps bool MakeGLDisplayListFirst(char first, int count, int baseDL) { int curListIndex; NSColor blackColor; NSMutableDictionary attribDict; int dListNum; NSString currentChar; char currentUnichar; CGSize charSize; CGRect charRect = CGRect.Empty; NSImage theImage; bool retval; // Make sure the list isn't already under construction GL.GetInteger(GetPName.ListIndex, out curListIndex); if (curListIndex != 0) { Console.WriteLine("Display list already under construction"); return(false); } // Save pixel unpacking state GL.PushClientAttrib(ClientAttribMask.ClientPixelStoreBit); GL.PixelStore(PixelStoreParameter.UnpackSwapBytes, 0); GL.PixelStore(PixelStoreParameter.UnpackLsbFirst, 0); GL.PixelStore(PixelStoreParameter.UnpackSkipPixels, 0); GL.PixelStore(PixelStoreParameter.UnpackSkipRows, 0); GL.PixelStore(PixelStoreParameter.UnpackRowLength, 0); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 0); blackColor = NSColor.Black; attribDict = new NSMutableDictionary(); attribDict.SetValueForKey(font, NSAttributedString.FontAttributeName); attribDict.SetValueForKey(NSColor.White, NSAttributedString.ForegroundColorAttributeName); attribDict.SetValueForKey(blackColor, NSAttributedString.BackgroundColorAttributeName); theImage = new NSImage(new CGSize(0, 0)); retval = true; for (dListNum = baseDL, currentUnichar = first; currentUnichar < first + count; dListNum++, currentUnichar++) { currentChar = new NSString(Char.ToString(currentUnichar)); charSize = currentChar.StringSize(attribDict); charRect.Size = charSize; charRect = charRect.Integral(); if (charRect.Size.Width > 0 && charRect.Size.Height > 0) { theImage.Size = charRect.Size; theImage.LockFocus(); NSGraphicsContext.CurrentContext.ShouldAntialias = false; blackColor.Set(); NSBezierPath.FillRect(charRect); currentChar.DrawString(charRect, attribDict); theImage.UnlockFocus(); if (!MakeDisplayList(dListNum, theImage)) { retval = false; break; } } } return(retval); }
public override void LayoutSubviews () { CGRect frame = Bounds; var newFrame = new CGRect (Bounds.X, frame.Size.Height - 20, Bounds.Width, 20); labelView.Frame = newFrame.Integral (); CGRect imageFrame = imageView.Frame; imageFrame.X = (newFrame.Size.Width - imageFrame.Size.Width) / 2; imageView.Frame = imageFrame.Integral (); }