/// <summary>
        /// Initializes a new instance of the
        /// <see cref="NControlDemo.Forms.Xamarin.Plugins.FormsApp.Controls.CircularButtonControl"/> class.
        /// </summary>
        public ActionButton()
        {
            HeightRequest = 66;
            WidthRequest  = 66;

            _label = new Label
            {
                Text                    = "+",
                TextColor               = Xamarin.Forms.Color.White,
                FontSize                = 30,
                BackgroundColor         = Xamarin.Forms.Color.Transparent,
                HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Center,
                VerticalTextAlignment   = Xamarin.Forms.TextAlignment.Center,
            };

            _circles = new NControlView
            {
                DrawingFunction = (canvas1, rect) => {
                    var fillColor = new NGraphics.Color(FillColor.R,
                                                        FillColor.G, FillColor.B, FillColor.A);

                    /*canvas1.FillEllipse(rect, fillColor);
                     * rect.Inflate(new NGraphics.Size(-2, -2));
                     * canvas1.FillEllipse(rect, Colors.White);*/
                    rect.Inflate(new NGraphics.Size(-4, -4));
                    canvas1.FillEllipse(rect, fillColor);
                }
            };

            Content = new Grid
            {
                Children =
                {
                    _circles,
                    _label,
                }
            };
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="AvatarButton"/> class.
        /// </summary>
        public AvatarButton()
        {
            HeightRequest = 44;
            WidthRequest = 44;

            _label = new Label
                     {
                         Text = "+",
                         TextColor = Xamarin.Forms.Color.White,
                         FontSize = 17,
                         BackgroundColor = Xamarin.Forms.Color.Transparent,
                         XAlign = Xamarin.Forms.TextAlignment.Center,
                         YAlign = Xamarin.Forms.TextAlignment.Center,
                     };

            _circle = new NControlView
                       {

                           DrawingFunction = (canvas1, rect) =>
                           {
                               var fillColor = new NGraphics.Color(FillColor.R,
                                                                   FillColor.G, FillColor.B, FillColor.A);

                               canvas1.FillEllipse(rect, fillColor);
                           }
                       };

            Content = new Grid
                      {
                          Children =
                          {
                              _circle,
                              _label,
                          }
                      };
        }
Beispiel #3
0
        private async void GenerateImage(object sender, EventArgs e)
        {
            _avatar.AvatarInitial = "C";
            _avatar.FillColor = Color.Blue;

            /*
             * 
                    01 - #71cfbf
                    02 - #e3a685
                    03 - #7eaae5
                    04 - #ca7c7a
                    05 - #bc789b
                    06 - #dd8785
             */
            var colours = new List<string>()
                          {
                              "#71cfbf","#e3a685", "#7eaae5", "#ca7c7a", "#bc789b", "#dd8785"
                          };

            // (NGraphics.IImageCanvas)
            double canvasSize = 96;
            double textSize = canvasSize / 2;

            var canvasx = new ApplePlatform().CreateImageCanvas(new Size(canvasSize), 2);
            //canvasx.FillEllipse(rect, new RadialGradientBrush(new NGraphics.Color("#0000ff"), new NGraphics.Color("#ff0000")));

            //canvasx.DrawRectangle(rect, new Pen("#9966CC", 5D), new SolidBrush(NGraphics.Color.FromRGB(0)));
            var rect = new Rect(new Size(canvasSize));

            var initials = new string[]
                            {
                                "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
                                "S", "T", "U", "V", "W", "X", "Y", "Z"
                            };

            foreach(var colourString in colours)
            {
                var backColour = new NGraphics.Color(colourString);
                canvasx.DrawRectangle(rect, new Pen(backColour), new SolidBrush(backColour));

                double penWidth = 1D;

                var innerBox = new Rect(new Point(rect.Center.X - textSize / 2, rect.Center.Y - textSize / 2), new Size(textSize));
                // DEBUG only to see where the text appears within the parent container for centering purposes
                //canvasx.DrawRectangle(innerBox, new Pen(Colors.LightGray));

                // bug in NGraphics on ios draws text ABOVE the rectangle you specify
                var textRec = new Rect(new Point(innerBox.Left + penWidth, innerBox.Top + innerBox.Height - penWidth - (textSize * 0.1)), new Size(textSize));
                var font = new Font("Metric-Regular", textSize);

                canvasx.DrawText("W", textRec, font, TextAlignment.Center, Pens.White, Brushes.White);
                //canvasx.DrawText("W", rect.Center, new Font(), new NGraphics.Color("#9966cc") );

                string fileName = System.IO.Path.Combine(_dataPath, string.Format("{0:dd-MM-yyyy-HH-mm-ss}.png", DateTime.Now));
                canvasx.GetImage().SaveAsPng(fileName);
                LogHost.Default.Debug(string.Format("image saved to {0}", fileName));

                _drawnImage.Source = ImageSource.FromFile(fileName);
                // var s = colourString;
                // await MainPage.DisplayAlert("Done", string.Format("Done with {0}", s), "OK");
            }
            Device.BeginInvokeOnMainThread(async () => await this.DisplayAlert("All Done", "All Done", "OK"));
            
        }