using System;
using System.Drawing;
namespace CC_Functions.Commandline.TUI
{
public abstract class Control
{
private Point _point;
private Size _size;
public abstract Pixel[,] Render();
protected abstract void Resize(int width, int height);
private void Resize(Size size) => Resize(size.Width, size.Height);
public Size Size
{
set
{
_size = value;
Resize(value);
}
get => _size;
}
public Point Point
{
get => _point;
set => _point = value;
}
public ConsoleColor ForeColor { get; set; } = Console.ForegroundColor;
public ConsoleColor BackColor { get; set; } = Console.BackgroundColor;
public abstract bool Selectable { get; }
///
/// 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 [enter] is pressed while the control is selected
///
public event OnClick Click;
///
/// 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 control is selected and unknown input is given
///
public event OnInput Input;
///
/// Whether the object is selected. Used internally and for drawing
///
public bool Selected { get; internal set; } = false;
///
/// 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));
}
///
/// Whether the control should be rendered
///
public bool Visible = true;
}
}