Example #1
0
 public WaveView ()
 {
   BackgroundColor = UIColor.Clear;
   Layer.MasksToBounds = true;
   waterWaveHeight = UIScreen.MainScreen.Bounds.Height / 2;
   waterWaveWidth = UIScreen.MainScreen.Bounds.Width;
 }
        //Generated with PaintCode 2.2
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

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

            // Color Declarations
            var darkBlue = UIColor.FromRGBA(0.053f, 0.123f, 0.198f, 1.000f);
            var lightBlue = UIColor.FromRGBA(0.191f, 0.619f, 0.845f, 1.000f);

            // Gradient Declarations
            var backgroundGradientColors = new CGColor [] {lightBlue.CGColor, darkBlue.CGColor};
            var backgroundGradientLocations = new nfloat [] {0.0f, 1.0f};
            var backgroundGradient = new CGGradient(colorSpace, backgroundGradientColors, backgroundGradientLocations);

            // Rectangle Drawing
            var rectangleRect = new CGRect(rect.GetMinX() + (float)Math.Floor(rect.Width * -0.12917f + 0.5f), rect.GetMinY() + (float)Math.Floor(rect.Height * 0.00000f + 0.5f), (float)Math.Floor(rect.Width * 1.00000f + 0.5f) - (float)Math.Floor(rect.Width * -0.12917f + 0.5f), (float)Math.Floor(rect.Height * 1.00000f + 0.5f) - (float)Math.Floor(rect.Height * 0.00000f + 0.5f));
            var rectanglePath = UIBezierPath.FromRect(rectangleRect);
            context.SaveState();
            rectanglePath.AddClip();
            context.DrawLinearGradient(backgroundGradient,
                new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMinY()),
                new PointF((float)rectangleRect.GetMidX(), (float)rectangleRect.GetMaxY()),
                0);
            context.RestoreState();
        }
 /// <summary>
 /// Draws the map rectangle.
 /// </summary>
 /// <param name="mapRect">Map rectangle.</param>
 /// <param name="zoomScale">Zoom scale.</param>
 /// <param name="context"> Graphics context.</param>
 public override void DrawMapRect(MKMapRect mapRect, nfloat zoomScale, CGContext context)
 {
     base.DrawMapRect(mapRect, zoomScale, context);
     var multiPolygons = (MultiPolygon)this.polygonOverlay;
     foreach (var item in multiPolygons.Polygons)
     {
         var path = new CGPath();
         this.InvokeOnMainThread(() =>
             {
                 path = PolyPath(item.Polygon);
             });
         if (path != null)
         {
             context.SetFillColor(item.FillColor);
             context.BeginPath();
             context.AddPath(path);
             context.DrawPath(CGPathDrawingMode.EOFill);
             if (item.DrawOutlines)
             {
                 context.BeginPath();
                 context.AddPath(path);
                 context.StrokePath();
             }
         }
     }
 }
Example #4
0
 public MediaFile()
 {
     var screenSize = UIScreen.MainScreen.Bounds; // this is size in points, not pixels
     var density = UIScreen.MainScreen.Scale; // this is the density of pixels to points
     _deviceWidth = screenSize.Width * density; // in true pixels
     _deviceHeight = screenSize.Height * density;
 }
        private void CreatePanGestureRecognizer()
        {
            panGesture = new UIPanGestureRecognizer(() =>
            {
                if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1))
                {

                    var p0 = panGesture.LocationInView(this);

                    if (dx == 0)
                        dx = p0.X - Subviews[0].Center.X;

                    if (dy == 0)
                        dy = p0.Y - Subviews[0].Center.Y;

                    var p1 = new PointF((float)(p0.X - dx), (float)(p0.Y - dy));

                    Subviews[0].Center = p1;
                }
                else if (panGesture.State == UIGestureRecognizerState.Ended)
                {
                    dx = 0;
                    dy = 0;
                }
            });
        }
        public override void Draw(CGRect rect)
        {
            //Stopwatch s = new Stopwatch();
            //s.Start();

            //Console.WriteLine (" ----- SatBrightPickerView Draw");

            CGContext context = UIGraphics.GetCurrentContext ();

            CGColor[] gradColors = new CGColor[] {UIColor.FromHSBA(hue,1,1,1).CGColor,new CGColor(1,1,1,1)};
            nfloat[] gradLocations = new nfloat[] { 0.0f, 1.0f };

            var colorSpace = CGColorSpace.CreateDeviceRGB ();

            CGGradient gradient = new CGGradient (colorSpace, gradColors, gradLocations);
             context.DrawLinearGradient(gradient,new CGPoint(rect.Size.Width,0),new CGPoint(0,0),CGGradientDrawingOptions.DrawsBeforeStartLocation);

            gradColors = new CGColor[] {new CGColor(0,0,0,0), new CGColor(0,0,0,1)};

            gradient = new CGGradient(colorSpace,gradColors, gradLocations);
             context.DrawLinearGradient(gradient,new CGPoint(0,0),new CGPoint(0,rect.Size.Height),CGGradientDrawingOptions.DrawsBeforeStartLocation);

            gradient.Dispose();
            colorSpace.Dispose();

            //s.Stop();
            //Console.WriteLine("-----> SatBright Draw time: " + s.Elapsed.ToString());
        }
		/// <summary>
		/// Initializes a new instance of UITableView.
		/// </summary>
		/// <param name="data">Source Data.</param>
		/// <param name="cellHeight">cellHeight, use 0 for default.</param>
		/// <param name="fSize">Cell Font size.</param>
		/// <param name="cellSelectedBackgroundColor">Cell selected background color, Use Clear for default</param>
		/// <param name="cellSelectedTextColor">Cell selected text color, Use Clear for default</param>
		public DropDownTable(IList<string> data, nfloat cellHeight,
			nfloat fSize, UIColor cellSelectedBackgroundColor, UIColor cellSelectedTextColor,
			string selectedText = "") : base()
		{
			CellLayoutMarginsFollowReadableWidth = false;
			this.MultipleTouchEnabled = true;
			this._FontSize = fSize;
			this._CellHeight = cellHeight;
			this._CellSBackgroundColor = cellSelectedBackgroundColor;
			this._CellSTextColor = cellSelectedTextColor;

			Source = new DropDownSource (data, this._FontSize, this._CellHeight, this._CellSBackgroundColor, 
				this._CellSTextColor, selectedText);

			//ContentInset =  new UIEdgeInsets(0, -10, 0, 0);
			LayoutMargins = UIEdgeInsets.Zero;
			SeparatorInset = UIEdgeInsets.Zero;

			// select default row
			var idx = data.ToList().FindIndex(x => x == selectedText);
			System.Diagnostics.Debug.WriteLine (idx);
			if (idx >= 0) {
				this.SelectRow (Foundation.NSIndexPath.FromItemSection (idx, 0), false, UITableViewScrollPosition.Top);
			}

			(Source as DropDownSource).OnSelected += RowSelected;
		}
		public static void AddBorder(this UIView view, UIRectEdge edge, UIColor color, nfloat thickness) {

			var border = new CALayer ();
			var f = view.Frame;
			switch(edge)
			{
			case UIRectEdge.Top:
				border.Frame = new CGRect(0, 0, f.Width, thickness);
				break;
			case UIRectEdge.Bottom:
				border.Frame = new CGRect (0, f.Height - thickness, f.Width, thickness);
				break;
			case UIRectEdge.Left:
				border.Frame = new CGRect(0, 0, thickness, f.Height);
				break;
			case UIRectEdge.Right:
				border.Frame = new CGRect(f.Width - thickness, 0, thickness, f.Height);
				break;
			default:
				break;
			}

			border.BackgroundColor = color.CGColor;
			view.Layer.AddSublayer (border);
		}
		static UnitsExtensions()
		{
			UIScreen.MainScreen.InvokeOnMainThread(() =>
				{
					_screenScale = UIScreen.MainScreen.Scale;
				});
		}
        public static UIImage ToImage(this AtlassianIcon @this, nfloat size, bool cache = true)
        {
            var cacheDir = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User)[0].Path;

            string extension = string.Empty;
            if (Scale > 1 && Scale < 3)
            {
                extension = "@2x";
            }
            else if (Scale >= 3)
            {
                extension = "@3x";
            }

            var fileName = string.Format("atlassian-{0}-{1}{2}.png", (int)@this.CharacterCode, size, extension);
            var combinedPath = Path.Combine(cacheDir, fileName);

            if (File.Exists(combinedPath))
            {
                var img = cache ? UIImage.FromBundle(combinedPath) : UIImage.FromFile(combinedPath);
                return img.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
            }
            else
            {
                var img = Graphics.ImageFromFont(UIFont.FromName("Atlassian-icons", size), @this.CharacterCode, UIColor.Black);
                if (img == null)
                    return null;
                var pngData = img.AsPNG();
                pngData.Save(combinedPath, false);
                return img.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
            }
        }
Example #11
0
        public static UIImage CropByX(this UIImage image, nfloat x)
        {
            UIGraphics.BeginImageContextWithOptions(new CGSize(image.Size.Width - x, image.Size.Height), false, 0);

            UIImage result = null;

            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                context.TranslateCTM(0, image.Size.Height);
                context.ScaleCTM(1, -1);

                context.DrawImage(new CGRect(CGPoint.Empty, image.Size), image.CGImage);

                using (CGImage img = context.AsBitmapContext().ToImage())
                {
                    result = new UIImage(img, image.CurrentScale, UIImageOrientation.Up);
                    img.Dispose();
                }

                context.Dispose();
                UIGraphics.EndImageContext();
            }

            return result;
        }
        public CalloutAnnotation(int count, CGRect rect, nfloat lineWidth, UIColor color)
        {
            Path = UIBezierPath.FromOval(rect);
            Path.LineWidth = lineWidth;

            var center = new CGPoint (rect.GetMidX(), rect.GetMidY());

            Center = center;

            nfloat startAngle = (nfloat)(Math.PI * 0.75);
            nfloat endAngle = (nfloat)(Math.PI * 0.60);

            Clip = UIBezierPath.FromArc(center, center.X + lineWidth, startAngle, endAngle, true);
            Clip.AddLineTo(center);
            Clip.ClosePath();
            Clip.LineWidth = lineWidth;

            Tail = new UIBezierPath ();
            Tail.MoveTo(new CGPoint (center.X - 11, center.Y + 9));
            Tail.AddLineTo(new CGPoint (center.X - 11, center.Y + 18));
            Tail.AddLineTo(new CGPoint (center.X - 3, center.Y + 13));
            Tail.LineWidth = lineWidth;

            Rect = rect;
            Color = color;
            Count = count;
        }
Example #13
0
 public NSEdgeInsets(nfloat top, nfloat left, nfloat bottom, nfloat right)
 {
     Top = top;
     Left = left;
     Bottom = bottom;
     Right = right;
 }
Example #14
0
        void DrawBorders(CGContext context, nfloat xMin, nfloat xMax, nfloat yMin, nfloat yMax, nfloat fWidth, nfloat fHeight)
        {
            if (BorderColorTop != null)
            {
                context.SetFillColor(BorderColorTop.CGColor);
                context.FillRect(new CGRect(xMin, yMin, fWidth, BorderWidth.Top));
            }

            if (BorderColorLeft != null)
            {
                context.SetFillColor(BorderColorLeft.CGColor);
                context.FillRect(new CGRect(xMin, yMin, BorderWidth.Left, fHeight));
            }

            if (BorderColorRight != null)
            {
                context.SetFillColor(BorderColorRight.CGColor);
                context.FillRect(new CGRect(xMax - BorderWidth.Right, yMin, BorderWidth.Right, fHeight));
            }

            if (BorderColorBottom != null)
            {
                context.SetFillColor(BorderColorBottom.CGColor);
                context.FillRect(new CGRect(xMin, yMax - BorderWidth.Bottom, fWidth, BorderWidth.Bottom));
            }
        }
Example #15
0
        private UIImage CreateImage (NSString title, nfloat scale)
        {
            var titleAttrs = new UIStringAttributes () {
                Font = UIFont.FromName ("HelveticaNeue", 13f),
                ForegroundColor = Color.Gray,
            };

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

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

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

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

            try {
                image.Draw (imageBounds);
                title.DrawString (titleBounds, titleAttrs);
                return UIGraphics.GetImageFromCurrentImageContext ();
            } finally {
                UIGraphics.EndImageContext ();
            }
        }
Example #16
0
		public void setSize()
		{
			//its iPhone. Find out which one?

				CGSize result = UIScreen.MainScreen.Bounds.Size;
				this.width = result.Width;
				this.height = result.Height;
			tableSize.Width = result.Width;
				if(result.Height == 480)
				{
				labelMHWidth = 100;
				tableSize.Height = 200;
				textSize = 13;
				}
				else if(result.Height == 568)
				{
				labelMHWidth = 120;
				tableSize.Height = 360;
				textSize = 15;
				}
				else if(result.Height == 667)
				{
				labelMHWidth = 150;
				tableSize.Height = 500;
				textSize = 15;
				}
				else if(result.Height == 736)
				{
				labelMHWidth = 180;
				tableSize.Height = 580;
				textSize = 17;
				}

		}
        private UIImage CreatePieSegment(CGSize size, nfloat endAngle)
        {
            // Add the arc
            var arc = new CGPath();

            arc.MoveToPoint(size.Width / 2.0f, size.Height / 2.0f);
            arc.AddLineToPoint(size.Width / 2.0f, 0);
            arc.AddArc(size.Width / 2.0f, size.Height / 2.0f, size.Width / 2.0f, _startAngle, endAngle, false);
            arc.AddLineToPoint(size.Width / 2.0f, size.Height / 2.0f);

            // Stroke the arc
            UIGraphics.BeginImageContextWithOptions(size, false, 0);

            var context = UIGraphics.GetCurrentContext();

            context.AddPath(arc);
            context.SetFillColor(UIColor.FromRGBA(0f, 0f, 0f, 1f).CGColor);
            context.FillPath();

            // Get the mask image
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return image;
        }
Example #18
0
 public AVEdgeWidths(nfloat left, nfloat top, nfloat right, nfloat bottom)
 {
     Left = left;
     Top = top;
     Right = right;
     Bottom = bottom;
 }
Example #19
0
		static ImageLoaderTask()
		{
			UIScreen.MainScreen.InvokeOnMainThread(() =>
				{
					_screenScale = UIScreen.MainScreen.Scale;
				});
		}
Example #20
0
 internal CropperResizerView(UIColor color = null, nfloat transparancy = default(nfloat), nfloat lineWidth = default(nfloat))
 {
     this.BackgroundColor = UIColor.Clear;
     _color = color ?? UIColor.Red;
     _transparancy = transparancy == 0 ? 0.8f : transparancy;
     _lineWidth = lineWidth == 0 ? 3f : lineWidth;
 }
		void Init (Tuple<GeoAnchor, GeoAnchor> anchors)
		{
			// To compute the distance between two geographical co-ordinates, we first need to
			// convert to MapKit co-ordinates
			fromAnchorFloorplanPoint = anchors.Item1.Pixel;
			fromAnchorMKPoint = MKMapPoint.FromCoordinate (anchors.Item1.LatitudeLongitude);
			MKMapPoint toAnchorMKPoint = MKMapPoint.FromCoordinate (anchors.Item2.LatitudeLongitude);

			// So that we can use MapKit's helper function to compute distance.
			// this helper function takes into account the curvature of the earth.
			var distanceBetweenPointsMeters = (nfloat)MKGeometry.MetersBetweenMapPoints (fromAnchorMKPoint, toAnchorMKPoint);

			var dx = anchors.Item1.Pixel.X - anchors.Item2.Pixel.X;
			var dy = anchors.Item1.Pixel.Y - anchors.Item2.Pixel.Y;

			// Distance between two points in pixels (on the floorplan image)
			var distanceBetweenPointsPixels = Hypot (dx, dy);

			// This gives us pixels/meter
			PixelsPerMeter = distanceBetweenPointsPixels / distanceBetweenPointsMeters;

			// Get the 2nd anchor's eastward/southward distance in meters from the first anchor point.
			var hyp = FetchRect (fromAnchorMKPoint, toAnchorMKPoint);

			// Angle of diagonal to east (in geographic)
			nfloat angleFromEastAndHypo = NMath.Atan2 (hyp.South, hyp.East);

			// Angle of diagonal to horizontal (in floorplan)
			nfloat angleFromXAndHypo = NMath.Atan2 (dy, dx);

			// Rotation amount from the geographic anchor line segment
			// to the floorplan anchor line segment
			// This is angle between X axis and East direction. This angle shows how you floor plan exists in real world
			radiansRotated = angleFromXAndHypo - angleFromEastAndHypo;
		}
 //FromRGB (234, 105, 92);
 public DashboardGraphView(CGRect frame, int lineWidth, nfloat degrees)
 {
     _lineWidth = lineWidth;
     _degrees = degrees;
     this.Frame = new CGRect(frame.X, frame.Y, frame.Width, frame.Height);
     this.BackgroundColor = UIColor.Clear;
 }
        public void SetFrameWithNavigationBar(nfloat navbarHeight)
        {
            nfloat width = UIScreen.MainScreen.Bounds.Size.Width;
            nfloat height = UIScreen.MainScreen.Bounds.Size.Height;

            List.Frame = new CGRect(0, navbarHeight, width, height - navbarHeight);
        }
		private static CGSize RCTTargetSize(CGSize sourceSize, nfloat sourceScale,
			CGSize destSize, nfloat destScale,
			RCTResizeMode resizeMode,
			bool allowUpscaling)
		{
			switch (resizeMode)
			{
				case RCTResizeMode.ScaleToFill:

					if (!allowUpscaling)
					{
						nfloat scale = sourceScale / destScale;
						destSize.Width = (nfloat)Math.Min(sourceSize.Width * scale, destSize.Width);
						destSize.Height = (nfloat)Math.Min(sourceSize.Height * scale, destSize.Height);
					}
					return RCTCeilSize(destSize, destScale);

				default: {

						// Get target size
						CGSize size = RCTTargetRect(sourceSize, destSize, destScale, resizeMode).Size;
						if (!allowUpscaling)
						{
							// return sourceSize if target size is larger
							if (sourceSize.Width * sourceScale < size.Width * destScale)
							{
								return sourceSize;
							}
						}
						return size;
					}
			}
		}
        public PhotoGalleryImageView(UIImage im)
        {
            //Link xib file to view.
            var arr = NSBundle.MainBundle.LoadNib("PhotoGalleryImageView", this, null);
            var v = Runtime.GetNSObject (arr.ValueAt (0)) as UIView;
            v.Frame = new CoreGraphics.CGRect (0,0,Frame.Width,Frame.Height);

            //Initialize Variables
            widthMax = 700f;
            heightMax = 800f;
            widthOfFrame = 752f;
            heightOfFrame = 988f;
            image = im;
            backgroundOffset = 30f;

            //Sync up button
            btn_back.TouchUpInside += Btn_exit_TouchUpInside;
            this.BackgroundColor = UIColor.Clear;
            this.Alpha = 1f;

            //Call load function
            loadImage ();

            AddSubview (v);
        }
Example #26
0
		/// <summary>
		/// Initializes a new instance of the <see cref="XibFree.LayoutParameters"/> class.
		/// </summary>
		/// <param name="width">Width.</param>
		/// <param name="height">Height.</param>
		/// <param name="weight">Weight.</param>
		public LayoutParameters(nfloat width, nfloat height, double weight=1.0)
		{
			Width = width;
			Height = height;
			Margins = UIEdgeInsets.Zero;
			Weight = 1;
			Gravity = Gravity.None;
		}
Example #27
0
		public static UNColor FromRgba (nfloat red, nfloat green, nfloat blue, nfloat alpha)
		{
#if __IOS__
			return UNColor.FromRGBA (red, green, blue, alpha);
#else
			return UNColor.FromRgba (red, green, blue, alpha);
#endif
		}
        public UICircleView(CGRect rect, CGPoint center, nfloat radius)
            : base(rect)
        {
            _center = center;
            _radius = radius;

            BackgroundColor = UIColor.Clear;
        }
Example #29
0
		public ImageLoaderTask(IDownloadCache downloadCache, IMainThreadDispatcher mainThreadDispatcher, IMiniLogger miniLogger, TaskParameter parameters, Func<UIView> getNativeControl, Action<UIImage, bool> doWithImage, nfloat imageScale)
			: base(mainThreadDispatcher, miniLogger, parameters)
		{
			_getNativeControl = getNativeControl;
			_doWithImage = doWithImage;
			_imageScale = imageScale;
			DownloadCache = downloadCache;
		}
		public static UIColor Random ()
		{
			var rand = new Random ();
			var hue = new nfloat ((rand.Next (0, 25600) % 256) / 256.0);
			var saturation = new nfloat ((rand.Next (0, 25600) % 128) / 256.0 + .5);
			var brightness = new nfloat ((rand.Next (0, 25600) % 128) / 256.0 + .5);
			return UIColor.FromHSB (hue, saturation, brightness);
		}
Example #31
0
 // Set new Mass for physics
 public void MassOfBody(nfloat mass)
 {
     PhysicsBody.Mass = mass;
 }
Example #32
0
 static public unsafe CGPath FromRoundedRect(CGRect rectangle, nfloat cornerWidth, nfloat cornerHeight, CGAffineTransform transform)
 {
     return(_FromRoundedRect(rectangle, cornerWidth, cornerHeight, &transform));
 }
		static extern IntPtr CTFontDescriptorCreateCopyWithVariation (IntPtr original, IntPtr variationIdentifier, nfloat variationValue);
        public void Update(UITableView tableView, Cell cell, UITableViewCell nativeCell)
        {
            var parentListView = cell.RealParent as ListView;
            var recycling      = parentListView != null &&
                                 ((parentListView.CachingStrategy & ListViewCachingStrategy.RecycleElement) != 0);

            if (_cell != cell && recycling)
            {
                if (_cell != null)
                {
                    ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged -= OnContextItemsChanged;
                }

                ((INotifyCollectionChanged)cell.ContextActions).CollectionChanged += OnContextItemsChanged;
            }

            var height = Frame.Height + (parentListView != null && parentListView.SeparatorVisibility == SeparatorVisibility.None ? 0.5f : 0f);
            var width  = ContentView.Frame.Width;

            nativeCell.Frame = new RectangleF(0, 0, width, height);
            nativeCell.SetNeedsLayout();

            var handler = new PropertyChangedEventHandler(OnMenuItemPropertyChanged);

            _tableView = tableView;

            if (_cell != null)
            {
                if (!recycling)
                {
                    _cell.PropertyChanged -= OnCellPropertyChanged;
                }
                if (_menuItems.Count > 0)
                {
                    if (!recycling)
                    {
                        ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged -= OnContextItemsChanged;
                    }

                    foreach (var item in _menuItems)
                    {
                        item.PropertyChanged -= handler;
                    }
                }

                _menuItems.Clear();
            }

            _menuItems.AddRange(cell.ContextActions);

            _cell = cell;
            if (!recycling)
            {
                cell.PropertyChanged += OnCellPropertyChanged;
                ((INotifyCollectionChanged)_cell.ContextActions).CollectionChanged += OnContextItemsChanged;
            }

            var isOpen = false;

            if (_scroller == null)
            {
                _scroller = new UIScrollView(new RectangleF(0, 0, width, height));
                _scroller.ScrollsToTop = false;
                _scroller.ShowsHorizontalScrollIndicator = false;

                _scroller.PreservesSuperviewLayoutMargins = true;

                ContentView.AddSubview(_scroller);
            }
            else
            {
                _scroller.Frame = new RectangleF(0, 0, width, height);
                isOpen          = ScrollDelegate.IsOpen;

                for (var i = 0; i < _buttons.Count; i++)
                {
                    var b = _buttons[i];
                    b.RemoveFromSuperview();
                    b.Dispose();
                }

                _buttons.Clear();

                ScrollDelegate.Unhook(_scroller);
                ScrollDelegate.Dispose();
            }

            if (ContentCell != nativeCell)
            {
                if (ContentCell != null)
                {
                    ContentCell.RemoveFromSuperview();
                    ContentCell = null;
                }

                ContentCell = nativeCell;

                //Hack: if we have a ImageCell the insets are slightly different,
                //the inset numbers user below were taken using the Reveal app from the default cells
                if ((ContentCell as CellTableViewCell)?.Cell is ImageCell)
                {
                    nfloat imageCellInsetLeft  = 57;
                    nfloat imageCellInsetRight = 0;
                    if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                    {
                        imageCellInsetLeft  = 89;
                        imageCellInsetRight = imageCellInsetLeft / 2;
                    }
                    SeparatorInset = new UIEdgeInsets(0, imageCellInsetLeft, 0, imageCellInsetRight);
                }

                _scroller.AddSubview(nativeCell);
            }

            SetupButtons(width, height);

            UIView container = null;

            var totalWidth = width;

            for (var i = _buttons.Count - 1; i >= 0; i--)
            {
                var b = _buttons[i];
                totalWidth += b.Frame.Width;

                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    _scroller.AddSubview(b);
                }
                else
                {
                    if (container == null)
                    {
                        container = new iOS7ButtonContainer(b.Frame.Width);
                        _scroller.InsertSubview(container, 0);
                    }

                    container.AddSubview(b);
                }
            }

            _scroller.Delegate    = new ContextScrollViewDelegate(container, _buttons, isOpen);
            _scroller.ContentSize = new SizeF(totalWidth, height);

            if (isOpen)
            {
                _scroller.SetContentOffset(new PointF(ScrollDelegate.ButtonsWidth, 0), false);
            }
            else
            {
                _scroller.SetContentOffset(new PointF(0, 0), false);
            }

            if (ContentCell != null)
            {
                SelectionStyle = ContentCell.SelectionStyle;
            }
        }
Example #35
0
        public PostGameMenu(CGSize frameSize, IGameUIState gameStateDelegate)
        {
            GameStateDelegate = gameStateDelegate;
            nfloat menuHeight = frameSize.Height * 0.8f;
            var    background = new SKSpriteNode(AppKit.NSColor.Black, new CGSize(frameSize.Width * 0.8f, menuHeight));

            background.ZPosition = -1;
            background.Alpha     = 0.5f;
            background.Position  = new CGPoint(0, -0.2f * menuHeight);

            myLabel          = InGameScene.LabelWithText("Final Score", 65);
            myLabel.Position = new CGPoint(Frame.GetMidX(), Frame.GetMidY());

            Position = new CGPoint(frameSize.Width * 0.5f, frameSize.Height * 0.5f);
            UserInteractionEnabled         = true;
            myLabel.UserInteractionEnabled = true;
            AddChild(myLabel);
            InGameScene.DropShadowOnLabel(myLabel);

            var bananaLocation      = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.4f);
            var coinLocation        = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.6f);
            var totalLocation       = new CGPoint(frameSize.Width * -0.4f, Frame.GetMidY() * -0.8f);
            var bananaScoreLocation = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.4f);
            var coinScoreLocation   = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.6f);
            var totalScoreLocation  = new CGPoint(frameSize.Width * +0.4f, Frame.GetMidY() * -0.8f);

            bananaText          = (SKLabelNode)myLabel.Copy();
            bananaText.Text     = "Bananas";
            bananaText.FontSize = 0.1f * menuHeight;
            bananaText.Scale    = 0.8f;
            bananaLocation.X   += bananaText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            bananaText.Position = new CGPoint(bananaLocation.X, -2000);
            AddChild(bananaText);
            InGameScene.DropShadowOnLabel(bananaText);

            bananaScore            = (SKLabelNode)bananaText.Copy();
            bananaScore.Text       = "000";
            bananaScoreLocation.X -= bananaScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            bananaScore.Position   = new CGPoint(bananaScoreLocation.X, -2000);
            AddChild(bananaScore);

            coinText          = (SKLabelNode)bananaText.Copy();
            coinText.Text     = "Large Bananas";
            coinLocation.X   += coinText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            coinText.Position = new CGPoint(coinLocation.X, -2000f);
            AddChild(coinText);
            InGameScene.DropShadowOnLabel(coinText);

            coinScore            = (SKLabelNode)coinText.Copy();
            coinScore.Text       = "000";
            coinScoreLocation.X -= coinScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            coinScore.Position   = new CGPoint(coinScoreLocation.X, -2000f);
            AddChild(coinScore);

            totalText          = (SKLabelNode)bananaText.Copy();
            totalText.Text     = "Total";
            totalLocation.X   += totalText.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            totalText.Position = new CGPoint(totalLocation.X, -2000f);
            AddChild(totalText);
            InGameScene.DropShadowOnLabel(totalText);

            totalScore            = (SKLabelNode)totalText.Copy();
            totalScore.Text       = "000";
            totalScoreLocation.X -= totalScore.CalculateAccumulatedFrame().Width * 0.5f + frameSize.Width * 0.1f;
            totalScore.Position   = new CGPoint(totalScoreLocation.X, -2000f);
            AddChild(totalScore);

            SKAction flyup = SKAction.MoveTo(new CGPoint(frameSize.Width * 0.5f, frameSize.Height - 100), 0.25);

            flyup.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupBananas = SKAction.MoveTo(bananaLocation, 0.25);

            flyupBananas.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupBananasScore = SKAction.MoveTo(bananaScoreLocation, 0.25f);

            flyupBananasScore.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupCoins = SKAction.MoveTo(coinLocation, 0.25);

            flyupCoins.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupCoinsScore = SKAction.MoveTo(coinScoreLocation, 0.25);

            flyupCoinsScore.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupTotal = SKAction.MoveTo(totalLocation, 0.25);

            flyupTotal.TimingMode = SKActionTimingMode.EaseInEaseOut;

            SKAction flyupTotalScore = SKAction.MoveTo(totalScoreLocation, 0.25);

            flyupTotalScore.TimingMode = SKActionTimingMode.EaseInEaseOut;

            int bananasCollected = gameStateDelegate.BananasCollected;
            int coinsCollected   = gameStateDelegate.CoinsCollected;
            int totalCollected   = bananasCollected + (coinsCollected * 100);

            SKAction countUpBananas = SKAction.CustomActionWithDuration(bananasCollected / 100f, ((node, elapsedTime) => {
                if (bananasCollected > 0)
                {
                    SKLabelNode label = (SKLabelNode)node;
                    nint total = (nint)(elapsedTime / (bananasCollected / 100.0f) * bananasCollected);
                    label.Text = total.ToString();

                    if (total % 10 == 0)
                    {
                        GameSimulation.Sim.PlaySound("deposit.caf");
                    }
                }
            }));

            SKAction countUpCoins = SKAction.CustomActionWithDuration(coinsCollected / 100f, ((node, elapsedTime) => {
                if (coinsCollected > 0)
                {
                    SKLabelNode label = (SKLabelNode)node;
                    nint total = (nint)((elapsedTime / (coinsCollected / 100.0f)) * coinsCollected);
                    label.Text = total.ToString();

                    if (total % 10 == 0)
                    {
                        GameSimulation.Sim.PlaySound("deposit.caf");
                    }
                }
            }));

            SKAction countUpTotal = SKAction.CustomActionWithDuration(totalCollected / 500.0f, ((node, elapsedTime) => {
                if (totalCollected > 0)
                {
                    SKLabelNode label = (SKLabelNode)node;
                    nint total = (nint)((elapsedTime / (totalCollected / 500.0f)) * totalCollected);
                    label.Text = total.ToString();

                    if (total % 25 == 0)
                    {
                        GameSimulation.Sim.PlaySound("deposit.caf");
                    }
                }
            }));

            RunAction(flyup, () => {
                bananaText.RunAction(flyupBananas);
                bananaScore.RunAction(flyupBananasScore, () => {
                    bananaScore.RunAction(countUpBananas, () => {
                        bananaScore.Text = bananasCollected.ToString();
                        coinText.RunAction(flyupCoins);
                        coinScore.RunAction(flyupCoinsScore, () => {
                            coinScore.RunAction(countUpCoins, () => {
                                coinScore.Text = coinsCollected.ToString();
                                totalText.RunAction(flyupTotal);
                                totalScore.RunAction(flyupTotalScore, () => {
                                    totalScore.RunAction(countUpTotal, () => {
                                        totalScore.Text = totalCollected.ToString();
                                    });
                                });
                            });
                        });
                    });
                });
            });
        }
Example #36
0
 public extern static void FrameRect(CGRect rect, nfloat frameWidth);
Example #37
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            UIView mainView   = new UIView();
            nfloat TotalWidth = Frame.Width - 20;
            int    height     = 150;

            mainView.Frame = new CGRect(0, 0, TotalWidth, Frame.Height);


            /*------Header Label-------*/

            UILabel label = new UILabel(new CGRect(20, 50, TotalWidth, 25));

            label.BackgroundColor = UIColor.Clear;
            label.Font            = UIFont.SystemFontOfSize(25);
            label.TextAlignment   = UITextAlignment.Left;
            label.TextColor       = UIColor.Gray;
            label.Text            = "Sample Pictures";


            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                height = 200;
            }
            UIButton imageView1 = new UIButton(new CGRect(0, 100, TotalWidth / 3, height));

            imageView1.SetImage(UIImage.FromBundle("Images/ImageEditor/image2.png"), UIControlState.Normal);
            imageView1.ImageView.ContentMode = UIViewContentMode.ScaleToFill;
            imageView1.TouchDown            += (sender, e) =>
            {
                navigationController.PushViewController(new ImageEditorViewController(imageView1.CurrentImage), false);
            };

            mainView.AddSubview(imageView1);



            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                height = 200;
            }
            UIButton imageView2 = new UIButton(new CGRect(TotalWidth / 3, 100, TotalWidth / 3, height));

            imageView2.SetImage(UIImage.FromBundle("Images/ImageEditor/image3.png"), UIControlState.Normal);
            imageView2.ImageView.ContentMode = UIViewContentMode.ScaleToFill;
            mainView.AddSubview(imageView2);

            imageView2.TouchDown += (sender, e) =>
            {
                navigationController.PushViewController(new ImageEditorViewController(imageView2.CurrentImage), false);
            };


            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                height = 200;
            }
            UIButton imageView3 = new UIButton(new CGRect(2 * (TotalWidth / 3), 100, TotalWidth / 3, height));

            imageView3.SetImage(UIImage.FromBundle("Images/ImageEditor/image4.png"), UIControlState.Normal);
            imageView3.ImageView.ContentMode = UIViewContentMode.ScaleToFill;
            imageView3.TouchDown            += (sender, e) =>
            {
                navigationController.PushViewController(new ImageEditorViewController(imageView3.CurrentImage), false);
            };
            mainView.AddSubview(imageView3);

            AddSubview(label);
            AddSubview(mainView);
        }
 public BackImageSlideView(nfloat pos) : base()
 {
     slidePos = pos;
     //initView ();
 }
Example #39
0
        public static UIImage OverlayRectangles(UIImage uiImage, CGSize imageSize, VNFaceObservation[] observations)
        {
            nfloat fWidth  = uiImage.Size.Width;
            nfloat fHeight = uiImage.Size.Height;

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();

            using (CGBitmapContext ctx = new CGBitmapContext(IntPtr.Zero, (nint)fWidth, (nint)fHeight, 8, 4 * (nint)fWidth, CGColorSpace.CreateDeviceRGB(), CGImageAlphaInfo.PremultipliedFirst))
            {
                Console.WriteLine("Orientation:" + uiImage.Orientation);

                if (uiImage.Orientation == UIImageOrientation.Up)
                {   // correct orientation
                    ctx.DrawImage(new CGRect(0, 0, (double)fWidth, (double)fHeight), uiImage.CGImage);
                }
                else
                {   // need to rotate image so that rectangle overlays match
                    UIGraphics.BeginImageContextWithOptions(uiImage.Size, false, 0);
                    uiImage.Draw(new CGRect(0, 0, (double)fWidth, (double)fHeight));
                    var img = UIGraphics.GetImageFromCurrentImageContext();
                    UIGraphics.EndImageContext();
                    ctx.DrawImage(new CGRect(0, 0, (double)fWidth, (double)fHeight), img.CGImage);
                }

                var count = 0;
                foreach (var o in observations)
                {
                    // Draw rectangle
                    var text = "Face: " + count++.ToString();
                    Console.WriteLine(o.BoundingBox + " " + o.Confidence);

                    // Fudge/switch coordinates to match UIImage
                    var topLeft     = new CGPoint(o.BoundingBox.Left, o.BoundingBox.Top).Scaled(imageSize);
                    var topRight    = new CGPoint(o.BoundingBox.Left, o.BoundingBox.Bottom).Scaled(imageSize);
                    var bottomLeft  = new CGPoint(o.BoundingBox.Right, o.BoundingBox.Top).Scaled(imageSize);
                    var bottomRight = new CGPoint(o.BoundingBox.Right, o.BoundingBox.Bottom).Scaled(imageSize);

                    //set up drawing attributes
                    ctx.SetStrokeColor(UIColor.Red.CGColor);
                    ctx.SetLineWidth(10);

                    //create geometry
                    var path = new CGPath();

                    path.AddLines(new CGPoint[] {
                        topLeft, topRight, bottomRight, bottomLeft
                    });

                    path.CloseSubpath();

                    //add geometry to graphics context and draw it
                    ctx.AddPath(path);
                    ctx.DrawPath(CGPathDrawingMode.Stroke);


                    // Draw text
                    ctx.SelectFont("Helvetica", 60, CGTextEncoding.MacRoman);
                    //Measure the text's width - This involves drawing an invisible string to calculate the X position difference
                    float start, end, textWidth;
                    //Get the texts current position
                    start = (float)ctx.TextPosition.X;
                    //Set the drawing mode to invisible
                    ctx.SetTextDrawingMode(CGTextDrawingMode.Invisible);
                    //Draw the text at the current position
                    ctx.ShowText(text);
                    //Get the end position
                    end = (float)ctx.TextPosition.X;
                    //Subtract start from end to get the text's width
                    textWidth = end - start;
                    ctx.SetFillColor(UIColor.Red.CGColor);

                    //Set the drawing mode back to something that will actually draw Fill for example
                    ctx.SetTextDrawingMode(CGTextDrawingMode.Fill);

                    //Draw the text at given coords.
                    ctx.ShowTextAtPoint(topLeft.X, topLeft.Y - 60, text);
                }
                return(UIImage.FromImage(ctx.ToImage()));
            }
        }
Example #40
0
        public CGSize DrawString(CGPoint point, nfloat width, XamCore.UIKit.UIFont font, nfloat minFontSize, nfloat actualFontSize, XamCore.UIKit.UILineBreakMode breakMode, XamCore.UIKit.UIBaselineAdjustment adjustment)
        {
            nfloat temp = actualFontSize;

            return(DrawString(point, width, font, minFontSize, ref temp, breakMode, adjustment));
        }
Example #41
0
        void LayoutChildren(bool animated)
        {
            var    frame       = Element.Bounds.ToRectangleF();
            var    masterFrame = frame;
            nfloat opacity     = 1;

            masterFrame.Width = (int)(Math.Min(masterFrame.Width, masterFrame.Height) * 0.8);
            var detailRenderer = Platform.GetRenderer(MasterDetailPage.Detail);

            if (detailRenderer == null)
            {
                return;
            }
            var detailView = detailRenderer.ViewController.View;

            var isRTL = (Element as IVisualElementController)?.EffectiveFlowDirection.IsRightToLeft() == true;

            if (isRTL)
            {
                masterFrame.X = (int)(masterFrame.Width * .25);
            }

            _masterController.View.Frame = masterFrame;

            var target = frame;

            if (Presented)
            {
                target.X += masterFrame.Width;
                if (_applyShadow)
                {
                    opacity = 0.5f;
                }
            }

            if (isRTL)
            {
                target.X = target.X * -1;
            }

            if (animated)
            {
                UIView.BeginAnimations("Flyout");
                var view = _detailController.View;
                view.Frame = target;
                detailView.Layer.Opacity = (float)opacity;
                UIView.SetAnimationCurve(UIViewAnimationCurve.EaseOut);
                UIView.SetAnimationDuration(250);
                UIView.CommitAnimations();
            }
            else
            {
                _detailController.View.Frame = target;
                detailView.Layer.Opacity     = (float)opacity;
            }

            MasterDetailPage.MasterBounds = new Rectangle(masterFrame.X, 0, masterFrame.Width, masterFrame.Height);
            MasterDetailPage.DetailBounds = new Rectangle(0, 0, frame.Width, frame.Height);

            if (Presented)
            {
                _clickOffView.Frame = _detailController.View.Frame;
            }
        }
Example #42
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            InitElements();

            var circleLayer = new CAShapeLayer();
            var circlePath  = UIBezierPath.FromRect(cadreIV.Frame);

            circlePath.UsesEvenOddFillRule = true;
            circleLayer.Path = circlePath.CGPath;
            var maskPath = UIBezierPath.FromRect(new CGRect(0, (int)headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2, View.Frame.Width, (int)(View.Frame.Height - (headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2 + View.Frame.Width / 8))));

            maskPath.AppendPath(circlePath);
            maskPath.UsesEvenOddFillRule = true;
            fillLayer.Path      = maskPath.CGPath;
            fillLayer.FillRule  = CAShapeLayer.FillRuleEvenOdd;
            fillLayer.FillColor = maskColor.CGColor;

            View.Layer.AddSublayer(fillLayer);

            nfloat width_height_ratio;
            int    image_height, image_width;

            if (imageView.Image.Size.Height > imageView.Image.Size.Width)
            {
                width_height_ratio = imageView.Image.Size.Height / imageView.Image.Size.Width;
                image_width        = (int)View.Frame.Width;
                image_height       = (int)(image_width * width_height_ratio);
                imageView.Frame    = new Rectangle(0, (int)(headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2), image_width, image_height);
            }
            else if (imageView.Image.Size.Height < imageView.Image.Size.Width)
            {
                width_height_ratio = imageView.Image.Size.Width / imageView.Image.Size.Height;
                image_width        = (int)View.Frame.Width;
                image_height       = (int)(image_width / width_height_ratio);
                imageView.Frame    = new Rectangle(0, (int)(headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2), image_width, image_height);
            }
            else if (imageView.Image.Size.Height == imageView.Image.Size.Width)
            {
                image_width     = (int)View.Frame.Width;
                image_height    = image_width;
                imageView.Frame = new Rectangle(0, (int)(headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2), image_width, image_height);
            }

            backBn.TouchUpInside += (s, e) =>
            {
                this.NavigationController.PopViewController(true);
            };
            pinchGesture = new UIPinchGestureRecognizer(() =>
            {
                if (pinchGesture.State == UIGestureRecognizerState.Began || pinchGesture.State == UIGestureRecognizerState.Changed)
                {
                    if (cadreIV.Frame.X > 0 && cadreIV.Frame.Y > (int)(headerView.Frame.Y + headerView.Frame.Height) && cadreIV.Frame.X + cadreIV.Frame.Width < View.Frame.Width && cadreIV.Frame.Y + cadreIV.Frame.Height < (imageView.Frame.Height + imageView.Frame.Y))
                    {
                        pinchGesture.View.Transform *= CGAffineTransform.MakeScale(pinchGesture.Scale, pinchGesture.Scale);
                        pinchGesture.Scale           = 1;

                        circleLayer = new CAShapeLayer();
                        circlePath  = UIBezierPath.FromRect(cadreIV.Frame);
                        circlePath.UsesEvenOddFillRule = true;
                        circleLayer.Path = circlePath.CGPath;
                        maskPath         = UIBezierPath.FromRect(new CGRect(0, (int)headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2, View.Frame.Width, (int)(View.Frame.Height - (headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2 + View.Frame.Width / 8))));
                        maskPath.AppendPath(circlePath);
                        maskPath.UsesEvenOddFillRule = true;
                        fillLayer.Path     = maskPath.CGPath;
                        fillLayer.FillRule = CAShapeLayer.FillRuleEvenOdd;

                        View.Layer.AddSublayer(fillLayer);
                    }
                    else
                    {
                        if (pinchGesture.Scale < 1)
                        {
                            pinchGesture.View.Transform *= CGAffineTransform.MakeScale(pinchGesture.Scale, pinchGesture.Scale);
                            pinchGesture.Scale           = 1;

                            circleLayer = new CAShapeLayer();
                            circlePath  = UIBezierPath.FromRect(cadreIV.Frame);
                            circlePath.UsesEvenOddFillRule = true;
                            circleLayer.Path = circlePath.CGPath;
                            maskPath         = UIBezierPath.FromRect(new CGRect(0, (int)headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2, View.Frame.Width, (int)(View.Frame.Height - (headerView.Frame.Y + headerView.Frame.Height + headerView.Frame.Height / 2 + View.Frame.Width / 8))));
                            maskPath.AppendPath(circlePath);
                            maskPath.UsesEvenOddFillRule = true;
                            fillLayer.Path     = maskPath.CGPath;
                            fillLayer.FillRule = CAShapeLayer.FillRuleEvenOdd;

                            View.Layer.AddSublayer(fillLayer);
                        }
                    }
                }
            });
            cadreIV.AddGestureRecognizer(pinchGesture);
            UIStoryboard sb = UIStoryboard.FromName("Main", null);
            //CropGalleryViewController.currentImage = current_imgBn.CurrentImage;
            var vc = sb.InstantiateViewController(nameof(CompanyDataViewControllerNew));

            if (came_from == "edit")
            {
                vc = sb.InstantiateViewController(nameof(EditCompanyDataViewControllerNew));
            }
            readyBn.TouchUpInside += (s, e) =>
            {
                x = cadreIV.Frame.X;
                y = cadreIV.Frame.Y;
                w = cadreIV.Frame.Width;
                h = cadreIV.Frame.Height;

                var wwww1 = (float)(imageView.Image.Size.Width / View.Frame.Width);
                var hhhh1 = (float)(imageView.Image.Size.Height / imageView.Frame.Height);
                var ppp   = (float)(cadreIV.Frame.X * wwww1);
                var lll   = (float)(cadreIV.Frame.Y * hhhh1 - imageView.Frame.Y * wwww1);
                var www   = (float)(cadreIV.Frame.Width * wwww1);
                var hhh   = (float)(cadreIV.Frame.Height * hhhh1);

                cropped_result = CenterCrop(imageView.Image, new RectangleF(ppp, lll, www, hhh));

                this.NavigationController.PushViewController(vc, true);
                var vc_list = this.NavigationController.ViewControllers.ToList();
                vc_list.RemoveAt(vc_list.Count - 2);
                vc_list.RemoveAt(vc_list.Count - 2);
                if (came_from_gallery_or_camera == Constants.camera)
                {
                    vc_list.RemoveAt(vc_list.Count - 2);
                }
                this.NavigationController.ViewControllers = vc_list.ToArray();
            };
            cancelBn.TouchUpInside += (s, e) =>
            {
                this.NavigationController.PushViewController(vc, true);
                //this.NavigationController.PopViewController(true);
            };
            remove_imageBn.TouchUpInside += (s, e) =>
            {
                EditCompanyDataViewControllerNew.logo_id = null;
                cropped_result = null;
                currentImage   = null;
                this.NavigationController.PushViewController(vc, true);
                var vc_list = this.NavigationController.ViewControllers.ToList();
                vc_list.RemoveAt(vc_list.Count - 2);
                vc_list.RemoveAt(vc_list.Count - 2);
                if (came_from_gallery_or_camera == Constants.camera)
                {
                    vc_list.RemoveAt(vc_list.Count - 2);
                }
                this.NavigationController.ViewControllers = vc_list.ToArray();
            };
            readyBn.Font        = UIFont.FromName(Constants.fira_sans, 17f);
            cancelBn.Font       = UIFont.FromName(Constants.fira_sans, 17f);
            remove_imageBn.Font = UIFont.FromName(Constants.fira_sans, 17f);
        }
Example #43
0
        public override void ViewDidLayoutSubviews( )
        {
            base.ViewDidLayoutSubviews( );

            nfloat headerHeight = 0;

            ScrollView.Bounds = View.Bounds;

            // see if there's a safe area due to this being a "notch" device
            nfloat safeAreaTopInset = 0;
            nfloat safeAreaBotInset = 0;

            // Make sure they're on iOS 11 before checking for insets. This is only needed for iPhone X anyways, which shipped with iOS 11.
            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                safeAreaTopInset = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Top;
                safeAreaBotInset = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Bottom;
            }

            // if there's no top safe area, there WILL be a header, so adjust for it.
            if (safeAreaTopInset == 0)
            {
                HeaderView.Frame = new CGRect(View.Frame.Left, 0, View.Frame.Width, StyledTextField.StyledFieldHeight);

                // setup the header shadow
                UIBezierPath shadowPath = UIBezierPath.FromRect(HeaderView.Bounds);
                HeaderView.Layer.MasksToBounds = false;
                HeaderView.Layer.ShadowColor   = UIColor.Black.CGColor;
                HeaderView.Layer.ShadowOffset  = new CoreGraphics.CGSize(0.0f, .0f);
                HeaderView.Layer.ShadowOpacity = .23f;
                HeaderView.Layer.ShadowPath    = shadowPath.CGPath;

                // the logo may not exist if we're on a display with a notch
                if (LogoView != null)
                {
                    LogoView.Layer.Position = new CoreGraphics.CGPoint((HeaderView.Bounds.Width - LogoView.Bounds.Width) / 2, 0);
                }

                headerHeight = HeaderView.Bounds.Height;

                // only move down the scrollview if there's a header
                ScrollView.Frame = new CGRect(View.Frame.Left, HeaderView.Frame.Bottom, View.Frame.Right, View.Frame.Bottom - headerHeight);
            }
            else
            {
                // otherwise, there's a safe area, so no header. We should therefore adjust the scrollview to be at the top of the window.
                ScrollView.Frame = new CGRect(View.Frame.Left, View.Frame.Top + safeAreaTopInset, View.Frame.Right, View.Frame.Bottom - (safeAreaBotInset + safeAreaTopInset));
            }


            UserNameField.SetFrame(new CGRect(-10, View.Frame.Height * .10f, View.Frame.Width + 20, StyledTextField.StyledFieldHeight));
            PasswordField.SetFrame(new CGRect(UserNameField.Background.Frame.Left, UserNameField.Background.Frame.Bottom, View.Frame.Width + 20, StyledTextField.StyledFieldHeight));

            // use the facebook image's button width, as it looks good.
            nfloat buttonWidth = FBImageView.Bounds.Width;

            LoginButton.Frame = new CGRect((ScrollView.Bounds.Width - buttonWidth) / 2, PasswordField.Background.Frame.Bottom + 20, buttonWidth, ControlStyling.ButtonHeight);
            LoginResult.SetFrame(new CGRect(UserNameField.Background.Frame.Left, LoginButton.Frame.Bottom + 20, View.Frame.Width + 20, StyledTextField.StyledFieldHeight));

            AdditionalOptions.Frame = new CGRect((View.Bounds.Width - AdditionalOptions.Bounds.Width) / 2, LoginResult.Background.Frame.Bottom + 10, AdditionalOptions.Bounds.Width, ControlStyling.ButtonHeight);

            // setup the "Forgot account, Register or Facebook"
            ForgotPasswordButton.Frame = new CGRect((View.Bounds.Width - buttonWidth) / 2, AdditionalOptions.Frame.Bottom + 5, buttonWidth, ControlStyling.ButtonHeight);
            RegisterButton.Frame       = new CGRect((View.Bounds.Width - buttonWidth) / 2, ForgotPasswordButton.Frame.Bottom + 15, buttonWidth, ControlStyling.ButtonHeight);
            OrSpacerLabel.Frame        = new CGRect((View.Bounds.Width - OrSpacerLabel.Bounds.Width) / 2, RegisterButton.Frame.Bottom + 5, OrSpacerLabel.Bounds.Width, FBImageView.Bounds.Height);
            FacebookLogin.Frame        = new CGRect((View.Bounds.Width - FBImageView.Bounds.Width) / 2, OrSpacerLabel.Frame.Bottom + 5, FBImageView.Bounds.Width, FBImageView.Bounds.Height);
            //

            CancelButton.Frame = new CGRect((View.Frame.Width - CancelButton.Frame.Width) / 2, FacebookLogin.Frame.Bottom + 20, CancelButton.Frame.Width, CancelButton.Frame.Height);

            FBImageView.Layer.Position = new CoreGraphics.CGPoint(FacebookLogin.Bounds.Width / 2, FacebookLogin.Bounds.Height / 2);

            if (WebLayout != null)
            {
                WebLayout.LayoutChanged(new CGRect(0, 0, ScrollView.Frame.Width, ScrollView.Frame.Height));
            }

            BlockerView.SetBounds(View.Frame.ToRectF( ));

            ScrollView.ContentSize = new CGSize(View.Bounds.Width, Math.Max(ScrollView.Bounds.Height * 1.02f, CancelButton.Frame.Bottom + 20 + headerHeight));
        }
Example #44
0
		public void UpdateIndicator(PagerTabStripViewController viewController, nint fromIndex, nint toIndex, nfloat progressPercentage, bool indexWasChanged)
		{
			if (!ShouldUpdateButtonBarView) return;
			ButtonBarView.Move(fromIndex, toIndex, progressPercentage, PagerScroll.Yes);
			if (ChangeCurrentIndexProgressive != null)
			{
				var oldCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(CurrentIndex != fromIndex ? fromIndex : toIndex, 0)) as ButtonBarViewCell;
				var newCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(CurrentIndex, 0)) as ButtonBarViewCell;
				ChangeCurrentIndexProgressive(oldCell, newCell, progressPercentage, indexWasChanged, true);
			}
		}
Example #45
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            BlockerView = new UIBlockerView(View, View.Frame.ToRectF( ));

            View.BackgroundColor = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.BackgroundColor);

            ScrollView                   = new UIScrollViewWrapper();
            ScrollView.Parent            = this;
            ScrollView.Layer.AnchorPoint = CGPoint.Empty;
            ScrollView.Bounds            = View.Bounds;
            //ScrollView.BackgroundColor = Rock.Mobile.UI.Util.GetUIColor( 0x0000FFFF );
            View.AddSubview(ScrollView);

            UserNameField = new StyledTextField();
            ScrollView.AddSubview(UserNameField.Background);

            UserNameField.Field.AutocapitalizationType = UITextAutocapitalizationType.None;
            UserNameField.Field.AutocorrectionType     = UITextAutocorrectionType.No;
            ControlStyling.StyleTextField(UserNameField.Field, LoginStrings.UsernamePlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(UserNameField.Background);
            UserNameField.Field.ShouldReturn += (textField) =>
            {
                textField.ResignFirstResponder();

                TryRockBind();
                return(true);
            };

            PasswordField = new StyledTextField();
            ScrollView.AddSubview(PasswordField.Background);
            PasswordField.Field.AutocorrectionType = UITextAutocorrectionType.No;
            PasswordField.Field.SecureTextEntry    = true;

            ControlStyling.StyleTextField(PasswordField.Field, LoginStrings.PasswordPlaceholder, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ControlStyling.StyleBGLayer(PasswordField.Background);
            PasswordField.Field.ShouldReturn += (textField) =>
            {
                textField.ResignFirstResponder();

                TryRockBind();
                return(true);
            };

            // obviously attempt a login if login is pressed
            LoginButton = UIButton.FromType(UIButtonType.System);
            ScrollView.AddSubview(LoginButton);
            ControlStyling.StyleButton(LoginButton, LoginStrings.LoginButton, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            LoginButton.SizeToFit( );
            LoginButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                if (RockMobileUser.Instance.LoggedIn == true)
                {
                    RockMobileUser.Instance.LogoutAndUnbind( );

                    SetUIState(LoginState.Out);
                }
                else
                {
                    TryRockBind();
                }
            };

            // if they forgot their password, kick them out to the forgot password page
            ForgotPasswordButton = UIButton.FromType(UIButtonType.System);
            ScrollView.AddSubview(ForgotPasswordButton);
            ControlStyling.StyleButton(ForgotPasswordButton, LoginStrings.ForgotPasswordButton, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            ForgotPasswordButton.SizeToFit( );
            ForgotPasswordButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                TaskWebViewController.HandleUrl(true, true, LoginConfig.ForgotPassword_Url, null, null, false, false, false);
            };

            AdditionalOptions = new UILabel( );
            ScrollView.AddSubview(AdditionalOptions);
            ControlStyling.StyleUILabel(AdditionalOptions, ControlStylingConfig.Font_Regular, ControlStylingConfig.Small_FontSize);
            AdditionalOptions.Text      = LoginStrings.AdditionalOptions;
            AdditionalOptions.TextColor = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.TextField_PlaceholderTextColor);
            AdditionalOptions.SizeToFit( );

            OrSpacerLabel = new UILabel( );
            ScrollView.AddSubview(OrSpacerLabel);
            ControlStyling.StyleUILabel(OrSpacerLabel, ControlStylingConfig.Font_Regular, ControlStylingConfig.Small_FontSize);
            OrSpacerLabel.TextColor = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.TextField_PlaceholderTextColor);
            OrSpacerLabel.Text      = LoginStrings.OrString;
            OrSpacerLabel.SizeToFit( );

            RegisterButton = UIButton.FromType(UIButtonType.System);
            ScrollView.AddSubview(RegisterButton);
            ControlStyling.StyleButton(RegisterButton, LoginStrings.RegisterButton, ControlStylingConfig.Font_Regular, ControlStylingConfig.Medium_FontSize);
            //RegisterButton.BackgroundColor = UIColor.Clear;
            RegisterButton.SizeToFit( );
            RegisterButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                Springboard.RegisterNewUser( );
            };

            // setup the result
            LoginResult = new StyledTextField( );
            ScrollView.AddSubview(LoginResult.Background);

            ControlStyling.StyleTextField(LoginResult.Field, "", ControlStylingConfig.Font_Regular, ControlStylingConfig.Small_FontSize);
            ControlStyling.StyleBGLayer(LoginResult.Background);
            LoginResult.Field.UserInteractionEnabled = false;
            LoginResult.Field.TextAlignment          = UITextAlignment.Center;

            // setup the facebook button
            FacebookLogin = new UIButton( );
            ScrollView.AddSubview(FacebookLogin);
            string imagePath = NSBundle.MainBundle.BundlePath + "/" + "facebook_login.png";

            FBImageView = new UIImageView(new UIImage(imagePath));

            FacebookLogin.SetTitle("", UIControlState.Normal);
            FacebookLogin.AddSubview(FBImageView);
            FacebookLogin.Layer.CornerRadius = 4;
            FBImageView.Layer.CornerRadius   = 4;

            FacebookLogin.TouchUpInside += (object sender, EventArgs e) =>
            {
                TryFacebookBind();
            };

            // If cancel is pressed, notify the springboard we're done.
            CancelButton = UIButton.FromType(UIButtonType.System);
            ScrollView.AddSubview(CancelButton);
            CancelButton.SetTitleColor(Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.Label_TextColor), UIControlState.Normal);
            CancelButton.SetTitle(GeneralStrings.Cancel, UIControlState.Normal);
            CancelButton.SizeToFit( );
            CancelButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                // don't allow canceling while we wait for a web request.
                if (LoginState.Trying != State)
                {
                    Springboard.ResignModelViewController(this, null);
                }
            };


            // set the title image for the bar if there's no safe area defined. (A safe area is like, say, the notch for iPhone X)
            nfloat safeAreaTopInset = 0;

            // Make sure they're on iOS 11 before checking for insets. This is only needed for iPhone X anyways, which shipped with iOS 11.
            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                safeAreaTopInset = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Top;
            }

            // setup the fake header if they're not on a device with save zones (iphone x)
            if (safeAreaTopInset == 0)
            {
                HeaderView = new UIView( );
                View.AddSubview(HeaderView);
                HeaderView.BackgroundColor = Rock.Mobile.UI.Util.GetUIColor(ControlStylingConfig.BackgroundColor);

                imagePath = NSBundle.MainBundle.BundlePath + "/" + PrivatePrimaryNavBarConfig.LogoFile_iOS;
                LogoView  = new UIImageView(new UIImage(imagePath));
                LogoView.SizeToFit( );
                LogoView.Layer.AnchorPoint = CGPoint.Empty;

                HeaderView.AddSubview(LogoView);
                HeaderView.SizeToFit( );
            }
        }
Example #46
0
        public override void DrawRect(CGRect dirtyRect)
        {
            if (Gradient != null)
            {
                Gradient.DrawInRect(dirtyRect, GradientAngle);
            }

            // -----------------------------------------
            nfloat textOffset   = 0f;
            nfloat imageXOffset = 0f;
            nfloat imageWidth   = 0f;

            if (Image != null)
            {
                if (Image.Size.Height > dirtyRect.Height)
                {
                    Image.Size = new CGSize(Image.Size.Height, dirtyRect.Height);
                }
                if (Image.Size.Width > dirtyRect.Width)
                {
                    Image.Size = new CGSize(dirtyRect.Width, Image.Size.Width);
                }

                imageWidth = Image.Size.Width;

                nfloat minXOffset = (dirtyRect.Height - Image.Size.Height) / 2f;

                imageXOffset = CornerRadius;
                if (imageXOffset < minXOffset)
                {
                    imageXOffset = minXOffset;
                }

                if (AttributedTitle == null)
                {
                    imageXOffset = dirtyRect.Width / 2f - Image.Size.Width / 2f;
                }
                else if (IconLocation == IconLocationEnum.Right_BeforeCenteredText)
                {
                    imageXOffset = dirtyRect.Width / 2f - AttributedTitle.Size.Width / 2f - Image.Size.Width - minXOffset / 2f;
                }
                else if (IconLocation == IconLocationEnum.Left_AfterCenteredText)
                {
                    imageXOffset = dirtyRect.Width / 2f + AttributedTitle.Size.Width / 2f + minXOffset / 2f;
                }
                else if (IconLocation == IconLocationEnum.Right_AfterCenteredText)
                {
                    imageXOffset = dirtyRect.Width - minXOffset / 2f - Image.Size.Width;
                }
                else if (IconLocation == IconLocationEnum.Right)
                {
                    nfloat space = (dirtyRect.Width - AttributedTitle.Size.Width - Image.Size.Width) / 3;
                    textOffset   = space;
                    imageXOffset = space + AttributedTitle.Size.Width + space;
                }
                else if (IconLocation == IconLocationEnum.Left)
                {
                    nfloat space = (dirtyRect.Width - AttributedTitle.Size.Width - Image.Size.Width) / 3;
                    imageXOffset = space;
                    textOffset   = space + Image.Size.Width + space;
                }

                CGRect imgRect = new CGRect(dirtyRect.X + imageXOffset,
                                            dirtyRect.Y + dirtyRect.Height / 2f - Image.Size.Height / 2f,
                                            Image.Size.Width,
                                            Image.Size.Height);
                Image.Draw(imgRect);
            }

            if (AttributedTitle != null)
            {
                if (IconLocation == IconLocationEnum.Right_BeforeCenteredText || IconLocation == IconLocationEnum.Left_BeforeCenteredText)
                {
                    if ((imageXOffset + imageWidth) > (dirtyRect.Width - AttributedTitle.Size.Width) / 2f)
                    {
                        textOffset = imageXOffset + imageWidth;
                    }
                }

                CGRect titleRect = new CGRect(dirtyRect.X + textOffset,
                                              dirtyRect.Y + dirtyRect.Height / 2f - AttributedTitle.Size.Height / 2f - 1f,
                                              dirtyRect.Width - textOffset,
                                              AttributedTitle.Size.Height);

                this.AttributedTitle.DrawInRect(titleRect);
            }

            if (Highlighted)
            {
                NSColor fillColor = HighlitedColorOverlay;
                if (fillColor == null)
                {
                    fillColor = NSColor.FromRgba(0, 0, 0, 0.1f);
                }
                fillColor.Set();

                NSBezierPath highlitedFill = new NSBezierPath();
                highlitedFill.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
                highlitedFill.Fill();
            }

            if (!this.Enabled && DoNotChangeColorWhenDisabled != true)
            {
                NSColor fillColor = HighlitedColorOverlay;
                if (fillColor == null)
                {
                    fillColor = NSColor.FromRgba(0, 0, 0, 0.1f);
                }
                fillColor.Set();

                NSBezierPath highlitedFill = new NSBezierPath();
                highlitedFill.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
                highlitedFill.Fill();
            }
            // -----------------------------------------
            //base.DrawRect (dirtyRect);

            if (!Highlighted && BorderShadow != null)
            {
                BorderShadow.Set();
            }


            NSBezierPath bounds = new NSBezierPath();

            bounds.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
            bounds.AddClip();

            bounds.LineWidth = BorderLineWidth;

            if (BorderColor != null)
            {
                BorderColor.SetStroke();
            }

            bounds.Stroke();
        }
Example #47
0
 public double GetTypographicBounds(NSRange range, out nfloat ascent, out nfloat descent, out nfloat leading)
 {
     return(CTRunGetTypographicBounds(handle, range, out ascent, out descent, out leading));
 }
Example #48
0
 public override void ZoomingEnded(UIScrollView scrollView, UIView withView, nfloat atScale)
 {
     if (SourceDelegate != null)
     {
         SourceDelegate.ZoomingEnded(scrollView, withView, atScale);
     }
 }
Example #49
0
 extern static double CTRunGetTypographicBounds(IntPtr h, NSRange range, out nfloat ascent, out nfloat descent, out nfloat leading);
Example #50
0
 public unsafe void AddRoundedRect(CGAffineTransform transform, CGRect rect, nfloat cornerWidth, nfloat cornerHeight)
 {
     CGPathAddRoundedRect(handle, &transform, rect, cornerWidth, cornerHeight);
 }
Example #51
0
        internal static UIFont BestFont(string family, nfloat size, bool bold = false, bool italic = false, Assembly assembly = null)
        {
            if (family == null)
            {
                family = ".AppleSystemUIFont";
            }
            if (family.ToLower() == "monospace")
            {
                family = "Menlo";
            }
            if (family.ToLower() == "serif")
            {
                family = "Times New Roman";
            }
            if (family.ToLower() == "sans-serif")
            {
                family = ".AppleSystemUIFont";
            }

            if (size < 0)
            {
                size = (nfloat)(UIFont.LabelFontSize * Math.Abs(size));
            }


            // is it in the cache?
            var key = new FontKey(family, size, bold, italic);
            Dictionary <FontKey, UIFont> dictionary = UiFontCache;

            lock (dictionary)
            {
                if (dictionary.TryGetValue(key, out UIFont storedUiFont))
                {
                    return(storedUiFont);
                }
            }

            UIFont bestAttemptFont = null;

            if (UIFont.FamilyNames.Contains(family))
            {
                // a system font
                var    fontNames    = FontFamilies.FontsForFamily(family);
                string baseFontName = null;
                string reqFontName  = null;
                //string fallbackFontName = null;


                if (fontNames != null && fontNames.Count > 0)
                {
                    if (fontNames.Count == 1)
                    {
                        baseFontName = fontNames[0];
                        if (!bold && !italic)
                        {
                            reqFontName = fontNames[0];
                        }
                    }
                    else
                    {
                        int shortestMatchLength = int.MaxValue;
                        int shortestBaseLength  = int.MaxValue;
                        foreach (var fontName in fontNames)
                        {
                            var  lowerName     = fontName.ToLower();
                            bool nameHasBold   = lowerName.Contains("bold") || lowerName == "avenir-black";
                            bool nameHasItalic = lowerName.Contains("italic") || lowerName.Contains("oblique");
                            // assume the shortest name is the base font name
                            if (lowerName.Length < shortestBaseLength)
                            {
                                baseFontName       = fontName;
                                shortestBaseLength = lowerName.Length;
                            }

                            // assume the shortest name with matching attributes is a match
                            if (nameHasBold == bold && nameHasItalic == italic && lowerName.Length < shortestMatchLength)
                            {
                                reqFontName         = fontName;
                                shortestMatchLength = lowerName.Length;
                            }

                            if (lowerName.Contains("-regular"))
                            {
                                baseFontName       = fontName;
                                shortestBaseLength = -1;
                                if (!bold && !italic)
                                {
                                    reqFontName         = fontName;
                                    shortestMatchLength = -1;
                                    break;
                                }
                            }
                        }
                    }
                }

                if (reqFontName != null)
                {
                    bestAttemptFont = UIFont.FromName(reqFontName, size);
                }
                if (bestAttemptFont == null && baseFontName != null && !bold && !italic)
                {
                    bestAttemptFont = UIFont.FromName(baseFontName, size);
                }
            }
            else
            {
                //  an embedded font or a explicitly named system font?
                bestAttemptFont = EmbeddedFont(family, size, assembly);

                if (bestAttemptFont == null && !family.StartsWith(".SFUI"))
                {
                    bestAttemptFont = UIFont.FromName(family, size);
                }
            }

            if (bestAttemptFont != null)
            {
                if (bold || italic)
                {
                    if (bestAttemptFont.FontDescriptor.CreateWithTraits(
                            (bold ? UIFontDescriptorSymbolicTraits.Bold : UIFontDescriptorSymbolicTraits.ClassUnknown)
                            |
                            (italic ? UIFontDescriptorSymbolicTraits.Italic : UIFontDescriptorSymbolicTraits.ClassUnknown)
                            ) is UIFontDescriptor descriptor)
                    {
                        bestAttemptFont = UIFont.FromDescriptor(descriptor, size);
                    }
                }

                // we have a match but is wasn't cached - so let's cache it for future reference
                lock (dictionary)
                {
                    if (!dictionary.TryGetValue(key, out UIFont storedUiFont))
                    {
                        // It could have been added by another thread so only add if we're really sure it's no there!
                        dictionary.Add(key, bestAttemptFont);
                    }
                }
                return(bestAttemptFont);
            }

            UIFontWeight fontWeight = UIFontWeight.Regular;

            if (family.StartsWith(".SFUI"))
            {
                var parts = family.Split("-");
                if (parts.Length > 1)
                {
                    var weightText = parts[1];
                    switch (weightText)
                    {
                    case nameof(UIFontWeight.Black):
                        fontWeight = UIFontWeight.Black;
                        break;

                    case nameof(UIFontWeight.Bold):
                        fontWeight = UIFontWeight.Bold;
                        break;

                    case nameof(UIFontWeight.Heavy):
                        fontWeight = UIFontWeight.Heavy;
                        break;

                    case nameof(UIFontWeight.Light):
                        fontWeight = UIFontWeight.Light;
                        break;

                    case nameof(UIFontWeight.Medium):
                        fontWeight = UIFontWeight.Medium;
                        break;

                    case nameof(UIFontWeight.Regular):
                        fontWeight = UIFontWeight.Medium;
                        break;

                    case nameof(UIFontWeight.Semibold):
                        fontWeight = UIFontWeight.Semibold;
                        break;

                    case nameof(UIFontWeight.Thin):
                        fontWeight = UIFontWeight.Thin;
                        break;

                    case nameof(UIFontWeight.UltraLight):
                        fontWeight = UIFontWeight.UltraLight;
                        break;

                    default:
                        fontWeight = UIFontWeight.Regular;
                        break;
                    }
                }
                // fall back to a system font
            }
            // fall back to a system font
            if (bold && italic || (fontWeight != UIFontWeight.Regular && (bold || italic)))
            {
                UIFont systemFont = UIFont.SystemFontOfSize(size, fontWeight);
                UIFontDescriptorSymbolicTraits traits = (bold ? UIFontDescriptorSymbolicTraits.Bold : (UIFontDescriptorSymbolicTraits)0) | (italic ? UIFontDescriptorSymbolicTraits.Italic : (UIFontDescriptorSymbolicTraits)0);
                var descriptor = systemFont.FontDescriptor.CreateWithTraits(traits);
                bestAttemptFont = UIFont.FromDescriptor(descriptor, size);
            }
            if (bestAttemptFont == null && italic)
            {
                bestAttemptFont = UIFont.ItalicSystemFontOfSize(size);
            }
            if (bestAttemptFont == null && bold)
            {
                bestAttemptFont = UIFont.BoldSystemFontOfSize(size);
            }
            if (bestAttemptFont == null)
            {
                bestAttemptFont = UIFont.SystemFontOfSize(size, fontWeight);
            }
            return(bestAttemptFont);
        }
		static extern IntPtr CTFontDescriptorCreateWithNameAndSize (IntPtr name, nfloat size);
Example #53
0
 public unsafe void AddRoundedRect(CGRect rect, nfloat cornerWidth, nfloat cornerHeight)
 {
     CGPathAddRoundedRect(handle, null, rect, cornerWidth, cornerHeight);
 }
Example #54
0
        public void SetBorderMiterLimit(float strokeMiterLimit)
        {
            _strokeMiterLimit = strokeMiterLimit;

            SetNeedsDisplay();
        }
Example #55
0
 unsafe extern static void CGPathAddRoundedRect(/* CGMutablePathRef */ IntPtr path, CGAffineTransform *transform, CGRect rect, /* CGFloat */ nfloat cornerWidth, /* CGFloat */ nfloat cornerHeight);
Example #56
0
 public static nfloat CountFrameHeight(nfloat height)
 {
     return(height - (height / 100f) * 10f);
 }
Example #57
0
 private nfloat CountOsyStep(nfloat yStep)
 {
     return((yStep - ((yStep / 100f) * 20f)) / 100f);
 }
Example #58
0
 public override void ConstrainTo(nfloat constant)
 {
     ConstrainedDimension = constant;
 }
		public CTFontDescriptor WithVariation (uint variationIdentifier, nfloat variationValue)
		{
			using (var id = new NSNumber (variationIdentifier))
				return CreateDescriptor (CTFontDescriptorCreateCopyWithVariation  (handle, 
							id.Handle, variationValue));
		}
Example #60
0
            public override void LayoutSubviews()
            {
                base.LayoutSubviews();

                var contentFrame = ContentView.Frame;

                const float durationLabelWidth = 80f;

                durationLabel.Frame = new CGRect(
                    x: contentFrame.Width - durationLabelWidth - HorizPadding,
                    y: 0,
                    width: durationLabelWidth,
                    height: contentFrame.Height
                    );

                const float billableTagsHeight = 20f;
                const float billableTagsWidth  = 20f;

                billableTagsImageView.Frame = new CGRect(
                    y: (contentFrame.Height - billableTagsHeight) / 2,
                    height: billableTagsHeight,
                    x: durationLabel.Frame.X - billableTagsWidth,
                    width: billableTagsWidth
                    );

                var runningHeight = runningImageView.Image.Size.Height;
                var runningWidth  = runningImageView.Image.Size.Width;

                runningImageView.Frame = new CGRect(
                    y: (contentFrame.Height - runningHeight) / 2,
                    height: runningHeight,
                    x: contentFrame.Width - (HorizPadding + runningWidth) / 2,
                    width: runningWidth
                    );

                textContentView.Frame = new CGRect(
                    x: 0, y: 0,
                    width: billableTagsImageView.Frame.X - 2f,
                    height: contentFrame.Height
                    );
                textContentView.Layer.Mask.Bounds = textContentView.Frame;

                var bounds = GetBoundingRect(projectLabel);

                projectLabel.Frame = new CGRect(
                    x: HorizPadding,
                    y: contentFrame.Height / 2 - bounds.Height,
                    width: bounds.Width,
                    height: bounds.Height
                    );

                const float clientLeftMargin = 7.5f;

                bounds            = GetBoundingRect(clientLabel);
                clientLabel.Frame = new CGRect(
                    x: projectLabel.Frame.X + projectLabel.Frame.Width + clientLeftMargin,
                    y: (float)Math.Floor(projectLabel.Frame.Y + projectLabel.Font.Ascender - clientLabel.Font.Ascender),
                    width: bounds.Width,
                    height: bounds.Height
                    );

                const float secondLineTopMargin = 3f;
                nfloat      offsetX             = HorizPadding + 1f;

                if (!taskLabel.Hidden)
                {
                    bounds          = GetBoundingRect(taskLabel);
                    taskLabel.Frame = new CGRect(
                        x: offsetX,
                        y: contentFrame.Height / 2 + secondLineTopMargin,
                        width: bounds.Width,
                        height: bounds.Height
                        );
                    offsetX += taskLabel.Frame.Width + 4f;

                    if (!taskSeparatorImageView.Hidden)
                    {
                        const float separatorOffsetY = -2f;
                        var         imageSize        = taskSeparatorImageView.Image != null ? taskSeparatorImageView.Image.Size : CGSize.Empty;
                        taskSeparatorImageView.Frame = new CGRect(
                            x: offsetX,
                            y: taskLabel.Frame.Y + taskLabel.Font.Ascender - imageSize.Height + separatorOffsetY,
                            width: imageSize.Width,
                            height: imageSize.Height
                            );

                        offsetX += taskSeparatorImageView.Frame.Width + 4f;
                    }

                    if (!descriptionLabel.Hidden)
                    {
                        bounds = GetBoundingRect(descriptionLabel);
                        descriptionLabel.Frame = new CGRect(
                            x: offsetX,
                            y: (float)Math.Floor(taskLabel.Frame.Y + taskLabel.Font.Ascender - descriptionLabel.Font.Ascender),
                            width: bounds.Width,
                            height: bounds.Height
                            );

                        offsetX += descriptionLabel.Frame.Width + 4f;
                    }
                }
                else if (!descriptionLabel.Hidden)
                {
                    bounds = GetBoundingRect(descriptionLabel);
                    descriptionLabel.Frame = new CGRect(
                        x: offsetX,
                        y: contentFrame.Height / 2 + secondLineTopMargin,
                        width: bounds.Width,
                        height: bounds.Height
                        );
                }
            }