using System; namespace Terminal.Gui; public partial class View { // TODO: Rename "Color"->"Attribute" given we'll soon have non-color information in Attributes? // TODO: See https://github.com/gui-cs/Terminal.Gui/issues/457 #region ColorScheme private ColorScheme _colorScheme; /// The color scheme for this view, if it is not defined, it returns the 's color scheme. public virtual ColorScheme ColorScheme { get { if (_colorScheme is null) { return SuperView?.ColorScheme; } return _colorScheme; } set { if (_colorScheme != value) { _colorScheme = value; if (Border is { } && Border.LineStyle != LineStyle.None && Border.ColorScheme is { }) { Border.ColorScheme = _colorScheme; } SetNeedsDraw (); } } } /// Determines the current based on the value. /// /// if is or /// if is . If it's /// overridden can return other values. /// public virtual Attribute GetFocusColor () { ColorScheme cs = ColorScheme; if (cs is null) { cs = new (); } return Enabled ? GetColor (cs.Focus) : cs.Disabled; } /// Determines the current based on the value. /// /// if is or /// if is . If it's /// overridden can return other values. /// public virtual Attribute GetHotFocusColor () { ColorScheme cs = ColorScheme ?? new (); return Enabled ? GetColor (cs.HotFocus) : cs.Disabled; } /// Determines the current based on the value. /// /// if is or /// if is . If it's /// overridden can return other values. /// public virtual Attribute GetHotNormalColor () { ColorScheme cs = ColorScheme; if (cs is null) { cs = new (); } return Enabled ? GetColor (cs.HotNormal) : cs.Disabled; } /// Determines the current based on the value. /// /// if is or /// if is . If it's /// overridden can return other values. /// public virtual Attribute GetNormalColor () { ColorScheme cs = ColorScheme; if (cs is null) { cs = new (); } Attribute disabled = new (cs.Disabled.Foreground, cs.Disabled.Background); if (Diagnostics.HasFlag (ViewDiagnosticFlags.Hover) && _hovering) { disabled = new (disabled.Foreground.GetDarkerColor (), disabled.Background.GetDarkerColor ()); } return Enabled ? GetColor (cs.Normal) : disabled; } private Attribute GetColor (Attribute inputAttribute) { Attribute attr = inputAttribute; if (Diagnostics.HasFlag (ViewDiagnosticFlags.Hover) && _hovering) { attr = new (attr.Foreground.GetDarkerColor (), attr.Background.GetDarkerColor ()); } return attr; } #endregion ColorScheme #region Attribute /// Selects the specified attribute as the attribute to use for future calls to AddRune and AddString. /// /// THe Attribute to set. public Attribute SetAttribute (Attribute attribute) { return Driver?.SetAttribute (attribute) ?? Attribute.Default; } /// Gets the current . /// The current attribute. public Attribute GetAttribute () { return Driver?.GetAttribute () ?? Attribute.Default; } #endregion Attribute }