9using System.Collections.Generic;
19 public class Color : IComparable
52 public bool Auto {
get;
private set; }
79 public double?
Tint {
get;
set; }
143 #region factory methods
335 public static implicit
operator Color(
string rgbValue)
345 public static implicit
operator Color(
int colorIndex)
369 return "RGBColor:" +
RgbColor.StringValue;
373 return "ThemeColor:" +
ThemeColor.StringValue;
379 return "Undefined Color";
391 return obj is Color color &&
392 Type == color.Type &&
393 Auto == color.Auto &&
394 EqualityComparer<SrgbColor>.Default.Equals(
RgbColor, color.RgbColor) &&
395 EqualityComparer<IndexedColor>.Default.Equals(
IndexedColor, color.IndexedColor) &&
396 EqualityComparer<ThemeColor>.Default.Equals(
ThemeColor, color.ThemeColor) &&
397 EqualityComparer<SystemColor>.Default.Equals(
SystemColor, color.SystemColor) &&
398 Tint == color.Tint &&
408 var hashCode = -1729664991;
409 hashCode = hashCode * -1521134295 +
Type.GetHashCode();
410 hashCode = hashCode * -1521134295 +
Auto.GetHashCode();
411 hashCode = hashCode * -1521134295 + EqualityComparer<AutoColor>.Default.GetHashCode(
AutoColor.
Instance);
412 hashCode = hashCode * -1521134295 + EqualityComparer<SrgbColor>.Default.GetHashCode(
RgbColor);
413 hashCode = hashCode * -1521134295 + EqualityComparer<IndexedColor>.Default.GetHashCode(
IndexedColor);
414 hashCode = hashCode * -1521134295 + EqualityComparer<ThemeColor>.Default.GetHashCode(
ThemeColor);
415 hashCode = hashCode * -1521134295 + EqualityComparer<SystemColor>.Default.GetHashCode(
SystemColor);
416 hashCode = hashCode * -1521134295 +
Tint.GetHashCode();
417 hashCode = hashCode * -1521134295 +
IsDefined.GetHashCode();
434 if (!(obj is Color other))
436 throw new StyleException(
"The provided object to compare is not a Color");
440 int typeCompare =
Type.CompareTo(other.Type);
441 if (typeCompare != 0)
454 return string.Compare(
456 other.RgbColor?.StringValue,
457 StringComparison.OrdinalIgnoreCase);
460 return IndexedColor.ColorValue.CompareTo(other.IndexedColor.ColorValue);
464 int themeCompare =
ThemeColor.ColorValue.CompareTo(other.ThemeColor.ColorValue);
465 if (themeCompare != 0)
470 return Nullable.Compare(
Tint, other.Tint);
474 return SystemColor.ColorValue.CompareTo(other.SystemColor.ColorValue);
477 return string.Compare(
479 other.Value?.StringValue,
480 StringComparison.OrdinalIgnoreCase);
Class representing an automatic color.
static readonly AutoColor Instance
Static instance of the AutoColor class to avoid multiple instances (instances does not deviate).
Compound class representing a color in various representations (RGB, indexed, theme,...
static Color CreateIndexed(IndexedColor color)
Creates an Color from an indexed color.
ThemeColor ThemeColor
Theme-based color when Type is Theme (See Theme.ColorSchemeElement).
static Color CreateTheme(int index, double? tint=null)
Creates an Color from the index of a theme color scheme element.
static Color CreateAuto()
Creates an Color with auto=true.
static Color CreateTheme(ThemeColor color, double? tint=null)
Creates an Color from a theme color instance.
static Color CreateTheme(Theme.ColorSchemeElement index, double? tint=null)
Creates an Color from a theme color scheme element.
SrgbColor RgbColor
RGB/ARGB value when Type is Rgb.
double? Tint
Optional tint value for colors (-1.0 to 1.0), mainly for theme colors Positive values lighten,...
static Color CreateIndexed(int index)
Creates an Color from a color index (0 to 65).
static Color CreateIndexed(IndexedColor.Value indexValue)
Creates an Color from an indexed color value (see IndexedColor.Value).
override int GetHashCode()
Gets the hash code of the instance.
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
bool IsDefined
Checks if this Color is defined (not None).
IColor Value
Gets the color value as IColor interface. If no color was defined (ColorType.None or property IsDefin...
static Color CreateRgb(string rgbValue)
Creates an Color from an RGB string (e.g., "FFAABBCC").
string GetArgbValue()
Gets the ARGB string value of the color, if applicable.
static Color CreateNone()
Creates an Color with no color (empty element).
static Color CreateRgb(SrgbColor color)
Creates an Color from an RGB/ARGB color.
int CompareTo(object obj)
Compares two instances for sorting purpose.
SystemColor SystemColor
System color when Type is System (See SystemColor.Value).
static Color CreateSystem(SystemColor.Value systemColorValue)
Creates an Color from a system color instance.
static Color CreateSystem(SystemColor color)
Creates an Color from a system color.
ColorType Type
The type of color this value represents.
ColorType
Enum defining the type of color representation.
@ Rgb
RGB/ARGB color value.
@ Indexed
Legacy indexed color (0-56+).
bool Auto
Auto attribute - if true, color is automatically determined.
IndexedColor IndexedColor
Indexed color when Type is Indexed (See IndexedColor.Value).
override string ToString()
String representation od a Color instance.
Class representing a generic sRGB color (with or without alpha channel).
Class for exceptions regarding Style incidents.
Class representing an Office theme.
ColorSchemeElement
Enum to define the sequence index of color scheme element, used in the implementations of Interfaces....
Interface to represent non typed color, either defined by the system or the user.