Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Takes the value to use and update the slider with it.
        /// </summary>
        /// <param name="valueToUse">The value to use.</param>
        private void TakeValue(float valueToUse)
        {
            switch (this.drawStyle)
            {
            case DrawStyle.Hue:
                this.HSL.H = valueToUse;
                this.RGBA  = AdobeColors.HSLToRGB(HSL);
                break;

            case DrawStyle.Saturation:
                this.HSL.S = valueToUse;
                this.RGBA  = AdobeColors.HSLToRGB(HSL);
                break;

            case DrawStyle.Brightness:
                this.HSL.L = valueToUse;
                this.RGBA  = AdobeColors.HSLToRGB(HSL);
                break;

            case DrawStyle.Red:
                this.RGBA.UpdateR((byte)valueToUse);
                this.HSL = AdobeColors.RGBToHSL(this.RGBA);
                break;

            case DrawStyle.Green:
                this.RGBA.UpdateG((byte)valueToUse);
                this.HSL = AdobeColors.RGBToHSL(this.RGBA);
                break;

            case DrawStyle.Blue:
                this.RGBA.UpdateB((byte)valueToUse);
                this.HSL = AdobeColors.RGBToHSL(this.RGBA);
                break;
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Takes the value that came from the relative position of the mouse , to update color.
        /// </summary>
        /// <param name="newValue">The new value.</param>
        private void TakeValue(DVector2 newValue)
        {
            switch (this.drawStyle)
            {
            case DrawStyle.Hue:
                HSL.S     = newValue.X;
                HSL.L     = 1 - newValue.Y;
                this.RGBA = AdobeColors.HSLToRGB(HSL);
                break;

            case DrawStyle.Saturation:
                HSL.H     = newValue.X;
                HSL.L     = 1 - newValue.Y;
                this.RGBA = AdobeColors.HSLToRGB(HSL);
                break;

            case DrawStyle.Brightness:
                HSL.H     = newValue.X;
                HSL.S     = 1 - newValue.Y;
                this.RGBA = AdobeColors.HSLToRGB(HSL);
                break;

            case DrawStyle.Red:
                this.RGBA.UpdateG((byte)(1 - newValue.Y));
                this.RGBA.UpdateB((byte)newValue.X);
                HSL = AdobeColors.RGBToHSL(this.RGBA);
                break;

            case DrawStyle.Green:
                this.RGBA.UpdateB((byte)newValue.X);
                this.RGBA.UpdateR((byte)(1 - newValue.Y));
                HSL = AdobeColors.RGBToHSL(this.RGBA);
                break;

            case DrawStyle.Blue:
                this.RGBA.UpdateR((byte)newValue.X);
                this.RGBA.UpdateG((byte)(1 - newValue.Y));
                HSL = AdobeColors.RGBToHSL(this.RGBA);
                break;
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 8
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);
                }
            }
        }
Ejemplo n.º 9
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);
                }
            }
        }