Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorPickerPhotoshop"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public ColorPickerPhotoshop(string name) : base(name)
        {
            HSL = new HSL(.3, .4, .5);

            Config.Width = Theme.ControlWidth + Theme.ControlHeight;
            Config.Height = Theme.ControlWidth + Theme.ControlHeight;
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorBoxGradient"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 public ColorBoxGradient(string name) : base(name)
 {
     this.hsl = new HSL { H = 0.3, S = 0.6, L = 0.8 };
     this.rgba = AdobeColors.HSLToRGB(this.hsl);
     this.drawStyle = DrawStyle.Hue;
     Config.Width = Theme.ControlWidth;
     Config.Height = Theme.ControlWidth;
     this.redrawControlFlag = true;
 }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorSliderVertical"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public ColorSliderVertical(string name) : base(name)
        {
            // Initialize Colors
            this.hsl = new HSL { H = 1.0, S = 1.0, L = 1.0 };
            this.rgba = AdobeColors.HSLToRGB(this.hsl);

            // pick a format to show
            this.drawStyle = DrawStyle.Hue;

            this.Padding = 9;

            Config.Width = Theme.ControlHeight;
            Config.Height = Theme.ControlWidth;
        }
Exemple #4
0
        /// <summary>Converts RGB to HSL.</summary>
        /// <remarks>Takes advantage of what is already built in to .NET by using the Color.GetHue, Color.GetSaturation and Color.GetBrightness methods.</remarks>
        /// <param name="colorToConvert">A Color to convert.</param>
        /// <returns>An HSL value.</returns>
        public static HSL RGBToHSL(GUIColor colorToConvert)
        {
            var hsl = new HSL();

            // ReSharper disable JoinDeclarationAndInitializer
            int max, min, diff;

            // ReSharper restore JoinDeclarationAndInitializer

            //	Of our RGB values, assign the highest value to Max, and the Smallest to Min
            if (colorToConvert.R > colorToConvert.G)
            {
                max = colorToConvert.R;
                min = colorToConvert.G;
            }
            else
            {
                max = colorToConvert.G;
                min = colorToConvert.R;
            }

            if (colorToConvert.B > max)
            {
                max = colorToConvert.B;
            }
            else if (colorToConvert.B < min)
            {
                min = colorToConvert.B;
            }

            diff = max - min;

            //	Luminance - a.k.a. Brightness - Adobe photoshop uses the logic that the
            //	site VBspeed regards (regarded) as too primitive = superior decides the
            //	level of brightness.
            hsl.L = (double)max / 255;

            //	Saturation
            if (max == 0)
            {
                hsl.S = 0; //	Protecting from the impossible operation of division by zero.
            }
            else
            {
                hsl.S = (double)diff / max; //	The logic of Adobe Photoshops is this simple.
            }

            //	Hue		R is situated at the angel of 360 degrees;
            //			G 120 degrees
            //			B 240 degrees
            double q;

            if (diff == 0)
            {
                q = 0; // Protecting from the impossible operation of division by zero.
            }
            else
            {
                q = (double)60 / diff;
            }

            if (max == colorToConvert.R)
            {
                if (colorToConvert.G < colorToConvert.B)
                {
                    hsl.H = (360 + (q * (colorToConvert.G - colorToConvert.B))) / 360;
                }
                else
                {
                    hsl.H = q * (colorToConvert.G - colorToConvert.B) / 360;
                }
            }
            else if (max == colorToConvert.G)
            {
                hsl.H = (120 + (q * (colorToConvert.B - colorToConvert.R))) / 360;
            }
            else if (max == colorToConvert.B)
            {
                hsl.H = (240 + (q * (colorToConvert.R - colorToConvert.G))) / 360;
            }
            else
            {
                hsl.H = 0.0;
            }

            return(hsl);
        }
Exemple #5
0
        /// <summary>Fills in the content of the control showing all values of Luminance (0 to 100%) for the given
        /// Hue and Saturation.</summary>
        /// <param name="map">The map to update.</param>
        private void DrawStyleLuminance(ref ColorMap map)
        {
            // Use the H and S values of the current color (m_hsl)
            var colorToConvert = new HSL
            {
                H = this.hsl.H,
                S = this.hsl.S
            };

            // i represents the current line of pixels we want to draw horizontally
            for (var i = 0; i < map.Height; i++)
            {
                // L (Luminance) is based on the current vertical position
                colorToConvert.L = 1.0 - ((double)i / map.Height);

                // Get the Color for this line
                var rgb = AdobeColors.HSLToRGB(colorToConvert);
                for (var l = 0; l < map.Width; l++)
                {
                    map.Set(l, i, rgb);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Fills in the content of the control showing all values of Hue (from 0 to 360) , a rainbow
        /// </summary>
        /// <param name="map">The map to update.</param>
        private static void DrawStyleHue(ref ColorMap map)
        {
            // S and L will both be at 100% for this DrawStyle
            var hsl = new HSL
            {
                S = 1.0,
                L = 1.0
            };

            // i represents the current line of pixels we want to draw horizontally
            for (var i = 0; i < map.Height; i++)
            {
                // H (hue) is based on the current vertical position
                hsl.H = 1.0 - ((double)i / map.Height);

                // Get the Color for this line
                var rgb = AdobeColors.HSLToRGB(hsl);
                for (var l = 0; l < map.Width; l++)
                {
                    map.Set(l, i, rgb);
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Called when graphics resources need to be loaded.
        ///
        /// Use this for the usage of :
        /// - creation of the internal embedded controls.
        /// - setting of the variables and resources in this control
        /// - to load any game-specific graphics resources
        /// - take over the config width and height and use it into State
        /// - overriding how this item looks like , by settings its texture or theme
        ///
        /// Call base.LoadContent before you do your override code, this will cause :
        /// - State.SourceRectangle to be reset to the Config.Size
        /// </summary>
        public override void LoadContent()
        {
            if (this.hsl == null)
            {
                this.hsl = new HSL { H = 1.0, S = 1.0, L = 1.0 };
                this.rgba = AdobeColors.HSLToRGB(this.hsl);
            }

            Config.Width = Theme.ControlHeight;
            Config.Height = Theme.ControlWidth;

            // create left indicator
            this.IndicatorLeft = new ColorSliderVerticalIndicator(Name + "-indicatorLeft")
            {
                Side = Side.Left,
                Manager = Manager
            };
            this.AddControl(this.IndicatorLeft);

            // create right indicator
            this.IndicatorRight = new ColorSliderVerticalIndicator(Name + "-indicatorRight")
            {
                Side = Side.Right,
                Manager = Manager
            };
            this.AddControl(this.IndicatorRight);

            this.SetIndicatorPosition(0);

            this.RedrawControl();

            // do the basic stuff
            base.LoadContent();
            this.UpdateDrawPositionByConfigAndParent();
            this.UpdateDrawSizeByConfig();
        }
Exemple #8
0
        /// <summary>Converts RGB to HSL.</summary>
        /// <remarks>Takes advantage of what is already built in to .NET by using the Color.GetHue, Color.GetSaturation and Color.GetBrightness methods.</remarks>
        /// <param name="colorToConvert">A Color to convert.</param>
        /// <returns>An HSL value.</returns>
        public static HSL RGBToHSL(GUIColor colorToConvert)
        {
            var hsl = new HSL();

            // ReSharper disable JoinDeclarationAndInitializer
            int max, min, diff;
            // ReSharper restore JoinDeclarationAndInitializer

            //	Of our RGB values, assign the highest value to Max, and the Smallest to Min
            if (colorToConvert.R > colorToConvert.G)
            {
                max = colorToConvert.R;
                min = colorToConvert.G;
            }
            else
            {
                max = colorToConvert.G;
                min = colorToConvert.R;
            }

            if (colorToConvert.B > max)
            {
                max = colorToConvert.B;
            }
            else if (colorToConvert.B < min)
            {
                min = colorToConvert.B;
            }

            diff = max - min;

            //	Luminance - a.k.a. Brightness - Adobe photoshop uses the logic that the
            //	site VBspeed regards (regarded) as too primitive = superior decides the 
            //	level of brightness.
            hsl.L = (double)max / 255;

            //	Saturation
            if (max == 0)
            {
                hsl.S = 0; //	Protecting from the impossible operation of division by zero.
            }
            else
            {
                hsl.S = (double)diff / max; //	The logic of Adobe Photoshops is this simple.
            }

            //	Hue		R is situated at the angel of 360 degrees; 
            //			G 120 degrees
            //			B 240 degrees
            double q;
            if (diff == 0)
            {
                q = 0; // Protecting from the impossible operation of division by zero.
            }
            else
            {
                q = (double)60 / diff;
            }

            if (max == colorToConvert.R)
            {
                if (colorToConvert.G < colorToConvert.B)
                {
                    hsl.H = (360 + (q * (colorToConvert.G - colorToConvert.B))) / 360;
                }
                else
                {
                    hsl.H = q * (colorToConvert.G - colorToConvert.B) / 360;
                }
            }
            else if (max == colorToConvert.G)
            {
                hsl.H = (120 + (q * (colorToConvert.B - colorToConvert.R))) / 360;
            }
            else if (max == colorToConvert.B)
            {
                hsl.H = (240 + (q * (colorToConvert.R - colorToConvert.G))) / 360;
            }
            else
            {
                hsl.H = 0.0;
            }

            return hsl;
        }
Exemple #9
0
        /// <summary>
        /// Converts a color from HSL to RGB. </summary>
        /// <remarks>Adapted from the algorithm in Foley and Van-Dam.</remarks>
        /// <param name="colorToConvert">The HSL value.</param>
        /// <returns>A Color structure containing the equivalent RGB values.</returns>
        public static GUIColor HSLToRGB(HSL colorToConvert)
        {
#if DEBUG
            if (colorToConvert == null)
            {
                throw new ArgumentNullException("colorToConvert");
            }
#endif

            // ReSharper disable JoinDeclarationAndInitializer
            int max, mid, min;
            double q;

            // ReSharper restore JoinDeclarationAndInitializer
            max = Round(colorToConvert.L * 255);
            min = Round((1.0 - colorToConvert.S) * (colorToConvert.L / 1.0) * 255);
            q = (double)(max - min) / 255;

            if (colorToConvert.H >= 0 && colorToConvert.H <= (double)1 / 6)
            {
                mid = Round((((colorToConvert.H - 0) * q) * 1530) + min);
                return GUIColor.FromARGB(max, mid, min);
            }

            if (colorToConvert.H <= (double)1 / 3)
            {
                mid = Round((-((colorToConvert.H - ((double)1 / 6)) * q) * 1530) + max);
                return GUIColor.FromARGB(mid, max, min);
            }

            if (colorToConvert.H <= 0.5)
            {
                mid = Round((((colorToConvert.H - ((double)1 / 3)) * q) * 1530) + min);
                return GUIColor.FromARGB(min, max, mid);
            }

            if (colorToConvert.H <= (double)2 / 3)
            {
                mid = Round((-((colorToConvert.H - 0.5) * q) * 1530) + max);
                return GUIColor.FromARGB(min, mid, max);
            }

            if (colorToConvert.H <= (double)5 / 6)
            {
                mid = Round((((colorToConvert.H - ((double)2 / 3)) * q) * 1530) + min);
                return GUIColor.FromARGB(mid, min, max);
            }

            if (colorToConvert.H <= 1.0)
            {
                mid = Round((-((colorToConvert.H - ((double)5 / 6)) * q) * 1530) + max);
                return GUIColor.FromARGB(max, min, mid);
            }

            return GUIColor.FromARGB(0, 0, 0);
        }
Exemple #10
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            this.colorBoxGradient.HSL = this.slider.HSL;
            this.colorBoxSolid.HSL = this.colorBoxGradient.HSL;
        }
Exemple #11
0
        /// <summary>
        /// Draws this control in the style hue.
        /// </summary>
        /// <param name="map">The map to update.</param>
        private void DrawStyleHue(ref ColorMap map)
        {
            var hslStart = new HSL();
            var hslEnd = new HSL();

            hslStart.H = this.hsl.H;
            hslEnd.H = this.hsl.H;

            hslStart.S = 0;
            hslEnd.S = 1;

            for (var y = 0; y < map.Height; y++)
            {
                hslStart.L = (float)y / map.Height;
                hslEnd.L = hslStart.L;

                var rgbStart = AdobeColors.HSLToRGB(hslStart);
                var rgbEnd = AdobeColors.HSLToRGB(hslEnd);

                for (var x = 0; x < map.Width; x++)
                {
                    var lerpValue = 1 - (x / (float)map.Width);

                    // System.Diagnostics.Debug.WriteLine(lerpValue);
                    var rgbValue = AdobeColors.Lerp(rgbStart, rgbEnd, lerpValue);
                    map.Set(x, y, rgbValue);
                }
            }
        }
Exemple #12
0
        /// <summary>
        /// Draws this control in the style saturation.
        /// </summary>
        /// <param name="map">The map to update.</param>
        private void DrawStyleSaturation(ref ColorMap map)
        {
            var hslStart = new HSL();
            var hslEnd = new HSL();
            hslStart.S = this.hsl.S;
            hslEnd.S = this.hsl.S;
            hslStart.L = 1.0;
            hslEnd.L = 0.0;

            for (var x = 0; x < map.Width; x++)
            {
                for (var y = 0; y < map.Height; y++)
                {
                    // Calculate Hue at this line (Saturation and Luminance are constant)
                    hslStart.H = (double)x / map.Width;
                    hslEnd.H = hslStart.H;

                    var rgbStart = AdobeColors.HSLToRGB(hslStart);
                    var rgbEnd = AdobeColors.HSLToRGB(hslEnd);

                    var lerpValue = y / map.Height;

                    var rgbValue = AdobeColors.Lerp(rgbStart, rgbEnd, lerpValue);
                    map.Set(x, y, rgbValue);
                }
            }
        }