Пример #1
0
        private GradientPoint AddPoint(
            float position,
            Color color)
        {
            var gp = new GradientPoint {
                Position = position, Color = color, Tag = new GradientStop(position, color)
            };

            gpeMain.GradientPoints.Add(gp);
            return(gp);
        }
Пример #2
0
        /// <summary>
        /// Adds a gradient point to this gradient object.
        /// </summary>
        /// <param name="gradientPos">The position of this gradient point.</param>
        /// <param name="color">The color of this gradient point.</param>
        /// <remarks>
        /// No two gradient points have the same position.
        /// It does not matter which order these gradient points are added.
        /// </remarks>
        public void AddGradientPoint(double gradientPos, Color color)
        {
            var gradientPoint = new GradientPoint(gradientPos, color);

            var s = gradientPoints.BinarySearch(gradientPoint);

            if (s >= 0)
            {
                throw new ArgumentException("All GradientPoints must have unique positions");
            }
            else
            {
                gradientPoints.Insert(~s, gradientPoint);
            }
        }
Пример #3
0
 public Color32 ColorAtX(float x, float alpha)
 {
     for (int i = 0; i < gradientPoints.Length - 1; i++)
     {
         GradientPoint lower = gradientPoints[i];
         GradientPoint upper = gradientPoints[i + 1];
         if (x >= lower.x && x <= upper.x)
         {
             Color result = Color.Lerp(upper.color, lower.color, (upper.x - x) / (upper.x - lower.x));
             result.a = alpha;
             return(result);
         }
     }
     return(UNASSIGNED);
 }
Пример #4
0
        internal void SetBeacon(BeaconData beacon)
        {
            if (beacon.Type == BeaconID.TrackGradientMemory.TrackGradientPoint)
            {
                int param_trackPos = Math.Abs(beacon.Optional % 1000000);
                int param_gradient = beacon.Optional / 1000000;

                int idxOfGradientPtAtHere = _gPtC.IndexOf(param_trackPos);

                if (idxOfGradientPtAtHere > -1) {
                    _gPtC[idxOfGradientPtAtHere] = new GradientPoint(param_gradient, param_trackPos);
                } else {
                    _gPtC.Add(new GradientPoint(param_gradient, param_trackPos));
                }

                OnGradientPointsDataRefreshed(_gPtC);
            }
        }
Пример #5
0
 public void SetGradientStops(GradientStopCollection stops)
 {
     // initialize gpeMain.GradientPoints from ThemeBlend object
     gpeMain.BeginUpdate();
     gpeMain.GradientPoints.Clear();
     if (!IsValid(stops))
     {
         // initialize gpeMain.GradientPoints with default values 0,0 : 1,1
         AddPoint(0, Color.Black);
         AddPoint(1, Color.White);
     }
     else
     {
         foreach (var stop in stops)
         {
             var gp = new GradientPoint {
                 Position = (float)stop.Position, Color = stop.Color, Tag = stop
             };
             gpeMain.GradientPoints.Add(gp);
         }
     }
     gpeMain.SelectedPoint = gpeMain.GradientPoints[0];
     gpeMain.EndUpdate();
 }
Пример #6
0
        /// <summary>
        /// Adds a gradient point to this gradient object.
        ///
        /// No two gradient points have the same position.
        ///
        /// @throw System.ArgumentException if two control points have the same position.
        ///
        /// It does not matter which order these gradient points are added.
        /// </summary>
        /// <param name="point">The gradient point to add</param>
        public void AddGradientPoint(GradientPoint point)
        {
            if (_gradientPoints.Contains(point))
            {
                throw new ArgumentException(
                    String.Format(
                        "Cannont insert GradientPoint({0}, {1}) : Each GradientPoint is required to contain a unique position",
                        point.Position, point.Color));
            }
            else
            {
                _gradientPoints.Add(point);

                // Desc order
                _gradientPoints.Sort(delegate(GradientPoint p1, GradientPoint p2)
                {
                    if (p1.Position > p2.Position)
                        return 1;
                    else if (p1.Position < p2.Position)
                        return -1;
                    else
                        return 0;
                });
            }
        }
Пример #7
0
 internal void AddRange(GradientPoint[] items)
 {
     this._gPts.AddRange(items);
 }
Пример #8
0
 internal void Add(GradientPoint item)
 {
     this._gPts.Add(item);
 }