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
319 public static implicit
operator Color(
string rgbValue)
329 public static implicit
operator Color(
int colorIndex)
353 return "RGBColor:" +
RgbColor.StringValue;
357 return "ThemeColor:" +
ThemeColor.StringValue;
363 return "Undefined Color";
375 return obj is Color color &&
376 Type == color.Type &&
377 Auto == color.Auto &&
378 EqualityComparer<SrgbColor>.Default.Equals(
RgbColor, color.RgbColor) &&
379 EqualityComparer<IndexedColor>.Default.Equals(
IndexedColor, color.IndexedColor) &&
380 EqualityComparer<ThemeColor>.Default.Equals(
ThemeColor, color.ThemeColor) &&
381 EqualityComparer<SystemColor>.Default.Equals(
SystemColor, color.SystemColor) &&
382 Tint == color.Tint &&
392 var hashCode = -1729664991;
393 hashCode = hashCode * -1521134295 +
Type.GetHashCode();
394 hashCode = hashCode * -1521134295 +
Auto.GetHashCode();
395 hashCode = hashCode * -1521134295 + EqualityComparer<AutoColor>.Default.GetHashCode(
AutoColor.
Instance);
396 hashCode = hashCode * -1521134295 + EqualityComparer<SrgbColor>.Default.GetHashCode(
RgbColor);
397 hashCode = hashCode * -1521134295 + EqualityComparer<IndexedColor>.Default.GetHashCode(
IndexedColor);
398 hashCode = hashCode * -1521134295 + EqualityComparer<ThemeColor>.Default.GetHashCode(
ThemeColor);
399 hashCode = hashCode * -1521134295 + EqualityComparer<SystemColor>.Default.GetHashCode(
SystemColor);
400 hashCode = hashCode * -1521134295 +
Tint.GetHashCode();
401 hashCode = hashCode * -1521134295 +
IsDefined.GetHashCode();
418 if (!(obj is Color other))
420 throw new StyleException(
"The provided object to compare is not a Color");
424 int typeCompare =
Type.CompareTo(other.Type);
425 if (typeCompare != 0)
438 return string.Compare(
440 other.RgbColor?.StringValue,
441 StringComparison.OrdinalIgnoreCase);
444 return IndexedColor.ColorValue.CompareTo(other.IndexedColor.ColorValue);
448 int themeCompare =
ThemeColor.ColorValue.CompareTo(other.ThemeColor.ColorValue);
449 if (themeCompare != 0)
454 return Nullable.Compare(
Tint, other.Tint);
458 return SystemColor.ColorValue.CompareTo(other.SystemColor.ColorValue);
461 return string.Compare(
463 other.Value?.StringValue,
464 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 CreateAuto()
Creates an Color with auto=true.
static Color CreateTheme(ThemeColor color, double? tint=null)
Creates an Color from a theme color instance.
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+).
static Color CreateTheme(Theme.ColorSchemeElement themeColor, double? tint=null)
Creates an Color from a theme color scheme element.
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.