예제 #1
0
                public int Compare(object a, object b)
                {
                    ColorWellInfo _a = (ColorWellInfo)a;
                    ColorWellInfo _b = (ColorWellInfo)b;

                    return(_a.distance.CompareTo(_b.distance));
                }
예제 #2
0
                public int Compare(object a, object b)
                {
                    ColorWellInfo _a = (ColorWellInfo)a;
                    ColorWellInfo _b = (ColorWellInfo)b;

                    return(_a.Color.Name.CompareTo(_b.Color.Name));
                }
예제 #3
0
                public int Compare(object a, object b)
                {
                    ColorWellInfo _a = (ColorWellInfo)a;
                    ColorWellInfo _b = (ColorWellInfo)b;

                    return(_a.unsorted_index.CompareTo(_b.unsorted_index));
                }
예제 #4
0
        /// <summary>
        /// Change the color currently selected.  Does not cause
        /// a ColorChanged event.
        /// </summary>
        /// <param name="newColor"></param>
        private void ChangeColor(ColorWellInfo newColor)
        {
            if (newColor != currentColor)
            {
                if (null != currentColor)
                {
                    Invalidate(currentColor.colorPosition);
                }

                currentColor = newColor;

                if (null != currentColor)
                {
                    Invalidate(currentColor.colorPosition);

                    toolTip.SetToolTip(this, currentColor.Color.Name);
                }
                else
                {
                    toolTip.SetToolTip(this, "");
                }

                Update();
            }
        }
예제 #5
0
                public int Compare(object a, object b)
                {
                    ColorWellInfo _a = (ColorWellInfo)a;
                    ColorWellInfo _b = (ColorWellInfo)b;

                    return(_a.Color.GetBrightness().CompareTo(_b.Color.GetBrightness()));
                }
예제 #6
0
            /// <summary>
            /// Sort the supplied colorWells according to the required sort order.
            /// </summary>
            /// <param name="colorWells"></param>
            /// <param name="colorSortOrder"></param>
            public static void SortColorWells(ColorWellInfo[] colorWells, ColorSortOrder colorSortOrder)
            {
                // Sort them
                switch (colorSortOrder)
                {
                case ColorSortOrder.Brightness:
                    Array.Sort(colorWells, ColorWellInfo.CompareColorBrightness());
                    break;

                case ColorSortOrder.Distance:
                    Array.Sort(colorWells, ColorWellInfo.CompareColorDistance());
                    break;

                case ColorSortOrder.Hue:
                    Array.Sort(colorWells, ColorWellInfo.CompareColorHue());
                    break;

                case ColorSortOrder.Name:
                    Array.Sort(colorWells, ColorWellInfo.CompareColorName());
                    break;

                case ColorSortOrder.Saturation:
                    Array.Sort(colorWells, ColorWellInfo.CompareColorSaturation());
                    break;

                case ColorSortOrder.Unsorted:
                    Array.Sort(colorWells, ColorWellInfo.CompareUnsorted());
                    break;
                }
            }
예제 #7
0
                public int Compare(object a, object b)
                {
                    ColorWellInfo _a = (ColorWellInfo)a;
                    ColorWellInfo _b = (ColorWellInfo)b;

                    return(_a.Color.GetSaturation().CompareTo(_b.Color.GetSaturation()));
                }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the ColorPanel class.
        /// </summary>
        /// <remarks>
        /// The default constructor initializes all fields to their default values.
        /// </remarks>
        public ColorPanel()
        {
            colorWells = ColorWellInfo.GetColorWells(colorSet, colorSortOrder);

            ResetCustomColors();

            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            UpdateBorderSize();

            AutoSizePanel();
        }
예제 #9
0
            /// <summary>
            /// Generate an array of ColorWellInfo from the supplied array of Color.
            /// </summary>
            /// <param name="customColors"></param>
            /// <param name="colorSortOrder"></param>
            /// <returns></returns>
            public static ColorWellInfo[] GetCustomColorWells(Color[] customColors, ColorSortOrder colorSortOrder)
            {
                int nColors = customColors.Length;

                ColorWellInfo[] colorWells = new ColorWellInfo[nColors];

                for (int i = 0; i < customColors.Length; i++)
                {
                    colorWells[i] = new ColorWellInfo(customColors[i], i);
                }

                SortColorWells(colorWells, colorSortOrder);

                return(colorWells);
            }
예제 #10
0
        private void UpdatePickColor(Color c)
        {
            pickColor = ColorWellFromColor(c);

            // if not found then try to find the default color
            if (null == pickColor)
            {
                pickColor = ColorWellFromColor(defaultColor);
            }

            // if still no pickColor then use first in palette
            if (null == pickColor)
            {
                pickColor = colorWells[0];
            }
        }
예제 #11
0
        /// <summary>
        /// Get the sorted index of the color well (not the original index).
        /// </summary>
        /// <param name="col"></param>
        /// <returns></returns>
        private int IndexFromColorWell(ColorWellInfo col)
        {
            int num_colorWells = colorWells.Length;

            int index = -1;

            for (int i = 0; i < num_colorWells; i++)
            {
                if (colorWells[i] == col)
                {
                    index = i;
                }
            }

            return(index);
        }
예제 #12
0
        /// <summary>
        /// Override OnSystemColorsChanged to that the System color palette
        /// can be updated when a user modifies the system colors.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSystemColorsChanged(System.EventArgs e)
        {
            base.OnSystemColorsChanged(e);

            if (colorSet == ColorSet.System)
            {
                // generate new set of system colors
                colorWells = ColorWellInfo.GetColorWells(colorSet, colorSortOrder);
                LayoutColorWells();

                UpdatePickColor();

                FireColorChanged();

                Refresh();
            }
        }
예제 #13
0
        /// <summary>
        /// Overrides OnMouseLeave in order to detect when the mouse
        /// has left the control.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseLeave(System.EventArgs e)
        {
            base.OnMouseLeave(e);

            if (!Enabled)
            {
                return;
            }

            ColorWellInfo invalidColor = currentColor;

            currentColor = null;

            if (null != invalidColor)
            {
                Invalidate(invalidColor.colorPosition);
                Update();
            }
        }
예제 #14
0
        /// <summary>
        /// Overrides the OnMouseMove event in order to track mouse movement.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (!Enabled)
            {
                return;
            }

            Point mousePosition = new Point(e.X, e.Y);

            // Invalidation causes an OnMouseMove event - filter it out so it doesn't
            // interfere with keyboard control
            if (ClientRectangle.Contains(mousePosition) && (lastMousePosition != mousePosition))
            {
                lastMousePosition = mousePosition;

                ColorWellInfo newColor = ColorWellFromPoint(e.X, e.Y);

                ChangeColor(newColor);
            }
        }
예제 #15
0
        /// <summary>
        /// Overrides the OnClick event in order to detect user color selection.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnClick(System.EventArgs e)
        {
            base.OnClick(e);

            if (null != currentColor)
            {
                // invalidate previous pick color
                if (null != pickColor)
                {
                    Invalidate(pickColor.colorPosition);
                }

                // set new pick color
                pickColor = currentColor;

                // invalidate new pick color
                Invalidate(pickColor.colorPosition);

                FireColorChanged();

                //Update();
            }
        }
예제 #16
0
		/// <summary>
		/// Overrides the OnClick event in order to detect user color selection.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnClick(System.EventArgs e)
		{
			base.OnClick(e);

			if( null != currentColor )
			{
				// invalidate previous pick color
				if( null != pickColor )
				{
					Invalidate(pickColor.colorPosition);
				}
				
				// set new pick color
				pickColor = currentColor;

				// invalidate new pick color
				Invalidate(pickColor.colorPosition);

				FireColorChanged();

				//Update();
			}
		}
예제 #17
0
		/// <summary>
		/// Get the sorted index of the color well (not the original index).
		/// </summary>
		/// <param name="col"></param>
		/// <returns></returns>
		private int IndexFromColorWell( ColorWellInfo col )
		{
			int num_colorWells = colorWells.Length;

			int index = -1;

			for( int i=0; i<num_colorWells; i++ )
			{
				if( colorWells[i] == col )
				{
					index = i;
				}
			}

			return index;
		}
예제 #18
0
            /// <summary>
            /// This method return an array of colorWells that belong to the desired ColorSet and
            /// that have been sorted in the desired ColorSortOrder.
            /// </summary>
            /// <param name="colorSet">The color palette to be generated.</param>
            /// <param name="colorSortOrder">The order the generated palette should be sorted.</param>
            /// <returns></returns>
            public static ColorWellInfo[] GetColorWells(ColorSet colorSet, ColorSortOrder colorSortOrder)
            {
                // get array of desired colorWells and sort
                // Could have sort order enum/property
                Array knownColors = Enum.GetValues(typeof(System.Drawing.KnownColor));

                int nColors = 0;

                // How many colors are there?
                switch (colorSet)
                {
                case ColorSet.Web:
                    foreach (KnownColor k in knownColors)
                    {
                        Color c = Color.FromKnownColor(k);
                        if (!c.IsSystemColor && (c.A > 0))
                        {
                            nColors++;
                        }
                    }
                    break;

                case ColorSet.System:
                    foreach (KnownColor k in knownColors)
                    {
                        Color c = Color.FromKnownColor(k);
                        if (c.IsSystemColor && (c.A > 0))
                        {
                            nColors++;
                        }
                    }
                    break;
                }

                ColorWellInfo[] colorWells = new ColorWellInfo[nColors];

                int index = 0;

                // Get the colors
                switch (colorSet)
                {
                case ColorSet.Web:
                    foreach (KnownColor k in knownColors)
                    {
                        Color c = Color.FromKnownColor(k);

                        if (!c.IsSystemColor && (c.A > 0))
                        {
                            colorWells[index] = new ColorWellInfo(c, index);
                            index++;
                        }
                    }
                    break;

                case ColorSet.System:
                    foreach (KnownColor k in knownColors)
                    {
                        Color c = Color.FromKnownColor(k);

                        if (c.IsSystemColor && (c.A > 0))
                        {
                            colorWells[index] = new ColorWellInfo(c, index);
                            index++;
                        }
                    }
                    break;
                }

                SortColorWells(colorWells, colorSortOrder);

                return(colorWells);
            }
예제 #19
0
		/// <summary>
		/// Change the color currently selected.  Does not cause
		/// a ColorChanged event.
		/// </summary>
		/// <param name="newColor"></param>
		private void ChangeColor( ColorWellInfo newColor )
		{
			if( newColor != currentColor )
			{
				if( null != currentColor )
				{
					Invalidate( currentColor.colorPosition );
				}

				currentColor = newColor;

				if( null != currentColor )
				{
					Invalidate( currentColor.colorPosition );

					toolTip.SetToolTip( this, currentColor.Color.Name );
				}
				else
				{
					toolTip.SetToolTip( this, "" );
				}

				Update();
			}
		}
예제 #20
0
		/// <summary>
		/// Overrides OnMouseLeave in order to detect when the mouse
		/// has left the control.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnMouseLeave(System.EventArgs e)
		{
			base.OnMouseLeave(e);

			if( !Enabled )
				return;

			ColorWellInfo invalidColor = currentColor;
			currentColor = null;

			if( null != invalidColor )
			{
				Invalidate( invalidColor.colorPosition );
				Update();
			}
		}
예제 #21
0
		/// <summary>
		/// Overrides OnKeyDown so that a color may be selected using the keyboard.<br></br><br></br>
		/// Use the keys - Left, Right, Up, Down and Enter.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
		{
			base.OnKeyDown(e);

			if( !Enabled )
				return;

			int index = IndexFromColorWell( (null!=currentColor) ? (currentColor) : (pickColor) );

			switch( e.KeyCode )
			{
			case Keys.Enter:
				if( null != currentColor )
				{
					ColorWellInfo oldColor = pickColor;

					pickColor = currentColor;
					FireColorChanged();

					Invalidate( oldColor.colorPosition );
					Invalidate( currentColor.colorPosition );

					Update();
				}
				break;
			case Keys.Left:
				if( index < 0 )
				{
					// start at the last color
					ChangeColor(colorWells[colorWells.Length-1]);
				}
				else
				{
					MoveColumn( index, false );
				}
				break;
			case Keys.Right:
				if( index < 0 || index > (colorWells.Length-1) )
				{
					// start at the first color
					ChangeColor(colorWells[0]);
				}
				else
				{
					MoveColumn( index, true );
				}
				break;
			case Keys.Down:
				if( index < 0 )
				{
					// start at the first color
					ChangeColor(colorWells[0]);
				}
				else
				{
					MoveRow( index, true );
				}
				break;
			case Keys.Up:
				if( index < 0 )
				{
					// start at the last color
					ChangeColor(colorWells[colorWells.Length-1]);
				}
				else
				{
					MoveRow( index, false );
				}
				break;
			}
		}
예제 #22
0
			/// <summary>
			/// Sort the supplied colorWells according to the required sort order.
			/// </summary>
			/// <param name="colorWells"></param>
			/// <param name="colorSortOrder"></param>
			public static void SortColorWells( ColorWellInfo[] colorWells, ColorSortOrder colorSortOrder )
			{
				// Sort them
				switch( colorSortOrder )
				{
				case ColorSortOrder.Brightness:
					Array.Sort(colorWells, ColorWellInfo.CompareColorBrightness());
					break;
				case ColorSortOrder.Distance:
					Array.Sort(colorWells, ColorWellInfo.CompareColorDistance());
					break;
				case ColorSortOrder.Hue:
					Array.Sort(colorWells, ColorWellInfo.CompareColorHue());
					break;
				case ColorSortOrder.Name:
					Array.Sort(colorWells, ColorWellInfo.CompareColorName());
					break;
				case ColorSortOrder.Saturation:
					Array.Sort(colorWells, ColorWellInfo.CompareColorSaturation());
					break;
				case ColorSortOrder.Unsorted:
					Array.Sort(colorWells, ColorWellInfo.CompareUnsorted());
					break;
				}
			}
예제 #23
0
			/// <summary>
			/// Generate an array of ColorWellInfo from the supplied array of Color.
			/// </summary>
			/// <param name="customColors"></param>
			/// <param name="colorSortOrder"></param>
			/// <returns></returns>
			public static ColorWellInfo[] GetCustomColorWells( Color[] customColors, ColorSortOrder colorSortOrder )
			{
				int nColors = customColors.Length;

				ColorWellInfo[] colorWells = new ColorWellInfo[nColors];

				for( int i=0; i<customColors.Length; i++ )
				{
					colorWells[i] = new ColorWellInfo(customColors[i], i);
				}

				SortColorWells(colorWells, colorSortOrder);

				return colorWells;
			}
예제 #24
0
			/// <summary>
			/// This method return an array of colorWells that belong to the desired ColorSet and 
			/// that have been sorted in the desired ColorSortOrder.
			/// </summary>
			/// <param name="colorSet">The color palette to be generated.</param>
			/// <param name="colorSortOrder">The order the generated palette should be sorted.</param>
			/// <returns></returns>
			public static ColorWellInfo[] GetColorWells( ColorSet colorSet, ColorSortOrder colorSortOrder )
			{
				// get array of desired colorWells and sort
				// Could have sort order enum/property
				Array knownColors = Enum.GetValues( typeof(System.Drawing.KnownColor) );

				int nColors = 0;

				// How many colors are there?
				switch( colorSet )
				{
				case ColorSet.Web:
					foreach( KnownColor k in knownColors )
					{
						Color c = Color.FromKnownColor(k);
						if( !c.IsSystemColor && (c.A > 0) )
						{
							nColors++;
						}
					}
					break;
				case ColorSet.System:
					foreach( KnownColor k in knownColors )
					{
						Color c = Color.FromKnownColor(k);
						if( c.IsSystemColor && (c.A > 0) )
						{
							nColors++;
						}
					}
					break;
				}

				ColorWellInfo[] colorWells = new ColorWellInfo[ nColors ];
				
				int index = 0;

				// Get the colors
				switch( colorSet )
				{
				case ColorSet.Web:
					foreach( KnownColor k in knownColors )
					{
						Color c = Color.FromKnownColor(k);

						if( !c.IsSystemColor && (c.A > 0) )
						{
							colorWells[index] = new ColorWellInfo(c,index);
							index++;
						}
					}
					break;
				case ColorSet.System:
					foreach( KnownColor k in knownColors )
					{
						Color c = Color.FromKnownColor(k);

						if( c.IsSystemColor && (c.A > 0) )
						{
							colorWells[index] = new ColorWellInfo(c,index);
							index++;
						}
					}
					break;
				}

				SortColorWells(colorWells, colorSortOrder);

				return colorWells;
			}
예제 #25
0
        /// <summary>
        /// Overrides OnKeyDown so that a color may be selected using the keyboard.<br></br><br></br>
        /// Use the keys - Left, Right, Up, Down and Enter.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (!Enabled)
            {
                return;
            }

            int index = IndexFromColorWell((null != currentColor) ? (currentColor) : (pickColor));

            switch (e.KeyCode)
            {
            case Keys.Enter:
                if (null != currentColor)
                {
                    ColorWellInfo oldColor = pickColor;

                    pickColor = currentColor;
                    FireColorChanged();

                    Invalidate(oldColor.colorPosition);
                    Invalidate(currentColor.colorPosition);

                    Update();
                }
                break;

            case Keys.Left:
                if (index < 0)
                {
                    // start at the last color
                    ChangeColor(colorWells[colorWells.Length - 1]);
                }
                else
                {
                    MoveColumn(index, false);
                }
                break;

            case Keys.Right:
                if (index < 0 || index > (colorWells.Length - 1))
                {
                    // start at the first color
                    ChangeColor(colorWells[0]);
                }
                else
                {
                    MoveColumn(index, true);
                }
                break;

            case Keys.Down:
                if (index < 0)
                {
                    // start at the first color
                    ChangeColor(colorWells[0]);
                }
                else
                {
                    MoveRow(index, true);
                }
                break;

            case Keys.Up:
                if (index < 0)
                {
                    // start at the last color
                    ChangeColor(colorWells[colorWells.Length - 1]);
                }
                else
                {
                    MoveRow(index, false);
                }
                break;
            }
        }
예제 #26
0
		private void UpdatePickColor( Color c )
		{
			pickColor = ColorWellFromColor( c );

			// if not found then try to find the default color
			if( null == pickColor )
			{
				pickColor = ColorWellFromColor( defaultColor );
			}

			// if still no pickColor then use first in palette 
			if( null == pickColor )
			{
				pickColor = colorWells[0];
			}
		}