Esempio n. 1
0
        /// <summary>
        /// Handles the Tick event raised by the sliderTimer object. This is
        /// used to guarantee fluidity between two different points on the
        /// color slider when the arrows are being dragged. Without this, the
        /// currently selected color panel and the updated structure values
        /// (RGB/HEX) jump awkwardly between points.
        ///
        /// This will probably be changed to a threaded solution since FXCop
        /// is complaining about the tick frequency.
        /// </summary>
        /// <param name="sender">The object that raised this event.</param>
        /// <param name="e">An EventArgs containing the event data.</param>

        private void sliderTimer_Tick(object sender, System.EventArgs e)
        {
            int difference = Math.Abs(m_currentYValue - m_targetYValue);
            int nextValue  = ( int )Math.Round(( double )difference / 2);

            if (nextValue == 0)
            {
                m_currentYValue = m_targetYValue;
                sliderTimer.Stop();
            }
            else
            {
                if (m_currentYValue < m_targetYValue)
                {
                    m_currentYValue += nextValue;
                }
                else
                {
                    m_currentYValue += -nextValue;
                }
            }

            if (m_currentColorSpace is RgbColorSpace)
            {
                hsbColorSpace.Structure = ColorConverter.RgbToHsb(( RGB )rgbColorSpace.Structure);
            }
            else if (m_currentColorSpace is HsbColorSpace)
            {
                rgbColorSpace.Structure = ColorConverter.HsbToRgb(( HSB )hsbColorSpace.Structure);
            }

            UpdateColorPanels(false, false, true);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the ComponentValueChanged event that the ColorSpace raises
        /// when the value of one of its components is changed by way of a
        /// keyboard user input. The color spaces are synced up and the color
        /// panels updated.
        /// </summary>
        /// <param name="sender">The ColorSpace object that raised the event.</param>
        /// <param name="e">An EventArgs object containing the event data.</param>

        private void ColorSpaceComponentValueChanged(ColorSpace sender, EventArgs e)
        {
            if (sender is RgbColorSpace)
            {
                hsbColorSpace.Structure = ColorConverter.RgbToHsb(( RGB )rgbColorSpace.Structure);
            }
            else if (sender is HsbColorSpace)
            {
                rgbColorSpace.Structure = ColorConverter.HsbToRgb(( HSB )hsbColorSpace.Structure);                    //, ( 255 - ( this.m_currentColorSliderArrowYLocation - m_colorSliderInnerRegion.Top ) ) );
            }

            UpdateColorSliderArrowRegions();
            UpdateColorPanels(true, true, true);
        }
Esempio n. 3
0
        /// <summary>
        /// Updates the color slider.
        /// </summary>

        private void UpdateColorSlider()
        {
            RGB       rgb    = ( RGB )this.rgbColorSpace.Structure;
            HSB       hsb    = ( HSB )this.hsbColorSpace.Structure;
            Rectangle region = new Rectangle(0, -1, 18, 257);

            using (Graphics g = Graphics.FromImage(m_colorSliderBitmap)) {
                if (this.m_currentColorSpace is RgbColorSpace)
                {
                    char dChar = this.m_currentColorSpace.SelectedComponent.DisplayCharacter;
                    int  red   = rgb.Red;
                    int  green = rgb.Green;
                    int  blue  = rgb.Blue;

                    Color startColor;
                    Color endColor;

                    switch (dChar)
                    {
                    case 'R':
                        startColor = Color.FromArgb(0, green, blue);
                        endColor   = Color.FromArgb(255, green, blue);
                        break;

                    case 'G':
                        startColor = Color.FromArgb(red, 0, blue);
                        endColor   = Color.FromArgb(red, 255, blue);
                        break;

                    default:
                        startColor = Color.FromArgb(red, green, 0);
                        endColor   = Color.FromArgb(red, green, 255);
                        break;
                    }

                    using (LinearGradientBrush lgb = new LinearGradientBrush(region, startColor, endColor, 270f)) {
                        g.FillRectangle(lgb, region);
                    }
                }
                else if (this.m_currentColorSpace is HsbColorSpace)
                {
                    if (this.m_currentColorSpace.SelectedComponent.DisplayCharacter == 'H')
                    {
                        Rectangle rect = new Rectangle(0, 0, 20, 256);

                        using (LinearGradientBrush brBrush = new LinearGradientBrush(rect, Color.Blue, Color.Red, 90f, false)) {
                            Color[] colorArray = { Color.Red, Color.Magenta, Color.Blue, Color.Cyan, Color.FromArgb(0, 255, 0), Color.Yellow, Color.Red };
                            float[] posArray   = { 0.0f, 0.1667f, 0.3372f, 0.502f, 0.6686f, 0.8313f, 1.0f };

                            ColorBlend colorBlend = new ColorBlend();
                            colorBlend.Colors           = colorArray;
                            colorBlend.Positions        = posArray;
                            brBrush.InterpolationColors = colorBlend;

                            g.FillRectangle(brBrush, region);
                        }
                    }
                    else if (this.m_currentColorSpace.SelectedComponent.DisplayCharacter == 'B')
                    {
                        RGB sRgb = ColorConverter.HsbToRgb(new HSB(hsb.Hue, hsb.Saturation, 100));
                        RGB eRgb = ColorConverter.HsbToRgb(new HSB(hsb.Hue, hsb.Saturation, 0));

                        using (LinearGradientBrush lgb = new LinearGradientBrush(region, Color.FromArgb(sRgb.Red, sRgb.Green, sRgb.Blue), Color.FromArgb(eRgb.Red, eRgb.Green, eRgb.Blue), 90f)) {
                            g.FillRectangle(lgb, region);
                        }
                    }
                    else
                    {
                        RGB sRgb = ColorConverter.HsbToRgb(new HSB(hsb.Hue, 100, hsb.Brightness));
                        RGB eRgb = ColorConverter.HsbToRgb(new HSB(hsb.Hue, 0, hsb.Brightness));

                        using (LinearGradientBrush lgb = new LinearGradientBrush(region, Color.FromArgb(sRgb.Red, sRgb.Green, sRgb.Blue), Color.FromArgb(eRgb.Red, eRgb.Green, eRgb.Blue), 90f)) {
                            g.FillRectangle(lgb, region);
                        }
                    }
                }
            }

            this.picColorSlider.Image = m_colorSliderBitmap;
        }
Esempio n. 4
0
        private Color CalculateSelectedColor(Point p)
        {
            IColorSpaceStructure selectedColor = null;

            if (m_colorSpace is HsbColorSpace)
            {
                HSB hsb = ( HSB )m_colorSpace.Structure;

                if (m_component == 'H')
                {
                    int brightness = ( int )((( double )255 - p.Y) / 2.55);
                    int saturation = ( int )(( double )p.X / 2.55);

                    selectedColor = new HSB(hsb.Hue, saturation, brightness);
                }
                else if (m_component == 'S')
                {
                    int hue        = ( int )(p.X * (( double )360 / 255));
                    int brightness = ( int )((( double )255 - p.Y) / 2.55);

                    if (hue == 360)
                    {
                        hue = 0;
                    }

                    selectedColor = new HSB(hue, hsb.Saturation, brightness);
                }
                else if (m_component == 'B')
                {
                    int hue        = ( int )(p.X * (( double )360 / 255));
                    int saturation = ( int )((( double )255 - p.Y) / 2.55);

                    if (hue == 360)
                    {
                        hue = 0;
                    }

                    selectedColor = new HSB(hue, saturation, hsb.Brightness);
                }
            }
            else if (m_colorSpace is RgbColorSpace)
            {
                RGB rgb = ( RGB )m_colorSpace.Structure;

                if (m_component == 'R')
                {
                    selectedColor = new RGB(rgb.Red, 255 - p.Y, p.X);
                }
                else if (m_component == 'G')
                {
                    selectedColor = new RGB(255 - p.Y, rgb.Green, p.X);
                }
                else if (m_component == 'B')
                {
                    selectedColor = new RGB(p.X, 255 - p.Y, rgb.Blue);
                }
            }

            RGB crgb;
            HSB hsbSelectedColor;

            if ((hsbSelectedColor = selectedColor as HSB) != null)
            {
                crgb = ColorConverter.HsbToRgb(hsbSelectedColor);
            }
            else
            {
                crgb = ( RGB )selectedColor;
            }

            return(ColorConverter.RgbToColor(crgb));
        }
Esempio n. 5
0
        /// <summary>
        /// Converts the coordinates represented by this color space to its
        /// equivalent HEX representation.
        /// </summary>
        /// <returns>A string containing a hexadecimal value.</returns>

        internal override Color GetColor()
        {
            RGB rgb = ColorConverter.HsbToRgb(new HSB(m_csHue.Value, m_csSaturation.Value, m_csBrightness.Value));

            return(Color.FromArgb(rgb.Red, rgb.Green, rgb.Blue));
        }