public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is System.Windows.Media.Color cc)
     {
         UniColor ac = cc.GetUniColor();
         if (ac.A != 255)
         {
             return(ac.ToString("awH"));
         }
         else
         {
             return(ac.ToString("rwH"));
         }
     }
     else if (value is UniColor uc)
     {
         if (uc.A != 255)
         {
             return(uc.ToString("awH"));
         }
         else
         {
             return(uc.ToString("rwH"));
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
 public static Color GetWinUIColor(this UniColor color)
 {
     return(new Color()
     {
         A = color.A,
         R = color.R,
         G = color.G,
         B = color.B
     });
 }
Exemple #3
0
        private string UniColorToHex(UniColor color)
        {
            if (color.IsEmpty)
            {
                return("#7d7d7d");
            }

            return(string.Format("#{0:X2}{1:X2}{2:X2}",
                                 color.R,
                                 color.G,
                                 color.B));
        }
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is string s)
     {
         if (targetType == typeof(UniColor))
         {
             return(UniColor.Parse(s));
         }
         else if (targetType == typeof(System.Windows.Media.Color))
         {
             return(UniColor.Parse(s).GetWPFColor());
         }
         else
         {
             throw new NotSupportedException();
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (ValidateSatVal || ValidateHue)
            {
                if (!double.TryParse(value.ToString(), NumberStyles.Any, cultureInfo, out double result))
                {
                    return(new ValidationResult(false, "Does Not Parse As Double"));
                }
                else if (ValidateSatVal && (result < 0d || result > 1))
                {
                    return(new ValidationResult(false, "Is Not Within Range 0 to 1"));
                }
                else if (ValidateHue && (result < 0d || result > 360d))
                {
                    return(new ValidationResult(false, "Is Not Within Range 0 to 360"));
                }
            }
            else if (ValidateWebHex)
            {
                try
                {
                    UniColor.Parse(value.ToString());
                }
                catch
                {
                    return(new ValidationResult(false, "Is Not Parseable Color"));
                }
            }
            else
            {
                if (!byte.TryParse(value.ToString(), NumberStyles.Any, cultureInfo, out _))
                {
                    return(new ValidationResult(false, "Does Not Parse As Byte"));
                }
            }

            return(ValidationResult.ValidResult);
        }
        /// <summary>
        /// Draws a grid onto an image.
        /// </summary>
        /// <param name="img">The image to work with.</param>
        /// <param name="GridX">The spacing of the X grid, in pixels.</param>
        /// <param name="GridY">The spacing of the Y grid, in pixels.</param>
        /// <param name="ColorX">The color of the X grid.</param>
        /// <param name="ColorY">The color of the Y grid.</param>
        /// <param name="Thickness">The line thickness in pixels.</param>
        /// <param name="GridType">The grid type.</param>
        /// <param name="DashPatternX">The X dash pattern.</param>
        /// <param name="DashPatternY">The Y dash pattern.</param>
        /// <remarks></remarks>
        public static void RenderGrid(Bitmap img, float GridX, float GridY, UniColor ColorX, UniColor ColorY, double Thickness = 1.0d, GridLinesType GridType = GridLinesType.Dotted, float[] DashPatternX = null, float[] DashPatternY = null)
        {
            var g = System.Drawing.Graphics.FromImage(img);
            int x;
            int y;
            int cx;
            int cy;
            var dashValuesX = new float[] { 1f, 0f, 1f, 0f };
            var dashValuesY = new float[] { 1f, 0f, 1f, 0f };

            if (DashPatternX is object)
            {
                dashValuesX = DashPatternX;
            }

            if (DashPatternY is object)
            {
                dashValuesY = DashPatternY;
            }

            Pen pnX;
            Pen pnY;

            pnX = new Pen(ColorX, (float)Thickness);
            pnY = new Pen(ColorY, (float)Thickness);

            // g.FillRectangle(br2, 0, 0, Me.Width, Me.Height)

            switch (GridType)
            {
            case GridLinesType.Dashed:
            {
                dashValuesX[0]  = Math.Max(1f, GridX / 4f - 2f);
                dashValuesX[1]  = 2f;
                dashValuesX[2]  = Math.Max(1f, GridX / 4f - 2f);
                dashValuesX[3]  = 2f;
                dashValuesY[0]  = Math.Max(1f, GridY / 4f - 2f);
                dashValuesY[1]  = 2f;
                dashValuesY[2]  = Math.Max(1f, GridY / 4f - 2f);
                dashValuesY[3]  = 2f;
                pnX.DashPattern = dashValuesX;
                pnY.DashPattern = dashValuesY;
                break;
            }

            case GridLinesType.Dotted:
            {
                dashValuesX[0]  = 1f;
                dashValuesX[1]  = Math.Max(1f, GridX - 1f);
                dashValuesX[2]  = 1f;
                dashValuesX[3]  = Math.Max(1f, GridX - 1f);
                dashValuesY[0]  = 1f;
                dashValuesY[1]  = Math.Max(1f, GridY - 1f);
                dashValuesY[2]  = 1f;
                dashValuesY[3]  = Math.Max(1f, GridY - 1f);
                pnX.DashPattern = dashValuesX;
                pnY.DashPattern = dashValuesY;
                break;
            }
            }

            cx = img.Width;
            cy = img.Height;

            for (x = (int)(GridX / 2f); (int)GridX >= 0 ? x <= cx : x >= cx; x += (int)GridX)
            {
                if (GridType == GridLinesType.Dotted)
                {
                    g.DrawLine(pnX, x, (int)Math.Floor(GridY / 2f), x, cy);
                }
                else
                {
                    // If (x = (GridX / 2)) Then Continue For
                    g.DrawLine(pnX, x, 0, x, cy);
                }
            }

            for (y = (int)(GridY / 2f); (int)GridY >= 0 ? y <= cy : y >= cy; y += (int)GridY)
            {
                if (GridType == GridLinesType.Dotted)
                {
                    g.DrawLine(pnX, (int)Math.Floor(GridX / 2f), y, cx, y);
                }
                else
                {
                    // If (y = (GridY / 2)) Then Continue For
                    g.DrawLine(pnX, 0, y, cx, y);
                }
            }

            pnX.Dispose();
            pnY.Dispose();
            g.Dispose();
        }
 public static Xamarin.Forms.Color GetXamarinColor(this UniColor c)
 {
     return(Xamarin.Forms.Color.FromHex(c.ToString(UniColorFormatOptions.HexArgbWebFormat)));
 }