Exemple #1
0
        private void SetPickedColor(Color pColor)
        {
            Bitmap cView = new Bitmap(colorBox.Width, colorBox.Height);

            using (Graphics g = Graphics.FromImage(cView))
            {
                g.Clear(pColor);
                using (SolidBrush sb = new SolidBrush(ColorUtils.Invert(pColor)))
                {
                    using (Pen p = new Pen(sb, 1))
                    {
                        g.DrawRectangle(p, new Rectangle(1, 1, cView.Width - 3, cView.Height - 3));
                    }
                }
            }

            HSLColor hlc = HSLColor.FromColor(pColor);
            HSVColor hvc = HSVColor.FromColor(pColor);
            RGBColor rgc = RGBColor.FromColor(pColor);
            HEXColor hxc = HEXColor.FromColor(pColor);

            lbl_HTML.Text = hxc.ToString();
            lbl_RGB.Text  = rgc.ToString();
            lbl_HSL.Text  = hlc.ToString();
            lbl_HSV.Text  = hvc.ToString();

            colorBox.Image?.Dispose();
            colorBox.Image = cView;
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (value is RGBColor)
     {
         return(RGBColor.FromColor((Color)base.EditValue(context, provider, ((RGBColor)value).ToColor())));
     }
     return(value);
 }
    public void FromColor()
    {
        var color = Color.FromArgb(140, 12, 59);

        var(r, g, b) = RGBColor.FromColor(color);
        Assert.Equal(0.5490196078431373, r, DoubleComparer);
        Assert.Equal(0.047058823529411764, g, DoubleComparer);
        Assert.Equal(0.23137254901960785, b, DoubleComparer);
    }
Exemple #4
0
    public void SamplesRgb()
    {
        // red
        var c1 = new RGBColor(0.937, 0.2, 0.251);
        var c2 = RGBColor.FromRGB8Bit(239, 51, 64);
        var c3 = RGBColor.FromColor(Color.FromArgb(239, 51, 64));

        // gray
        var c4 = new RGBColor(0.5, 0.5, 0.5);
        var c5 = RGBColor.FromGray(0.5);

        // white
        var c6 = new RGBColor(1, 1, 1);

        // black
        var c7 = new RGBColor(0, 0, 0);
    }
        /// <summary>Converts the given object to the converter's native type.</summary>
        /// <returns>An <see cref="T:System.Object"></see> representing the converted value.</returns>
        /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see> that specifies the culture to represent the color. </param>
        /// <param name="context">A <see cref="T:System.ComponentModel.TypeDescriptor"></see> that provides a format context. You can use this object to get additional information about the environment from which this converter is being invoked. </param>
        /// <param name="value">The object to convert. </param>
        /// <exception cref="T:System.ArgumentException">The conversion cannot be performed.</exception>
        /// <filterpriority>1</filterpriority>
        /// <PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string text1 = value as string;

            if (text1 == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }
            object obj1  = null;
            string text2 = text1.Trim();

            if (text2.Length == 0)
            {
                return(RGBColor.FromColor(Color.Empty));
            }
            obj1 = GetNamedColor(text2);
            if (obj1 == null)
            {
                if (culture == null)
                {
                    culture = CultureInfo.CurrentCulture;
                }
                char          ch1        = culture.TextInfo.ListSeparator[0];
                bool          flag1      = true;
                TypeConverter converter1 = TypeDescriptor.GetConverter(typeof(int));
                if (text2.IndexOf(ch1) == -1)
                {
                    if (((text2.Length >= 2) && ((text2[0] == '\'') || (text2[0] == '"'))) &&
                        (text2[0] == text2[text2.Length - 1]))
                    {
                        string text3 = text2.Substring(1, text2.Length - 2);
                        obj1  = Color.FromName(text3);
                        flag1 = false;
                    }
                    else if ((((text2.Length == 7) && (text2[0] == '#')) ||
                              ((text2.Length == 8) && (text2.StartsWith("0x") || text2.StartsWith("0X")))) ||
                             ((text2.Length == 8) && (text2.StartsWith("&h") || text2.StartsWith("&H"))))
                    {
                        obj1 =
                            Color.FromArgb(-16777216 | ((int)converter1.ConvertFromString(context, culture, text2)));
                    }
                }
                if (obj1 == null)
                {
                    string[] textArray1 = text2.Split(new char[] { ch1 });
                    int[]    numArray1  = new int[textArray1.Length];
                    for (int num1 = 0; num1 < numArray1.Length; num1++)
                    {
                        numArray1[num1] = (int)converter1.ConvertFromString(context, culture, textArray1[num1]);
                    }
                    switch (numArray1.Length)
                    {
                    case 1:
                        obj1 = Color.FromArgb(numArray1[0]);
                        break;

                    case 3:
                        obj1 = Color.FromArgb(numArray1[0], numArray1[1], numArray1[2]);
                        break;

                    case 4:
                        obj1 = Color.FromArgb(numArray1[0], numArray1[1], numArray1[2], numArray1[3]);
                        break;
                    }
                    flag1 = true;
                }
                if ((obj1 != null) && flag1)
                {
                    int num2 = ((Color)obj1).ToArgb();
                    foreach (Color color1 in Colors.Values)
                    {
                        if (color1.ToArgb() == num2)
                        {
                            obj1 = color1;
                            break;
                        }
                    }
                }
            }
            if (obj1 == null)
            {
                throw new ArgumentException("InvalidColor");
            }
            return(RGBColor.FromColor((Color)obj1));
        }
Exemple #6
0
 private void lbl_RGB_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     Copy(RGBColor.FromColor(ldcPlate.SelectedColor));
 }
Exemple #7
0
        // 임시 핫키 세팅과 연동 필요함
        private void InitHotKey()
        {
            Keys[]  semi_hkKeys   = new Keys[] { Keys.Left, Keys.Right, Keys.Up, Keys.Down };
            Point[] semi_hkDeltas = new Point[] { new Point(-1, 0), new Point(1, 0), new Point(0, -1), new Point(0, 1) };

            for (int i = 0; i < semi_hkDeltas.Length; i++)
            {
                int idx = i;

                HotkeyManager.Register($"SEMI_{semi_hkKeys[idx].ToString()}", new HotKey()
                {
                    Keys   = new Keys[] { semi_hkKeys[idx] },
                    Action = () =>
                    {
                        if (setting.SemiControl)
                        {
                            Point acPt = Point.Empty;

                            if (HotkeyManager.IsShift())
                            {
                                acPt = new Point(semi_hkDeltas[idx].X * 3, semi_hkDeltas[idx].Y * 3);
                            }

                            SetCursorPosDelta(semi_hkDeltas[idx] + (Size)acPt);
                        }
                    }
                });
            }

            HotkeyManager.Register("Pause", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F1 },
                Action = () =>
                {
                    mPause = !mPause;
                }
            });

            HotkeyManager.Register("ZoomIn", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.Add },
                Action = () =>
                {
                    zoomSlider.Value += 1;
                }
            });

            HotkeyManager.Register("ZoomOut", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.Subtract },
                Action = () =>
                {
                    zoomSlider.Value -= 1;
                }
            });

            HotkeyManager.Register("RGB", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F2 },
                Action = () =>
                {
                    AddColor(RGBColor.FromColor(ldcPlate.SelectedColor));
                }
            });

            HotkeyManager.Register("HEX", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F3 },
                Action = () =>
                {
                    AddColor(HEXColor.FromColor(ldcPlate.SelectedColor));
                }
            });

            HotkeyManager.Register("HSL", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F4 },
                Action = () =>
                {
                    AddColor(HSLColor.FromColor(ldcPlate.SelectedColor));
                }
            });

            HotkeyManager.Register("HSB", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F5 },
                Action = () =>
                {
                    AddColor(HSVColor.FromColor(ldcPlate.SelectedColor));
                }
            });
        }