コード例 #1
0
        /// <summary>
        /// The timer is used to control the color wheel update from the text boxes.
        /// If we update instantly, we are unable to type, therefore allow a delay for typing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            // The tag contains the control that started the timer
            Control c = (Control)timer1.Tag;

            try
            {
                if ((Color)c.Tag == Color.White)
                {
                    this.color.Alpha = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Red)
                {
                    this.color.Red = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Green)
                {
                    this.color.Green = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Blue)
                {
                    this.color.Blue = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                this.hsvColor = ColorHandler.RGBtoHSV(this.color);
                updateBar();
            }
            catch
            {
            }
            timer1.Stop();
        }
コード例 #2
0
 /// <summary>
 /// The control_ lost focus.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void Control_LostFocus(object sender, EventArgs e)
 {
     // In case they leave the text box before the timer has expired, call the
     // timer1_tick to update the color wheel with the new data.
     if (timer1.Enabled)
     {
         timer1_Tick(sender, e);
     }
     hsvColor = ColorHandler.RGBtoHSV(this.color);
     updateBar();
     this.Refresh();
 }
コード例 #3
0
        /// <summary>
        /// The get colors.
        /// </summary>
        /// <returns>
        /// </returns>
        private Color[] GetColors()
        {
            Color[] colors = new Color[colorTesselation];

            for (int i = 0; i < colorTesselation; i++)
            {
                int hue = (i * 360) / colorTesselation;
                colors[i] = ColorHandler.HSVtoColor(new ColorHandler.HSV(hue, 100, 100));
            }

            return(colors);
        }
コード例 #4
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;
        }
コード例 #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);
        }
コード例 #6
0
        /// <summary>
        /// The draw bar.
        /// </summary>
        /// <param name="g">
        /// The g.
        /// </param>
        /// <param name="width">
        /// The width.
        /// </param>
        /// <param name="height">
        /// The height.
        /// </param>
        private void DrawBar(Graphics g, int width, int height)
        {
            PointF[] points = new PointF[2];

            for (int i = 0; i < points.Length; i++)
            {
                points[i].X = width / 2;
                points[i].Y = i * height;
            }

            ColorHandler.HSV col = new ColorHandler.HSV(hsvColor.Hue, hsvColor.Saturation, 100);

            using (
                LinearGradientBrush lgb = new LinearGradientBrush(
                    points[0], points[1], ColorHandler.HSVtoColor(col), Color.Black))
            {
                g.FillRectangle(lgb, 0, 0, width, height);
            }
        }
コード例 #7
0
ファイル: ColorWheel.cs プロジェクト: forksnd/Blam_BSP
        /// <summary>
        /// The control_ text changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Control_TextChanged(object sender, EventArgs e)
        {
            if (updatingColors)
            {
                return;
            }

            Control c = (Control)sender;

            try
            {
                if ((Color)c.Tag == Color.White)
                {
                    this.color.Alpha = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Red)
                {
                    this.color.Red = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Green)
                {
                    this.color.Green = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Blue)
                {
                    this.color.Blue = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                this.hsvColor = ColorHandler.RGBtoHSV(this.color);
                updateBar();
            }
            catch
            {
            }
        }
コード例 #8
0
ファイル: ColorWheel.cs プロジェクト: forksnd/Blam_BSP
 /// <summary>
 /// The control_ lost focus.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void Control_LostFocus(object sender, EventArgs e)
 {
     hsvColor = ColorHandler.RGBtoHSV(this.color);
     updateBar();
     this.Refresh();
 }
コード例 #9
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;
 }