using System; using System.Drawing; namespace CC_Functions.Commandline.TUI { /// /// Abstract class inherited by all controls /// public abstract class Control { /// /// Called when [enter] is pressed while the control is selected /// /// An instance of the calling screen /// Args public delegate void OnClick(Screen screen, EventArgs e); /// /// Called when the control is selected and unknown input is given /// /// An instance of the calling screen /// Args public delegate void OnInput(Screen screen, InputEventArgs e); /// /// Called when the controls Size property is changed /// /// The calling control /// Args public delegate void OnResize(Control caller, EventArgs e); private Size _size; /// /// Whether the control can be interacted with /// public bool Enabled = true; /// /// Whether the control should be rendered /// public bool Visible = true; /// /// The size of the control /// public Size Size { set { if (_size != value) { _size = value; Resize?.Invoke(this, new EventArgs()); } } get => _size; } /// /// The position of this control /// public Point Point { get; set; } /// /// The foreground color for this control /// public ConsoleColor ForeColor { get; set; } = Console.ForegroundColor; /// /// The background color for this control /// public ConsoleColor BackColor { get; set; } = Console.BackgroundColor; /// /// Whether the control can be selected /// public abstract bool Selectable { get; } /// /// Whether the object is selected. Used internally and for drawing /// public bool Selected { get; internal set; } = false; /// /// Called when the controls Size property is changed /// public event OnResize Resize; /// /// Renders the control /// /// The rendered pixels public abstract Pixel[,] Render(); /// /// Called when [enter] is pressed while the control is selected /// public event OnClick Click; /// /// Called when the control is selected and unknown input is given /// public event OnInput Input; /// /// Invokes click events /// /// The calling screen internal void InvokeClick(Screen screen) { Click?.Invoke(screen, new EventArgs()); } /// /// Invokes input events /// /// The calling screen /// The input data internal void InvokeInput(Screen screen, ConsoleKeyInfo info) { Input?.Invoke(screen, new InputEventArgs(info)); } } }