public int Compare(object a, object b) { ColorWellInfo _a = (ColorWellInfo)a; ColorWellInfo _b = (ColorWellInfo)b; return(_a.distance.CompareTo(_b.distance)); }
public int Compare(object a, object b) { ColorWellInfo _a = (ColorWellInfo)a; ColorWellInfo _b = (ColorWellInfo)b; return(_a.Color.Name.CompareTo(_b.Color.Name)); }
public int Compare(object a, object b) { ColorWellInfo _a = (ColorWellInfo)a; ColorWellInfo _b = (ColorWellInfo)b; return(_a.unsorted_index.CompareTo(_b.unsorted_index)); }
/// <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(); } }
public int Compare(object a, object b) { ColorWellInfo _a = (ColorWellInfo)a; ColorWellInfo _b = (ColorWellInfo)b; return(_a.Color.GetBrightness().CompareTo(_b.Color.GetBrightness())); }
/// <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; } }
public int Compare(object a, object b) { ColorWellInfo _a = (ColorWellInfo)a; ColorWellInfo _b = (ColorWellInfo)b; return(_a.Color.GetSaturation().CompareTo(_b.Color.GetSaturation())); }
/// <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(); }
/// <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); }
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]; } }
/// <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); }
/// <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(); } }
/// <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(); } }
/// <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); } }
/// <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(); } }
/// <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(); } }
/// <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; }
/// <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); }
/// <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(); } }
/// <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(); } }
/// <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; } }
/// <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; } }
/// <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; }
/// <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; }
/// <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; } }
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]; } }