Пример #1
0
        private void ColorScroll(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && mCurrentIdx > -1)
            {
                HSLColor oHlc = HSLColor.FromColor(_bColor);

                int idx = (int)Math.Floor(e.Y / (this.Height / 22f));
                int dt  = idx - mCurrentIdx;

                if (dt >= 0 && dt <= 1)
                {
                    idx = mCurrentIdx;
                }

                if (idx > mCurrentIdx)
                {
                    idx -= 1;
                }

                SelectedIndex = Math.Max(Math.Min(idx, 20), 0);

                oHlc.Lightness = 1f - (SelectedIndex * 5f) / 100;

                _selectedColor = oHlc.ToColor();
                SelectedColorChanged?.Invoke(this, _selectedColor);
            }
        }
Пример #2
0
        public static Color InterpolateHslColor(Color color1, Color color2, double lambda)
        {
            HSLColor hslColor1 = HSLColor.FromColor(color1.ToDrawingColor());
            HSLColor hslColor2 = HSLColor.FromColor(color2.ToDrawingColor());

            return(HSLColor.Interpolate(hslColor1, hslColor2, lambda).ToColor().ToMediaColor());
        }
Пример #3
0
        private void SetPickedColor(Color pColor)
        {
            Bitmap cView = new Bitmap(colorBox.Width, colorBox.Height);

            using (Graphics g = Graphics.FromImage(cView))
            {
                g.Clear(pColor);
                using (SolidBrush sb = new SolidBrush(ColorUtils.Invert(pColor)))
                {
                    using (Pen p = new Pen(sb, 1))
                    {
                        g.DrawRectangle(p, new Rectangle(1, 1, cView.Width - 3, cView.Height - 3));
                    }
                }
            }

            HSLColor hlc = HSLColor.FromColor(pColor);
            HSVColor hvc = HSVColor.FromColor(pColor);
            RGBColor rgc = RGBColor.FromColor(pColor);
            HEXColor hxc = HEXColor.FromColor(pColor);

            lbl_HTML.Text = hxc.ToString();
            lbl_RGB.Text  = rgc.ToString();
            lbl_HSL.Text  = hlc.ToString();
            lbl_HSV.Text  = hvc.ToString();

            colorBox.Image?.Dispose();
            colorBox.Image = cView;
        }
Пример #4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            HSLColor oHlc   = HSLColor.FromColor(_bColor);
            float    oLight = oHlc.Lightness;

            float height = this.Height / 22f;

            mCurrentIdx = _selectedIndex;

            for (int i = 0; i <= 20; i++)
            {
                bool c  = false;
                bool fc = (mCurrentIdx < i && mCurrentIdx != -1);

                oHlc.Lightness = 1f - (i * 5f) / 100;

                // 오차범위 계산
                if (_selectedIndex == -1 && Math.Abs(oLight - oHlc.Lightness) <= 0.025)
                {
                    mCurrentIdx = i;
                    c           = true;
                }

                float dHeight = height * (fc ? 1f : 2f);
                float top     = (i + (fc ? 1 : 0)) * height + dHeight / 2f;

                using (SolidBrush sb = new SolidBrush(c ? _bColor : oHlc.ToColor()))
                {
                    using (Pen p = new Pen(sb, dHeight))
                    {
                        g.DrawLine(p, new PointF(0, top), new PointF(this.Width, top));
                    }
                }
            }

            if (mCurrentIdx > -1)
            {
                float top = mCurrentIdx * height;

                oHlc.Lightness = 1f - (mCurrentIdx * 5f) / 100;

                using (SolidBrush sb = new SolidBrush(ColorUtils.Invert(oHlc.ToColor())))
                {
                    using (Pen p = new Pen(sb))
                    {
                        g.DrawRectangle(p, new Rectangle(0, (int)top, this.Width - 1, (int)(height * 2f)));
                    }
                }
            }

            base.OnPaint(e);
        }
Пример #5
0
 public static HSLColor ToHSL(this Color c1)
 {
     return(HSLColor.FromColor(c1));
 }
Пример #6
0
 private void lbl_HSL_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     Copy(HSLColor.FromColor(ldcPlate.SelectedColor));
 }
Пример #7
0
        // 임시 핫키 세팅과 연동 필요함
        private void InitHotKey()
        {
            Keys[]  semi_hkKeys   = new Keys[] { Keys.Left, Keys.Right, Keys.Up, Keys.Down };
            Point[] semi_hkDeltas = new Point[] { new Point(-1, 0), new Point(1, 0), new Point(0, -1), new Point(0, 1) };

            for (int i = 0; i < semi_hkDeltas.Length; i++)
            {
                int idx = i;

                HotkeyManager.Register($"SEMI_{semi_hkKeys[idx].ToString()}", new HotKey()
                {
                    Keys   = new Keys[] { semi_hkKeys[idx] },
                    Action = () =>
                    {
                        if (setting.SemiControl)
                        {
                            Point acPt = Point.Empty;

                            if (HotkeyManager.IsShift())
                            {
                                acPt = new Point(semi_hkDeltas[idx].X * 3, semi_hkDeltas[idx].Y * 3);
                            }

                            SetCursorPosDelta(semi_hkDeltas[idx] + (Size)acPt);
                        }
                    }
                });
            }

            HotkeyManager.Register("Pause", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F1 },
                Action = () =>
                {
                    mPause = !mPause;
                }
            });

            HotkeyManager.Register("ZoomIn", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.Add },
                Action = () =>
                {
                    zoomSlider.Value += 1;
                }
            });

            HotkeyManager.Register("ZoomOut", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.Subtract },
                Action = () =>
                {
                    zoomSlider.Value -= 1;
                }
            });

            HotkeyManager.Register("RGB", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F2 },
                Action = () =>
                {
                    AddColor(RGBColor.FromColor(ldcPlate.SelectedColor));
                }
            });

            HotkeyManager.Register("HEX", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F3 },
                Action = () =>
                {
                    AddColor(HEXColor.FromColor(ldcPlate.SelectedColor));
                }
            });

            HotkeyManager.Register("HSL", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F4 },
                Action = () =>
                {
                    AddColor(HSLColor.FromColor(ldcPlate.SelectedColor));
                }
            });

            HotkeyManager.Register("HSB", new HotKey()
            {
                Keys   = new Keys[] { Keys.None, Keys.F5 },
                Action = () =>
                {
                    AddColor(HSVColor.FromColor(ldcPlate.SelectedColor));
                }
            });
        }