Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Document all non-mathematical functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JFronny committed May 23, 2020
1 parent bc6d83a commit d05f215
Show file tree
Hide file tree
Showing 18 changed files with 682 additions and 161 deletions.
21 changes: 14 additions & 7 deletions Commandline/TUI/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@

namespace CC_Functions.Commandline.TUI
{
/// <summary>
/// A basic button type
/// </summary>
public class Button : Control
{
/// <summary>
/// The text inside this button
/// </summary>
public string Content;
/// <summary>
/// Creates a new button
/// </summary>
/// <param name="content">The text inside this button</param>
public Button(string content)
{
Content = content;
char[,] tmp = Content.ToNDArray2D();
char[,] tmp = Content.ToNdArray2D();
Size = new Size(tmp.GetLength(0), tmp.GetLength(1));
}

/// <inheritdoc />
public override Pixel[,] Render()
{
char[,] inp = Content.ToNDArray2D();
char[,] inp = Content.ToNdArray2D();
inp = inp.Resize(Size.Width, Size.Height);
Pixel[,] output = new Pixel[Size.Width, Size.Height];
for (int x = 0; x < Size.Width; x++)
Expand All @@ -24,11 +35,7 @@ public Button(string content)
return output;
}

protected override void Resize(int width, int height)
{
//ignored for [Render]s sake, do not use
}

/// <inheritdoc />
public override bool Selectable { get; } = true;
}
}
33 changes: 26 additions & 7 deletions Commandline/TUI/CheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@

namespace CC_Functions.Commandline.TUI
{
/// <summary>
/// Provides a control for users to select a boolean
/// </summary>
public class CheckBox : Control
{
/// <summary>
/// The text inside this checkbox
/// </summary>
public string Content;
/// <summary>
/// Whether the box is checked
/// </summary>
public bool Checked = false;
/// <summary>
/// Creates a new checkbox
/// </summary>
/// <param name="content">The text inside this CheckBox</param>
public CheckBox(string content)
{
Content = content;
Expand All @@ -30,14 +43,15 @@ public CheckBox(string content)
};
}

/// <inheritdoc />
public override Pixel[,] Render()
{
char[,] inp1 = Content.ToNDArray2D();
char[,] inp1 = Content.ToNdArray2D();
char[,] inp = new char[inp1.GetLength(0), inp1.GetLength(1) + 4];
inp.Populate(' ');
inp1.CopyTo(inp, new Point(4, 0));
inp[0, 0] = '[';
inp[0, 1] = Checked ? 'X' : SpecialChars.empty;
inp[0, 1] = Checked ? 'X' : SpecialChars.Empty;
inp[0, 2] = ']';
int w = inp.GetLength(0);
int h = inp.GetLength(1);
Expand All @@ -49,13 +63,18 @@ public CheckBox(string content)
return output;
}

protected override void Resize(int width, int height)
{
//ignored for [Render]s sake, do not use
}

/// <inheritdoc />
public override bool Selectable { get; } = true;

/// <summary>
/// Called when the state of this checkbox is changed
/// </summary>
/// <param name="screen">The current screen instance</param>
/// <param name="e">Args</param>
public delegate void OnCheckedChanged(Screen screen, EventArgs e);
/// <summary>
/// Called when the state of this checkbox is changed
/// </summary>
public event OnClick CheckedChanged;
}
}
49 changes: 41 additions & 8 deletions Commandline/TUI/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,62 @@

namespace CC_Functions.Commandline.TUI
{
/// <summary>
/// Abstract class inherited by all controls
/// </summary>
public abstract class Control
{
/// <summary>
/// Called when the controls Size property is changed
/// </summary>
/// <param name="caller">The calling control</param>
/// <param name="e">Args</param>
public delegate void OnResize(Control caller, EventArgs e);
/// <summary>
/// Called when the controls Size property is changed
/// </summary>
public event OnResize Resize;
private Point _point;
private Size _size;
/// <summary>
/// Renders the control
/// </summary>
/// <returns>The rendered pixels</returns>
public abstract Pixel[,] Render();
protected abstract void Resize(int width, int height);
private void Resize(Size size) => Resize(size.Width, size.Height);

/// <summary>
/// The size of the control
/// </summary>
public Size Size
{
set
{
_size = value;
Resize(value);
if (_size != value)
{
_size = value;
Resize?.Invoke(this, new EventArgs());
}
}
get => _size;
}

/// <summary>
/// The position of this control
/// </summary>
public Point Point
{
get => _point;
set => _point = value;
}

/// <summary>
/// The foreground color for this control
/// </summary>
public ConsoleColor ForeColor { get; set; } = Console.ForegroundColor;
/// <summary>
/// The background color for this control
/// </summary>
public ConsoleColor BackColor { get; set; } = Console.BackgroundColor;
/// <summary>
/// Whether the control can be selected
/// </summary>
public abstract bool Selectable { get; }

/// <summary>
Expand Down Expand Up @@ -72,10 +102,13 @@ internal void InvokeInput(Screen screen, ConsoleKeyInfo info)
{
Input?.Invoke(screen, new InputEventArgs(info));
}

/// <summary>
/// Whether the control should be rendered
/// </summary>
public bool Visible = true;
/// <summary>
/// Whether the control can be interacted with
/// </summary>
public bool Enabled = true;
}
}
78 changes: 70 additions & 8 deletions Commandline/TUI/DiffDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ public static class DiffDraw
{
private static Pixel[,] Screen { get; set; } = new Pixel[0, 0];
private static Pixel[,] _last = new Pixel[0,0];
/// <summary>
/// The regions width
/// </summary>
public static int Width => Screen.GetLength(1);
/// <summary>
/// The regions height
/// </summary>
public static int Height => Screen.GetLength(0);

/// <summary>
/// Draws to the console
/// </summary>
/// <param name="color">Whether to use color</param>
public static void Draw(bool color)
{
Console.CursorTop = 0;
Expand Down Expand Up @@ -43,7 +52,10 @@ public static void Draw(bool color)
Console.BackgroundColor = bcol;
_last = Screen;
}

/// <summary>
/// Redraws the entire screen (should be done from time to time to prevent corruption)
/// </summary>
/// <param name="color">Whether to use color</param>
public static void FullDraw(bool color)
{
Console.CursorTop = 0;
Expand Down Expand Up @@ -73,26 +85,76 @@ public static void FullDraw(bool color)
Console.BackgroundColor = bcol;
_last = Screen;
}

/// <summary>
/// Gets the char at a location
/// </summary>
/// <param name="p">The location</param>
/// <returns>The char</returns>
public static char Get(Point p) => Get(p.X, p.Y);
/// <summary>
/// Gets the char at a location
/// </summary>
/// <param name="x">The locations X coordinate</param>
/// <param name="y">The locations Y coordinate</param>
/// <returns>The char</returns>
public static char Get(int x, int y) => Screen[y, x].Content;
/// <summary>
/// Gets the foreground color at a location
/// </summary>
/// <param name="p">The location</param>
/// <returns>The color</returns>
public static ConsoleColor GetForeColor(Point p) => GetForeColor(p.X, p.Y);
/// <summary>
/// Gets the foreground color at a location
/// </summary>
/// <param name="x">The locations X coordinate</param>
/// <param name="y">The locations Y coordinate</param>
/// <returns>The color</returns>
public static ConsoleColor GetForeColor(int x, int y) => Screen[y, x].ForeColor;
/// <summary>
/// Gets the background color at a location
/// </summary>
/// <param name="p">The location</param>
/// <returns>The color</returns>
public static ConsoleColor GetBackColor(Point p) => GetBackColor(p.X, p.Y);
/// <summary>
/// Gets the background color at a location
/// </summary>
/// <param name="x">The locations X coordinate</param>
/// <param name="y">The locations Y coordinate</param>
/// <returns>The color</returns>
public static ConsoleColor GetBackColor(int x, int y) => Screen[y, x].BackColor;

/// <summary>
/// Sets a pixel at a point
/// </summary>
/// <param name="p">The point to place at</param>
/// <param name="c">The pixel to place</param>
public static void Set(Point p, Pixel c) => Set(p.X, p.Y, c);

/// <summary>
/// Sets a pixel at a location
/// </summary>
/// <param name="x">The locations X coordinate</param>
/// <param name="y">The locations Y coordinate</param>
/// <param name="c">The pixel to place</param>
public static void Set(int x, int y, Pixel c) => Screen[y, x] = c;

/// <summary>
/// Clears the screen
/// </summary>
public static void Clear() => Clear(Width, Height);

/// <summary>
/// Resizes and clears the screen
/// </summary>
/// <param name="width">The new width</param>
/// <param name="height">The new height</param>
public static void Clear(int width, int height)
{
Screen = new Pixel[height, width];
_last = _last.Resize(height, width);
}

/// <summary>
/// Replaces the screen state
/// </summary>
/// <param name="content">The new state</param>
public static void Clear(Pixel[,] content)
{
Screen = content;
Expand Down
11 changes: 10 additions & 1 deletion Commandline/TUI/InputEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

namespace CC_Functions.Commandline.TUI
{
/// <summary>
/// Arguments containing input data
/// </summary>
public class InputEventArgs : EventArgs
{
private readonly ConsoleKeyInfo _info;
/// <summary>
/// The inputs data
/// </summary>
public ConsoleKeyInfo Info => _info;

/// <summary>
/// Generates new arguments
/// </summary>
/// <param name="info">The input data</param>
public InputEventArgs(ConsoleKeyInfo info) => _info = info;
}
}
21 changes: 13 additions & 8 deletions Commandline/TUI/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@

namespace CC_Functions.Commandline.TUI
{
/// <summary>
/// A basic text control
/// </summary>
public class Label : Control
{
/// <summary>
/// The text inside this label
/// </summary>
public string Content;
/// <summary>
/// Creates a new label
/// </summary>
/// <param name="content">The text inside this label</param>
public Label(string content) => Content = content;

/// <inheritdoc />
public override Pixel[,] Render()
{
char[,] inp = Content.ToNDArray2D();
char[,] inp = Content.ToNdArray2D();
int w = inp.GetLength(0);
int h = inp.GetLength(1);
Pixel[,] output = new Pixel[w, h];
Expand All @@ -20,12 +30,7 @@ public class Label : Control
Size = new Size(w, h);
return output;
}

protected override void Resize(int width, int height)
{
//ignored for [Render]s sake, do not use
}

/// <inheritdoc />
public override bool Selectable { get; } = false;
}
}

0 comments on commit d05f215

Please sign in to comment.