コード例 #1
0
        public void PerformNCCalc(CGSize newSize)
        {
            //FIXME! Should not reference Win32 variant here or NEED to do so.
            var ncp = new XplatUIWin32.NCCALCSIZE_PARAMS();

            ncp.rgrc1 = new XplatUIWin32.RECT(0, 0, (int)newSize.Width, (int)newSize.Height);

            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ncp));

            Marshal.StructureToPtr(ncp, ptr, true);
            NativeWindow.WndProc(Handle, Msg.WM_NCCALCSIZE, (IntPtr)1, ptr);
            ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(ptr, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
            Marshal.FreeHGlobal(ptr);

            var savedBounds = ClientBounds;

            ClientBounds = CGRect.FromLTRB(ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right, ncp.rgrc1.bottom);

            // Update subview locations
            var offset = new CGPoint(ClientBounds.X - savedBounds.X, ClientBounds.Y - savedBounds.Y);

            if (offset.X != 0 || offset.Y != 0)
            {
                foreach (var subView in Subviews)
                {
                    subView.SetFrameOrigin(subView.Frame.Location.Move(offset.X, offset.Y));
                }
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.Title = LangUtil.Get("SettingsViewController.Coordinates.Format.Title");

            View.BackgroundColor = ColorHelper.FromType(ColorType.SystemGroupedBackground);

            table.BackgroundColor = UIColor.Clear;

            table.RowHeight          = UITableView.AutomaticDimension;
            table.EstimatedRowHeight = 70;
            var footer = new UIView(CGRect.FromLTRB(0, 0, View.Frame.Width, 1));

            footer.BackgroundColor = ColorHelper.FromType(ColorType.Separator);
            table.TableFooterView  = footer;

            labHeader.TextColor = ColorHelper.FromType(ColorType.Label);
            labHeader.Font      = FontConst.fontMediumRegular;
            labHeader.Text      = LangUtil.Get("SettingsViewController.Coordinates.Format.Header");

            settingsCoordinateFormatTableViewSource = new SettingsCoordinateFormatTableViewSource(this);
            table.Source = settingsCoordinateFormatTableViewSource;

            SetupData();
        }
コード例 #3
0
        bool IsGrayScale(UIImage sourceBitmap)
        {
            var source           = sourceBitmap.CGImage;
            var width            = source.Width;
            var height           = source.Height;
            var imageData        = new byte[width * height * 4];
            var bytesPerPixel    = 4;
            var bytesPerRow      = bytesPerPixel * width;
            var bitsPerComponent = 8;

            var imageContext = new CGBitmapContext(imageData, width, height, bitsPerComponent, bytesPerRow, source.ColorSpace, CGImageAlphaInfo.PremultipliedLast);

            imageContext.SetBlendMode(CGBlendMode.Copy);
            imageContext.DrawImage(CGRect.FromLTRB(0, 0, width, height), source);
            imageContext.Dispose();

            int  byteIndex        = 0;
            bool imageIsGrayscale = true;

            for (; byteIndex < width * height * 4; byteIndex += 4)
            {
                var red   = imageData[byteIndex] / 255.0f;
                var green = imageData[byteIndex + 1] / 255.0f;
                var blue  = imageData[byteIndex + 2] / 255.0f;
                var alpha = imageData[byteIndex + 3] / 255.0f;

                if (alpha == 1 && (red != green || red != blue || green != blue))
                {
                    imageIsGrayscale = false;
                    break;
                }
            }

            return(imageIsGrayscale);
        }
コード例 #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            var backImage = UIImage.FromBundle("Background");

            this.View.BackgroundColor = UIColor.FromPatternImage(backImage);

            // Put the image onto the screen
            var cow = new CowImageView();

            cow.Frame = CGRect.FromLTRB(50, 50, 50 + cow.Image.Size.Width, 50 + cow.Image.Size.Height);
            cow.UserInteractionEnabled = true;

            this.View.AddSubview(cow);

            // Grab the observable (what we want "pushed" to us)
            var moveObservable = cow.MovementObservable;

            // Apply any operations
            var moveStream = moveObservable
                             .Select(imd => new { X = imd.ParentCoordinate.X, Y = imd.ParentCoordinate.Y })
                             .Where(l => l.X < this.View.Frame.Width / 2)
                             .Where(l => l.Y < this.View.Frame.Height / 2);

            // Subscribe to the stream - nothing happens until we subscribe
            moveStream.Subscribe(l =>
                                 cow.Frame = CGRect.FromLTRB(
                                     l.X, l.Y,
                                     l.X + cow.Image.Size.Width,
                                     l.Y + cow.Image.Size.Height
                                     ));
        }
コード例 #5
0
        public AppLoadingHUD(UIViewController controller)
        {
            UIView view = UIViewControllersUtils.GetPresentedViewController().View;

            view.BackgroundColor = UIColor.Black;

            _hud = new MTMBProgressHUD(view)
            {
                RemoveFromSuperViewOnHide = true,
                BackgroundColor           = UIColor.Black.ColorWithAlpha((float)0.7)
            };

            _hud.Mode          = MBProgressHUDMode.CustomView;
            _hud.DimBackground = false;

            _hud.Square     = true;
            _hud.LabelText  = @"";
            _hud.Color      = UIColor.Clear;
            _hud.LabelColor = UIColor.Clear;


            view.AddSubview(_hud);

            UIImageView imageView = new UIImageView(CGRect.FromLTRB(0, 0, 45, 45));
            var         url       = NSBundle.MainBundle.GetUrlForResource("loading", "gif", "Loading");

            imageView.ContentMode = UIViewContentMode.ScaleAspectFit;
            imageView.SetImage(url);
            _hud.CustomView = imageView;



            _hud.Show(animated: true);
        }
コード例 #6
0
 public static CGRect ToRect(this Xamarin.Forms.Rectangle rectangle)
 {
     return(CGRect.FromLTRB(
                (nfloat)rectangle.Left,
                (nfloat)rectangle.Top,
                (nfloat)rectangle.Right,
                (nfloat)rectangle.Bottom
                ));
 }
コード例 #7
0
 public static CGRect ToRect(this CGPoint tl, CGPoint rb)
 {
     return(CGRect.FromLTRB(
                tl.X,
                tl.Y,
                rb.X,
                rb.Y
                ));
 }
コード例 #8
0
 public static CGRect ToRect(this CGPoint pos, nfloat radius)
 {
     return(CGRect.FromLTRB(
                pos.X - radius,
                pos.Y - radius,
                pos.X + radius,
                pos.Y + radius
                ));
 }
コード例 #9
0
        public override void DrawLayer(CALayer layer, CGContext context)
        {
            var   radius = (float)FormsButton.WidthRequest / 2;
            var   offset = BorderThickness / 2;
            float angle  = (FormsButton.Completion + .75f) * 2 * (float)Math.PI;

            context.AddEllipseInRect(CGRect.FromLTRB(offset, offset, (float)FormsButton.WidthRequest - offset, (float)FormsButton.HeightRequest - offset));
            context.SetStrokeColor(UIColor.White.CGColor);
            context.SetLineWidth(BorderThickness);
            context.StrokePath();

            context.SetStrokeColor(UIColor.Red.CGColor);
            context.AddArc(radius, radius, radius - offset, 1.5f * (float)Math.PI, angle, false);
            context.StrokePath();
        }
コード例 #10
0
        void ReloadData()
        {
            if (EmptyViewShown)
            {
                RemovePages(1);
                EmptyViewShown = false;
            }

            var count = ViewModel.Dates.Value.Count;
            var diff  = count - ChildViewControllers.Length;

            if (diff > 0)
            {
                AddPages(diff, "VplanDayViewController");
            }
            if (diff < 0)
            {
                if (PageControl.CurrentPage > ViewModel.Dates.Value.Count)
                {
                    ScrollView.ScrollRectToVisible(CGRect.FromLTRB(0, 0, 0, 0), true);
                }
                RemovePages(Math.Abs(diff));
            }

            PageControl.Pages = count > 1 ? count : 0;

            if (count > 0)
            {
                for (var i = 0; i < count; i++)
                {
                    var viewController = ChildViewControllers[i] as VplanDayViewController;
                    viewController.ViewModel = ViewModel.Dates.Value[i];
                }
            }
            else
            {
                EmptyViewShown = true;
                AddPages(1, "EmptyVplanViewController");
                var viewController = ChildViewControllers[0] as EmptyVplanViewController;
                viewController.ViewModel = ViewModel;
            }
        }
コード例 #11
0
ファイル: ScanView.cs プロジェクト: msioen/MenuBarCodeReader
        CGRect BuildRect(CGPoint startPoint, CGPoint endPoint)
        {
            var x1 = startPoint.X;
            var x2 = endPoint.X;

            if (x2 < x1)
            {
                x1 = x2;
                x2 = startPoint.X;
            }

            var y1 = startPoint.Y;
            var y2 = endPoint.Y;

            if (y2 < y1)
            {
                y1 = y2;
                y2 = startPoint.Y;
            }

            return(CGRect.FromLTRB(x1, y1, x2, y2));
        }
コード例 #12
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            const int across = 4;
            const int down   = 5;

            var sizeX = (Bounds.Width - (buttonMargin + (across - 1) * buttonPadding + buttonMargin)) / across;
            var sizeY = (Bounds.Height - (buttonMargin + (down + 1 - 1) * buttonPadding + buttonMargin)) / (down + 1);

            for (int y = 0; y < down; y++)
            {
                for (int x = 0; x < across; x++)
                {
                    var pos = new CGPoint(buttonMargin + x * (sizeX + buttonPadding), buttonMargin + (y + 1) * (sizeY + buttonPadding));
                    buttons[(across * y) + x].Frame = new CGRect(pos, new CGSize(sizeX, sizeY));
                }
            }

            displayContainer.Frame = new CGRect(buttonMargin, buttonMargin, Bounds.Width - buttonMargin - buttonMargin, sizeY);
            display.Frame          = CGRect.FromLTRB(buttonPadding, buttonPadding, displayContainer.Bounds.Width - buttonPadding, displayContainer.Bounds.Height - buttonPadding);
        }
コード例 #13
0
        //Crops an image to even width and height
        private static UIImage CenterCrop(UIImage originalImage)
        {
            // Use smallest side length as crop square length
            double squareLength = Math.Min(originalImage.Size.Width, originalImage.Size.Height);

            nfloat x, y;

            x = ( nfloat )((originalImage.Size.Width - squareLength) / 2.0);
            y = ( nfloat )((originalImage.Size.Height - squareLength) / 2.0);

            //This Rect defines the coordinates to be used for the crop
            CGRect croppedRect = CGRect.FromLTRB(x, y, x + ( nfloat )squareLength, y + ( nfloat )squareLength);

            // Center-Crop the image
            UIGraphics.BeginImageContextWithOptions(croppedRect.Size, false, originalImage.CurrentScale);
            originalImage.Draw(new CGPoint(-croppedRect.X, -croppedRect.Y));
            UIImage croppedImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(croppedImage);
        }
コード例 #14
0
        void DrawFaceRects(UIImage oldImage, Face[] faces)
        {
            if (faces == null || faces.Length == 0)
            {
                return;
            }

            UIGraphics.BeginImageContext(oldImage.Size);

            oldImage.Draw(new CGPoint(0, 0));

            var ctx = UIGraphics.GetCurrentContext();

            ctx.SetLineWidth(10);

            foreach (var face in faces)
            {
                var rectColor = UIColor.Red.CGColor;
                ctx.SetStrokeColor(rectColor);

                var right  = (nfloat)(face.FaceRectangle.Left + face.FaceRectangle.Width);
                var bottom = (nfloat)(face.FaceRectangle.Top + face.FaceRectangle.Height);

                var left = (nfloat)face.FaceRectangle.Left;
                var top  = (nfloat)face.FaceRectangle.Top;

                var factRect = CGRect.FromLTRB(left, top, right, bottom);

                ctx.StrokeRect(factRect);
            }

            var newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            thePhoto.Image = newImage;
        }
コード例 #15
0
        void DrawEmotionsOnImage(UIImage theImage, List <Emotion> allEmotions)
        {
            if (allEmotions == null)
            {
                return;
            }

            UIGraphics.BeginImageContext(theImage.Size);

            theImage.Draw(new CGPoint(0, 0));

            var ctx = UIGraphics.GetCurrentContext();

            ctx.SetLineWidth(10);

            foreach (var emotion in allEmotions)
            {
                var emotionColor = GetColorBasedOnEmotion(emotion.GetMainEmotion());
                ctx.SetStrokeColor(emotionColor);

                var right  = (nfloat)(emotion.FaceRectangle.Left + emotion.FaceRectangle.Width);
                var bottom = (nfloat)(emotion.FaceRectangle.Top + emotion.FaceRectangle.Height);

                var left = (nfloat)emotion.FaceRectangle.Left;
                var top  = (nfloat)emotion.FaceRectangle.Top;

                var factRect = CGRect.FromLTRB(left, top, right, bottom);

                ctx.StrokeRect(factRect);
            }

            var newImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            personPhoto.Image = newImage;
        }
コード例 #16
0
        public void SetUp()
        {
            window = new TestWindow(
                CGRect.FromLTRB(0, 0, 400, 400)
                );

            viewA = new TestView();
            window.AddSubview(viewA);

            viewB = new TestView();
            window.AddSubview(viewB);

            viewC = new TestView();
            window.AddSubview(viewC);

            Constrain(viewA, (a) =>
            {
                a.Width.Equal(100);
                a.Height.Equal(200);

                a.Top.Equal(a.Superview.Top + 10);
                a.Left.Equal(a.Superview.Left + 10);
            });
        }
コード例 #17
0
        public override void DrawRect(CGRect dirtyRect)
        {
            if (!drawInit)
            {
                this.Window.Title = "PixelFarm";
                drawInit          = true;
                destImg           = new ActualImage(destImgW, destImgH, PixelFarm.Agg.PixelFormat.ARGB32);
                imgGfx2d          = new ImageGraphics2D(destImg);        //no platform
                p      = new AggCanvasPainter(imgGfx2d);
                stride = destImg.Stride;
                LoadGlyphs();
            }
            //base.Draw(rect);
            base.DrawRect(dirtyRect);


            p.Clear(Color.Yellow);
            p.FillColor = Color.Black;
            p.Fill(vxs);

            var            data     = Foundation.NSData.FromArray(ActualImage.GetBuffer(destImg));
            CGDataProvider provider = new CGDataProvider(data);

            using (var myImg2 = new CGImage(
                       destImgW, destImgH,
                       8, 32,
                       stride, CGColorSpace.CreateGenericRgb(),
                       CGBitmapFlags.PremultipliedLast,
                       provider,
                       null, true,
                       CGColorRenderingIntent.AbsoluteColorimetric))

                using (var nsGraphics = AppKit.NSGraphicsContext.CurrentContext)
                {
                    CGContext g      = nsGraphics.CGContext;
                    CGColor   color0 = new CGColor(1, 1, 1, 1);
                    g.SetFillColor(color0);
                    //g.ClearRect(new CGRect(0, 0, 800, 600));
                    //----------

                    CGColor color1 = new CGColor(1, 0, 0, 1);
                    g.SetFillColor(color1);

                    CGRect s1    = CGRect.FromLTRB(0, 0, 50, 50);
                    CGPath gpath = new CGPath();
                    gpath.AddRect(CGAffineTransform.MakeTranslation(20, 20), s1);
                    g.AddPath(gpath);
                    g.FillPath();


                    CGRect s2 = new CGRect(50, 50, destImgW, destImgH);
                    g.DrawImage(s2, myImg2);

                    //

                    //g.FillRect(s1);

                    CGColor color2 = new CGColor(0, 0, 1, 1);
                    g.SetFillColor(color2);
                    g.TranslateCTM(30, 30);


                    var strAttr = new CTStringAttributes
                    {
                        ForegroundColorFromContext = true,
                        Font = new CTFont("Arial", 24)
                    };


                    g.ScaleCTM(1, -1);            //flip
                    NSAttributedString a_str = new NSAttributedString("abcd", strAttr);
                    using (CTLine line = new CTLine(a_str))
                    {
                        line.Draw(g);
                    }


                    ////if (chkBorder.Checked)
                    ////{
                    ////	//5.4
                    ////	p.StrokeColor = PixelFarm.Drawing.Color.Green;
                    ////	//user can specific border width here...
                    ////	//p.StrokeWidth = 2;
                    ////	//5.5
                    ////	p.Draw(vxs);
                    ////}
                    ////6. use this util to copy image from Agg actual image to System.Drawing.Bitmap
                    //BitmapHelper.CopyToWindowsBitmap(destImg, winBmp, new RectInt(0, 0, 300, 300));
                    ////---------------
                    ////7. just render our bitmap
                    //g.ClearRect(rect);

                    //g.DrawImage(winBmp, new Point(10, 0));
                }



            //// scale and translate the CTM so the image appears upright
            //g.ScaleCTM (1, -1);
            //g.TranslateCTM (0, -Bounds.Height);
            //g.DrawImage (rect, UIImage.FromFile ("MyImage.png").CGImage);
            //// translate the CTM by the font size so it displays on screen
            //float fontSize = 35f;
            //g.TranslateCTM (0, fontSize);

            //// set general-purpose graphics state
            //g.SetLineWidth (1.0f);
            //g.SetStrokeColor (UIColor.Yellow.CGColor);
            //g.SetFillColor (UIColor.Red.CGColor);
            //g.SetShadow (new CGSize (5, 5), 0, UIColor.Blue.CGColor);

            //// set text specific graphics state
            //g.SetTextDrawingMode (CGTextDrawingMode.FillStroke);
            //g.SelectFont ("Helvetica", fontSize, CGTextEncoding.MacRoman);

            //// show the text
            //g.ShowText ("Hello Core Graphics");
        }
コード例 #18
0
        // Only override drawRect: if you perform custom drawing.
        // An empty implementation adversely affects performance during animation.
        public override void Draw(CGRect rect)
        {
            if (barRect == null || barRect.Capacity == 0)
            {
                return;
            }

            try
            {
                int padding       = 0;
                int contentWidth  = int.Parse(rect.Size.Width.ToString()) - padding * 2;
                int contentHeight = int.Parse(rect.Size.Height.ToString()) - padding * 2;

                float boxHeight = 0;

                int noOfBars = barcolors.Count;

                int textWidth  = 20; //get the height dynamically
                int textHeight = 0;  //get the height dynamically


                float fcontentWidth  = contentWidth - textWidth;
                float fcontentHeight = contentHeight - textHeight * 2;

                float left   = padding + textWidth * 2;
                float top    = padding * 2 + textHeight + (circleRadius * 3) + 5;
                float right  = fcontentWidth - left;
                float bottom = fcontentHeight - top;

                right = fcontentWidth;
                //bottom = fcontentHeight;

                CGRect rectGraph = CGRect.FromLTRB(left, top, right, bottom);


                CGContext context = UIGraphics.GetCurrentContext();

                context.SetFillColor(UIColor.Green.CGColor);
                context.FillRect(rectGraph);

                noOfBars = barcolors.Count;

                float prevVal = baseValue;
                float diffVal = float.Parse(yValues[noOfBars - 1]) - prevVal;

                float boxHeight1 = 0;

                barRect.Clear();
                linesPoint.Clear();

                // draw bars/Strips
                for (int i = 0; i < noOfBars; i++)
                {
                    float cVal = float.Parse(yValues[i]) - prevVal;

                    boxHeight = (cVal * 100) / diffVal;
                    boxHeight = (float.Parse(rectGraph.Size.Height.ToString()) * boxHeight) / 100;

                    prevVal = float.Parse(yValues[i]);

                    context.SetFillColor(this.colorWithHexString(barcolors[i]).CGColor);

                    CGRect tempBarRect = new CGRect(rectGraph.X, (rectGraph.Y + rectGraph.Size.Height) - boxHeight1 - boxHeight, rectGraph.Size.Width, boxHeight);

                    barRect.Add(tempBarRect);

                    context.FillRect(tempBarRect);


                    string text1 = barText[i];

                    CGSize size1 = text1.StringSize(font1);

                    CGRect r1 = new CGRect(tempBarRect.X + 10, tempBarRect.Y + tempBarRect.Size.Height / 2 - size1.Height / 2, size1.Width, size1.Height);

                    context.SetFillColor(UIColor.White.CGColor);
                    text1.DrawString(r1, font1, UILineBreakMode.Clip, UITextAlignment.Left);


                    r1 = new CGRect(tempBarRect.X, tempBarRect.Y, tempBarRect.Size.Width, 2);

                    context.FillRect(r1);
                    //Draw y values
                    text1 = yValues[i];
                    size1 = text1.StringSize(font1);

                    r1 = new CGRect(tempBarRect.X - size1.Width - 5, tempBarRect.Y - size1.Height / 2, size1.Width, size1.Height);
                    context.SetFillColor(UIColor.Black.CGColor);
                    text1.DrawString(r1, font1, UILineBreakMode.Clip, UITextAlignment.Right);

                    boxHeight1 += boxHeight;
                }
                //Draw bottom text

                string text = baseValue.ToString();

                CGSize size = text.StringSize(font1);

                CGRect r = new CGRect(rectGraph.X - size.Width - 5, rectGraph.Y + rectGraph.Size.Height - size.Height, size.Width, size.Height);

                text.DrawString(r, font1, UILineBreakMode.Clip, UITextAlignment.Right);



                //Draw x & y axis border
                r = new CGRect(rectGraph.X, rectGraph.Y, 2, rectGraph.Size.Height);
                context.FillRect(r);

                r = new CGRect(rectGraph.X, rectGraph.Y + rectGraph.Size.Height - 2, rectGraph.Size.Width, 2);
                context.FillRect(r);

                int horizontalpadding = 20;

                int pointdistance = (int)(rectGraph.Size.Width - horizontalpadding * 2) / (xValues.Count + 1);



                CGPoint lastPoint = new CGPoint();

                linesRect.Clear();
                var drawLines = new List <CGPoint>();
                // draw Line and x axis
                for (int i = 0; i < xValues.Count; i++)
                {
                    context.SetFillColor(UIColor.Black.CGColor);

                    float currentValue = float.Parse(xValues[i]);

                    int quadrant = this.getQuadrant(currentValue);

                    float tempvalue  = 0;
                    int   percentage = 0;
                    float difference = 0;

                    if (quadrant > 0)
                    {
                        tempvalue  = currentValue - float.Parse(yValues[quadrant - 1]);
                        difference = float.Parse(yValues[quadrant]) - float.Parse(yValues[quadrant - 1]);
                        percentage = (int)((tempvalue * 100) / difference);
                    }
                    else
                    {
                        tempvalue  = currentValue - baseValue;
                        difference = float.Parse(yValues[quadrant]) - baseValue;
                        percentage = (int)((tempvalue * 100) / difference);
                    }

                    if (percentage > 100)
                    {
                        percentage = 100 + circleRadius;
                    }


                    float ycenterpoint = (boxHeight * percentage) / 100;

                    CGRect someRect = new CGRect(barRect[quadrant].X, barRect[quadrant].Y, barRect[quadrant].Width, barRect[quadrant].Height);

                    r = new CGRect(pointdistance * (i + 2), someRect.Y + someRect.Size.Height - ycenterpoint, 2, ycenterpoint);

                    context.SetFillColor(UIColor.LightGray.CGColor);
                    context.SetStrokeColor(0, 0, 0, 0.5f);
                    context.SetLineWidth(1);
                    context.BeginPath();
                    context.MoveTo(pointdistance * (i + 2), someRect.Y + someRect.Size.Height - ycenterpoint);
                    context.AddLineToPoint(pointdistance * (i + 2), rectGraph.Y + rectGraph.Size.Height);


                    context.StrokePath();


                    if (i == 0)
                    {
                        lastPoint = new CGPoint(pointdistance * (i + 2), someRect.Y + someRect.Size.Height - ycenterpoint);
                    }
                    else
                    {
                        context.SetStrokeColor(UIColor.White.CGColor);
                        context.SetFillColor(UIColor.White.CGColor);
                        context.BeginPath();
                        context.MoveTo(lastPoint.X, lastPoint.Y);
                        context.AddLineToPoint(pointdistance * (i + 2), someRect.Y + someRect.Size.Height - ycenterpoint);
                        context.StrokePath();

                        lastPoint = new CGPoint(pointdistance * (i + 2), someRect.Y + someRect.Size.Height - ycenterpoint);
                    }

                    linesPoint.Add(lastPoint);
                    linesRect.Add(new CGRect(pointdistance * (i + 2) - circleRadius / 2, someRect.Y + someRect.Size.Height - ycenterpoint - circleRadius / 2, circleRadius, circleRadius));
                }

                // draw legend
                context.BeginPath();
                context.SetFillColor(colorWithHexString("#409bd6").CGColor);
                context.SetLineWidth(2);
                context.SetStrokeColor(1.0f, 1.0f, 1.0f, 1.0f);

                for (int i = 0; i < xValues.Count; i++)
                {
                    CGRect someRect = linesRect[i];
                    context.FillEllipseInRect(someRect);
                    context.StrokeEllipseInRect(someRect);
                }

                context.StrokePath();
                context.SetFillColor(UIColor.Black.CGColor);
                context.FillRect(new CGRect(rectGraph.X, rectGraph.Y + 2, 2, rectGraph.Size.Height - 2));
                context.FillRect(new CGRect(rectGraph.X, rectGraph.Y + rectGraph.Size.Height - 2, rectGraph.Size.Width, 2));
                context.SetFillColor(UIColor.Black.CGColor);

                // Draw X values
                for (int i = 0; i < xValues.Count; i++)
                {
                    context.SetFillColor(UIColor.White.CGColor);

                    CGRect rect1 = linesRect[i];

                    string text1 = xValues[i];
                    CGSize size1 = text1.StringSize(font2);

                    CGRect r1 = new CGRect(rect1.X, rect1.Y + (rect1.Size.Height - size1.Height) / 2, rect1.Size.Width, size1.Height);
                    text1.DrawString(r1, font2, UILineBreakMode.Clip, UITextAlignment.Center);

                    text1 = legends[i];
                    size1 = text1.StringSize(font1);
                    r1    = new CGRect((rect1.X + circleRadius / 2) - size1.Width / 2, rectGraph.Y + rectGraph.Size.Height, size1.Width, size1.Height);
                    context.SetFillColor(UIColor.Black.CGColor);
                    text1.DrawString(r1, font1, UILineBreakMode.Clip, UITextAlignment.Center);
                }
            }
            catch (System.Exception e)
            {
                throw new System.Exception("Draw failed", e);
            }
        }
コード例 #19
0
        private void OnRequestHeaderImages(List <string> images)
        {
            var defaultImage = UIImage.FromFile(ViewModel.DefaultAccountImageName);

            AccountImageView.Hidden = images.Count == 0;

            // clear all existing entries before beginning
            foreach (UIView view in AccountsView.Subviews)
            {
                if (!view.Equals(AccountImageView))
                {
                    AccountsView.RemoveConstraints(view.Constraints);
                    view.RemoveFromSuperview();
                }
            }

            if (images.Count > 0)
            {
                // proceed and add the new ones
                var prevImageView          = AccountImageView;
                var prevTrailingConstraint = AccountImageViewTrailingConstraint;
                var rect          = CGRect.FromLTRB(prevImageView.Frame.X + 2, prevImageView.Frame.Y + 2, prevImageView.Frame.Width - 4, prevImageView.Frame.Height - 4);
                var path          = UIBezierPath.FromRoundedRect(rect, prevImageView.Frame.Height / 2);
                var prevMaskLayer = new CAShapeLayer();

                if (!AccountsView.Constraints.Contains(AccountImageViewTrailingConstraint))
                {
                    AccountsView.AddConstraint(AccountImageViewTrailingConstraint);
                }

                prevMaskLayer.Path          = path.CGPath;
                prevMaskLayer.ShadowColor   = UIColor.Black.CGColor;
                prevMaskLayer.ShadowOpacity = 0.35f;
                prevMaskLayer.ShadowOffset  = new CGSize(0, 1);
                prevMaskLayer.ShadowRadius  = 2;
                prevMaskLayer.ShadowPath    = path.CGPath;

                prevImageView.ClipsToBounds       = false;
                prevImageView.Layer.Mask          = prevMaskLayer;
                prevImageView.Layer.MasksToBounds = false;
                prevImageView.SetImage(new NSUrl(images [0]), defaultImage);

                images.RemoveAt(0);
                AccountsView.Layer.MasksToBounds = false;
                AccountsView.ClipsToBounds       = false;

                foreach (string imageUrl in images)
                {
                    var imageView = new UIImageView();
                    var maskLayer = new CAShapeLayer();

                    maskLayer.Path          = path.CGPath;
                    maskLayer.ShadowColor   = prevMaskLayer.ShadowColor;
                    maskLayer.ShadowOpacity = prevMaskLayer.ShadowOpacity;
                    maskLayer.ShadowOffset  = prevMaskLayer.ShadowOffset;
                    maskLayer.ShadowRadius  = prevMaskLayer.ShadowRadius;
                    maskLayer.ShadowPath    = prevMaskLayer.ShadowPath;

                    imageView.ClipsToBounds       = prevImageView.ClipsToBounds;
                    imageView.Layer.Mask          = maskLayer;
                    imageView.Layer.MasksToBounds = prevImageView.Layer.MasksToBounds;
                    imageView.TranslatesAutoresizingMaskIntoConstraints = false;

                    imageView.SetImage(new NSUrl(imageUrl), defaultImage);

                    var heightConstraint   = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, prevImageView.Frame.Height);
                    var widthConstraint    = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, prevImageView.Frame.Width);
                    var leadingConstraint  = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, prevImageView, NSLayoutAttribute.Trailing, 1, -prevImageView.Frame.Width / 2);
                    var centerYConstraint  = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, AccountsView, NSLayoutAttribute.CenterY, 1, 0);
                    var trailingConstraint = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, AccountsView, NSLayoutAttribute.Trailing, 1, 0);

                    AccountsView.AddSubview(imageView);
                    AccountsView.SendSubviewToBack(imageView);

                    AccountsView.RemoveConstraint(prevTrailingConstraint);
                    AccountsView.AddConstraint(heightConstraint);
                    AccountsView.AddConstraint(widthConstraint);
                    AccountsView.AddConstraint(leadingConstraint);
                    AccountsView.AddConstraint(centerYConstraint);
                    AccountsView.AddConstraint(trailingConstraint);

                    prevMaskLayer          = maskLayer;
                    prevImageView          = imageView;
                    prevTrailingConstraint = trailingConstraint;
                }
                AccountsView.LayoutIfNeeded();
            }
        }