Esempio n. 1
0
        protected override void OnMouseUp(
            MouseEventArgs e)
        {
            if (_draggedPoint == null)
            {
                // add new point in specified position
                Rectangle gradientRect = GetGradientRect();
                if (e.X >= gradientRect.Left && e.X <= gradientRect.Right)
                {
                    //
                    float pos = Math.Min(1f, (e.X - gradientRect.Left) / (float)gradientRect.Width);
                    int   i;
                    for (i = 0; i < _gradientPoints.Count && _gradientPoints[i].Position <= pos; i++)
                    {
                        ;
                    }

                    //
                    AddPoint(i, i == 0 ? pos : pos - _gradientPoints[i - 1].Position);
                }
            }
            else
            {
                _draggedPoint = null;
            }
            base.OnMouseUp(e);
        }
Esempio n. 2
0
 private Color GetPointColor(
     GradientPoint gp,
     Bitmap bmp)
 {
     return(_gradientType == GradientType.InterpolationColors
         ? gp.Color
         : bmp.GetPixel((int)Math.Round((bmp.Width - 1) * gp.Position), 0));
 }
Esempio n. 3
0
 protected virtual void OnPointChanged(
     GradientPoint point)
 {
     if (PointChanged != null)
     {
         PointChanged(this, new GradientPointEventArgs(point));
     }
 }
Esempio n. 4
0
        protected override void OnMouseDown(
            MouseEventArgs e)
        {
            HitTestInfo hti = HitTest(e.X, e.Y);

            if (hti.Point != null)
            {
                _draggedPoint   = hti.Point;
                HighlightedItem = hti.Point;
                SelectedPoint   = hti.Point;
                OnSelectedPointChanged();
            }
            Focus();
            base.OnMouseDown(e);
        }
Esempio n. 5
0
        private PointState GetPointState(
            GradientPoint point)
        {
            var result = PointState.None;

            if (point == _selectedPoint)
            {
                result |= PointState.Selected;
            }
            if (point == _highlightedPoint)
            {
                result |= PointState.Highlighted;
            }
            return(result);
        }
Esempio n. 6
0
        private Rectangle GetPointRect(
            GradientPoint point,
            PointState state,
            Rectangle gradientRect)
        {
            var result = new Rectangle(
                gradientRect.Left + (int)Math.Round(gradientRect.Width * point.Position) - c_MarkWidth / 2,
                Padding.Top + 2,
                c_MarkWidth,
                ClientSize.Height - Padding.Top - Padding.Bottom - 2 - 2);

            if (state != PointState.None)
            {
                result.Inflate(2, 2);
            }
            return(result);
        }
Esempio n. 7
0
        public GradientPointsControl()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.Opaque, true);
            SetStyle(ControlStyles.Selectable, true);
            SetStyle(ControlStyles.DoubleBuffer, true);

            _gradientPoints = new GradientPointCollection(this);
            ResetGradientPoints();
            _startColor = c_DefStartColor;
            _endColor   = c_DefEndColor;
            Padding     = c_DefPadding;

            _selectedPoint = _gradientPoints[0];
        }
Esempio n. 8
0
        private GradientPoint AddPoint(
            int index,
            float posRelativeToLeftPoint)
        {
            _internalChanges = true;

            var gp = new GradientPoint();

            if (index == 0)
            {
                gp.Position = posRelativeToLeftPoint;
                gp.Factor   = posRelativeToLeftPoint;
                gp.Color    = _gradientPoints[0].Color;
            }
            else if (index >= _gradientPoints.Count)
            {
                gp.Position = _gradientPoints[_gradientPoints.Count - 1].Position + posRelativeToLeftPoint;
                gp.Factor   = _gradientPoints[_gradientPoints.Count - 1].Factor + posRelativeToLeftPoint / (1 - _gradientPoints[_gradientPoints.Count - 1].Position) * (1 - _gradientPoints[_gradientPoints.Count - 1].Factor);
                gp.Color    = _gradientPoints[_gradientPoints.Count - 1].Color;
            }
            else
            {
                gp.Position = _gradientPoints[index - 1].Position + posRelativeToLeftPoint;
                gp.Factor   = _gradientPoints[index - 1].Factor + posRelativeToLeftPoint / (_gradientPoints[index].Position - _gradientPoints[index - 1].Position) * (_gradientPoints[index].Factor - _gradientPoints[index - 1].Factor);
                gp.Color    = GetMixedColor(
                    _gradientPoints[index - 1].Color,
                    _gradientPoints[index].Color,
                    posRelativeToLeftPoint / (_gradientPoints[index].Position - _gradientPoints[index - 1].Position));
            }
            _gradientPoints.Insert(index, gp);

            _internalChanges = false;

            SelectedPoint   = gp;
            HighlightedItem = gp;
            Invalidate(GetPointRect(gp, GetGradientRect()));
            OnPointAdded(gp);
            OnSelectedPointChanged();

            return(gp);
        }
Esempio n. 9
0
        /// <summary>
        /// Adds new <see cref="GradientPoint"/> after currently selected point.
        /// </summary>
        /// <returns></returns>
        public GradientPoint AddPoint()
        {
            GradientPoint gp = SelectedPoint;

            if (gp == null)
            {
                return(null);
            }

            int index = GradientPoints.IndexOf(gp);

            if (index == 0)
            {
                return(AddPoint(index + 1, (GradientPoints[index + 1].Position - gp.Position) / 2));
            }
            if (index >= GradientPoints.Count - 1)
            {
                return(AddPoint(index, (gp.Position - GradientPoints[index - 1].Position) / 2));
            }
            return(AddPoint(index + 1, (GradientPoints[index + 1].Position - gp.Position) / 2));
        }
Esempio n. 10
0
 private Rectangle GetPointRect(
     GradientPoint point,
     Rectangle gradientRect)
 {
     return(GetPointRect(point, GetPointState(point), gradientRect));
 }
Esempio n. 11
0
 public GradientPointEventArgs(
     GradientPoint point)
 {
     _point = point;
 }
Esempio n. 12
0
 public HitTestInfo(
     GradientPoint point)
 {
     _area  = HitTestArea.Point;
     _point = point;
 }
Esempio n. 13
0
 public HitTestInfo(
     HitTestArea area)
 {
     _area  = area;
     _point = null;
 }