public override void Draw (CGRect rect) { base.Draw (rect); if (!initialPoint.IsEmpty) { //get graphics context using(CGContext g = UIGraphics.GetCurrentContext ()){ //set up drawing attributes g.SetLineWidth (2); UIColor.Red.SetStroke (); //add lines to the touch points if (path.IsEmpty) { path.AddLines (new CGPoint[]{initialPoint, latestPoint}); } else { path.AddLineToPoint (latestPoint); } //use a dashed line g.SetLineDash (0, new nfloat[] { 5, 2 * (nfloat)Math.PI }); //add geometry to graphics context and draw it g.AddPath (path); g.DrawPath (CGPathDrawingMode.Stroke); } } }
public override void Draw(CGRect rect) { base.Draw(rect); var inset = this.TextContainerInset; var leftInset = inset.Left + this.TextContainer.LineFragmentPadding; var rightInset = inset.Left + this.TextContainer.LineFragmentPadding; var maxSize = new CGSize() { Width = this.Frame.Width - (leftInset + rightInset), Height = this.Frame.Height - (inset.Top + inset.Bottom) }; var size = new NSString(this.Placeholder).StringSize(this.PlaceholderFont, maxSize, UILineBreakMode.WordWrap); var frame = new CGRect(new CGPoint(leftInset, inset.Top), size); this.placeholderLabel = new UILabel(frame) { BackgroundColor = UIColor.Clear, Font = this.PlaceholderFont, LineBreakMode = UILineBreakMode.WordWrap, Lines = 0, Text = this.Placeholder, TextColor = this.PlaceholderColor }; this.Add(this.placeholderLabel); }
public override void LoadView() { CGRect frame; if (ParentViewController != null && ParentViewController.View != null) { frame = new CGRect(CGPoint.Empty, ParentViewController.View.Frame.Size); } else { UIScreen screen = UIScreen.MainScreen; // iOS 7 and older reverses width/height in landscape mode when reporting resolution, // iOS 8+ reports resolution correctly in all cases if (InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight) { frame = new CGRect(0, 0, (nfloat)Math.Max(screen.Bounds.Width, screen.Bounds.Height), (nfloat)Math.Min(screen.Bounds.Width, screen.Bounds.Height)); } else { frame = new CGRect(0, 0, screen.Bounds.Width, screen.Bounds.Height); } } base.View = new iOSGameView(_platform, frame); // Need to set resize mask to ensure a view resize (which in iOS 8+ corresponds with a rotation) adjusts // the view and underlying CALayer correctly View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; }
protected override void NativeArrange(CGRect finalRect) { this.ScrollView.ContentSize = finalRect.Size; // That's right. We don't need to rearrange page; ////base.NativeArrange(finalRect); }
// This sets up a NSOutlineView for demonstration internal static NSView SetupOutlineView (CGRect frame) { // Create our NSOutlineView and set it's frame to a reasonable size. It will be autosized via the NSClipView NSOutlineView outlineView = new NSOutlineView () { Frame = frame }; // Every NSOutlineView must have at least one column or your Delegate will not be called. NSTableColumn column = new NSTableColumn ("Values"); outlineView.AddColumn (column); // You must set OutlineTableColumn or the arrows showing children/expansion will not be drawn outlineView.OutlineTableColumn = column; // Setup the Delegate/DataSource instances to be interrogated for data and view information // In Unified, these take an interface instead of a base class and you can combine these into // one instance. outlineView.Delegate = new OutlineViewDelegate (); outlineView.DataSource = new OutlineViewDataSource (); // NSOutlineView expects to be hosted inside an NSClipView and won't draw correctly otherwise NSClipView clipView = new NSClipView (frame) { AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable }; clipView.DocumentView = outlineView; return clipView; }
public override void Draw(CGRect rect) { //get graphics context using (CGContext g = UIGraphics.GetCurrentContext()) { //set up drawing attributes UIColor.Black.SetFill(); //create geometry _overlay = new CGPath(); _overlay.AddRect(new RectangleF(0f, 0f, _width, _height)); if(_isRound) _overlay.AddEllipseInRect(new RectangleF((float)_rect.X, (float)_rect.Y, (float)_rect.Width, (float)_rect.Height)); else _overlay.AddRect(new RectangleF((float)_rect.X, (float)_rect.Y, (float)_rect.Width, (float)_rect.Height)); g.SetStrokeColor(UIColor.Clear.CGColor); g.SetAlpha(0.6f); //add geometry to graphics context and draw it g.AddPath(_overlay); g.DrawPath(CGPathDrawingMode.EOFillStroke); } }
public void ShareUrl(object sender, Uri uri) { var item = new NSUrl(uri.AbsoluteUri); var activityItems = new NSObject[] { item }; UIActivity[] applicationActivities = null; var activityController = new UIActivityViewController (activityItems, applicationActivities); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { var window = UIApplication.SharedApplication.KeyWindow; var pop = new UIPopoverController (activityController); var barButtonItem = sender as UIBarButtonItem; if (barButtonItem != null) { pop.PresentFromBarButtonItem(barButtonItem, UIPopoverArrowDirection.Any, true); } else { var rect = new CGRect(window.RootViewController.View.Frame.Width / 2, window.RootViewController.View.Frame.Height / 2, 0, 0); pop.PresentFromRect (rect, window.RootViewController.View, UIPopoverArrowDirection.Any, true); } } else { var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController; viewController.PresentViewController(activityController, true, null); } }
public override void ViewDidLoad() { base.ViewDidLoad (); // Create the chart View.BackgroundColor = UIColor.White; nfloat margin = UserInterfaceIdiomIsPhone ? 10 : 50; CGRect frame = new CGRect (margin, margin, View.Bounds.Width - 2 * margin, View.Bounds.Height - 2 * margin); chart = new ShinobiChart (frame) { Title = "Apple Stock Price", AutoresizingMask = ~UIViewAutoresizing.None, LicenseKey = "", // TODO: add your trail licence key here! // add the axes XAxis = new SChartDateTimeAxis { Title = "Date" }, YAxis = new SChartNumberAxis { Title = "Price (USD)" } }; foreach(SChartAxis axis in chart.AllAxes) { axis.EnableGesturePanning = true; axis.EnableGestureZooming = true; axis.EnableMomentumPanning = true; axis.EnableMomentumZooming = true; } View.AddSubview(chart); chart.Delegate = new AddingAnnotationsDelegate (); chart.DataSource = new AddingAnnotationsDataSource (); }
private void AddBox (string title, CGRect frame, int level, NSColor color) { var node = Utils.SCBoxNode (title, frame, color, 2.0f, true); node.Scale = new SCNVector3 (0.02f, 0.02f, 0.02f); node.Position = new SCNVector3 (-5, 1.5f * level, 10); ContentNode.AddChildNode (node); }
public DrawingView(CGRect rect) : base(rect) { ContentMode = UIViewContentMode.Redraw; AutoresizingMask = UIViewAutoresizing.All; BackgroundColor = UIColor.White; }
public override void ViewDidLoad() { base.ViewDidLoad (); // Create the chart View.BackgroundColor = UIColor.White; nfloat margin = UserInterfaceIdiomIsPhone ? 10 : 50; CGRect frame = new CGRect (margin, margin, View.Bounds.Width - 2 * margin, View.Bounds.Height - 2 * margin); chart = new ShinobiChart (frame) { Title = "Apple Stock Price", AutoresizingMask = ~UIViewAutoresizing.None, LicenseKey = "" // TODO: add your trail licence key here! }; // Add a discountinuous date axis chart.XAxis = new SChartDateTimeAxis () { Title = "Date", EnableGesturePanning = true, EnableGestureZooming = true }; chart.YAxis = new SChartNumberAxis () { Title = "Price (USD)", EnableGesturePanning = true, EnableGestureZooming = true }; // Add to the view View.AddSubview (chart); chart.DataSource = new CandlestickChartDataSource (); }
public override void Draw(CGRect rect) { var context = UIGraphics.GetCurrentContext(); var bounds = Bounds; UIColor background = Enabled ? pressed ? HighlightedColor : NormalColor : DisabledColor; nfloat alpha = 1; CGPath container = GraphicsUtil.MakeRoundedRectPath(bounds, 14); context.AddPath(container); context.Clip(); using (var cs = CGColorSpace.CreateDeviceRGB()) { var topCenter = new CGPoint(bounds.GetMidX(), 0); var midCenter = new CGPoint(bounds.GetMidX(), bounds.GetMidY()); var bottomCenter = new CGPoint(bounds.GetMidX(), bounds.GetMaxY()); using ( var gradient = new CGGradient(cs, new[] { 0.23f, 0.23f, 0.23f, alpha, 0.47f, 0.47f, 0.47f, alpha }, new nfloat[] { 0, 1 })) { context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0); } container = GraphicsUtil.MakeRoundedRectPath(bounds.Inset(1, 1), 13); context.AddPath(container); context.Clip(); using ( var gradient = new CGGradient(cs, new[] { 0.05f, 0.05f, 0.05f, alpha, 0.15f, 0.15f, 0.15f, alpha }, new nfloat[] { 0, 1 })) { context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0); } var nb = bounds.Inset(4, 4); container = GraphicsUtil.MakeRoundedRectPath(nb, 10); context.AddPath(container); context.Clip(); background.SetFill(); context.FillRect(nb); using (var gradient = new CGGradient(cs, new nfloat[] { 1, 1, 1, .35f, 1, 1, 1, 0.06f }, new nfloat[] { 0, 1 })) { context.DrawLinearGradient(gradient, topCenter, midCenter, 0); } context.SetLineWidth(2); context.AddPath(container); context.ReplacePathWithStrokedPath(); context.Clip(); using ( var gradient = new CGGradient(cs, new nfloat[] { 1, 1, 1, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f }, new nfloat[] { 0, 1 }) ) { context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0); } } }
public MyOpenGLView (CGRect frame,NSOpenGLContext context) : base(frame) { var attribs = new object [] { NSOpenGLPixelFormatAttribute.Accelerated, NSOpenGLPixelFormatAttribute.NoRecovery, NSOpenGLPixelFormatAttribute.DoubleBuffer, NSOpenGLPixelFormatAttribute.ColorSize, 24, NSOpenGLPixelFormatAttribute.DepthSize, 16 }; pixelFormat = new NSOpenGLPixelFormat (attribs); if (pixelFormat == null) Console.WriteLine ("No OpenGL pixel format"); // NSOpenGLView does not handle context sharing, so we draw to a custom NSView instead openGLContext = new NSOpenGLContext (pixelFormat, context); openGLContext.MakeCurrentContext (); // Synchronize buffer swaps with vertical refresh rate openGLContext.SwapInterval = true; // Initialize our newly created view. InitGL (); SetupDisplayLink (); // Look for changes in view size // Note, -reshape will not be called automatically on size changes because NSView does not export it to override notificationProxy = NSNotificationCenter.DefaultCenter.AddObserver (NSView.GlobalFrameChangedNotification, HandleReshape); }
public iOSCardsView(CGRect frame) : base(frame) { this.Setup(); this.Draw(frame); }
public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect) { double duration = 0.5; List<CAAnimation> animations = new List<CAAnimation> (); for (int i = 0; i<(int)state.Points.Count; i++) { string keyPath = string.Format ("seriesRenderStates.{0}.points.{1}.y", series.Index, i); TKChartVisualPoint point = (TKChartVisualPoint)state.Points.ObjectAtIndex((uint)i); double oldY = rect.Height; double half = oldY + (point.Y - oldY)/2.0; CAKeyFrameAnimation a = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath(keyPath); a.KeyTimes = new NSNumber[] { new NSNumber (0), new NSNumber (0), new NSNumber (1) }; a.Values = new NSObject[] { new NSNumber (oldY), new NSNumber (half), new NSNumber (point.Y) }; a.Duration = duration; a.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseOut); animations.Add(a); } CAAnimationGroup group = new CAAnimationGroup (); group.Duration = duration; group.Animations = animations.ToArray(); return group; }
public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect) { double duration = 0; List<CAAnimation> animations = new List<CAAnimation>(); for (int i = 0; i<(int)state.Points.Count; i++) { string pointKeyPath = state.AnimationKeyPathForPointAtIndex ((uint)i); string keyPath = string.Format("{0}.distanceFromCenter", pointKeyPath); CAKeyFrameAnimation a = CAKeyFrameAnimation.GetFromKeyPath(keyPath); a.Values = new NSNumber[] { new NSNumber(50), new NSNumber(50), new NSNumber(0) }; a.KeyTimes = new NSNumber[] { new NSNumber(0), new NSNumber(i/(i+1.0)), new NSNumber(1) }; a.Duration = 0.3 * (i+1.1); animations.Add(a); keyPath = string.Format("{0}.opacity", pointKeyPath); a = CAKeyFrameAnimation.GetFromKeyPath(keyPath); a.Values = new NSNumber[] { new NSNumber(0), new NSNumber(0), new NSNumber(1) }; a.KeyTimes = new NSNumber[] { new NSNumber(0), new NSNumber(i/(i+1.0)), new NSNumber(1) }; a.Duration = 0.3 * (i+1.1); animations.Add(a); duration = a.Duration; } CAAnimationGroup g = new CAAnimationGroup(); g.Duration = duration; g.Animations = animations.ToArray(); return g; }
/// <summary> /// Adds the text. /// </summary> /// <param name="image">The image.</param> /// <param name="text">The text.</param> /// <param name="point">The point.</param> /// <param name="font">The font.</param> /// <param name="color">The color.</param> /// <param name="alignment">The alignment.</param> /// <returns>UIImage.</returns> public static UIImage AddText( this UIImage image, string text, CGPoint point, UIFont font, UIColor color, UITextAlignment alignment = UITextAlignment.Left) { //var labelRect = new RectangleF(point, new SizeF(image.Size.Width - point.X, image.Size.Height - point.Y)); var h = text.StringHeight(font, image.Size.Width); var labelRect = new CGRect(point, new CGSize(image.Size.Width - point.X, h)); var label = new UILabel(labelRect) { Font = font, Text = text, TextColor = color, TextAlignment = alignment, BackgroundColor = UIColor.Clear }; var labelImage = label.ToNativeImage(); using (var context = image.Size.ToBitmapContext()) { var rect = new CGRect(new CGPoint(0, 0), image.Size); context.DrawImage(rect, image.CGImage); context.DrawImage(labelRect, labelImage.CGImage); context.StrokePath(); return UIImage.FromImage(context.ToImage()); } }
public override void Draw(CGRect rect) { base.Draw(rect); using (var g = UIGraphics.GetCurrentContext()) { if (image != null) g.SetFillColor((UIColor.FromPatternImage(image).CGColor)); else g.SetFillColor(UIColor.LightGray.CGColor); g.FillRect(rect); if (!initialPoint.IsEmpty) { g.SetLineWidth(20); g.SetBlendMode(CGBlendMode.Clear); UIColor.Clear.SetColor(); if (path.IsEmpty || startNewPath) { path.AddLines(new CGPoint[] { initialPoint, latestPoint }); startNewPath = false; } else { path.AddLineToPoint(latestPoint); } g.SetLineCap(CGLineCap.Round); g.AddPath(path); g.DrawPath(CGPathDrawingMode.Stroke); } } }
public TabControlItem(CGRect frame, string title) { this.Frame = frame; var parentFrame = frame; var labelFont = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? UIFont.BoldSystemFontOfSize(15) : UIFont.BoldSystemFontOfSize(10); this.labelTitle = new UILabel(new CGRect(0, 0, parentFrame.Width / 2, parentFrame.Height)) { Text = title, TextAlignment = UITextAlignment.Center, AdjustsFontSizeToFitWidth = true, LineBreakMode = UILineBreakMode.TailTruncation, Lines = 2, Font = labelFont }; this.button = new UIButton(new CGRect(0, 0, parentFrame.Width, parentFrame.Height)); this.viewColor = new UIView(new CGRect(0, parentFrame.Height - 1, parentFrame.Width, 1)); this.Add(this.labelTitle); this.Add(this.button); this.Add(this.viewColor); this.button.TouchUpInside += (s, e) => { if (tabEnabled) { SelectTab(); } }; }
public override void DrawRect(CGRect dirtyRect) { var g = Graphics.FromCurrentContext(); // NSView does not have a background color so we just use Clear to white here g.Clear(Color.White); //RectangleF ClientRectangle = this.Bounds; CGRect ClientRectangle = dirtyRect; // Following codes draw a line from (0, 0) to (1, 1) in unit of inch: /*g.PageUnit = GraphicsUnit.Inch; Pen blackPen = new Pen(Color.Black, 1/g.DpiX); g.DrawLine(blackPen, 0, 0, 1, 1);*/ // Following code shifts the origin to the center of // client area, and then draw a line from (0,0) to (1, 1) inch: g.PageUnit = GraphicsUnit.Inch; g.TranslateTransform(((float)ClientRectangle.Width / g.DpiX) / 2, ((float)ClientRectangle.Height / g.DpiY) / 2); Pen greenPen = new Pen(Color.Green, 1 / g.DpiX); g.DrawLine(greenPen, 0, 0, 1, 1); g.Dispose (); }
protected override void NativeArrangeContent(CGRect finalRect) { if (this.Content is UIElement) { ((UIElement)this.Content).Arrange(finalRect); } }
void UpdateUI () { var x = 44 + 6; if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0)) x += 15; // okay, we need a more thorough iOS 7 update than this, but for now this'll have to do var fn = person.FirstNameAndInitials; firstNameLabel.Text = fn; var fnw = string.IsNullOrEmpty (fn) ? 0.0f : UIStringDrawing.StringSize (fn, NormalFont).Width; var f = new CGRect (x, 4, fnw + 4, 20); firstNameLabel.Frame = f; var ln = person.SafeLastName; lastNameLabel.Text = ln; var lnw = string.IsNullOrEmpty (ln) ? 0.0f : UIStringDrawing.StringSize (ln, BoldFont).Width; f.X = f.Right; f.Width = lnw; lastNameLabel.Frame = f; detailsLabel.Text = person.TitleAndDepartment ?? string.Empty; detailsLabel.Frame = new CGRect (x, 25, 258, 14); }
public override void ViewDidLoad () { base.ViewDidLoad (); // set the background color of the view to white View.BackgroundColor = UIColor.White; // instantiate a new image view that takes up the whole screen and add it to // the view hierarchy CGRect imageViewFrame = new CGRect (0, -NavigationController.NavigationBar.Frame.Height, View.Frame.Width, View.Frame.Height); imageView = new UIImageView (imageViewFrame); View.AddSubview (imageView); // create our offscreen bitmap context // size CGSize bitmapSize = new CGSize (imageView.Frame.Size); using (CGBitmapContext context = new CGBitmapContext (IntPtr.Zero, (int)bitmapSize.Width, (int)bitmapSize.Height, 8, (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB (), CGImageAlphaInfo.PremultipliedFirst)) { // draw our coordinates for reference DrawCoordinateSpace (context); // draw our flag DrawFlag (context); // add a label DrawCenteredTextAtPoint (context, 384, 700, "Stars and Stripes", 60); // output the drawing to the view imageView.Image = UIImage.FromImage (context.ToImage ()); } }
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions) { // Two disjoint rects var r1 = new CGRect (50, 50, 10, 10); var r2 = new CGRect (100, 100, 10, 10); // This condradicts with Apple's doc – https://developer.apple.com/reference/coregraphics/cgrectnull // The null rectangle. This is the rectangle returned when, for example, you intersect two disjoint rectangles. // Note that the null rectangle is not the same as the zero rectangle. // For example, the union of a rectangle with the null rectangle is the original rectangle (that is, the null rectangle contributes nothing). var tmp = r1; tmp.Intersect (r2); // this is mutable method Console.WriteLine (tmp.IsNull ()); // Expected true, but result is false tmp = CGRectIntersection (r1, r2); Console.WriteLine (tmp.IsNull ()); // Expected true, actual true // This should be CGRectNull var rectNull = new CGRect (nfloat.PositiveInfinity, nfloat.PositiveInfinity, 0, 0); Console.WriteLine (rectNull.IsNull ()); // Expected true, actual true // CGRectEmpty and CGRectNull are different var union1 = r1.UnionWith (CGRect.Empty); // new rect {0, 0, 60, 60} Console.WriteLine (union1); var union2 = r1.UnionWith (rectNull); // r1 Console.WriteLine (union2); return true; }
/// <summary> /// Initializes a new instance of the <see cref="GridCollectionView"/> class. /// </summary> /// <param name="frm">The FRM.</param> public GridCollectionView(CGRect frm) : base(frm, new UICollectionViewFlowLayout()) { AutoresizingMask = UIViewAutoresizing.All; ContentMode = UIViewContentMode.ScaleToFill; RegisterClassForCell(typeof(GridViewCell), new NSString (GridViewCell.Key)); }
public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews (); UIView[] subviews = View.Subviews.Where (v => v != NavigationBar).ToArray (); var toolBarViews = subviews.Where (v => v is UIToolbar).ToArray (); var otherViews = subviews.Where (v => !(v is UIToolbar)).ToArray (); nfloat toolbarHeight = 0; foreach (var uIView in toolBarViews) { uIView.SizeToFit (); uIView.Frame = new CGRect { X = 0, Y = View.Bounds.Height - uIView.Frame.Height, Width = View.Bounds.Width, Height = uIView.Frame.Height, }; var thisToolbarHeight = uIView.Frame.Height; if (toolbarHeight < thisToolbarHeight) { toolbarHeight = thisToolbarHeight; } } var othersHeight = View.Bounds.Height - toolbarHeight; var othersFrame = new CGRect (View.Bounds.X, View.Bounds.Y, View.Bounds.Width, othersHeight); foreach (var uIView in otherViews) { uIView.Frame = othersFrame; } }
public TouchDrawView(CGRect rect) : base(rect) { linesInProcess = new Dictionary<string, Line>(); this.BackgroundColor = UIColor.White; this.MultipleTouchEnabled = true; UITapGestureRecognizer tapRecognizer = new UITapGestureRecognizer(tap); this.AddGestureRecognizer(tapRecognizer); UITapGestureRecognizer dbltapRecognizer = new UITapGestureRecognizer(dblTap); dbltapRecognizer.NumberOfTapsRequired = 2; this.AddGestureRecognizer(dbltapRecognizer); UILongPressGestureRecognizer pressRecognizer = new UILongPressGestureRecognizer(longPress); this.AddGestureRecognizer(pressRecognizer); moveRecognizer = new UIPanGestureRecognizer(moveLine); moveRecognizer.WeakDelegate = this; moveRecognizer.CancelsTouchesInView = false; this.AddGestureRecognizer(moveRecognizer); UISwipeGestureRecognizer swipeRecognizer = new UISwipeGestureRecognizer(swipe); swipeRecognizer.Direction = UISwipeGestureRecognizerDirection.Up; swipeRecognizer.NumberOfTouchesRequired = 3; this.AddGestureRecognizer(swipeRecognizer); selectedColor = UIColor.Red; }
private UIImage CreateImage (NSString title, nfloat scale) { var titleAttrs = new UIStringAttributes () { Font = UIFont.FromName ("HelveticaNeue", 13f), ForegroundColor = Color.Gray, }; var titleBounds = new CGRect ( new CGPoint (0, 0), title.GetSizeUsingAttributes (titleAttrs) ); var image = Image.TagBackground; var imageBounds = new CGRect ( 0, 0, (float)Math.Ceiling (titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f, (float)Math.Ceiling (titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom ); titleBounds.X = image.CapInsets.Left + 2f; titleBounds.Y = image.CapInsets.Top; UIGraphics.BeginImageContextWithOptions (imageBounds.Size, false, scale); try { image.Draw (imageBounds); title.DrawString (titleBounds, titleAttrs); return UIGraphics.GetImageFromCurrentImageContext (); } finally { UIGraphics.EndImageContext (); } }
public static BaseItemView Create (CGRect frame, NodeViewController nodeViewController, TreeNode node, string filePath, UIColor kleur) { var view = BaseItemView.Create(frame, nodeViewController, node, kleur); UIWebView webView = new UIWebView(); string extension = Path.GetExtension (filePath); if (extension == ".odt") { string viewerPath = NSBundle.MainBundle.PathForResource ("over/viewer/index", "html"); Uri fromUri = new Uri(viewerPath); Uri toUri = new Uri(filePath); Uri relativeUri = fromUri.MakeRelativeUri(toUri); String relativePath = Uri.UnescapeDataString(relativeUri.ToString()); NSUrl finalUrl = new NSUrl ("#" + relativePath.Replace(" ", "%20"), new NSUrl(viewerPath, false)); webView.LoadRequest(new NSUrlRequest(finalUrl)); webView.ScalesPageToFit = true; view.ContentView = webView; return view; } else { NSUrl finalUrl = new NSUrl (filePath, false); webView.LoadRequest(new NSUrlRequest(finalUrl)); webView.ScalesPageToFit = true; view.ContentView = webView; return view; } }
private void Email(string exportType) { if(!MFMailComposeViewController.CanSendMail) return; var title = exampleInfo.Title + "." + exportType; NSData nsData = null; string attachmentType = "text/plain"; var rect = new CGRect(0,0,800,600); switch(exportType) { case "png": nsData = View.ToPng(rect); attachmentType = "image/png"; break; case "pdf": nsData = View.ToPdf(rect); attachmentType = "text/x-pdf"; break; } var mail = new MFMailComposeViewController (); mail.SetSubject("OxyPlot - " + title); mail.SetMessageBody ("Please find attached " + title, false); mail.Finished += HandleMailFinished; mail.AddAttachmentData(nsData, attachmentType, title); this.PresentViewController (mail, true, null); }
public BindableMapView(CGRect frame) : base(frame) { this.CreateBindingContext(); }
private CAGradientLayer CreateGradientLayer(Point startPoint, Point endPoint, CGRect rect) { // Create a gradient layer that draws our background. return(new CAGradientLayer { Frame = rect, LayerType = CAGradientLayerType.Axial, StartPoint = new CGPoint(startPoint.X, startPoint.Y), EndPoint = new CGPoint(endPoint.X, endPoint.Y) }); }
private static bool SizeAreEqual(CGRect frame, MaterialFrame element) { return(frame.Width == element.Width && frame.Height == element.Height); }
public static Rect GetRect(this CGRect rect) { return(new Rect(rect.X, rect.Y, rect.Width, rect.Height)); }
/// <summary> /// Initializes a new instance of the <see cref="ReactiveControl"/> class. /// </summary> /// <param name="frame">The frame.</param> protected ReactiveControl(CGRect frame) : base(frame) { }
protected TemplatedCell(CGRect frame) : base(frame) { }
public override void Draw(CGRect rect) { base.Draw(rect); previewLayer.Frame = rect; }
public static SKPhysicsBody BodyWithEdgeLoopFromRect(CGRect rect) { return(CreateEdgeLoop(rect)); }
/// <summary> /// Initializes a new instance of the <see cref="ReactiveCollectionViewCell"/> class. /// </summary> /// <param name="frame">The frame.</param> protected ReactiveCollectionViewCell(CGRect frame) : base(frame) { SetupRxObj(); }
public override void ViewDidLoad() { base.ViewDidLoad(); _icons = new Dictionary <string, UIImage>() { { "icImage", UIImage.FromBundle("icImage") }, { "icPanorama", UIImage.FromBundle("icPanorama") }, { "icVideo", UIImage.FromBundle("icVideo") }, { "icPhoto", UIImage.FromBundle("icPhoto") }, { "icTimelapse", UIImage.FromBundle("icTimelapse") }, { "icMacro", UIImage.FromBundle("icMacro") }, { "icPortrait", UIImage.FromBundle("icPortrait") }, { "icSeries", UIImage.FromBundle("icSeries") }, { "icTimer", UIImage.FromBundle("icTimer") }, { "icSixteenToNine", UIImage.FromBundle("icSixteenToNine") }, { "icOneToOne", UIImage.FromBundle("icOneToOne") }, { "icHDR", UIImage.FromBundle("icHDR") } }; _circleMenu = new CircleMenu(); _circleMenu.Clicked += (object sender, int id) => { if (id == 100) { _navigationBarEnabled = !_navigationBarEnabled; ToggleNavigationBar(_navigationBarEnabled); } else { if (!_submenuIds.Contains(id)) { ShowItemController(_icons.ElementAt(id).Key); } } }; _circleMenu.CircleMenuItems = CreateSource(9); _circleMenu.Attach(this); View.AddGestureRecognizer(new UITapGestureRecognizer(() => { _dropDowns.ForEach(dropDown => dropDown.CloseInputControl()); })); _dropDowns = new List <EOSSandboxDropDown>() { themeDropDown, unfocusedButtonColorDropDown, unfocusedIconColorDropDown, focusedButtonColorDropDown, focusedIconColorDropDown, itemsCountDropDown }; var rect = new CGRect(0, 0, 100, 150); InitThemeDropDown(rect); InitItemsCountDropDown(rect); InitSources(rect); InitResetButton(); }
/// <summary> /// Returns a rectangle representing the location and size of the top view /// when this Panel is hidden /// </summary> /// <returns>The top view position when slider is visible.</returns> /// <param name="topViewCurrentFrame">Top view current frame.</param> public override CGRect GetTopViewPositionWhenSliderIsHidden(CGRect topViewCurrentFrame) { topViewCurrentFrame.X = 0; return topViewCurrentFrame; }
public PageView(CGRect rect) : base(rect) { }
internal override void Setup(Graphics graphics, bool fill) { // if this is the same as the last that was set then return and no changes have been made // then return. if (graphics.LastBrush == this && !changed) { return; } // obtain our width and height so we can set the pattern rectangle float textureWidth = textureImage.Width; float textureHeight = textureImage.Height; if (wrapMode == WrapMode.TileFlipX || wrapMode == WrapMode.TileFlipY) { textureWidth *= 2; } if (wrapMode == WrapMode.TileFlipXY) { textureWidth *= 2; textureHeight *= 2; } // this is here for testing only var textureOffset = new PointF(0, -0); //choose the pattern to be filled based on the currentPattern selected var patternSpace = CGColorSpace.CreatePattern(null); graphics.context.SetFillColorSpace(patternSpace); patternSpace.Dispose(); // Pattern default work variables var patternRect = new CGRect(HALF_PIXEL_X, HALF_PIXEL_Y, textureWidth + HALF_PIXEL_X, textureHeight + HALF_PIXEL_Y); var patternTransform = CGAffineTransform.MakeIdentity(); // We need to take into account the orientation of the graphics object #if MONOMAC if (!graphics.isFlipped) { patternTransform = new CGAffineTransform(1, 0, 0, -1, textureOffset.X, textureHeight + textureOffset.Y); } #endif #if MONOTOUCH if (graphics.isFlipped) { patternTransform = new CGAffineTransform(1, 0, 0, -1, textureOffset.X, textureHeight + textureOffset.Y); } #endif patternTransform = CGAffineTransform.Multiply(patternTransform, textureTransform.transform); // DrawPattern callback which will be set depending on hatch style CGPattern.DrawPattern drawPattern; drawPattern = DrawTexture; //set the pattern as the Current Context’s fill pattern var pattern = new CGPattern(patternRect, patternTransform, textureWidth, textureHeight, //textureHeight, CGPatternTiling.NoDistortion, true, drawPattern); //we dont need to set any color, as the pattern cell itself has chosen its own color graphics.context.SetFillPattern(pattern, new nfloat[] { 1 }); changed = false; graphics.LastBrush = this; // I am setting this to be used for Text coloring in DrawString //graphics.lastBrushColor = foreColor; }
/// <summary> /// Called when sliding has started on this Panel /// </summary> /// <param name="touchPosition">Touch position.</param> /// <param name="topViewCurrentFrame">Top view current frame.</param> public override void SlidingStarted (CGPoint touchPosition, CGRect topViewCurrentFrame) { _touchPositionStartXPosition = touchPosition.X; _topViewStartXPosition = topViewCurrentFrame.X; }
// This method is invoked when the application has loaded its UI and its ready to run public override bool FinishedLaunching(UIApplication app, NSDictionary options) { CGRect rect = UIScreen.MainScreen.ApplicationFrame; window.BackgroundColor = UIColor.Black; //Create the OpenGL drawing view and add it to the window drawingView = new PaintingView(new CGRect(rect.Location, rect.Size)); var viewController = new UIViewController { View = drawingView }; window.RootViewController = viewController; // Create a segmented control so that the user can choose the brush color. var images = new[] { UIImage.FromFile("Images/Red.png"), UIImage.FromFile("Images/Yellow.png"), UIImage.FromFile("Images/Green.png"), UIImage.FromFile("Images/Blue.png"), UIImage.FromFile("Images/Purple.png") }; if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { // we want the original colors, which is not the default iOS7 behaviour, so we need to // replace them with ones having the right UIImageRenderingMode for (int i = 0; i < images.Length; i++) { images [i] = images [i].ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); } } var segmentedControl = new UISegmentedControl(images); // Compute a rectangle that is positioned correctly for the segmented control you'll use as a brush color palette var frame = new CGRect(rect.X + LeftMarginPadding, rect.Height - PaletteHeight - TopMarginPadding, rect.Width - (LeftMarginPadding + RightMarginPadding), PaletteHeight); segmentedControl.Frame = frame; // When the user chooses a color, the method changeBrushColor: is called. segmentedControl.ValueChanged += ChangeBrushColor; // Make sure the color of the color complements the black background segmentedControl.TintColor = UIColor.DarkGray; // Set the third color (index values start at 0) segmentedControl.SelectedSegment = 2; // Add the control to the window window.AddSubview(segmentedControl); // Now that the control is added, you can release it // [segmentedControl release]; float r, g, b; // Define a starting color HslToRgb(2.0f / PaletteSize, PaintingView.Saturation, PaintingView.Luminosity, out r, out g, out b); // Set the color using OpenGL GL.Color4(r, g, b, PaintingView.BrushOpacity); // Look in the Info.plist file and you'll see the status bar is hidden // Set the style to black so it matches the background of the application app.SetStatusBarStyle(UIStatusBarStyle.Default, false); // Now show the status bar, but animate to the style. app.SetStatusBarHidden(false, true); //Configure and enable the accelerometer UIAccelerometer.SharedAccelerometer.UpdateInterval = 1.0f / AccelerometerFrequency; UIAccelerometer.SharedAccelerometer.Acceleration += OnAccelerated; //Show the window window.MakeKeyAndVisible(); return(true); }
/// <summary> /// Returns a rectangle representing the location and size of the top view /// when this Panel is showing /// </summary> /// <returns>The top view position when slider is visible.</returns> /// <param name="topViewCurrentFrame">Top view current frame.</param> public override CGRect GetTopViewPositionWhenSliderIsVisible(CGRect topViewCurrentFrame) { topViewCurrentFrame.X = - Size.Width; return topViewCurrentFrame; }
static extern CGPoint VNImagePointForFaceLandmarkPoint(Vector2 faceLandmarkPoint, CGRect faceBoundingBox, nuint imageWidth, nuint imageHeight, out IntPtr error);
public override nfloat Height(CGRect bounds) { return(GetTextSize(Animating ? LoadingCaption : NormalCaption).Height + 2 * Padding); }
public static extern CGRect GetNormalizedRect(CGRect imageRect, nuint imageWidth, nuint imageHeight);
public RangeSliderControl(CGRect frame) : base(frame) { ConfigureView(); }
void UpdatePosition(bool textOnly = false) { nfloat hudWidth = 100f; nfloat hudHeight = 100f; nfloat stringWidth = 0f; nfloat stringHeight = 0f; nfloat stringHeightBuffer = 20f; nfloat stringAndImageHeightBuffer = 80f; CGRect labelRect = new CGRect(); string @string = StringLabel.Text; // False if it's text-only bool imageUsed = (ImageView.Image != null) || (ImageView.Hidden); if (textOnly) { imageUsed = false; } if (imageUsed) { hudHeight = stringAndImageHeightBuffer + stringHeight; } else { hudHeight = (textOnly ? stringHeightBuffer : stringHeightBuffer + 40); } if (!string.IsNullOrEmpty(@string)) { int lineCount = Math.Min(10, @string.Split('\n').Length + 1); if (IsIOS7OrNewer) { var stringSize = new NSString(@string).GetBoundingRect(new CGSize(200, 30 * lineCount), NSStringDrawingOptions.UsesLineFragmentOrigin, new UIStringAttributes { Font = StringLabel.Font }, null); stringWidth = stringSize.Width; stringHeight = stringSize.Height; } else { var stringSize = new NSString(@string).StringSize(StringLabel.Font, new CGSize(200, 30 * lineCount)); stringWidth = stringSize.Width; stringHeight = stringSize.Height; } hudHeight += stringHeight; if (stringWidth > hudWidth) { hudWidth = (float)Math.Ceiling(stringWidth / 2) * 2; } float labelRectY = imageUsed ? 66 : 9; if (hudHeight > 100) { labelRect = new CGRect(12, labelRectY, hudWidth, stringHeight); hudWidth += 24; } else { hudWidth += 24; labelRect = new CGRect(0, labelRectY, hudWidth, stringHeight); } } // Adjust for Cancel Button var cancelRect = new CGRect(); string @cancelCaption = _cancelHud == null ? null : CancelHudButton.Title(UIControlState.Normal); if (!string.IsNullOrEmpty(@cancelCaption)) { const int gap = 20; if (IsIOS7OrNewer) { var stringSize = new NSString(@cancelCaption).GetBoundingRect(new CGSize(200, 300), NSStringDrawingOptions.UsesLineFragmentOrigin, new UIStringAttributes { Font = StringLabel.Font }, null); stringWidth = stringSize.Width; stringHeight = stringSize.Height; } else { var stringSize = new NSString(@cancelCaption).StringSize(StringLabel.Font, new CGSize(200, 300)); stringWidth = stringSize.Width; stringHeight = stringSize.Height; } if (stringWidth > hudWidth) { hudWidth = (float)Math.Ceiling(stringWidth / 2) * 2; } // Adjust for label nfloat cancelRectY = 0f; if (labelRect.Height > 0) { cancelRectY = labelRect.Y + labelRect.Height + (nfloat)gap; } else { if (string.IsNullOrEmpty(@string)) { cancelRectY = 76; } else { cancelRectY = (imageUsed ? 66 : 9); } } if (hudHeight > 100) { cancelRect = new CGRect(12, cancelRectY, hudWidth, stringHeight); labelRect = new CGRect(12, labelRect.Y, hudWidth, labelRect.Height); hudWidth += 24; } else { hudWidth += 24; cancelRect = new CGRect(0, cancelRectY, hudWidth, stringHeight); labelRect = new CGRect(0, labelRect.Y, hudWidth, labelRect.Height); } CancelHudButton.Frame = cancelRect; hudHeight += (cancelRect.Height + (string.IsNullOrEmpty(@string) ? 10 : gap)); } HudView.Bounds = new CGRect(0, 0, hudWidth, hudHeight); if (!string.IsNullOrEmpty(@string)) { ImageView.Center = new CGPoint(HudView.Bounds.Width / 2, 36); } else { ImageView.Center = new CGPoint(HudView.Bounds.Width / 2, HudView.Bounds.Height / 2); } StringLabel.Hidden = false; StringLabel.Frame = labelRect; if (!textOnly) { if (!string.IsNullOrEmpty(@string) || !string.IsNullOrEmpty(@cancelCaption)) { SpinnerView.Center = new CGPoint((float)Math.Ceiling(HudView.Bounds.Width / 2.0f) + 0.5f, 40.5f); if (_progress != -1) { BackgroundRingLayer.Position = RingLayer.Position = new CGPoint(HudView.Bounds.Width / 2, 36f); } } else { SpinnerView.Center = new CGPoint((float)Math.Ceiling(HudView.Bounds.Width / 2.0f) + 0.5f, (float)Math.Ceiling(HudView.Bounds.Height / 2.0f) + 0.5f); if (_progress != -1) { BackgroundRingLayer.Position = RingLayer.Position = new CGPoint(HudView.Bounds.Width / 2, HudView.Bounds.Height / 2.0f + 0.5f); } } } }
public static CGPoint GetNormalizedFaceBoundingBoxPoint(Vector2 faceLandmarkPoint, CGRect faceBoundingBox, nuint imageWidth, nuint imageHeight) { IntPtr error; var result = VNNormalizedFaceBoundingBoxPointForLandmarkPoint(faceLandmarkPoint, faceBoundingBox, imageWidth, imageHeight, out error); if (error != IntPtr.Zero) { throw new InvalidOperationException(Marshal.PtrToStringAuto(error)); } return(result); }
void SetFrame(CGRect frame) { base.Frame = frame; (this as UIScrollView).TPKeyboardAvoiding_updateContentInset(); }
public static extern bool IsIdentityRect(CGRect rect);
protected override nfloat LayoutItemsInGroup(int group, nfloat availableBreadth, ref CGRect frame, bool createLayoutInfo, Dictionary <NSIndexPath, CGSize?> oldItemSizes) { var itemsInGroup = CollectionView.NumberOfItemsInSection(group); if (itemsInGroup == 0) { _sectionEnd[group] = GetExtentEnd(frame); return(0); } var itemSize = ResolveItemSize(group, availableBreadth); var itemBreadth = GetBreadth(itemSize); var itemsDisplayablePerLine = Math.Max((int)(availableBreadth / itemBreadth), 1); var itemsPerLine = MaximumRowsOrColumns > 0 ? Math.Min(itemsDisplayablePerLine, MaximumRowsOrColumns) : itemsDisplayablePerLine; var numberOfLines = (itemsInGroup + itemsPerLine - 1) / itemsPerLine; //Rounds up var groupBreadthStart = GetBreadthStart(frame); frame.Size = itemSize; int item = -1; for (int line = 0; line < numberOfLines; line++) { for (int column = 0; column < itemsPerLine; column++) { item++; if (item == itemsInGroup) { break; } if (createLayoutInfo) { CreateItemLayoutInfo(item, group, frame); } IncrementBreadth(ref frame); } _sectionEnd[group] = GetExtentEnd(frame); IncrementExtent(ref frame); SetBreadthStart(ref frame, groupBreadthStart); } return((nfloat)(itemBreadth * Math.Min(itemsPerLine, itemsInGroup))); }
void PositionHUD(NSNotification notification) { nfloat keyboardHeight = 0; double animationDuration = 0; Frame = UIScreen.MainScreen.Bounds; UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation; bool ignoreOrientation = UIDevice.CurrentDevice.CheckSystemVersion(8, 0); if (notification != null) { var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification); animationDuration = UIKeyboard.AnimationDurationFromNotification(notification); if (notification.Name == UIKeyboard.WillShowNotification || notification.Name == UIKeyboard.DidShowNotification) { if (ignoreOrientation || IsPortrait(orientation)) { keyboardHeight = keyboardFrame.Size.Height; } else { keyboardHeight = keyboardFrame.Size.Width; } } else { keyboardHeight = 0; } } else { keyboardHeight = VisibleKeyboardHeight; } CGRect orientationFrame = this.Window.Bounds; CGRect statusBarFrame = UIApplication.SharedApplication.StatusBarFrame; if (!ignoreOrientation && IsLandscape(orientation)) { orientationFrame.Size = new CGSize(orientationFrame.Size.Height, orientationFrame.Size.Width); statusBarFrame.Size = new CGSize(statusBarFrame.Size.Height, statusBarFrame.Size.Width); } var activeHeight = orientationFrame.Size.Height; if (keyboardHeight > 0) { activeHeight += statusBarFrame.Size.Height * 2; } activeHeight -= keyboardHeight; nfloat posY = (float)Math.Floor(activeHeight * 0.45); nfloat posX = orientationFrame.Size.Width / 2; nfloat textHeight = _stringLabel.Frame.Height / 2 + 40; switch (toastPosition) { case ToastPosition.Bottom: posY = activeHeight - textHeight; break; case ToastPosition.Center: // Already set above break; case ToastPosition.Top: posY = textHeight; break; default: break; } CGPoint newCenter; float rotateAngle; if (ignoreOrientation) { rotateAngle = 0.0f; newCenter = new CGPoint(posX, posY); } else { switch (orientation) { case UIInterfaceOrientation.PortraitUpsideDown: rotateAngle = (float)Math.PI; newCenter = new CGPoint(posX, orientationFrame.Size.Height - posY); break; case UIInterfaceOrientation.LandscapeLeft: rotateAngle = (float)(-Math.PI / 2.0f); newCenter = new CGPoint(posY, posX); break; case UIInterfaceOrientation.LandscapeRight: rotateAngle = (float)(Math.PI / 2.0f); newCenter = new CGPoint(orientationFrame.Size.Height - posY, posX); break; default: // as UIInterfaceOrientationPortrait rotateAngle = 0.0f; newCenter = new CGPoint(posX, posY); break; } } if (notification != null) { UIView.Animate(animationDuration, 0, UIViewAnimationOptions.AllowUserInteraction, delegate { MoveToPoint(newCenter, rotateAngle); }, null); } else { MoveToPoint(newCenter, rotateAngle); } }
public PopoverContentView(CGRect frameRect) : base(frameRect) { }
public TPKeyboardAvoidingScrollView(CGRect frame) : base(frame) { Setup(); }
public static extern CGPoint GetNormalizedPoint(CGPoint imagePoint, nuint imageWidth, nuint imageHeight, CGRect regionOfInterest);
public UniversalView(CGRect bounds) : base(bounds) { Initialize(); }