예제 #1
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            CustomBoxView specialBoxView = (CustomBoxView)Element;

            Rect rect = new Rect();

            GetDrawingRect(rect);

            Rect inside = rect;

            inside.Inset((int)specialBoxView.BorderThickness, (int)specialBoxView.BorderThickness);

            Paint p = new Paint();

            p.Color = specialBoxView.Color.ToAndroid();

            canvas.DrawRect(inside, p);

            p.Color       = specialBoxView.BorderColor.ToAndroid();
            p.StrokeWidth = (float)specialBoxView.BorderThickness;
            p.SetStyle(Paint.Style.Stroke);

            canvas.DrawRect(rect, p);
        }
        private static CustomBoxView CalculateNewEmptyArea(CustomBoxView currentEmptyArea, Orientation orientation, double rowToAllRatio)
        {
            CustomBoxView newEmptyArea = new CustomBoxView();

            if (orientation == Orientation.Horizontal)
            {
                double size = Math.Round(currentEmptyArea.HeightRequest * rowToAllRatio);
                if (currentEmptyArea.HeightRequest > size)
                {
                    newEmptyArea.MyX = currentEmptyArea.MyX;
                    newEmptyArea.MyY = currentEmptyArea.MyY + size;

                    newEmptyArea.WidthRequest = currentEmptyArea.WidthRequest;
                    newEmptyArea.HeightRequest = currentEmptyArea.HeightRequest - size;
                }
            }
            else
            {
                double size = Math.Round(currentEmptyArea.WidthRequest * rowToAllRatio);
                if (currentEmptyArea.WidthRequest > size)
                {
                    newEmptyArea.MyX = currentEmptyArea.MyX + size;
                    newEmptyArea.MyY = currentEmptyArea.MyY;

                    newEmptyArea.WidthRequest = currentEmptyArea.WidthRequest - size;
                    newEmptyArea.HeightRequest = currentEmptyArea.HeightRequest;
                }
            }

            return newEmptyArea;
        }
예제 #3
0
        private async Task <Item> sendRequest()
        {
            Item item = new Item();

            HttpClient hTTPClient = new HttpClient();

            var response = await hTTPClient.GetAsync(new Uri("http://www.colourlovers.com/api/colors/random"));

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(content);
                XmlNodeList xnList = xml.GetElementsByTagName("color");

                foreach (XmlNode xn in xnList)
                {
                    item.id          = xn["id"].InnerText;
                    item.hex         = xn["hex"].InnerText;
                    item.dateCreated = xn["dateCreated"].InnerText;
                    item.red         = xn["rgb"]["red"].InnerText;
                    item.green       = xn["rgb"]["green"].InnerText;
                    item.blue        = xn["rgb"]["blue"].InnerText;
                    //item.length = Convert.ToInt32(GetRandomNumber(50, layout.Height == 0 ? 50 : layout.Height / 2));
                    item.length = Convert.ToInt32(GetRandomNumber(30, 70));
                }

                if (mode)
                {
                    var topBox = new BoxView {
                        Color = Color.FromHex("#" + item.hex)
                    };
                    AbsoluteLayout.SetLayoutBounds(topBox, new Rectangle(location.X, location.Y, item.length, item.length));
                    layout.Children.Add(topBox);
                }
                else
                {
                    var topBox = new CustomBoxView {
                        Color = Color.FromHex("#" + item.hex), CornerRadius = item.length
                    };
                    AbsoluteLayout.SetLayoutBounds(topBox, new Rectangle(location.X, location.Y, item.length, item.length));
                    layout.Children.Add(topBox);
                }
            }

            return(item);
        }
예제 #4
0
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);
            CustomBoxView control = (CustomBoxView)Element;

            Paint p = new Paint();

            p.StrokeWidth = (float)control.Espessura;
            p.Color       = Android.Graphics.Color.Black;
            p.SetStyle(Paint.Style.Stroke);
            Rect rect = new Rect(0, 0, 200, 200);

            canvas.DrawRect(rect, p);
            canvas.DrawLine(100, 0, 100, 200, p);
            canvas.DrawLine(0, 100, 200, 100, p);
        }
예제 #5
0
        public override void Draw(CGRect rect)
        {
            //base.Draw(rect);
            CustomBoxView control = (CustomBoxView)Element;

            using (var context = UIGraphics.GetCurrentContext())
            {
                context.SetStrokeColor(new CGColor(0, 0, 0));
                context.SetLineWidth((float)control.Espessura);

                var recPath = new CGRect(0, 0, 200, 200);

                context.AddRect(recPath);
                context.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
예제 #6
0
        /* */
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            CustomBoxView boxView = (CustomBoxView)Element;

            using (var context = UIGraphics.GetCurrentContext())           //using bloc to set the context
            {
                context.SetFillColor(boxView.Color.ToCGColor());           //fill color
                context.SetStrokeColor(boxView.BorderColor.ToCGColor());   //border color
                context.SetLineWidth((float)boxView.BorderThikness);       //width of border
                var rectangle = Bounds.Inset((int)boxView.BorderThikness,
                                             (int)boxView.BorderThikness); //
                var path = CGPath.FromRect(rectangle);
                context.AddPath(path);
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);
            CustomBoxView control = (CustomBoxView)Element;
            Paint         p       = new Paint();

            p.StrokeWidth = (float)control.Espessura;
            p.Color       = Color.White;

            //Retangulo
            Rect rect = new Rect(0, 0, 200, 200);

            canvas.DrawRect(rect, p);

            //Linhas
            canvas.DrawLine(100, 0, 100, 100, p);
            canvas.DrawLine(0, 100, 100, 100, p);
        }
        public override void Draw(CoreGraphics.CGRect rect)
        {
            CustomBoxView boxView = (CustomBoxView)Element;

            using (var context = UIGraphics.GetCurrentContext())
            {
                context.SetFillColor(boxView.Color.ToCGColor());
                context.SetStrokeColor(boxView.BorderColor.ToCGColor());
                context.SetLineWidth((float)boxView.BorderThickness);


                var rectangle = Bounds.Inset((int)boxView.BorderThickness,
                                             (int)boxView.BorderThickness);

                var path = CGPath.FromRect(rectangle);
                context.AddPath(path);
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
예제 #9
0
        public override void Draw(Canvas canvas)
        {
            CustomBoxView boxView = (CustomBoxView)Element;
            Rect          rect    = new Rect();

            GetDrawingRect(rect);
            Rect inside = rect;

            inside.Inset((int)boxView.BorderThickness,
                         (int)boxView.BorderThickness);
            Paint p = new Paint
            {
                Color = boxView.Color.ToAndroid()
            };

            canvas.DrawRect(inside, p);

            p.Color       = boxView.BorderColor.ToAndroid();
            p.StrokeWidth = (float)boxView.BorderThickness;
            p.SetStyle(Paint.Style.Stroke);
            canvas.DrawRect(rect, p);
        }
        private static IEnumerable<SquarifiedInfo> Squarify(IEnumerable<SquarifiedInfo> squarifiedInfos, CustomBoxView emptyArea)
        {
            var sortedSquarifiedInfos = squarifiedInfos.OrderByDescending (c => c.Area).ToList ();

            var resultCollection = new Collection<SquarifiedInfo> ();

            var newEmptyAreaSum = sortedSquarifiedInfos.Sum (c => c.Area);

            CustomBoxView newEmptyArea = emptyArea;

            while (sortedSquarifiedInfos.Any())
            {
                double shortestSide = SquarifiedAlgorithm.GetShortestSide(newEmptyArea);

                var list2 = SquarifiedAlgorithm.DetermineRow(sortedSquarifiedInfos, shortestSide);

                SquarifiedAlgorithm.LayoutRow(list2, newEmptyArea, newEmptyAreaSum, out newEmptyArea, out newEmptyAreaSum);

                foreach (var squarifiedInfo in list2) {

                    resultCollection.Add (squarifiedInfo);

                    sortedSquarifiedInfos.Remove (squarifiedInfo);
                }
            }

            return resultCollection;
        }
        private static void LayoutRow(IEnumerable<SquarifiedInfo> row, CustomBoxView emptyArea, double emptyAreaSum, out CustomBoxView newEmptyArea, out double newEmptyAreaSum)
        {
            Orientation orientation = SquarifiedAlgorithm.GetOrientation(emptyArea);

            double num1 = row.Sum (c=>c.Area);

            if (num1 == 0.0)
            {
                newEmptyArea = new CustomBoxView ();
                newEmptyAreaSum = 0.0;
            }
            else
            {
                double rowToAllRatio = num1 / emptyAreaSum;
                double num2 = 0.0;

                newEmptyArea = SquarifiedAlgorithm.CalculateNewEmptyArea(emptyArea, orientation, rowToAllRatio);

                foreach (SquarifiedInfo squarifiedInfo in row)
                {
                    if (orientation == Orientation.Horizontal)
                    {
                        double num3 = emptyArea.MyX + num2 * emptyArea.WidthRequest / num1;
                        squarifiedInfo.X = num3;
                        squarifiedInfo.Y = emptyArea.MyY;
                        squarifiedInfo.Width = squarifiedInfo.Area / num1 * emptyArea.WidthRequest;
                        squarifiedInfo.Height = emptyArea.HeightRequest * rowToAllRatio;
                    }
                    else
                    {
                        double num3 = emptyArea.MyY + num2 * emptyArea.HeightRequest / num1;
                        squarifiedInfo.X = emptyArea.MyX;
                        squarifiedInfo.Y = num3;
                        squarifiedInfo.Width = emptyArea.WidthRequest * rowToAllRatio;
                        squarifiedInfo.Height = squarifiedInfo.Area / num1 * emptyArea.HeightRequest;
                    }
                    num2 += squarifiedInfo.Area;
                }
                newEmptyAreaSum = emptyAreaSum - num1;
            }
        }
        private static double GetShortestSide(CustomBoxView rectangle)
        {
            var result= Math.Min(rectangle.WidthRequest, rectangle.HeightRequest);

            return result;
        }
 private static Orientation GetOrientation(CustomBoxView rectangle)
 {
     return rectangle.WidthRequest <= rectangle.HeightRequest ? Orientation.Horizontal : Orientation.Vertical;
 }