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.GetBrightness().CompareTo(_b.Color.GetBrightness())); }
public int Compare(object a, object b) { ColorWellInfo _a = (ColorWellInfo)a; ColorWellInfo _b = (ColorWellInfo)b; return(_a.UnsortedIndex.CompareTo(_b.UnsortedIndex)); }
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.Color.GetSaturation().CompareTo(_b.Color.GetSaturation())); }
private void UpdatePickColor(Color c) { pickColor = ColorWellFromColor(c); if (null == pickColor) { pickColor = ColorWellFromColor(defaultColor); } }
/// <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(List <Color> customColors, ColorSortOrder colorSortOrder) { int nColors = customColors.Count; ColorWellInfo[] colorWells = new ColorWellInfo[nColors]; for (int i = 0; i < customColors.Count; i++) { colorWells[i] = new ColorWellInfo((Color)customColors[i], i); } SortColorWells(colorWells, colorSortOrder); return(colorWells); }
/// <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> /// 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> /// 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(); } }
/// <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> /// Get the first color well with the specified color. /// There may be multiple color wells with the same color for custom color palettes. /// Note that Color.White != Color.Window even when Color.Window is white! /// </summary> /// <param name="col"></param> /// <returns></returns> private ColorWellInfo ColorWellFromColor(Color col) { if (col == Color.Empty) { ColorWellInfo cwi = new ColorWellInfo(Color.Empty, 0); } else { foreach (ColorWellInfo c in colorWells) { if (c.Color == col) { return(c); } } } return(null); }
/// <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.ColorName); } else { toolTip.SetToolTip(this, ""); } Update(); } }
/// <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: case ColorSet.Continues: nColors = 216; 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; int r = 0, g = 0, b = 0, i = 0; // Get the colors switch (colorSet) { case ColorSet.Continues: int[] ContR = new int[] { 0xCC, 0x66, 0x00, 0xFF, 0x99, 0x33 }; int[] ContG = new int[] { 0xFF, 0xCC, 0x99, 0x66, 0x33, 0x00, 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF }; int[] ContB = new int[] { 0xFF, 0xCC, 0x99, 0x66, 0x33, 0x00, 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF, 0xFF, 0xCC, 0x99, 0x66, 0x33, 0x00 }; for (int y = 0; y < 12; y++) { g = ContG[y]; for (int x = 0; x < 18; x++) { r = ContR[(x / 6) + ((y < 6) ? 0 : 3)]; b = ContB[x]; colorWells[i++] = new ColorWellInfo(Color.FromArgb(r, g, b), i); } } break; case ColorSet.Web: int[] WebSafe = new int[] { 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF }; for (int y = 0; y < 12; y++) { b = WebSafe[y % 6]; for (int x = 0; x < 18; x++) { g = WebSafe[x % 6]; r = (y < 6) ? WebSafe[x / 6] : WebSafe[(x / 6) + 3]; colorWells[i++] = new ColorWellInfo(Color.FromArgb(r, g, b), i); } } 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> /// Draws the ColorWell on the Graphics surface. /// </summary> /// <remarks> /// This method draws the ColorWell as either enabled or disabled. /// It also indicates the currently selected color and the color /// that is ready to chosed (picked) by the mouse or keyboard. /// </remarks> /// <param name="g">Graphics object.</param> /// <param name="enabled">Enable appearance</param> /// <param name="selected">Selected appearance.</param> /// <param name="pickColor">Color used.</param> /// <param name="cwi">ColorWellInfo object.</param> public static void DrawColorWell(System.Drawing.Graphics g, bool enabled, bool selected, bool pickColor, ColorWellInfo cwi) { Rectangle r = cwi.ColorPosition; if (!enabled) { r.Inflate(-SystemInformation.BorderSize.Width, -SystemInformation.BorderSize.Height); ControlPaint.DrawBorder3D(g, r, Border3DStyle.Flat); r.Inflate(-SystemInformation.BorderSize.Width, -SystemInformation.BorderSize.Height); g.FillRectangle(SystemBrushes.Control, r); } else { SolidBrush br = new SolidBrush(cwi.Color); if (pickColor) { ControlPaint.DrawBorder3D(g, r, Border3DStyle.Sunken); r.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height); g.FillRectangle(br, r); } else { if (selected) { ControlPaint.DrawBorder3D(g, r, Border3DStyle.Raised); r.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height); g.FillRectangle(br, r); } else { g.FillRectangle(SystemBrushes.Control, r); r.Inflate(-SystemInformation.BorderSize.Width, -SystemInformation.BorderSize.Height); ControlPaint.DrawBorder3D(g, r, Border3DStyle.Flat); r.Inflate(-SystemInformation.BorderSize.Width, -SystemInformation.BorderSize.Height); g.FillRectangle(br, r); } } br.Dispose(); br = null; } }
/// <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; } }