Handle conversions between RGB and HSV (and Color types, as well).
Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorWheel"/> class.
        /// </summary>
        /// <param name="r">
        /// The r.
        /// </param>
        /// <param name="g">
        /// The g.
        /// </param>
        /// <param name="b">
        /// The b.
        /// </param>
        public ColorWheel(int r, int g, int b)
        {
            color = new ColorHandler.RGB(r, g, b);
            InitializeComponent();
            this.Dock             = DockStyle.Top;
            this.Controls[0].Text = EntName;
            this.AutoSize         = false;

            // hsvColor = new ColorHandler.HSV(0, 0, brightness);
        }
Esempio n. 2
0
        /// <summary>
        /// The update box.
        /// </summary>
        public void updateBox()
        {
            colorBox.BackColor = ColorHandler.HSVtoColor(hsvColor);
            ColorHandler.RGB tempRGB = ColorHandler.HSVtoRGB(hsvColor);
            updatingColors = true;
            if (alphaText != null)
            {
                alphaText.Text = (this.color.Alpha / 255f).ToString();
            }

            redText.Text   = (tempRGB.Red / 255f).ToString();
            greenText.Text = (tempRGB.Green / 255f).ToString();
            blueText.Text  = (tempRGB.Blue / 255f).ToString();
            updatingColors = false;
        }
Esempio n. 3
0
        private void GrabColor(object sender, Point mouseXY)
        {
            int cntlNum = this.Controls.IndexOf((Control)sender);
            int cx      = mouseXY.X;
            int cy      = mouseXY.Y;

            switch (cntlNum)
            {
            case 0:
                // center our coordinate system so the middle is (0,0), and positive Y is facing up
                cx -= (this.Controls[cntlNum].Width / 2);
                cy -= (this.Controls[cntlNum].Height / 2);
                if (cx < this.Controls[cntlNum].Width / 2)
                {
                    double theta = Math.Atan2(cy, cx);

                    if (theta < 0)
                    {
                        theta += 2 * Math.PI;
                    }

                    double alpha = Math.Sqrt((cx * cx) + (cy * cy));

                    int h = (int)((theta / (Math.PI * 2)) * 360.0);
                    int s = (int)Math.Min(100.0, (alpha / (double)(this.Controls[0].Width / 2)) * 100);
                    int v = hsvColor.value;

                    hsvColor = new ColorHandler.HSV(h, s, v);

                    OnColorChanged();
                    updateBar();
                }
                break;

            case 1:
                if (cx < this.Controls[cntlNum].Width)
                {
                    hsvColor.value = Math.Max(0, Math.Min(100, 100 - (cy * 100 / this.Controls[cntlNum].Height)));
                    updateBox();
                }
                break;
            }
            this.color = ColorHandler.HSVtoRGB(hsvColor);
            Invalidate(true);
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorChangedEventArgs"/> class.
 /// </summary>
 /// <param name="RGB">The RGB.</param>
 /// <param name="HSV">The HSV.</param>
 /// <remarks></remarks>
 public ColorChangedEventArgs(ColorHandler.RGB RGB, ColorHandler.HSV HSV)
 {
     mRGB = RGB;
     mHSV = HSV;
 }
Esempio n. 5
0
        private void GrabColor(object sender, Point mouseXY)
        {
            int cntlNum = this.Controls.IndexOf((Control)sender);
            int cx = mouseXY.X;
            int cy = mouseXY.Y;

            switch (cntlNum)
            {
                case 0:
                    // center our coordinate system so the middle is (0,0), and positive Y is facing up
                    cx -= (this.Controls[cntlNum].Width / 2);
                    cy -= (this.Controls[cntlNum].Height / 2);
                    if (cx < this.Controls[cntlNum].Width / 2)
                    {
                        double theta = Math.Atan2(cy, cx);

                        if (theta < 0)
                        {
                            theta += 2 * Math.PI;
                        }

                        double alpha = Math.Sqrt((cx * cx) + (cy * cy));

                        int h = (int)((theta / (Math.PI * 2)) * 360.0);
                        int s = (int)Math.Min(100.0, (alpha / (double)(this.Controls[0].Width / 2)) * 100);
                        int v = hsvColor.value;

                        hsvColor = new ColorHandler.HSV(h, s, v);

                        OnColorChanged();
                        updateBar();
                    }
                    break;
                case 1:
                    if (cx < this.Controls[cntlNum].Width)
                    {
                        hsvColor.value = Math.Max(0, Math.Min(100, 100 - (cy * 100 / this.Controls[cntlNum].Height)));
                        updateBox();
                    }
                    break;
            }
            this.color = ColorHandler.HSVtoRGB(hsvColor);
            Invalidate(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorWheel"/> class.
        /// </summary>
        /// <param name="r">
        /// The r.
        /// </param>
        /// <param name="g">
        /// The g.
        /// </param>
        /// <param name="b">
        /// The b.
        /// </param>
        public ColorWheel(int r, int g, int b)
        {
            color = new ColorHandler.RGB(r, g, b);
            InitializeComponent();
            this.Dock = DockStyle.Top;
            this.Controls[0].Text = EntName;
            this.AutoSize = false;

            // hsvColor = new ColorHandler.HSV(0, 0, brightness);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorChangedEventArgs"/> class.
 /// </summary>
 /// <param name="RGB">The RGB.</param>
 /// <param name="HSV">The HSV.</param>
 /// <remarks></remarks>
 public ColorChangedEventArgs(ColorHandler.RGB RGB, ColorHandler.HSV HSV)
 {
     mRGB = RGB;
     mHSV = HSV;
 }