using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Drawing; using System.Text; namespace InABox.Core { public enum UnderlineType { None, Single, Double } public class DFLayoutTextStyle : EnclosedEntity { [EditorSequence(0)] [CheckBoxEditor] public bool IsItalic { get; set; } [EditorSequence(1)] [CheckBoxEditor] public bool IsBold { get; set; } [EditorSequence(2)] [EnumLookupEditor(typeof(UnderlineType))] public UnderlineType Underline { get; set; } [EditorSequence(3)] [DoubleEditor(Caption = "Font size in points. Set to 0 for the default size.")] public double FontSize { get; set; } [EditorSequence(4)] [ColorEditor] public string Foreground { get; set; } [EditorSequence(5)] [ColorEditor] public string Background { get; set; } [JsonIgnore] [NullEditor] public Color ForegroundColour { get => GetForegroundColour(); set => SetForegroundColour(value); } [JsonIgnore] [NullEditor] public Color BackgroundColour { get => GetBackgroundColour(); set => SetBackgroundColour(value); } protected override void Init() { base.Init(); IsItalic = false; IsBold = false; Underline = UnderlineType.None; Foreground = ""; Background = ""; FontSize = 0; } public Color GetForegroundColour() => ColourFromString(Foreground); public Color GetBackgroundColour() => ColourFromString(Background); public string SetForegroundColour(Color colour) => Foreground = ColourToString(colour); public string SetBackgroundColour(Color colour) => Background = ColourToString(colour); public static Color ColourFromString(string colour) => string.IsNullOrWhiteSpace(colour) ? Color.Empty : DFLayoutUtils.ConvertObjectToColour(colour) ?? Color.Empty; public static string ColourToString(Color colour) => colour == Color.Empty ? "" : colour.IsKnownColor ? colour.ToString() : $"#{colour.ToArgb():X4}"; } }