Esempio n. 1
0
        static TabStripCloseButton()
        {
            ColorHLS hls = new ColorHLS(SystemColors.Highlight);
            hls.Lighten(0.3f);
            hls.Alpha = 150;

            _HighLightColor = hls.Color;
        }
Esempio n. 2
0
        public static ColorHLS[] CreateGradientColorArray(ColorHLS[] colors, int stepCount)
        {
            if (stepCount == 0 || colors.Length == 0)
            {
                return(new ColorHLS[0]);
            }
            if (colors.Length == 1)
            {
                return(colors);
            }
            if (stepCount == 1)
            {
                return(new ColorHLS[] { new ColorHLS(ColorUtils.BlendColors(colors[0].Color, colors[colors.Length - 1].Color, 50)) });
            }

            ColorHLS[] retColors = new ColorHLS[stepCount];


            float step        = stepCount / (float)(colors.Length - 1);
            int   currentStep = 0;

            for (int i = 0; i < colors.Length - 1; i++)
            {
                float r = colors[i].Red;
                float g = colors[i].Green;
                float b = colors[i].Blue;

                ColorHLS c1    = colors[i];
                ColorHLS c2    = colors[i + 1];
                float    stepR = (c2.Red - c1.Red) / step;
                float    stepG = (c2.Green - c1.Green) / step;
                float    stepB = (c2.Blue - c1.Blue) / step;

                int count = (int)(step * (i + 1));
                int k     = (int)(step * i);
                while (k < count)
                {
                    retColors[currentStep] = new ColorHLS(255, (byte)r, (byte)g, (byte)b);
                    r += stepR;
                    g += stepG;
                    b += stepB;
                    currentStep++;
                    k++;
                }
            }
            retColors[stepCount - 1] = colors[colors.Length - 1].Clone();

            return(retColors);
        }
Esempio n. 3
0
        public static float[] GetGradientColorStep(ColorHLS startColor, ColorHLS endColor, int stepCount)
        {
            if (stepCount == 0)
            {
                return new float[0];
            }
            if (stepCount == 1)
            {
                return new float[] { 0 };
            }

            float stepR = (endColor.Red - startColor.Red) / (float)stepCount;
            float stepG = (endColor.Green - startColor.Green) / (float)stepCount;
            float stepB = (endColor.Blue - startColor.Blue) / (float)stepCount;

            return new float[] { stepR, stepG, stepB };
        }
Esempio n. 4
0
        public static float[] GetGradientColorStep(ColorHLS startColor, ColorHLS endColor, int stepCount)
        {
            if (stepCount == 0)
            {
                return(new float[0]);
            }
            if (stepCount == 1)
            {
                return(new float[] { 0 });
            }

            float stepR = (endColor.Red - startColor.Red) / (float)stepCount;
            float stepG = (endColor.Green - startColor.Green) / (float)stepCount;
            float stepB = (endColor.Blue - startColor.Blue) / (float)stepCount;

            return(new float[] { stepR, stepG, stepB });
        }
Esempio n. 5
0
        public static float[,] GetGradientColorSteps(ColorHLS startColor, ColorHLS endColor, int stepCount)
        {
            if (stepCount == 0)
            {
                return new float[0,0];
            }

            float r = startColor.Red;
            float g = startColor.Green;
            float b = startColor.Blue;

            float[,] steps = new float[stepCount, 3];

            if (stepCount == 1)
            {
                for (int i = 0; i < stepCount; i++)
                {
                    steps[i, 0] = r;
                    steps[i, 1] = g;
                    steps[i, 2] = b;
                }
                return steps;
            }

            float stepR = (endColor.Red - startColor.Red) / (float)stepCount;
            float stepG = (endColor.Green - startColor.Green) / (float)stepCount;
            float stepB = (endColor.Blue - startColor.Blue) / (float)stepCount;

            for (int i = 0; i < stepCount; i++)
            {
                steps[i, 0] = r;
                steps[i, 1] = g;
                steps[i, 2] = b;

                r += stepR;
                g += stepG;
                b += stepB;
            }

            return steps;
        }
Esempio n. 6
0
        public static float[,] GetGradientColorSteps(ColorHLS startColor, ColorHLS endColor, int stepCount)
        {
            if (stepCount == 0)
            {
                return(new float[0, 0]);
            }

            float r = startColor.Red;
            float g = startColor.Green;
            float b = startColor.Blue;

            float[,] steps = new float[stepCount, 3];

            if (stepCount == 1)
            {
                for (int i = 0; i < stepCount; i++)
                {
                    steps[i, 0] = r;
                    steps[i, 1] = g;
                    steps[i, 2] = b;
                }
                return(steps);
            }

            float stepR = (endColor.Red - startColor.Red) / (float)stepCount;
            float stepG = (endColor.Green - startColor.Green) / (float)stepCount;
            float stepB = (endColor.Blue - startColor.Blue) / (float)stepCount;

            for (int i = 0; i < stepCount; i++)
            {
                steps[i, 0] = r;
                steps[i, 1] = g;
                steps[i, 2] = b;

                r += stepR;
                g += stepG;
                b += stepB;
            }

            return(steps);
        }
Esempio n. 7
0
        public static ColorHLS[] CreateGradientColorArray(ColorHLS startColor, ColorHLS endColor, int stepCount)
        {
            if (stepCount == 0)
            {
                return new ColorHLS[0];
            }
            if (stepCount == 1)
            {
                return new ColorHLS[] { new ColorHLS(255, (byte)((startColor.Red + endColor.Red) / 2), (byte)((startColor.Green + endColor.Green) / 2), (byte)((startColor.Blue + endColor.Blue) / 2)) };
            }

            float stepR = (endColor.Red - startColor.Red) / (float)stepCount;
            float stepG = (endColor.Green - startColor.Green) / (float)stepCount;
            float stepB = (endColor.Blue - startColor.Blue) / (float)stepCount;

            float r = startColor.Red;
            float g = startColor.Green;
            float b = startColor.Blue;

            ColorHLS[] colors = new ColorHLS[stepCount];
            for (int i = 0; i < stepCount - 1; i++)
            {
                colors[i] = new ColorHLS(
                    255,
                    (byte)Math.Round(r, MidpointRounding.ToEven),
                    (byte)Math.Round(g, MidpointRounding.ToEven),
                    (byte)Math.Round(b, MidpointRounding.ToEven)
                    );

                r += stepR;
                g += stepG;
                b += stepB;
            }
            colors[colors.Length - 1] = endColor;

            return colors;
        }
Esempio n. 8
0
        public static ColorHLS[] CreateGradientColorArray(ColorHLS startColor, ColorHLS endColor, int stepCount)
        {
            if (stepCount == 0)
            {
                return(new ColorHLS[0]);
            }
            if (stepCount == 1)
            {
                return(new ColorHLS[] { new ColorHLS(255, (byte)((startColor.Red + endColor.Red) / 2), (byte)((startColor.Green + endColor.Green) / 2), (byte)((startColor.Blue + endColor.Blue) / 2)) });
            }

            float stepR = (endColor.Red - startColor.Red) / (float)stepCount;
            float stepG = (endColor.Green - startColor.Green) / (float)stepCount;
            float stepB = (endColor.Blue - startColor.Blue) / (float)stepCount;

            float r = startColor.Red;
            float g = startColor.Green;
            float b = startColor.Blue;

            ColorHLS[] colors = new ColorHLS[stepCount];
            for (int i = 0; i < stepCount - 1; i++)
            {
                colors[i] = new ColorHLS(
                    255,
                    (byte)Math.Round(r, MidpointRounding.ToEven),
                    (byte)Math.Round(g, MidpointRounding.ToEven),
                    (byte)Math.Round(b, MidpointRounding.ToEven)
                    );

                r += stepR;
                g += stepG;
                b += stepB;
            }
            colors[colors.Length - 1] = endColor;

            return(colors);
        }
Esempio n. 9
0
        public void DrawGlyph(Graphics gfx)
        {
            if (_IsMouseOver)
            {
                ColorHLS hls = new ColorHLS(SystemColors.Highlight);
                hls.Lighten(0.3f);
                hls.Alpha = 150;

                gfx.FillRectangle(new SolidBrush(hls.Color), glyphRect);

                Rectangle borderRect = glyphRect;

                borderRect.Width--;
                borderRect.Height--;

                gfx.DrawRectangle(SystemPens.Highlight, borderRect);
            }

            SmoothingMode bak = gfx.SmoothingMode;

            gfx.SmoothingMode = SmoothingMode.Default;

            using (Pen pen = new Pen(Color.Black))
            {
                pen.Width = 2;

                gfx.DrawLine(pen, new Point(glyphRect.Left + (glyphRect.Width / 3) - 2, glyphRect.Height / 2-1),
                    new Point(glyphRect.Right - (glyphRect.Width / 3), glyphRect.Height / 2-1));
            }

            gfx.FillPolygon(Brushes.Black, new Point[]{
                new Point(glyphRect.Left + (glyphRect.Width / 3)-2, glyphRect.Height / 2+2),
                new Point(glyphRect.Right - (glyphRect.Width / 3), glyphRect.Height / 2+2),
                new Point(glyphRect.Left + glyphRect.Width / 2-1,glyphRect.Bottom-4)});

            gfx.SmoothingMode = bak;
        }
Esempio n. 10
0
            protected override void OnMouseDown(MouseEventArgs e)
            {
                base.OnMouseDown(e);

                _previusColor = _currentColor.Clone();
                MouseEvent(e);
                _onDrag = true;
            }
Esempio n. 11
0
 private void ChangeCurrentColor(ColorHLS color)
 {
     throw new NotImplementedException();
 }
Esempio n. 12
0
 private void ChangeBaseColor(ColorHLS color)
 {
     FillBuffer();
     this.Invalidate();
 }
Esempio n. 13
0
 private void SetValue(float value)
 {
     float y = -3;
     switch (_colorMode)
     {
         default:
         case ColorSliderMode.Hue:
             value %= 360;
             y = 255- (((value / 359) * 255)+3);
             _hue = value;
             break;
         case ColorSliderMode.Saturation:
             if (value < 0 || value > 1)
             {
                 throw new ArgumentOutOfRangeException("value");
             }
             y = (((1 - value) * 255))-3;
             _saturation = value;
             break;
         case ColorSliderMode.Brightness:
             if (value < 0 || value > 1)
             {
                 throw new ArgumentOutOfRangeException("value");
             }
             y = ((1 - value) * 255)-3;
             _luminance = value;
             break;
     }
     _cursorRect.Y = (int)y;
     _currentColor = GetColorAt(1, _cursorRect.Y + 3);
     this.Invalidate();
 }
Esempio n. 14
0
            public ColorSlider(ColorSliderMode colorMode)
            {
                _colorMode = colorMode;

                _baseColor = new ColorHLS(255, 255, 0, 0);
                _currentColor = _baseColor.Clone();
                _previusColor = _baseColor.Clone();

                this.SetStyle(
                    ControlStyles.AllPaintingInWmPaint |
                    ControlStyles.FixedHeight |
                    ControlStyles.FixedWidth |
                    ControlStyles.OptimizedDoubleBuffer |
                    ControlStyles.UserPaint,
                    true);
                this.Size = new System.Drawing.Size(20, 256);

                _cursorRect = new Rectangle(0, 256-4, 20, 7);
                _onDrag = false;

                _pixBuffer = new PixelBuffer(20, 256);
                FillBuffer();

                this.Invalidate();
            }
Esempio n. 15
0
        public ColorChooseControl()
        {
            InitializeComponent();
            _currentColor = new ColorHLS(255,255, 0, 0);

            lsView.BaseColor = _currentColor;
            hueView.BaseColor = _currentColor;
            saturationView.BaseColor = _currentColor;
            luminanceView.BaseColor = _currentColor;

            hueView.ColorMode = ColorSliderMode.Hue;
            saturationView.ColorMode = ColorSliderMode.Saturation;
            luminanceView.ColorMode = ColorSliderMode.Brightness;

            hueView.Value = 0;
            saturationView.Value = 1;
            luminanceView.Value = 1;

            lsView.ColorChanged += new ColorChangedDelegate(lsView_ColorChanged);
            hueView.ColorChanged += new ColorChangedDelegate(hueView_ColorChanged);
            saturationView.ColorChanged += new ColorChangedDelegate(saturationView_ColorChanged);
            luminanceView.ColorChanged += new ColorChangedDelegate(luminanceView_ColorChanged);

            lsView.Invalidate();

        }
Esempio n. 16
0
        public static ColorHLS[] CreateGradientColorArray(ColorHLS[] colors, int stepCount)
        {
            if (stepCount == 0||colors.Length==0)
            {
                return new ColorHLS[0];
            }
            if (colors.Length == 1)
            {
                return colors;
            }
            if (stepCount == 1)
            {
                return new ColorHLS[] { new ColorHLS(ColorUtils.BlendColors(colors[0].Color,colors[colors.Length-1].Color,50) )};
            }

            ColorHLS[] retColors = new ColorHLS[stepCount];
            

            float step =  stepCount / (float)(colors.Length-1);
            int currentStep = 0;

            for (int i = 0; i < colors.Length-1; i++)
            {
                float r = colors[i].Red;
                float g = colors[i].Green;
                float b = colors[i].Blue;

                ColorHLS c1 = colors[i];
                ColorHLS c2 = colors[i + 1];
                float stepR = (c2.Red - c1.Red) / step;
                float stepG = (c2.Green - c1.Green) / step;
                float stepB = (c2.Blue- c1.Blue) / step;

                int count = (int)(step * (i+1));
                int k = (int)(step * i);
                while (k < count)
                {
                    retColors[currentStep] = new ColorHLS(255, (byte)r, (byte)g, (byte)b);
                    r += stepR;
                    g += stepG;
                    b += stepB;
                    currentStep++;
                    k++;
                }
            }
            retColors[stepCount - 1] = colors[colors.Length - 1].Clone();

            return retColors;
        }
Esempio n. 17
0
            public void SetSaturation(float saturation)
            {
                _cursorRect.X = (int)(255 * saturation) - 4;

                this.Invalidate();

                _currentColor = this.GetColorAt(
                                    _cursorRect.Left + 4,
                                    _cursorRect.Top + 4
                                    );
            }
Esempio n. 18
0
            public void SetHue(float hue)
            {
                _baseColor = new ColorHLS(hue, 0.5f, 1);
                FillBuffer();

                this.Invalidate();

                _currentColor = this.GetColorAt(
                                    _cursorRect.Left + 4,
                                    _cursorRect.Top + 4
                                    );
            }
Esempio n. 19
0
            public ColorPicker()
            {
                _baseColor = new ColorHLS(255,255, 0, 0);
                _currentColor = _baseColor.Clone();
                _previusColor = _baseColor.Clone();
                this.SetStyle(
                    ControlStyles.AllPaintingInWmPaint |
                    ControlStyles.FixedHeight |
                    ControlStyles.FixedWidth |
                    ControlStyles.OptimizedDoubleBuffer |
                    ControlStyles.UserPaint,
                    true);
                this.Size = new System.Drawing.Size(256, 256);

                _cursorRect = new Rectangle(252, -3, 9, 9);
                _onDrag = false;

                _pixBuffer = new PixelBuffer(256, 256);
                FillBuffer();

                

                MouseEvent(new MouseEventArgs(MouseButtons.Left, 1, _cursorRect.X + 4, _cursorRect.Y + 4, 0));

            }
Esempio n. 20
0
 public ColorChangedEventArgs(ColorHLS oldColor, ColorHLS newColor)
 {
     OldColor = oldColor;
     NewColor = newColor;
 }
Esempio n. 21
0
        private void numHue_ValueChanged(object sender, EventArgs e)
        {
            lsView.SetHue((float)numHue.Value);
            hueView.Value = (float)numHue.Value;

            ColorHLS baseColor = new ColorHLS((float)numHue.Value, 0.5f, 1);
            saturationView.BaseColor = baseColor;
            luminanceView.BaseColor = baseColor;

            this.panelColor2.BackColor = lsView.CurrentColor.Color;
        }
Esempio n. 22
0
        void lsView_ColorChanged(object sender, ColorChooseControl.ColorChangedEventArgs e)
        {
            _currentColor = lsView.CurrentColor;

            numR.Value = _currentColor.Red;
            numG.Value = _currentColor.Green;
            numB.Value = _currentColor.Blue;

            numHue.Value = new decimal(lsView.Hue);
            numSat.Value = new decimal(lsView.Saturation * 100);
            numLum.Value = new decimal(lsView.Luminance * 100);
        }
Esempio n. 23
0
            public void SetLuminance(float luminance)
            {
                _cursorRect.Y = 255 - (int)(255 * luminance) - 4;

                this.Invalidate();

                _currentColor = this.GetColorAt(
                                    _cursorRect.Left + 4,
                                    _cursorRect.Top + 4
                                    );
            }
Esempio n. 24
0
            private void FillBuffer()
            {
                ColorHLS[] colors=new ColorHLS[0];

                switch (_colorMode)
                {
                    default:
                    case ColorSliderMode.Hue:
                        colors = ColorUtils.CreateGradientColorArray(
                            new ColorHLS[]
                            {
                                new ColorHLS(255,   255,    0,      0), 
                                new ColorHLS(255,   255,    255,    0),
                                new ColorHLS(255,   0,      255,    0),
                                new ColorHLS(255,   0,      255,    255),
                                new ColorHLS(255,   0,      0,      255),
                                new ColorHLS(255,   255,    0,      255),
                                new ColorHLS(255,   255,    0,      0)
                            },
                            256
                            );
                        break;
                    case ColorSliderMode.Saturation:
                        colors = ColorUtils.CreateGradientColorArray(
                            new ColorHLS[]
                            {
                                new ColorHLS(255,   255,    255,      255), 
                                _baseColor
                            },
                            256
                            );
                        break;
                    case ColorSliderMode.Brightness:
                        colors = ColorUtils.CreateGradientColorArray(
                            new ColorHLS[]
                            {
                                new ColorHLS(255,   0,    0,      0), 
                                _baseColor
                            },
                            256
                            );
                        break;
                }

                //ColorHLS[] colors = ColorUtils.CreateGradientColorArray(new ColorHLS(255,255, 0, 0), new ColorHLS(255,255, 255, 0), 256);
                for (int y = 0; y < this.Height; y++)
                {
                    _pixBuffer.DrawLine(0, this.Height-1-y, this.Width, this.Height-1-y, colors[y]);
                }
            }
Esempio n. 25
0
            private void MouseEvent(MouseEventArgs e)
            {
                Point newPos = new Point(e.X - 4, e.Y - 4);
                if (newPos.X < -4) newPos.X = -4;
                if (newPos.Y < -4) newPos.Y = -4;
                if (newPos.X > (256 - 5)) newPos.X = (256 - 5);
                if (newPos.Y > (256 - 5)) newPos.Y = (256 - 5);
                _cursorRect.Location = newPos;

                _currentColor = GetColorAt(newPos.X + 4, newPos.Y + 4);

                this.Invalidate();

                if (this.ColorChanged != null)
                    this.ColorChanged(this, new ColorChangedEventArgs(_previusColor, _currentColor));
            }
Esempio n. 26
0
            private void FillBuffer()
            {
                ColorHLS startColor=new ColorHLS(255, 255, 255, 255);
                ColorHLS endColor = _baseColor.Clone();
                float[,] colorsStepStart = ColorUtils.GetGradientColorSteps(startColor, new ColorHLS(255,0,0,0), 256);
                float[,] colorsStepEnd = ColorUtils.GetGradientColorSteps(endColor, new ColorHLS(255, 0, 0, 0), 256);
                
                for (int i = 0; i < 256; i++)
                {
                    startColor.SetRGB((byte)colorsStepStart[i, 0], (byte)colorsStepStart[i, 1], (byte)colorsStepStart[i, 2]);
                    endColor.SetRGB((byte)colorsStepEnd[i,0],(byte)colorsStepEnd[i,1],(byte)colorsStepEnd[i,2]);
                    _pixBuffer.DrawLine(0, i, 256, i, startColor, endColor);
                }

            }
Esempio n. 27
0
            private void MouseEvent(MouseEventArgs e)
            {
                Point newPos = new Point(0, e.Y - 3);
                if (newPos.Y < -3) newPos.Y = -3;
                if (newPos.Y > (256 - 4)) newPos.Y = (256 - 4);
                _cursorRect.Location = newPos;

                _currentColor = GetColorAt(1, newPos.Y + 3);

                switch (_colorMode)
                {
                    case ColorSliderMode.Saturation:
                        _saturation =  1-((float)(newPos.Y + 3) / 255);
                        break;
                    case ColorSliderMode.Brightness:
                        _luminance = 1-((float)(newPos.Y + 3) / 255); //_currentColor.Luminance * 2;
                        break;
                    case ColorSliderMode.Hue:
                        _hue = (float)Math.Round(((double)(255 - (newPos.Y + 3)) / 255)*359,MidpointRounding.ToEven); //_currentColor.Hue;
                        break;
                }

                this.Invalidate();

                if (this.ColorChanged != null)
                    this.ColorChanged(this, new ColorChangedEventArgs(_previusColor, _currentColor));
            }