Пример #1
0
        private PointF GetColorLocation(HSLManager _manager)
        {
            double angle          = (_manager.H * Math.PI) / 180;
            double locationRadius = _radius * _manager.S;

            return(GetColorLocation(angle, locationRadius));
        }
Пример #2
0
 static HSLManager()
 {
     Empty = new HSLManager
     {
         IsEmpty = true
     };
 }
Пример #3
0
        /// <summary>Raises the <see cref="ColorChanged" /> event.</summary>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void OnColorChanged(EventArgs e)
        {
            if (!LockUpdates)
            {
                HslManager = new HSLManager(Color);
            }

            Refresh();
            EventHandler handler = (EventHandler)Events[EventColorChanged];

            handler?.Invoke(this, e);
        }
Пример #4
0
            public override bool Equals(object obj)
            {
                bool result;

                if (obj is HSLManager)
                {
                    HSLManager _manager = (HSLManager)obj;
                    result = this == _manager;
                }
                else
                {
                    result = false;
                }

                return(result);
            }
Пример #5
0
        private void DrawColorPicker(PaintEventArgs e, HSLManager _manager, bool includeFocus)
        {
            var x = 0;
            var y = 0;

            switch (_pickType)
            {
            case PickerType.Rectangle:
            {
                x = _mousePosition.X;
                y = _mousePosition.Y;

                break;
            }

            case PickerType.Wheel:
            {
                PointF location = GetColorLocation(_manager);

                if (!float.IsNaN(location.X) && !float.IsNaN(location.Y))
                {
                    x = (int)location.X - (SelectionSize / 2);
                    y = (int)location.Y - (SelectionSize / 2);
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            // Create the button path
            GraphicsPath _buttonGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(new Rectangle(x - (SelectionSize / 2), y - (SelectionSize / 2), SelectionSize, SelectionSize), 10, 1, ShapeTypes.Rounded);

            // Draw button
            e.Graphics.FillPath(new SolidBrush(_buttonColor), _buttonGraphicsPath);

            // Draw border
            VisualBorderRenderer.DrawBorderStyle(e.Graphics, _pickerBorder, _buttonGraphicsPath, MouseState);

            if (Focused && includeFocus)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle(x - 1, y - 1, SelectionSize + 2, SelectionSize + 2));
            }
        }
Пример #6
0
        private void SetColor(Point point)
        {
            if (_pickType == PickerType.Rectangle)
            {
                LockUpdates = true;
                Color       = ColorUtil.CursorPointerColor();
                LockUpdates = false;
            }
            else
            {
                double dx         = Math.Abs(point.X - _centerPoint.X - Padding.Left);
                double dy         = Math.Abs(point.Y - _centerPoint.Y - Padding.Top);
                double angle      = (Math.Atan(dy / dx) / Math.PI) * 180;
                double distance   = Math.Pow(Math.Pow(dx, 2) + Math.Pow(dy, 2), 0.5);
                double saturation = distance / _radius;

                if (distance < 6)
                {
                    saturation = 0; // snap to center
                }

                if (point.X < _centerPoint.X)
                {
                    angle = 180 - angle;
                }

                if (point.Y > _centerPoint.Y)
                {
                    angle = 360 - angle;
                }

                LockUpdates = true;
                HslManager  = new HSLManager(angle, saturation, 0.5);
                Color       = HslManager.ToRgbColor();
                LockUpdates = false;
            }
        }