Пример #1
0
        public void Remove(GradientKey gk)
        {
            gk.ColorChanged    -= new EventHandler(OnDataChanged);
            gk.PositionChanged -= new EventHandler(KeySequenceChanged);

            base.List.Remove(gk);
        }
Пример #2
0
        public void Insert(int index, GradientKey gk)
        {
            gk.ColorChanged    += new EventHandler(OnDataChanged);
            gk.PositionChanged += new EventHandler(KeySequenceChanged);

            base.List.Insert(index, gk);
            KeySequenceChanged();
        }
Пример #3
0
 /// <summary>
 /// construct from a given GradientKey instance
 /// </summary>
 /// <param name="fromKey">key to construct from</param>
 public GradientKey(
     GradientKey fromKey)
 {
     mPosition       = fromKey.Position;
     mColor          = fromKey.KeyColor;
     mBounds         = Rectangle.Empty;
     mBoundHash      = 0;
     PositionChanged = fromKey.PositionChanged;
     ColorChanged    = fromKey.ColorChanged;
 }
Пример #4
0
        /// <summary>
        /// construct from a given GradientKey instance
        /// </summary>
        /// <param name="fromKey">key to construct from</param>
        public GradientKey(
			GradientKey fromKey)
        {
            mPosition = fromKey.Position;
            mColor = fromKey.KeyColor;
            mBounds = Rectangle.Empty;
            mBoundHash = 0;
            PositionChanged = fromKey.PositionChanged;
            ColorChanged = fromKey.ColorChanged;
        }
Пример #5
0
        public int Add(GradientKey gk)
        {
            gk.ColorChanged    += new EventHandler(OnDataChanged);
            gk.PositionChanged += new EventHandler(KeySequenceChanged);

            int n = base.List.Add(gk);

            KeySequenceChanged();

            return(n);
        }
Пример #6
0
        /// <summary>
        /// add a new gradient key at the cursor's point on the screen (mapped to
        /// the gradient view area)
        /// </summary>
        /// <returns>index of new key</returns>
        internal Int32 addNewKeyAtCursor()
        {
            Rectangle gradientViewRect = getGradientViewRect();
            Point     clientPoint      = PointToClient(Cursor.Position);

            // add a new key, set to the colour at the point clicked
            GradientKey newKey = new GradientKey();

            newKey.Position = ((1.0 / (Double)gradientViewRect.Width) * (Double)(clientPoint.X));
            newKey.KeyColor = getColorAtPoint(newKey.Position);

            return(mGradientKeyCollection.Add(newKey));
        }
Пример #7
0
        /// <summary>
        /// Compares two gradient keys (positions) and returns standard IComparable values
        /// for use with sorting etc
        /// </summary>
        /// <param name="keyB">key to compare against</param>
        /// <returns>using Position values, -1 if this key is less that the given, 0 if same, 1 if greater</returns>
        public int CompareTo(
            object keyB)
        {
            GradientKey gkB = (GradientKey)keyB;

            if (mPosition < gkB.Position)
            {
                return(-1);
            }
            else if (mPosition == gkB.Position)
            {
                return(0);
            }

            return(1);
        }
Пример #8
0
 public bool Contains(GradientKey value)
 {
     return(base.List.Contains(value as object));
 }
Пример #9
0
        public void AddRange(GradientKey[] items)
        {
            foreach (GradientKey gk in items)
            {
                gk.ColorChanged += new EventHandler(OnDataChanged);
                gk.PositionChanged += new EventHandler(KeySequenceChanged);

                base.List.Add(gk);
            }

            KeySequenceChanged();
        }
Пример #10
0
        public int Add(GradientKey gk)
        {
            gk.ColorChanged += new EventHandler(OnDataChanged);
            gk.PositionChanged += new EventHandler(KeySequenceChanged);

            int n = base.List.Add(gk);
            KeySequenceChanged();

            return n;
        }
Пример #11
0
        public void Insert(int index, GradientKey gk)
        {
            gk.ColorChanged += new EventHandler(OnDataChanged);
            gk.PositionChanged += new EventHandler(KeySequenceChanged);

            base.List.Insert(index, gk);
            KeySequenceChanged();
        }
Пример #12
0
 public int IndexOf(GradientKey value)
 {
     return base.List.IndexOf(value);
 }
Пример #13
0
 public bool Contains(GradientKey value)
 {
     return base.List.Contains(value as object);
 }
Пример #14
0
        /// <summary>
        /// publically and internally used function to interpolate the gradient
        /// and return a color value at the given point
        /// </summary>
        /// <param name="value">a value between 0 and 1, 0% and 100% of the gradient</param>
        /// <returns>the interpolated color at this point</returns>
        public Color getColorAtPoint(Double value)
        {
            ArrayList gkArray = mGradientKeyCollection.getSortedArray();

            // continue if we have some keys to work with
            if (gkArray.Count > 0)
            {
                // if only one key, just return that colour
                if (gkArray.Count == 1)
                {
                    return(((GradientKey)gkArray[0]).KeyColor);
                }

                // get the first/last keys to check for out-of-bounds requests
                GradientKey firstKey = gkArray[0] as GradientKey;
                GradientKey lastKey  = gkArray[gkArray.Count - 1] as GradientKey;

                // if value is before the first or after the last key, just return their colours to repeat
                if (value <= firstKey.Position)
                {
                    return(firstKey.KeyColor);
                }
                else if (value >= lastKey.Position)
                {
                    return(lastKey.KeyColor);
                }
                else
                {
                    // go search for the keys that will be used as interpolators
                    for (Int32 i = 0; i < gkArray.Count - 1; i++)
                    {
                        if (((GradientKey)gkArray[i + 1]).Position >= value)
                        {
                            // get the key pair to use
                            GradientKey primary   = gkArray[i] as GradientKey;
                            GradientKey secondary = gkArray[i + 1] as GradientKey;

                            // work out a interpolation pair based on position of keys and value passed
                            Double keyDelta = 1.0 / (secondary.Position - primary.Position);
                            Double interPos = keyDelta * (value - primary.Position);
                            if (interPos > 1.0)
                            {
                                interPos = 1.0;
                            }
                            if (interPos < 0.0)
                            {
                                interPos = 0.0;
                            }
                            Double invInterPos = 1.0 - interPos;

                            // interpolate the keys
                            Double fR = ((Double)primary.KeyColor.R * invInterPos) + ((Double)secondary.KeyColor.R * interPos);
                            Double fG = ((Double)primary.KeyColor.G * invInterPos) + ((Double)secondary.KeyColor.G * interPos);

                            Double fB = 0;
                            if (!mOnlyRedGreen)
                            {
                                fB = ((Double)primary.KeyColor.B * invInterPos) + ((Double)secondary.KeyColor.B * interPos);
                            }

                            // spit out a Color class
                            return(Color.FromArgb((Int32)fR, (Int32)fG, (Int32)fB));
                        }
                    }
                }
            }

            // 'empty' colour
            return(Color.Gray);
        }
Пример #15
0
 public int IndexOf(GradientKey value)
 {
     return(base.List.IndexOf(value));
 }
Пример #16
0
        public void Remove(GradientKey gk)
        {
            gk.ColorChanged -= new EventHandler(OnDataChanged);
            gk.PositionChanged -= new EventHandler(KeySequenceChanged);

            base.List.Remove(gk);
        }
Пример #17
0
        /// <summary>
        /// add a new gradient key at the cursor's point on the screen (mapped to
        /// the gradient view area)
        /// </summary>
        /// <returns>index of new key</returns>
        internal Int32 addNewKeyAtCursor()
        {
            Rectangle gradientViewRect = getGradientViewRect();
            Point clientPoint = PointToClient(Cursor.Position);

            // add a new key, set to the colour at the point clicked
            GradientKey newKey = new GradientKey();
            newKey.Position = ((1.0 / (Double)gradientViewRect.Width) * (Double)(clientPoint.X));
            newKey.KeyColor = getColorAtPoint(newKey.Position);

            return mGradientKeyCollection.Add(newKey);
        }