Centered Screen (like Dialog) and fixes
This commit is contained in:
parent
d05f215a62
commit
f6950a0d4c
|
@ -5,71 +5,77 @@ using CC_Functions.Commandline.TUI;
|
||||||
|
|
||||||
namespace CLITest
|
namespace CLITest
|
||||||
{
|
{
|
||||||
class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.BackgroundColor = ConsoleColor.Black;
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Screen screen = new Screen(40, 20);
|
CenteredScreen cScreen = new CenteredScreen(40, 20, ConsoleColor.Green);
|
||||||
|
Panel screen = cScreen.ContentPanel;
|
||||||
Button btn1 = new Button("Test")
|
Button btn1 = new Button("Test")
|
||||||
{
|
{
|
||||||
Point = new Point(2, 0)
|
Point = new Point(2, 0),
|
||||||
|
BackColor = ConsoleColor.DarkGreen
|
||||||
};
|
};
|
||||||
screen.Controls.Add(btn1);
|
screen.Controls.Add(btn1);
|
||||||
btn1.Click += (screen1, eventArgs) =>
|
btn1.Click += (screen1, eventArgs) => { DiffDraw.FullDraw(true); };
|
||||||
{
|
|
||||||
DiffDraw.FullDraw(true);
|
|
||||||
};
|
|
||||||
Label lab1 = new Label("Meem")
|
Label lab1 = new Label("Meem")
|
||||||
{
|
{
|
||||||
Point = new Point(2, 1)
|
Point = new Point(2, 1),
|
||||||
|
BackColor = ConsoleColor.Green
|
||||||
};
|
};
|
||||||
screen.Controls.Add(lab1);
|
screen.Controls.Add(lab1);
|
||||||
screen.Controls.Add(new Label("Saas\nSoos")
|
screen.Controls.Add(new Label("Saas\nSoos")
|
||||||
{
|
{
|
||||||
Point = new Point(2, 2)
|
Point = new Point(2, 2),
|
||||||
|
BackColor = ConsoleColor.Green
|
||||||
});
|
});
|
||||||
Button btn2 = new Button("X");
|
Button btn2 = new Button("X")
|
||||||
|
{
|
||||||
|
BackColor = ConsoleColor.Red,
|
||||||
|
ForeColor = ConsoleColor.White
|
||||||
|
};
|
||||||
screen.Controls.Add(btn2);
|
screen.Controls.Add(btn2);
|
||||||
|
|
||||||
CheckBox box = new CheckBox("Are u gae?")
|
CheckBox box = new CheckBox("Are u gae?")
|
||||||
{
|
{
|
||||||
Point = new Point(2, 3)
|
Point = new Point(2, 3),
|
||||||
|
BackColor = ConsoleColor.DarkGreen
|
||||||
};
|
};
|
||||||
screen.Controls.Add(box);
|
screen.Controls.Add(box);
|
||||||
box.CheckedChanged += (screen1, eventArgs) =>
|
box.CheckedChanged += (screen1, eventArgs) => { lab1.Content = box.Checked ? "Sas" : "Meem"; };
|
||||||
{
|
|
||||||
lab1.Content = box.Checked ? "Sas" : "Meem";
|
|
||||||
};
|
|
||||||
|
|
||||||
TextBox tbox = new TextBox("Hello\nWorld1\n\nHow are u?")
|
TextBox tbox = new TextBox("Hello\nWorld1\n\nHow are u?")
|
||||||
{
|
{
|
||||||
Size = new Size(20, 10),
|
Size = new Size(20, 10),
|
||||||
Point = new Point(0, 6)
|
Point = new Point(0, 6),
|
||||||
|
BackColor = ConsoleColor.DarkYellow
|
||||||
};
|
};
|
||||||
screen.Controls.Add(tbox);
|
screen.Controls.Add(tbox);
|
||||||
|
|
||||||
Slider slider = new Slider
|
Slider slider = new Slider
|
||||||
{
|
{
|
||||||
Point = new Point(2, 4),
|
Point = new Point(2, 4),
|
||||||
Size = new Size(8, 2),
|
Size = new Size(16, 2),
|
||||||
MaxValue = 75,
|
MaxValue = 75,
|
||||||
StepSize = 14,
|
StepSize = 14,
|
||||||
MinValue = -3,
|
MinValue = -3,
|
||||||
Value = 7
|
Value = 7,
|
||||||
|
BackColor = ConsoleColor.Magenta
|
||||||
};
|
};
|
||||||
screen.Controls.Add(slider);
|
screen.Controls.Add(slider);
|
||||||
|
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
btn2.Click += (screen1, eventArgs) => visible = false;
|
btn2.Click += (screen1, eventArgs) => visible = false;
|
||||||
screen.Close += (screen1, eventArgs) => visible = false;
|
cScreen.Close += (screen1, eventArgs) => visible = false;
|
||||||
screen.Render();
|
cScreen.TabChanged += (screen1, eventArgs) => btn1.Content = $"Test {cScreen.TabPoint}";
|
||||||
|
cScreen.Render();
|
||||||
while (visible)
|
while (visible)
|
||||||
{
|
{
|
||||||
Thread.Sleep(50);
|
Thread.Sleep(50);
|
||||||
screen.ReadInput();
|
cScreen.ReadInput();
|
||||||
}
|
}
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
|
|
@ -1,41 +1,67 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
using CC_Functions.Misc;
|
using CC_Functions.Misc;
|
||||||
|
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A basic button type
|
/// A basic button type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Button : Control
|
public class Button : Control
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The text inside this button
|
/// The text inside this button
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Content;
|
public string Content;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new button
|
/// Creates a new button
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">The text inside this button</param>
|
/// <param name="content">The text inside this button</param>
|
||||||
public Button(string content)
|
public Button(string content)
|
||||||
{
|
{
|
||||||
Content = content;
|
Content = content;
|
||||||
char[,] tmp = Content.ToNdArray2D();
|
char[,] tmp = Content.ToNdArray2D();
|
||||||
Size = new Size(tmp.GetLength(0), tmp.GetLength(1));
|
Size = new Size(tmp.GetLength(1), tmp.GetLength(0));
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Pixel[,] Render()
|
|
||||||
{
|
|
||||||
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++)
|
|
||||||
for (int y = 0; y < Size.Height; y++)
|
|
||||||
output[x, y] = new Pixel(Selected ? ForeColor : BackColor, Selected ? BackColor : ForeColor, inp[x, y]);
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool Selectable { get; } = true;
|
public override bool Selectable { get; } = true;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Pixel[,] Render()
|
||||||
|
{
|
||||||
|
char[,] inp = Indent(SplitLines(Content, Size.Width), Size.Width).ToNdArray2D();
|
||||||
|
inp = inp.Resize(Size.Height, Size.Width);
|
||||||
|
Pixel[,] output = new Pixel[Size.Height, Size.Width];
|
||||||
|
for (int x = 0; x < Size.Height; x++)
|
||||||
|
for (int y = 0; y < Size.Width; y++)
|
||||||
|
output[x, y] = new Pixel(Selected ? ForeColor : BackColor, Selected ? BackColor : ForeColor, inp[x, y]);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Indent(string source, int maxLen)
|
||||||
|
{
|
||||||
|
string[] tmp = source.Split('\n');
|
||||||
|
for (int i = 0; i < tmp.Length; i++) tmp[i] = new string(SpecialChars.Empty, (maxLen - tmp[i].Length) / 2) + tmp[i];
|
||||||
|
return string.Join('\n', tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string SplitLines(string source, int maxLen)
|
||||||
|
{
|
||||||
|
List<string> parts = new List<string>(source.Split());
|
||||||
|
while (parts.Any(s => s.Length > maxLen))
|
||||||
|
{
|
||||||
|
parts = parts.SelectMany(s =>
|
||||||
|
{
|
||||||
|
if (s.Length > maxLen)
|
||||||
|
return s.Insert(maxLen, "\n").Split('\n');
|
||||||
|
else
|
||||||
|
return new[] {s};
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
return string.Join('\n', parts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using CC_Functions.Misc;
|
||||||
|
|
||||||
|
namespace CC_Functions.Commandline.TUI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a screen that stays in the middle of the console. Use ContentPanel to attach controls
|
||||||
|
/// </summary>
|
||||||
|
public class CenteredScreen : Screen
|
||||||
|
{
|
||||||
|
private bool _resizing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The actual size of this control. The "Size" property is assigned automatically
|
||||||
|
/// </summary>
|
||||||
|
public Size ActualSize;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The panel used for storing and rendering the actual controls
|
||||||
|
/// </summary>
|
||||||
|
public Panel ContentPanel;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The title to display at the top of the console
|
||||||
|
/// </summary>
|
||||||
|
public string Title = "CC-Functions.CommandLine app";
|
||||||
|
|
||||||
|
private readonly Label _titleLabel;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a screen that stays in the middle of the console. Use ContentPanel to attach controls
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">The width of the content panel</param>
|
||||||
|
/// <param name="height">The height of the content panel</param>
|
||||||
|
/// <param name="contentBack">The content panels background (Should be different from Console.BackgroundColor)</param>
|
||||||
|
/// <param name="color">Whether to use color when drawing</param>
|
||||||
|
public CenteredScreen(int width, int height, ConsoleColor contentBack, bool color = true) : base(width, height, color)
|
||||||
|
{
|
||||||
|
ContentPanel = new Panel {BackColor = contentBack};
|
||||||
|
ActualSize = new Size(width, height);
|
||||||
|
_titleLabel = new Label(Title);
|
||||||
|
Controls.Add(ContentPanel);
|
||||||
|
Controls.Add(_titleLabel);
|
||||||
|
WindowResize += (screen, args) => CalculatePosition();
|
||||||
|
((Control) this).Resize += (caller, args) => CalculatePosition();
|
||||||
|
CalculatePosition(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates the Size variable, Title and ContentPanel position/size
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="initial">Whether this is the initial calculation</param>
|
||||||
|
public void CalculatePosition(bool initial = false)
|
||||||
|
{
|
||||||
|
if (!_resizing)
|
||||||
|
{
|
||||||
|
_resizing = true;
|
||||||
|
Size = new Size(Console.WindowWidth, Console.WindowHeight - 1);
|
||||||
|
_titleLabel.Content = Title + Environment.NewLine + new string(SpecialChars.OneLineSimple.LeftRight, Console.WindowWidth);
|
||||||
|
ContentPanel.Size = ActualSize;
|
||||||
|
ContentPanel.Point = new Point((Console.WindowWidth - ActualSize.Width) / 2,
|
||||||
|
(Console.WindowHeight - ActualSize.Height) / 2);
|
||||||
|
if (!initial)
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
DiffDraw.FullDraw(Color);
|
||||||
|
}
|
||||||
|
_resizing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,20 +5,29 @@ using CC_Functions.Misc;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a control for users to select a boolean
|
/// Provides a control for users to select a boolean
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CheckBox : Control
|
public class CheckBox : Control
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The text inside this checkbox
|
/// 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>
|
||||||
|
/// Whether the box is checked
|
||||||
|
/// </summary>
|
||||||
|
public bool Checked;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The text inside this checkbox
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Content;
|
public string Content;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the box is checked
|
/// Creates a new checkbox
|
||||||
/// </summary>
|
|
||||||
public bool Checked = false;
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new checkbox
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">The text inside this CheckBox</param>
|
/// <param name="content">The text inside this CheckBox</param>
|
||||||
public CheckBox(string content)
|
public CheckBox(string content)
|
||||||
|
@ -43,6 +52,9 @@ namespace CC_Functions.Commandline.TUI
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool Selectable { get; } = true;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Pixel[,] Render()
|
public override Pixel[,] Render()
|
||||||
{
|
{
|
||||||
|
@ -63,17 +75,8 @@ namespace CC_Functions.Commandline.TUI
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool Selectable { get; } = true;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the state of this checkbox is changed
|
/// 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>
|
/// </summary>
|
||||||
public event OnClick CheckedChanged;
|
public event OnClick CheckedChanged;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,29 +4,45 @@ using System.Drawing;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract class inherited by all controls
|
/// Abstract class inherited by all controls
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class Control
|
public abstract class Control
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the controls Size property is changed
|
/// Called when [enter] is pressed while the control is selected
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="screen">An instance of the calling screen</param>
|
||||||
|
/// <param name="e">Args</param>
|
||||||
|
public delegate void OnClick(Screen screen, EventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the control is selected and unknown input is given
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="screen">An instance of the calling screen</param>
|
||||||
|
/// <param name="e">Args</param>
|
||||||
|
public delegate void OnInput(Screen screen, InputEventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the controls Size property is changed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="caller">The calling control</param>
|
/// <param name="caller">The calling control</param>
|
||||||
/// <param name="e">Args</param>
|
/// <param name="e">Args</param>
|
||||||
public delegate void OnResize(Control caller, EventArgs e);
|
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;
|
private Size _size;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Renders the control
|
/// Whether the control can be interacted with
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The rendered pixels</returns>
|
public bool Enabled = true;
|
||||||
public abstract Pixel[,] Render();
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The size of the control
|
/// Whether the control should be rendered
|
||||||
|
/// </summary>
|
||||||
|
public bool Visible = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The size of the control
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Size Size
|
public Size Size
|
||||||
{
|
{
|
||||||
|
@ -40,61 +56,64 @@ namespace CC_Functions.Commandline.TUI
|
||||||
}
|
}
|
||||||
get => _size;
|
get => _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The position of this control
|
/// The position of this control
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Point Point
|
public Point Point { get; set; }
|
||||||
{
|
|
||||||
get => _point;
|
|
||||||
set => _point = value;
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The foreground color for this control
|
/// The foreground color for this control
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ConsoleColor ForeColor { get; set; } = Console.ForegroundColor;
|
public ConsoleColor ForeColor { get; set; } = Console.ForegroundColor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The background color for this control
|
/// The background color for this control
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ConsoleColor BackColor { get; set; } = Console.BackgroundColor;
|
public ConsoleColor BackColor { get; set; } = Console.BackgroundColor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the control can be selected
|
/// Whether the control can be selected
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract bool Selectable { get; }
|
public abstract bool Selectable { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when [enter] is pressed while the control is selected
|
/// Whether the object is selected. Used internally and for drawing
|
||||||
/// </summary>
|
|
||||||
/// <param name="screen">An instance of the calling screen</param>
|
|
||||||
/// <param name="e">Args</param>
|
|
||||||
public delegate void OnClick(Screen screen, EventArgs e);
|
|
||||||
/// <summary>
|
|
||||||
/// Called when [enter] is pressed while the control is selected
|
|
||||||
/// </summary>
|
|
||||||
public event OnClick Click;
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the control is selected and unknown input is given
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="screen">An instance of the calling screen</param>
|
|
||||||
/// <param name="e">Args</param>
|
|
||||||
public delegate void OnInput(Screen screen, InputEventArgs e);
|
|
||||||
/// <summary>
|
|
||||||
/// Called when the control is selected and unknown input is given
|
|
||||||
/// </summary>
|
|
||||||
public event OnInput Input;
|
|
||||||
/// <summary>
|
|
||||||
/// Whether the object is selected. Used internally and for drawing
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Selected { get; internal set; } = false;
|
public bool Selected { get; internal set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes click events
|
/// Called when the controls Size property is changed
|
||||||
|
/// </summary>
|
||||||
|
public event OnResize Resize;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Renders the control
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The rendered pixels</returns>
|
||||||
|
public abstract Pixel[,] Render();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when [enter] is pressed while the control is selected
|
||||||
|
/// </summary>
|
||||||
|
public event OnClick Click;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the control is selected and unknown input is given
|
||||||
|
/// </summary>
|
||||||
|
public event OnInput Input;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes click events
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="screen">The calling screen</param>
|
/// <param name="screen">The calling screen</param>
|
||||||
internal void InvokeClick(Screen screen)
|
internal void InvokeClick(Screen screen)
|
||||||
{
|
{
|
||||||
Click?.Invoke(screen, new EventArgs());
|
Click?.Invoke(screen, new EventArgs());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes input events
|
/// Invokes input events
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="screen">The calling screen</param>
|
/// <param name="screen">The calling screen</param>
|
||||||
/// <param name="info">The input data</param>
|
/// <param name="info">The input data</param>
|
||||||
|
@ -102,13 +121,5 @@ namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
Input?.Invoke(screen, new InputEventArgs(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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,22 +5,25 @@ using CC_Functions.Misc;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides differential drawing of a char[,] Do not use in combination with System.Console
|
/// Provides differential drawing of a char[,] Do not use in combination with System.Console
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class DiffDraw
|
public static class DiffDraw
|
||||||
{
|
{
|
||||||
|
private static Pixel[,] _last = new Pixel[0, 0];
|
||||||
private static Pixel[,] Screen { get; set; } = new Pixel[0, 0];
|
private static Pixel[,] Screen { get; set; } = new Pixel[0, 0];
|
||||||
private static Pixel[,] _last = new Pixel[0,0];
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The regions width
|
/// The regions width
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static int Width => Screen.GetLength(1);
|
public static int Width => Screen.GetLength(1);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The regions height
|
/// The regions height
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static int Height => Screen.GetLength(0);
|
public static int Height => Screen.GetLength(0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draws to the console
|
/// Draws to the console
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">Whether to use color</param>
|
/// <param name="color">Whether to use color</param>
|
||||||
public static void Draw(bool color)
|
public static void Draw(bool color)
|
||||||
|
@ -39,8 +42,10 @@ namespace CC_Functions.Commandline.TUI
|
||||||
if (tmp1 == _last[y, x]) continue;
|
if (tmp1 == _last[y, x]) continue;
|
||||||
if (color)
|
if (color)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = tmp1.ForeColor;
|
if (Console.ForegroundColor != tmp1.ForeColor)
|
||||||
Console.BackgroundColor = tmp1.BackColor;
|
Console.ForegroundColor = tmp1.ForeColor;
|
||||||
|
if (Console.BackgroundColor != tmp1.BackColor)
|
||||||
|
Console.BackgroundColor = tmp1.BackColor;
|
||||||
}
|
}
|
||||||
Console.CursorLeft = x;
|
Console.CursorLeft = x;
|
||||||
Console.Write(tmp1);
|
Console.Write(tmp1);
|
||||||
|
@ -52,8 +57,9 @@ namespace CC_Functions.Commandline.TUI
|
||||||
Console.BackgroundColor = bcol;
|
Console.BackgroundColor = bcol;
|
||||||
_last = Screen;
|
_last = Screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Redraws the entire screen (should be done from time to time to prevent corruption)
|
/// Redraws the entire screen (should be done from time to time to prevent corruption)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="color">Whether to use color</param>
|
/// <param name="color">Whether to use color</param>
|
||||||
public static void FullDraw(bool color)
|
public static void FullDraw(bool color)
|
||||||
|
@ -72,8 +78,10 @@ namespace CC_Functions.Commandline.TUI
|
||||||
Pixel tmp1 = Screen[y, x];
|
Pixel tmp1 = Screen[y, x];
|
||||||
if (color)
|
if (color)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = tmp1.ForeColor;
|
if (Console.ForegroundColor != tmp1.ForeColor)
|
||||||
Console.BackgroundColor = tmp1.BackColor;
|
Console.ForegroundColor = tmp1.ForeColor;
|
||||||
|
if (Console.BackgroundColor != tmp1.BackColor)
|
||||||
|
Console.BackgroundColor = tmp1.BackColor;
|
||||||
}
|
}
|
||||||
Console.CursorLeft = x;
|
Console.CursorLeft = x;
|
||||||
Console.Write(tmp1);
|
Console.Write(tmp1);
|
||||||
|
@ -85,64 +93,74 @@ namespace CC_Functions.Commandline.TUI
|
||||||
Console.BackgroundColor = bcol;
|
Console.BackgroundColor = bcol;
|
||||||
_last = Screen;
|
_last = Screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the char at a location
|
/// Gets the char at a location
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p">The location</param>
|
/// <param name="p">The location</param>
|
||||||
/// <returns>The char</returns>
|
/// <returns>The char</returns>
|
||||||
public static char Get(Point p) => Get(p.X, p.Y);
|
public static char Get(Point p) => Get(p.X, p.Y);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the char at a location
|
/// Gets the char at a location
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">The locations X coordinate</param>
|
/// <param name="x">The locations X coordinate</param>
|
||||||
/// <param name="y">The locations Y coordinate</param>
|
/// <param name="y">The locations Y coordinate</param>
|
||||||
/// <returns>The char</returns>
|
/// <returns>The char</returns>
|
||||||
public static char Get(int x, int y) => Screen[y, x].Content;
|
public static char Get(int x, int y) => Screen[y, x].Content;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the foreground color at a location
|
/// Gets the foreground color at a location
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p">The location</param>
|
/// <param name="p">The location</param>
|
||||||
/// <returns>The color</returns>
|
/// <returns>The color</returns>
|
||||||
public static ConsoleColor GetForeColor(Point p) => GetForeColor(p.X, p.Y);
|
public static ConsoleColor GetForeColor(Point p) => GetForeColor(p.X, p.Y);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the foreground color at a location
|
/// Gets the foreground color at a location
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">The locations X coordinate</param>
|
/// <param name="x">The locations X coordinate</param>
|
||||||
/// <param name="y">The locations Y coordinate</param>
|
/// <param name="y">The locations Y coordinate</param>
|
||||||
/// <returns>The color</returns>
|
/// <returns>The color</returns>
|
||||||
public static ConsoleColor GetForeColor(int x, int y) => Screen[y, x].ForeColor;
|
public static ConsoleColor GetForeColor(int x, int y) => Screen[y, x].ForeColor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the background color at a location
|
/// Gets the background color at a location
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p">The location</param>
|
/// <param name="p">The location</param>
|
||||||
/// <returns>The color</returns>
|
/// <returns>The color</returns>
|
||||||
public static ConsoleColor GetBackColor(Point p) => GetBackColor(p.X, p.Y);
|
public static ConsoleColor GetBackColor(Point p) => GetBackColor(p.X, p.Y);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the background color at a location
|
/// Gets the background color at a location
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">The locations X coordinate</param>
|
/// <param name="x">The locations X coordinate</param>
|
||||||
/// <param name="y">The locations Y coordinate</param>
|
/// <param name="y">The locations Y coordinate</param>
|
||||||
/// <returns>The color</returns>
|
/// <returns>The color</returns>
|
||||||
public static ConsoleColor GetBackColor(int x, int y) => Screen[y, x].BackColor;
|
public static ConsoleColor GetBackColor(int x, int y) => Screen[y, x].BackColor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a pixel at a point
|
/// Sets a pixel at a point
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="p">The point to place at</param>
|
/// <param name="p">The point to place at</param>
|
||||||
/// <param name="c">The pixel to place</param>
|
/// <param name="c">The pixel to place</param>
|
||||||
public static void Set(Point p, Pixel c) => Set(p.X, p.Y, c);
|
public static void Set(Point p, Pixel c) => Set(p.X, p.Y, c);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a pixel at a location
|
/// Sets a pixel at a location
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">The locations X coordinate</param>
|
/// <param name="x">The locations X coordinate</param>
|
||||||
/// <param name="y">The locations Y coordinate</param>
|
/// <param name="y">The locations Y coordinate</param>
|
||||||
/// <param name="c">The pixel to place</param>
|
/// <param name="c">The pixel to place</param>
|
||||||
public static void Set(int x, int y, Pixel c) => Screen[y, x] = c;
|
public static void Set(int x, int y, Pixel c) => Screen[y, x] = c;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears the screen
|
/// Clears the screen
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Clear() => Clear(Width, Height);
|
public static void Clear() => Clear(Width, Height);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resizes and clears the screen
|
/// Resizes and clears the screen
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="width">The new width</param>
|
/// <param name="width">The new width</param>
|
||||||
/// <param name="height">The new height</param>
|
/// <param name="height">The new height</param>
|
||||||
|
@ -151,8 +169,9 @@ namespace CC_Functions.Commandline.TUI
|
||||||
Screen = new Pixel[height, width];
|
Screen = new Pixel[height, width];
|
||||||
_last = _last.Resize(height, width);
|
_last = _last.Resize(height, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces the screen state
|
/// Replaces the screen state
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">The new state</param>
|
/// <param name="content">The new state</param>
|
||||||
public static void Clear(Pixel[,] content)
|
public static void Clear(Pixel[,] content)
|
||||||
|
|
|
@ -3,19 +3,19 @@ using System;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Arguments containing input data
|
/// Arguments containing input data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class InputEventArgs : EventArgs
|
public class InputEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
private readonly ConsoleKeyInfo _info;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The inputs data
|
/// Generates new arguments
|
||||||
/// </summary>
|
|
||||||
public ConsoleKeyInfo Info => _info;
|
|
||||||
/// <summary>
|
|
||||||
/// Generates new arguments
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="info">The input data</param>
|
/// <param name="info">The input data</param>
|
||||||
public InputEventArgs(ConsoleKeyInfo info) => _info = info;
|
public InputEventArgs(ConsoleKeyInfo info) => Info = info;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The inputs data
|
||||||
|
/// </summary>
|
||||||
|
public ConsoleKeyInfo Info { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,19 +4,24 @@ using CC_Functions.Misc;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A basic text control
|
/// A basic text control
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Label : Control
|
public class Label : Control
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The text inside this label
|
/// The text inside this label
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Content;
|
public string Content;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new label
|
/// Creates a new label
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">The text inside this label</param>
|
/// <param name="content">The text inside this label</param>
|
||||||
public Label(string content) => Content = content;
|
public Label(string content) => Content = content;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool Selectable { get; } = false;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Pixel[,] Render()
|
public override Pixel[,] Render()
|
||||||
{
|
{
|
||||||
|
@ -30,7 +35,5 @@ namespace CC_Functions.Commandline.TUI
|
||||||
Size = new Size(w, h);
|
Size = new Size(w, h);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool Selectable { get; } = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,37 +5,47 @@ using CC_Functions.Misc;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A panel containing other components. MUST be inherited for all other controls that contain others
|
/// A panel containing other components. MUST be inherited for all other controls that contain others
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Panel : Control
|
public class Panel : Control
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The controls inside this panel
|
/// Enable to draw a simple border around this control
|
||||||
|
/// </summary>
|
||||||
|
public bool Border = true;
|
||||||
|
/// <summary>
|
||||||
|
/// The controls inside this panel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<Control> Controls = new List<Control>();
|
public List<Control> Controls = new List<Control>();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool Selectable { get; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Renders the control and all contained controls
|
/// Renders the control and all contained controls
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The rendered pixels</returns>
|
/// <returns>The rendered pixels</returns>
|
||||||
public override Pixel[,] Render()
|
public override Pixel[,] Render()
|
||||||
{
|
{
|
||||||
Pixel[,] tmp = new Pixel[Size.Height, Size.Width];
|
Pixel[,] tmp = new Pixel[Size.Height, Size.Width];
|
||||||
tmp.Populate(new Pixel(BackColor, ForeColor, SpecialChars.Empty));
|
tmp.Populate(new Pixel(BackColor, ForeColor, SpecialChars.Empty));
|
||||||
foreach (Control control in Controls)
|
if (Border)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < Size.Width; i++) tmp[Size.Height - 1, i] = new Pixel(BackColor, ForeColor, SpecialChars.OneLineSimple.LeftRight);
|
||||||
|
for (int i = 0; i < Size.Height; i++) tmp[i, Size.Width - 1] = new Pixel(BackColor, ForeColor, SpecialChars.OneLineSimple.UpDown);
|
||||||
|
tmp[Size.Height - 1, Size.Width - 1] = new Pixel(BackColor, ForeColor, '┘');
|
||||||
|
}
|
||||||
|
foreach (Control control in Controls)
|
||||||
if (control.Visible)
|
if (control.Visible)
|
||||||
{
|
{
|
||||||
Pixel[,] render = control.Render();
|
Pixel[,] render = control.Render();
|
||||||
render.CopyTo(tmp, control.Point);
|
render.CopyTo(tmp, control.Point);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool Selectable { get; } = false;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recursively enumerates all controls
|
/// Recursively enumerates all controls
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A list of all controls</returns>
|
/// <returns>A list of all controls</returns>
|
||||||
public Control[] EnumerateRecursive()
|
public Control[] EnumerateRecursive()
|
||||||
|
@ -50,4 +60,4 @@ namespace CC_Functions.Commandline.TUI
|
||||||
return output.ToArray();
|
return output.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,10 +4,106 @@ using System.Collections.Generic;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a pixel
|
/// Represents a pixel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Pixel
|
public class Pixel
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This pixels background color
|
||||||
|
/// </summary>
|
||||||
|
public ConsoleColor BackColor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This pixels content character
|
||||||
|
/// </summary>
|
||||||
|
public char Content;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This pixels foregound color
|
||||||
|
/// </summary>
|
||||||
|
public ConsoleColor ForeColor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a new pixel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="backColor">The background color</param>
|
||||||
|
/// <param name="foreColor">The foreground color</param>
|
||||||
|
/// <param name="content">The new content</param>
|
||||||
|
public Pixel(ConsoleColor backColor, ConsoleColor foreColor, char content)
|
||||||
|
{
|
||||||
|
BackColor = backColor;
|
||||||
|
ForeColor = foreColor;
|
||||||
|
Content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a new pixel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">The content for this pixel</param>
|
||||||
|
public Pixel(char content) : this(Console.BackgroundColor, Console.ForegroundColor, content)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a new pixel
|
||||||
|
/// </summary>
|
||||||
|
public Pixel() : this(' ')
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use this in functions that require equality comparers
|
||||||
|
/// </summary>
|
||||||
|
public static IEqualityComparer<Pixel> ColorContentComparer { get; } = new ColorContentEqualityComparer();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this is equal to another pixel
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">The other pixel to compare</param>
|
||||||
|
/// <returns>Whether they are equal</returns>
|
||||||
|
protected bool Equals(Pixel other) => ColorContentComparer.Equals(this, other);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this is equal to another object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The other object to compare</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(null, obj)) return false;
|
||||||
|
if (ReferenceEquals(this, obj)) return true;
|
||||||
|
if (obj.GetType() != GetType()) return false;
|
||||||
|
return Equals((Pixel) obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates an integer for comparing this object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The generated hash</returns>
|
||||||
|
public override int GetHashCode() => HashCode.Combine((int) BackColor, (int) ForeColor, Content);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether two pixels are equal
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">First pixel to compare</param>
|
||||||
|
/// <param name="b">Second pixel to compare</param>
|
||||||
|
/// <returns>Whether they are equal</returns>
|
||||||
|
public static bool operator ==(Pixel a, Pixel b) => a.Equals(b);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to pixels are not equal
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">First pixel to compare</param>
|
||||||
|
/// <param name="b">Second pixel to compare</param>
|
||||||
|
/// <returns>Whether they are not equal</returns>
|
||||||
|
public static bool operator !=(Pixel a, Pixel b) => !a.Equals(b);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the content of this pixel
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The content of this pixel</returns>
|
||||||
|
public override string ToString() => Content.ToString();
|
||||||
|
|
||||||
private sealed class ColorContentEqualityComparer : IEqualityComparer<Pixel>
|
private sealed class ColorContentEqualityComparer : IEqualityComparer<Pixel>
|
||||||
{
|
{
|
||||||
public bool Equals(Pixel x, Pixel y)
|
public bool Equals(Pixel x, Pixel y)
|
||||||
|
@ -21,89 +117,5 @@ namespace CC_Functions.Commandline.TUI
|
||||||
|
|
||||||
public int GetHashCode(Pixel obj) => obj.GetHashCode();
|
public int GetHashCode(Pixel obj) => obj.GetHashCode();
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Use this in functions that require equality comparers
|
|
||||||
/// </summary>
|
|
||||||
public static IEqualityComparer<Pixel> ColorContentComparer { get; } = new ColorContentEqualityComparer();
|
|
||||||
/// <summary>
|
|
||||||
/// Whether this is equal to another pixel
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="other">The other pixel to compare</param>
|
|
||||||
/// <returns>Whether they are equal</returns>
|
|
||||||
protected bool Equals(Pixel other) => ColorContentComparer.Equals(this, other);
|
|
||||||
/// <summary>
|
|
||||||
/// Whether this is equal to another object
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">The other object to compare</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
if (ReferenceEquals(null, obj)) return false;
|
|
||||||
if (ReferenceEquals(this, obj)) return true;
|
|
||||||
if (obj.GetType() != GetType()) return false;
|
|
||||||
return Equals((Pixel) obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates an integer for comparing this object
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The generated hash</returns>
|
|
||||||
public override int GetHashCode() => HashCode.Combine((int) BackColor, (int) ForeColor, Content);
|
|
||||||
/// <summary>
|
|
||||||
/// This pixels background color
|
|
||||||
/// </summary>
|
|
||||||
public ConsoleColor BackColor;
|
|
||||||
/// <summary>
|
|
||||||
/// This pixels foregound color
|
|
||||||
/// </summary>
|
|
||||||
public ConsoleColor ForeColor;
|
|
||||||
/// <summary>
|
|
||||||
/// This pixels content character
|
|
||||||
/// </summary>
|
|
||||||
public char Content;
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a new pixel
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="backColor">The background color</param>
|
|
||||||
/// <param name="foreColor">The foreground color</param>
|
|
||||||
/// <param name="content">The new content</param>
|
|
||||||
public Pixel(ConsoleColor backColor, ConsoleColor foreColor, char content)
|
|
||||||
{
|
|
||||||
BackColor = backColor;
|
|
||||||
ForeColor = foreColor;
|
|
||||||
Content = content;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a new pixel
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="content">The content for this pixel</param>
|
|
||||||
public Pixel(char content) : this(Console.BackgroundColor, Console.ForegroundColor, content)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a new pixel
|
|
||||||
/// </summary>
|
|
||||||
public Pixel() : this(' ')
|
|
||||||
{
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Whether two pixels are equal
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First pixel to compare</param>
|
|
||||||
/// <param name="b">Second pixel to compare</param>
|
|
||||||
/// <returns>Whether they are equal</returns>
|
|
||||||
public static bool operator ==(Pixel a, Pixel b) => a.Equals(b);
|
|
||||||
/// <summary>
|
|
||||||
/// Whether to pixels are not equal
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="a">First pixel to compare</param>
|
|
||||||
/// <param name="b">Second pixel to compare</param>
|
|
||||||
/// <returns>Whether they are not equal</returns>
|
|
||||||
public static bool operator !=(Pixel a, Pixel b) => !a.Equals(b);
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the content of this pixel
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The content of this pixel</returns>
|
|
||||||
public override string ToString() => Content.ToString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,22 +5,46 @@ using System.Linq;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a front-end renderer for panels, draws using DiffDraw
|
/// Provides a front-end renderer for panels, draws using DiffDraw
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Screen : Panel
|
public class Screen : Panel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to output in color. Recommended for most terminals, might cause slowdowns in others
|
/// Called if Escape is pressed, use this for flow control
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="screen">This instance of the screen class</param>
|
||||||
|
/// <param name="e">Args</param>
|
||||||
|
public delegate void OnClose(Screen screen, EventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the selected control is changed
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="screen">This instance of the screen class</param>
|
||||||
|
/// <param name="args">Args</param>
|
||||||
|
public delegate void OnTabChanged(Screen screen, EventArgs args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called by ReadInput if a change in the window size is detected. Use this for positioning
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="screen">This instance of the screen class</param>
|
||||||
|
/// <param name="e">Args</param>
|
||||||
|
public delegate void OnWindowResize(Screen screen, EventArgs e);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to output in color. Recommended for most terminals, might cause slowdowns in others
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly bool Color;
|
public readonly bool Color;
|
||||||
/// <summary>
|
|
||||||
/// The current index of the tab-selected control in an array of selectable controls
|
|
||||||
/// </summary>
|
|
||||||
public int TabPoint = 0;
|
|
||||||
private int _wndWidth = Console.WindowWidth;
|
|
||||||
private int _wndHeight = Console.WindowHeight;
|
private int _wndHeight = Console.WindowHeight;
|
||||||
|
private int _wndWidth = Console.WindowWidth;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a screen object. Multiple can be instantiated but drawing one overrides others. Use panels for that
|
/// The current index of the tab-selected control in an array of selectable controls
|
||||||
|
/// </summary>
|
||||||
|
public int TabPoint;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a screen object. Multiple can be instantiated but drawing one overrides others. Use panels for that
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="width">The screens with</param>
|
/// <param name="width">The screens with</param>
|
||||||
/// <param name="height">The screens height</param>
|
/// <param name="height">The screens height</param>
|
||||||
|
@ -28,12 +52,13 @@ namespace CC_Functions.Commandline.TUI
|
||||||
public Screen(int width, int height, bool color = true)
|
public Screen(int width, int height, bool color = true)
|
||||||
{
|
{
|
||||||
Color = color;
|
Color = color;
|
||||||
|
Border = false;
|
||||||
Resize(width, height);
|
Resize(width, height);
|
||||||
Tab();
|
Tab();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resizes the screen. Make sure that this does not exceed the console size
|
/// Resizes the screen. Make sure that this does not exceed the console size
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="width"></param>
|
/// <param name="width"></param>
|
||||||
/// <param name="height"></param>
|
/// <param name="height"></param>
|
||||||
|
@ -42,9 +67,9 @@ namespace CC_Functions.Commandline.TUI
|
||||||
Size = new Size(width, height);
|
Size = new Size(width, height);
|
||||||
DiffDraw.Clear(width, height);
|
DiffDraw.Clear(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Renders the screen, draws it to the console and outputs the new state
|
/// Renders the screen, draws it to the console and outputs the new state
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The new state of the screen</returns>
|
/// <returns>The new state of the screen</returns>
|
||||||
public new Pixel[,] Render()
|
public new Pixel[,] Render()
|
||||||
|
@ -56,9 +81,12 @@ namespace CC_Functions.Commandline.TUI
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads input from Console and calls according functions
|
/// Reads input from Console and calls according functions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="canRedraw">Set to false to prevent redrawing if the screen should be updated. You can Render manually in that case</param>
|
/// <param name="canRedraw">
|
||||||
|
/// Set to false to prevent redrawing if the screen should be updated. You can Render manually in
|
||||||
|
/// that case
|
||||||
|
/// </param>
|
||||||
public void ReadInput(bool canRedraw = true)
|
public void ReadInput(bool canRedraw = true)
|
||||||
{
|
{
|
||||||
bool render = false;
|
bool render = false;
|
||||||
|
@ -101,8 +129,9 @@ namespace CC_Functions.Commandline.TUI
|
||||||
if (canRedraw && render)
|
if (canRedraw && render)
|
||||||
Render();
|
Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Increases the TabPoint or reverts back to 0 if at the end of selectables
|
/// Increases the TabPoint or reverts back to 0 if at the end of selectables
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="positive">Set to false to decrease instead</param>
|
/// <param name="positive">Set to false to decrease instead</param>
|
||||||
public void Tab(bool positive = true)
|
public void Tab(bool positive = true)
|
||||||
|
@ -111,8 +140,9 @@ namespace CC_Functions.Commandline.TUI
|
||||||
Control[] selectable = controls.Where(s => s.Selectable).ToArray();
|
Control[] selectable = controls.Where(s => s.Selectable).ToArray();
|
||||||
Tab(selectable, positive);
|
Tab(selectable, positive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Increases the TabPoint or reverts back to 0 if at the end of selectables
|
/// Increases the TabPoint or reverts back to 0 if at the end of selectables
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="selectable">The array of selectable controls to select from. You should most likely not use this</param>
|
/// <param name="selectable">The array of selectable controls to select from. You should most likely not use this</param>
|
||||||
/// <param name="positive">Set to false to decrease instead</param>
|
/// <param name="positive">Set to false to decrease instead</param>
|
||||||
|
@ -132,28 +162,24 @@ namespace CC_Functions.Commandline.TUI
|
||||||
}
|
}
|
||||||
foreach (Control control in selectable) control.Selected = false;
|
foreach (Control control in selectable) control.Selected = false;
|
||||||
selectable[TabPoint].Selected = true;
|
selectable[TabPoint].Selected = true;
|
||||||
|
TabChanged?.Invoke(this, new EventArgs());
|
||||||
Render();
|
Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called if Escape is pressed, use this for flow control
|
/// Called if Escape is pressed, use this for flow control
|
||||||
/// </summary>
|
|
||||||
/// <param name="screen">This instance of the screen class</param>
|
|
||||||
/// <param name="e">Args</param>
|
|
||||||
public delegate void OnClose(Screen screen, EventArgs e);
|
|
||||||
/// <summary>
|
|
||||||
/// Called if Escape is pressed, use this for flow control
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event OnClose Close;
|
public event OnClose Close;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called by ReadInput if a change in the window size is detected. Use this for positioning
|
/// Called by ReadInput if a change in the window size is detected. Use this for positioning
|
||||||
/// </summary>
|
|
||||||
/// <param name="screen">This instance of the screen class</param>
|
|
||||||
/// <param name="e">Args</param>
|
|
||||||
public delegate void OnWindowResize(Screen screen, EventArgs e);
|
|
||||||
/// <summary>
|
|
||||||
/// Called by ReadInput if a change in the window size is detected. Use this for positioning
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event OnWindowResize WindowResize;
|
public event OnWindowResize WindowResize;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the selected control is changed
|
||||||
|
/// </summary>
|
||||||
|
public event OnTabChanged TabChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,12 +4,21 @@ using CC_Functions.Misc;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a control to select a number from a range of numbers
|
/// Provides a control to select a number from a range of numbers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Slider : Control
|
public class Slider : Control
|
||||||
{
|
{
|
||||||
|
private int _maxValue = 10;
|
||||||
|
private int _minValue;
|
||||||
|
private int _value = 5;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates a new slider
|
/// The size of steps in this slider
|
||||||
|
/// </summary>
|
||||||
|
public int StepSize = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a new slider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Slider()
|
public Slider()
|
||||||
{
|
{
|
||||||
|
@ -32,8 +41,9 @@ namespace CC_Functions.Commandline.TUI
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum value for this slider
|
/// The maximum value for this slider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if too low/high</exception>
|
/// <exception cref="ArgumentOutOfRangeException">Thrown if too low/high</exception>
|
||||||
public int MaxValue
|
public int MaxValue
|
||||||
|
@ -44,11 +54,13 @@ namespace CC_Functions.Commandline.TUI
|
||||||
if (value > MinValue && value >= Value)
|
if (value > MinValue && value >= Value)
|
||||||
_maxValue = value;
|
_maxValue = value;
|
||||||
else
|
else
|
||||||
throw new ArgumentOutOfRangeException("MaxValue must be larger than MinValue and equal to or larger than Value");
|
throw new ArgumentOutOfRangeException(
|
||||||
|
"MaxValue must be larger than MinValue and equal to or larger than Value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The minimal value for this slider
|
/// The minimal value for this slider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if too low/high</exception>
|
/// <exception cref="ArgumentOutOfRangeException">Thrown if too low/high</exception>
|
||||||
public int MinValue
|
public int MinValue
|
||||||
|
@ -59,11 +71,13 @@ namespace CC_Functions.Commandline.TUI
|
||||||
if (value < MaxValue && value <= Value)
|
if (value < MaxValue && value <= Value)
|
||||||
_minValue = value;
|
_minValue = value;
|
||||||
else
|
else
|
||||||
throw new ArgumentOutOfRangeException("MaxValue must be larger than MinValue and equal to or smaller than Value");
|
throw new ArgumentOutOfRangeException(
|
||||||
|
"MaxValue must be larger than MinValue and equal to or smaller than Value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current value of this slider
|
/// The current value of this slider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if too low/high</exception>
|
/// <exception cref="ArgumentOutOfRangeException">Thrown if too low/high</exception>
|
||||||
public int Value
|
public int Value
|
||||||
|
@ -77,13 +91,10 @@ namespace CC_Functions.Commandline.TUI
|
||||||
throw new ArgumentOutOfRangeException("Value must be between MinValue and MaxValue");
|
throw new ArgumentOutOfRangeException("Value must be between MinValue and MaxValue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// The size of steps in this slider
|
/// <inheritdoc />
|
||||||
/// </summary>
|
public override bool Selectable { get; } = true;
|
||||||
public int StepSize = 1;
|
|
||||||
private int _value = 5;
|
|
||||||
private int _maxValue = 10;
|
|
||||||
private int _minValue = 0;
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Pixel[,] Render()
|
public override Pixel[,] Render()
|
||||||
{
|
{
|
||||||
|
@ -91,16 +102,17 @@ namespace CC_Functions.Commandline.TUI
|
||||||
int litValLen = Math.Max(MaxValue.ToString().Length, MinValue.ToString().Length);
|
int litValLen = Math.Max(MaxValue.ToString().Length, MinValue.ToString().Length);
|
||||||
int prevpts = Math.Max((Value - MinValue) * Size.Width / delta - litValLen - 2, 0);
|
int prevpts = Math.Max((Value - MinValue) * Size.Width / delta - litValLen - 2, 0);
|
||||||
int postpts = Math.Max(Size.Width - prevpts - litValLen - 2, 0);
|
int postpts = Math.Max(Size.Width - prevpts - litValLen - 2, 0);
|
||||||
char[,] rend = $"{new string('=', prevpts)}[{Value.ToString($"D{litValLen}")}]{new string('=', postpts)}".ToNdArray2D();
|
char[,] rend = $"{new string('=', prevpts)}[{Value.ToString($"D{(Value < 0 ? litValLen - 1 : litValLen)}")}]{new string('=', postpts)}"
|
||||||
|
.ToNdArray2D();
|
||||||
int f1 = rend.GetLength(0);
|
int f1 = rend.GetLength(0);
|
||||||
int f2 = rend.GetLength(1);
|
int f2 = rend.GetLength(1);
|
||||||
Pixel[,] output = new Pixel[f1, f2];
|
Pixel[,] output = new Pixel[f1, f2];
|
||||||
output.Populate(new Pixel());
|
output.Populate(new Pixel());
|
||||||
for (int i = 0; i < f1; i++)
|
for (int i = 0; i < f1; i++)
|
||||||
for (int j = 0; j < f2; j++) output[i, j] = new Pixel(Selected ? ForeColor : BackColor, Selected ? BackColor : ForeColor, rend[i, j]);
|
for (int j = 0; j < f2; j++)
|
||||||
|
output[i, j] = new Pixel(Selected ? ForeColor : BackColor, Selected ? BackColor : ForeColor,
|
||||||
|
rend[i, j]);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool Selectable { get; } = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,38 +7,42 @@ using CC_Functions.Misc;
|
||||||
namespace CC_Functions.Commandline.TUI
|
namespace CC_Functions.Commandline.TUI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A basic non-scrolling text-editor control
|
/// A basic non-scrolling text-editor control
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TextBox : Control
|
public class TextBox : Control
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The text inside this textbox
|
/// The text inside this textbox
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Content;
|
public string Content;
|
||||||
private string[] Lines
|
|
||||||
{
|
|
||||||
get => Content.Split('\n');
|
|
||||||
set => Content = string.Join('\n', value);
|
|
||||||
}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The "Cursors" position in this text box
|
/// The "Cursors" position in this text box
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Point Cursor = new Point(0, 0);
|
public Point Cursor = new Point(0, 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new text box
|
/// Creates a new text box
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">The text inside this text box</param>
|
/// <param name="content">The text inside this text box</param>
|
||||||
public TextBox(string content)
|
public TextBox(string content)
|
||||||
{
|
{
|
||||||
Content = content;
|
Content = content;
|
||||||
Input += (screen, args) =>
|
Input += (screen, args) => { ProcessInput(args.Info.Key, args.Info); };
|
||||||
{
|
|
||||||
ProcessInput(args.Info.Key, args.Info);
|
|
||||||
};
|
|
||||||
Click += (screen, args) => ProcessInput(ConsoleKey.Enter, new ConsoleKeyInfo());
|
Click += (screen, args) => ProcessInput(ConsoleKey.Enter, new ConsoleKeyInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string[] Lines
|
||||||
|
{
|
||||||
|
get => Content.Split('\n');
|
||||||
|
set => Content = string.Join('\n', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool Selectable { get; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Function to process input
|
/// Function to process input
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="key">The pressed key</param>
|
/// <param name="key">The pressed key</param>
|
||||||
/// <param name="info">Input metadata</param>
|
/// <param name="info">Input metadata</param>
|
||||||
|
@ -123,7 +127,7 @@ namespace CC_Functions.Commandline.TUI
|
||||||
tmp.RemoveAt(Cursor.Y);
|
tmp.RemoveAt(Cursor.Y);
|
||||||
lines = tmp.ToArray();
|
lines = tmp.ToArray();
|
||||||
Cursor.Y--;
|
Cursor.Y--;
|
||||||
Cursor.X = tmplen - 1;
|
Cursor.X = tmplen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Lines = lines;
|
Lines = lines;
|
||||||
|
@ -132,7 +136,7 @@ namespace CC_Functions.Commandline.TUI
|
||||||
if (lines.Length < Size.Height)
|
if (lines.Length < Size.Height)
|
||||||
{
|
{
|
||||||
tmp = lines.ToList();
|
tmp = lines.ToList();
|
||||||
lines[Cursor.Y] = lines[Cursor.Y].Insert(Cursor.X, "\n");
|
lines[Cursor.Y] = lines[Cursor.Y].Insert(Math.Max(Cursor.X, 0), "\n");
|
||||||
Cursor.Y++;
|
Cursor.Y++;
|
||||||
Cursor.X = 0;
|
Cursor.X = 0;
|
||||||
Lines = lines;
|
Lines = lines;
|
||||||
|
@ -142,6 +146,7 @@ namespace CC_Functions.Commandline.TUI
|
||||||
if (lines[Cursor.Y].Length < Size.Width)
|
if (lines[Cursor.Y].Length < Size.Width)
|
||||||
{
|
{
|
||||||
lines[Cursor.Y] = lines[Cursor.Y].Insert(Cursor.X, info.KeyChar.ToString());
|
lines[Cursor.Y] = lines[Cursor.Y].Insert(Cursor.X, info.KeyChar.ToString());
|
||||||
|
Cursor.X++;
|
||||||
Lines = lines;
|
Lines = lines;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -152,7 +157,7 @@ namespace CC_Functions.Commandline.TUI
|
||||||
public override Pixel[,] Render()
|
public override Pixel[,] Render()
|
||||||
{
|
{
|
||||||
char[,] inp1 = Content.ToNdArray2D();
|
char[,] inp1 = Content.ToNdArray2D();
|
||||||
inp1 = inp1.Resize(Size.Height, Size.Width - 2);
|
inp1 = inp1.Resize(Size.Height, Size.Width - 2, SpecialChars.Empty);
|
||||||
char[,] inp = new char[Size.Width, Size.Height];
|
char[,] inp = new char[Size.Width, Size.Height];
|
||||||
inp.Populate(SpecialChars.Empty);
|
inp.Populate(SpecialChars.Empty);
|
||||||
for (int i = 0; i < Size.Height; i++)
|
for (int i = 0; i < Size.Height; i++)
|
||||||
|
@ -160,18 +165,17 @@ namespace CC_Functions.Commandline.TUI
|
||||||
inp[0, i] = '[';
|
inp[0, i] = '[';
|
||||||
inp[Size.Width - 1, i] = ']';
|
inp[Size.Width - 1, i] = ']';
|
||||||
}
|
}
|
||||||
for (int i = 0; i < Size.Width; i++) inp[i, Size.Height - 1] = '.';
|
if (Lines.Length < Size.Width)
|
||||||
|
for (int i = 0; i < Size.Width; i++) inp[i, Size.Height - 1] = '.';
|
||||||
inp1.Rotate().CopyTo(inp, new Point(0, 1));
|
inp1.Rotate().CopyTo(inp, new Point(0, 1));
|
||||||
if (Selected)
|
if (Selected)
|
||||||
inp[Cursor.X + 1, Cursor.Y] = '▒';
|
inp[Math.Max(Cursor.X + 1, 1), Cursor.Y] = '▒';
|
||||||
Pixel[,] output = new Pixel[Size.Height, Size.Width];
|
Pixel[,] output = new Pixel[Size.Height, Size.Width];
|
||||||
|
output.Populate(new Pixel(Selected ? ForeColor : BackColor, Selected ? BackColor : ForeColor, SpecialChars.Empty));
|
||||||
for (int x = 0; x < Size.Width; x++)
|
for (int x = 0; x < Size.Width; x++)
|
||||||
for (int y = 0; y < Size.Height; y++)
|
for (int y = 0; y < Size.Height; y++)
|
||||||
output[y, x] = new Pixel(Selected ? ForeColor : BackColor, Selected ? BackColor : ForeColor, inp[x, y]);
|
output[y, x] = new Pixel(Selected ? ForeColor : BackColor, Selected ? BackColor : ForeColor, inp[x, y]);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool Selectable { get; } = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,12 +9,13 @@ using System.Text;
|
||||||
namespace CC_Functions.Commandline
|
namespace CC_Functions.Commandline
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides functions for parsing enumerables to powershell-like tables
|
/// Provides functions for parsing enumerables to powershell-like tables
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class TableParser
|
public static class TableParser
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses the enumerable to a table using with the specified headers and transformed to strings with the specified selector
|
/// Parses the enumerable to a table using with the specified headers and transformed to strings with the specified
|
||||||
|
/// selector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="values">The values to display</param>
|
/// <param name="values">The values to display</param>
|
||||||
/// <param name="columnHeaders">The headers for columns</param>
|
/// <param name="columnHeaders">The headers for columns</param>
|
||||||
|
@ -23,8 +24,9 @@ namespace CC_Functions.Commandline
|
||||||
/// <returns>The generated table</returns>
|
/// <returns>The generated table</returns>
|
||||||
public static string ToStringTable<T>(this IEnumerable<T> values, string[] columnHeaders,
|
public static string ToStringTable<T>(this IEnumerable<T> values, string[] columnHeaders,
|
||||||
params Func<T, object>[] valueSelectors) => ToStringTable(values.ToArray(), columnHeaders, valueSelectors);
|
params Func<T, object>[] valueSelectors) => ToStringTable(values.ToArray(), columnHeaders, valueSelectors);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses the array to a table using with the specified headers and transformed to strings with the specified selector
|
/// Parses the array to a table using with the specified headers and transformed to strings with the specified selector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="values">The values to display</param>
|
/// <param name="values">The values to display</param>
|
||||||
/// <param name="columnHeaders">The headers for columns</param>
|
/// <param name="columnHeaders">The headers for columns</param>
|
||||||
|
@ -53,8 +55,9 @@ namespace CC_Functions.Commandline
|
||||||
|
|
||||||
return ToStringTable(arrValues);
|
return ToStringTable(arrValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses the array to a table
|
/// Parses the array to a table
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="arrValues">The cells of the table</param>
|
/// <param name="arrValues">The cells of the table</param>
|
||||||
/// <returns>The generated table</returns>
|
/// <returns>The generated table</returns>
|
||||||
|
@ -104,8 +107,9 @@ namespace CC_Functions.Commandline
|
||||||
|
|
||||||
return maxColumnsWidth;
|
return maxColumnsWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses the enumerable to a table, transformed to strings with the specified selector
|
/// Parses the enumerable to a table, transformed to strings with the specified selector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="values">The values to display</param>
|
/// <param name="values">The values to display</param>
|
||||||
/// <param name="valueSelectors">Functions to get data for the cells</param>
|
/// <param name="valueSelectors">Functions to get data for the cells</param>
|
||||||
|
|
|
@ -5,12 +5,12 @@ using System.Linq;
|
||||||
namespace CC_Functions.Misc
|
namespace CC_Functions.Misc
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains extension functions to work with 1D and 2D arrays
|
/// Contains extension functions to work with 1D and 2D arrays
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ArrayFormatter
|
public static class ArrayFormatter
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies and resizes the array
|
/// Copies and resizes the array
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="original">The original array. This is not modified</param>
|
/// <param name="original">The original array. This is not modified</param>
|
||||||
/// <param name="elements">The new amount of elements</param>
|
/// <param name="elements">The new amount of elements</param>
|
||||||
|
@ -23,8 +23,9 @@ namespace CC_Functions.Misc
|
||||||
Array.Resize(ref output, elements);
|
Array.Resize(ref output, elements);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies and resizes the array
|
/// Copies and resizes the array
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="original">The original array. This is not modified</param>
|
/// <param name="original">The original array. This is not modified</param>
|
||||||
/// <param name="rows">The new amount of elements in dimension 0</param>
|
/// <param name="rows">The new amount of elements in dimension 0</param>
|
||||||
|
@ -43,8 +44,9 @@ namespace CC_Functions.Misc
|
||||||
newArray[i, j] = original[i, j];
|
newArray[i, j] = original[i, j];
|
||||||
return newArray;
|
return newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a string to a 2d char array using newlines
|
/// Converts a string to a 2d char array using newlines
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">The source string</param>
|
/// <param name="source">The source string</param>
|
||||||
/// <param name="defaultEl">The element to place in empty fields of the new array</param>
|
/// <param name="defaultEl">The element to place in empty fields of the new array</param>
|
||||||
|
@ -64,17 +66,20 @@ namespace CC_Functions.Misc
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears and fills the array with the specified value
|
/// Clears and fills the array with the specified value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="arr">The array to populate</param>
|
/// <param name="arr">The array to populate</param>
|
||||||
/// <param name="value">The value to copy to the array, defaults to the default value (usually null)</param>
|
/// <param name="value">The value to copy to the array, defaults to the default value (usually null)</param>
|
||||||
/// <typeparam name="T">The type of elements in the array</typeparam>
|
/// <typeparam name="T">The type of elements in the array</typeparam>
|
||||||
public static void Populate<T>(this T[] arr, T value = default) {
|
public static void Populate<T>(this T[] arr, T value = default)
|
||||||
|
{
|
||||||
for (int i = 0; i < arr.Length; i++) arr[i] = value;
|
for (int i = 0; i < arr.Length; i++) arr[i] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears and fills the array with the specified value
|
/// Clears and fills the array with the specified value
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="arr">The array to populate</param>
|
/// <param name="arr">The array to populate</param>
|
||||||
/// <param name="value">The value to copy to the array, defaults to the default value (usually null)</param>
|
/// <param name="value">The value to copy to the array, defaults to the default value (usually null)</param>
|
||||||
|
@ -84,10 +89,12 @@ namespace CC_Functions.Misc
|
||||||
int w = arr.GetLength(0);
|
int w = arr.GetLength(0);
|
||||||
int h = arr.GetLength(1);
|
int h = arr.GetLength(1);
|
||||||
for (int i = 0; i < w; i++)
|
for (int i = 0; i < w; i++)
|
||||||
for (int j = 0; j < h; j++) arr[i, j] = value;
|
for (int j = 0; j < h; j++)
|
||||||
|
arr[i, j] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies the content of a 2D array to another with offset
|
/// Copies the content of a 2D array to another with offset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="arr">The array to copy from</param>
|
/// <param name="arr">The array to copy from</param>
|
||||||
/// <param name="target">The array to copy to</param>
|
/// <param name="target">The array to copy to</param>
|
||||||
|
@ -101,12 +108,14 @@ namespace CC_Functions.Misc
|
||||||
int mh = target.GetLength(0);
|
int mh = target.GetLength(0);
|
||||||
int ow = offset.X;
|
int ow = offset.X;
|
||||||
int oh = offset.Y;
|
int oh = offset.Y;
|
||||||
for (int x = ow; x < Math.Min(mw, w + ow); x++)
|
if (oh >= 0 && ow >= 0 && mw >= 0 && mh >= 0 && w >= 0 && h >= 0)
|
||||||
for (int y = oh; y < Math.Min(mh, h + oh); y++)
|
for (int x = ow; x < Math.Min(mw, w + ow); x++)
|
||||||
target[y, x] = arr[y - oh, x - ow];
|
for (int y = oh; y < Math.Min(mh, h + oh); y++)
|
||||||
|
target[y, x] = arr[y - oh, x - ow];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies and rotates the 2d array (row->column, column->row)
|
/// Copies and rotates the 2d array (row->column, column->row)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="arr">The array to copy from</param>
|
/// <param name="arr">The array to copy from</param>
|
||||||
/// <typeparam name="T">The type of elements in the array</typeparam>
|
/// <typeparam name="T">The type of elements in the array</typeparam>
|
||||||
|
@ -117,7 +126,8 @@ namespace CC_Functions.Misc
|
||||||
int h = arr.GetLength(1);
|
int h = arr.GetLength(1);
|
||||||
T[,] target = new T[h, w];
|
T[,] target = new T[h, w];
|
||||||
for (int x = 0; x < w; x++)
|
for (int x = 0; x < w; x++)
|
||||||
for (int y = 0; y < h; y++) target[y, x] = arr[x, y];
|
for (int y = 0; y < h; y++)
|
||||||
|
target[y, x] = arr[x, y];
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,12 @@ using System.Security.Cryptography;
|
||||||
namespace CC_Functions.Misc
|
namespace CC_Functions.Misc
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains cryptographic functions
|
/// Contains cryptographic functions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Crypto
|
public static class Crypto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encrypts an array of bytes using SHA512. Use with <see cref="Decrypt">Decrypt</see>
|
/// Encrypts an array of bytes using SHA512. Use with <see cref="Decrypt">Decrypt</see>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">The array of bytes to encrypt</param>
|
/// <param name="data">The array of bytes to encrypt</param>
|
||||||
/// <param name="key">The key for encryption, later required to decrypt</param>
|
/// <param name="key">The key for encryption, later required to decrypt</param>
|
||||||
|
@ -49,8 +49,9 @@ namespace CC_Functions.Misc
|
||||||
|
|
||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decrypts an SHA512-encrypted byte array. Use with <see cref="Encrypt">Encrypt</see>
|
/// Decrypts an SHA512-encrypted byte array. Use with <see cref="Encrypt">Encrypt</see>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="encrypted">The array of bytes to decrypt</param>
|
/// <param name="encrypted">The array of bytes to decrypt</param>
|
||||||
/// <param name="key">The key the data was encrypted with</param>
|
/// <param name="key">The key the data was encrypted with</param>
|
||||||
|
|
|
@ -9,12 +9,12 @@ using System.Net;
|
||||||
namespace CC_Functions.Misc
|
namespace CC_Functions.Misc
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extension methods for various types
|
/// Extension methods for various types
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class GenericExtensions
|
public static class GenericExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an element from the dictionary or adds the default
|
/// Gets an element from the dictionary or adds the default
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dict">The dictionary to get from</param>
|
/// <param name="dict">The dictionary to get from</param>
|
||||||
/// <param name="key">The key to check</param>
|
/// <param name="key">The key to check</param>
|
||||||
|
@ -28,8 +28,9 @@ namespace CC_Functions.Misc
|
||||||
dict[key] = def;
|
dict[key] = def;
|
||||||
return dict[key];
|
return dict[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets an element and returns it
|
/// Sets an element and returns it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dict">The dictionary to set in</param>
|
/// <param name="dict">The dictionary to set in</param>
|
||||||
/// <param name="key">The key to set at</param>
|
/// <param name="key">The key to set at</param>
|
||||||
|
@ -42,8 +43,9 @@ namespace CC_Functions.Misc
|
||||||
dict[key] = val;
|
dict[key] = val;
|
||||||
return dict[key];
|
return dict[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to cast an object
|
/// Tries to cast an object
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="o">The object to try to parse</param>
|
/// <param name="o">The object to try to parse</param>
|
||||||
/// <param name="parsed">The parsed object (if successful) or the default (usually null)</param>
|
/// <param name="parsed">The parsed object (if successful) or the default (usually null)</param>
|
||||||
|
@ -62,8 +64,9 @@ namespace CC_Functions.Misc
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs a function that transforms an object in-line
|
/// Runs a function that transforms an object in-line
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">The object to run on</param>
|
/// <param name="self">The object to run on</param>
|
||||||
/// <param name="func">The function to run</param>
|
/// <param name="func">The function to run</param>
|
||||||
|
@ -71,8 +74,9 @@ namespace CC_Functions.Misc
|
||||||
/// <typeparam name="TOut">The output type</typeparam>
|
/// <typeparam name="TOut">The output type</typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TOut SelectO<TIn, TOut>(this TIn self, Func<TIn, TOut> func) => func.Invoke(self);
|
public static TOut SelectO<TIn, TOut>(this TIn self, Func<TIn, TOut> func) => func.Invoke(self);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs a function under a condition in-line (equal to if)
|
/// Runs a function under a condition in-line (equal to if)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="condition">The condition to check</param>
|
/// <param name="condition">The condition to check</param>
|
||||||
/// <param name="func">The function to run</param>
|
/// <param name="func">The function to run</param>
|
||||||
|
@ -81,8 +85,9 @@ namespace CC_Functions.Misc
|
||||||
if (condition)
|
if (condition)
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses a string to a value of an enum
|
/// Parses a string to a value of an enum
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The string to parse</param>
|
/// <param name="value">The string to parse</param>
|
||||||
/// <typeparam name="TEnum">The enum type (MUST be an enum)</typeparam>
|
/// <typeparam name="TEnum">The enum type (MUST be an enum)</typeparam>
|
||||||
|
@ -91,53 +96,60 @@ namespace CC_Functions.Misc
|
||||||
Enum.GetNames(typeof(TEnum)).First(s => s.ToLower() == value.ToLower()));
|
Enum.GetNames(typeof(TEnum)).First(s => s.ToLower() == value.ToLower()));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses a string to a nullable bool (defaults to null if parse fails)
|
/// Parses a string to a nullable bool (defaults to null if parse fails)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The st string to parse</param>
|
/// <param name="value">The st string to parse</param>
|
||||||
/// <returns>The output nullable bool</returns>
|
/// <returns>The output nullable bool</returns>
|
||||||
public static bool? ParseBool(string value) =>
|
public static bool? ParseBool(string value) =>
|
||||||
bool.TryParse(value, out bool tmp) ? (bool?)tmp : null;
|
bool.TryParse(value, out bool tmp) ? (bool?) tmp : null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// AND operation for nullable bools (uses <see cref="True">True</see>)
|
/// AND operation for nullable bools (uses <see cref="True">True</see>)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="left">First bool to check</param>
|
/// <param name="left">First bool to check</param>
|
||||||
/// <param name="right">Second bool to check</param>
|
/// <param name="right">Second bool to check</param>
|
||||||
/// <returns>The operation result</returns>
|
/// <returns>The operation result</returns>
|
||||||
public static bool And(this bool? left, bool? right) => left.True() && right.True();
|
public static bool And(this bool? left, bool? right) => left.True() && right.True();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// OR operation for nullable bools (uses <see cref="True">True</see>)
|
/// OR operation for nullable bools (uses <see cref="True">True</see>)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="left">First bool to check</param>
|
/// <param name="left">First bool to check</param>
|
||||||
/// <param name="right">Second bool to check</param>
|
/// <param name="right">Second bool to check</param>
|
||||||
/// <returns>The operation result</returns>
|
/// <returns>The operation result</returns>
|
||||||
public static bool Or(this bool? left, bool? right) => left.True() || right.True();
|
public static bool Or(this bool? left, bool? right) => left.True() || right.True();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// XOR operation for nullable bools (uses <see cref="True">True</see>)
|
/// XOR operation for nullable bools (uses <see cref="True">True</see>)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="left">First bool to check</param>
|
/// <param name="left">First bool to check</param>
|
||||||
/// <param name="right">Second bool to check</param>
|
/// <param name="right">Second bool to check</param>
|
||||||
/// <returns>The operation result</returns>
|
/// <returns>The operation result</returns>
|
||||||
public static bool Xor(this bool? left, bool? right) => left.Or(right) && !left.And(right);
|
public static bool Xor(this bool? left, bool? right) => left.Or(right) && !left.And(right);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the nullable bool is true (null->false)
|
/// Whether the nullable bool is true (null->false)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">Value to check</param>
|
/// <param name="self">Value to check</param>
|
||||||
/// <returns>Whether it is true</returns>
|
/// <returns>Whether it is true</returns>
|
||||||
public static bool True(this bool? self) => self == true;
|
public static bool True(this bool? self) => self == true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the nullable bool is false (null->false)
|
/// Whether the nullable bool is false (null->false)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">Value to check</param>
|
/// <param name="self">Value to check</param>
|
||||||
/// <returns>Whether it is false</returns>
|
/// <returns>Whether it is false</returns>
|
||||||
public static bool False(this bool? self) => self == false;
|
public static bool False(this bool? self) => self == false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the nullable bool is null
|
/// Whether the nullable bool is null
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">Value to check</param>
|
/// <param name="self">Value to check</param>
|
||||||
/// <returns>Whether it is null</returns>
|
/// <returns>Whether it is null</returns>
|
||||||
public static bool Null(this bool? self) => self == null;
|
public static bool Null(this bool? self) => self == null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes an element from a dictionary by its index (not key)
|
/// Removes an element from a dictionary by its index (not key)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dict">The dictionary to remove from</param>
|
/// <param name="dict">The dictionary to remove from</param>
|
||||||
/// <param name="index">The index of the value</param>
|
/// <param name="index">The index of the value</param>
|
||||||
|
@ -145,14 +157,16 @@ namespace CC_Functions.Misc
|
||||||
/// <typeparam name="TValue">The value type</typeparam>
|
/// <typeparam name="TValue">The value type</typeparam>
|
||||||
public static void RemoveAt<TKey, TValue>(this Dictionary<TKey, TValue> dict, int index) =>
|
public static void RemoveAt<TKey, TValue>(this Dictionary<TKey, TValue> dict, int index) =>
|
||||||
dict.Remove(dict.Keys.ToArray()[index]);
|
dict.Remove(dict.Keys.ToArray()[index]);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the size of a dictionary
|
/// Gets the size of a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="directory">The dictionary to check</param>
|
/// <param name="directory">The dictionary to check</param>
|
||||||
/// <returns>The size of the dictionary</returns>
|
/// <returns>The size of the dictionary</returns>
|
||||||
public static long GetSize(this DirectoryInfo directory) => IO.GetDirectorySize(directory.FullName);
|
public static long GetSize(this DirectoryInfo directory) => IO.GetDirectorySize(directory.FullName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a directory to an archive recursively
|
/// Adds a directory to an archive recursively
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="archive">The archive to add to</param>
|
/// <param name="archive">The archive to add to</param>
|
||||||
/// <param name="folderPath">The directory to add</param>
|
/// <param name="folderPath">The directory to add</param>
|
||||||
|
@ -177,8 +191,9 @@ namespace CC_Functions.Misc
|
||||||
ignoredPaths);
|
ignoredPaths);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// "Unshorten" (follow) an URL
|
/// "Unshorten" (follow) an URL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">The URL to unshorten</param>
|
/// <param name="self">The URL to unshorten</param>
|
||||||
/// <returns>The unshortened URL</returns>
|
/// <returns>The unshortened URL</returns>
|
||||||
|
@ -190,8 +205,9 @@ namespace CC_Functions.Misc
|
||||||
WebResponse resp = req.GetResponse();
|
WebResponse resp = req.GetResponse();
|
||||||
return resp.ResponseUri;
|
return resp.ResponseUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pings an URL to check for availability
|
/// Pings an URL to check for availability
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">The URL to check</param>
|
/// <param name="self">The URL to check</param>
|
||||||
/// <returns>Whether the service is online</returns>
|
/// <returns>Whether the service is online</returns>
|
||||||
|
@ -199,7 +215,7 @@ namespace CC_Functions.Misc
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(self);
|
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(self);
|
||||||
request.Timeout = 3000;
|
request.Timeout = 3000;
|
||||||
request.AllowAutoRedirect = true;
|
request.AllowAutoRedirect = true;
|
||||||
using WebResponse response = request.GetResponse();
|
using WebResponse response = request.GetResponse();
|
||||||
|
@ -210,27 +226,31 @@ namespace CC_Functions.Misc
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rounds a RectangleF to a Rectangle instead of flooring
|
/// Rounds a RectangleF to a Rectangle instead of flooring
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">The RectangleF to round</param>
|
/// <param name="self">The RectangleF to round</param>
|
||||||
/// <returns>The rounded Rectangle</returns>
|
/// <returns>The rounded Rectangle</returns>
|
||||||
public static Rectangle Round(this RectangleF self) => Rectangle.Round(self);
|
public static Rectangle Round(this RectangleF self) => Rectangle.Round(self);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ceilings a RectangleF to a Rectangle instead of flooring
|
/// Ceilings a RectangleF to a Rectangle instead of flooring
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">The RectangleF to ceil (?)</param>
|
/// <param name="self">The RectangleF to ceil (?)</param>
|
||||||
/// <returns>The ceiled (?) Rectangle</returns>
|
/// <returns>The ceiled (?) Rectangle</returns>
|
||||||
public static Rectangle Ceiling(this RectangleF self) => Rectangle.Ceiling(self);
|
public static Rectangle Ceiling(this RectangleF self) => Rectangle.Ceiling(self);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extension method for <see cref="Crypto">Crypto's</see> Encrypt
|
/// Extension method for <see cref="Crypto">Crypto's</see> Encrypt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">The data to encrypt</param>
|
/// <param name="self">The data to encrypt</param>
|
||||||
/// <param name="key">The key to encrypt with</param>
|
/// <param name="key">The key to encrypt with</param>
|
||||||
/// <returns>The encrypted data</returns>
|
/// <returns>The encrypted data</returns>
|
||||||
public static byte[] Encrypt(this byte[] self, byte[] key) => Crypto.Encrypt(self, key);
|
public static byte[] Encrypt(this byte[] self, byte[] key) => Crypto.Encrypt(self, key);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extension method for <see cref="Crypto">Crypto's</see> Decrypt
|
/// Extension method for <see cref="Crypto">Crypto's</see> Decrypt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="self">The data to decrypt</param>
|
/// <param name="self">The data to decrypt</param>
|
||||||
/// <param name="key">The key to decrypt with</param>
|
/// <param name="key">The key to decrypt with</param>
|
||||||
|
|
27
Misc/HID.cs
27
Misc/HID.cs
|
@ -8,17 +8,18 @@ using System.Text;
|
||||||
namespace CC_Functions.Misc
|
namespace CC_Functions.Misc
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Functions for hardware identidiers
|
/// Functions for hardware identidiers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Hid
|
public static class Hid
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to force Win32-based operation
|
/// Whether to force Win32-based operation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool ForceWindows = false;
|
public static bool ForceWindows = false;
|
||||||
|
|
||||||
private static byte[] _fingerPrint;
|
private static byte[] _fingerPrint;
|
||||||
|
|
||||||
private static readonly string HIDClasses = @"Win32_Processor:UniqueId
|
private static readonly string HidClasses = @"Win32_Processor:UniqueId
|
||||||
Win32_Processor:ProcessorId
|
Win32_Processor:ProcessorId
|
||||||
Win32_Processor:Name
|
Win32_Processor:Name
|
||||||
Win32_Processor:Manufacturer
|
Win32_Processor:Manufacturer
|
||||||
|
@ -33,8 +34,9 @@ Win32_BaseBoard:Manufacturer
|
||||||
Win32_BaseBoard:Name
|
Win32_BaseBoard:Name
|
||||||
Win32_BaseBoard:SerialNumber
|
Win32_BaseBoard:SerialNumber
|
||||||
Win32_NetworkAdapterConfiguration:MACAddress";
|
Win32_NetworkAdapterConfiguration:MACAddress";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The HID for this machine
|
/// The HID for this machine
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static byte[] Value
|
public static byte[] Value
|
||||||
{
|
{
|
||||||
|
@ -42,9 +44,13 @@ Win32_NetworkAdapterConfiguration:MACAddress";
|
||||||
{
|
{
|
||||||
if (_fingerPrint != null) return _fingerPrint;
|
if (_fingerPrint != null) return _fingerPrint;
|
||||||
string fingerprintTmp = "";
|
string fingerprintTmp = "";
|
||||||
if (ForceWindows || new [] {PlatformID.Xbox, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT, PlatformID.WinCE}.Contains(Environment.OSVersion.Platform))
|
if (ForceWindows ||
|
||||||
{
|
new[]
|
||||||
HIDClasses.Split(new[] {"\r\n"}, StringSplitOptions.None).Select(s =>
|
{
|
||||||
|
PlatformID.Xbox, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT,
|
||||||
|
PlatformID.WinCE
|
||||||
|
}.Contains(Environment.OSVersion.Platform))
|
||||||
|
HidClasses.Split(new[] {"\r\n"}, StringSplitOptions.None).Select(s =>
|
||||||
{
|
{
|
||||||
if (s.StartsWith("\n"))
|
if (s.StartsWith("\n"))
|
||||||
s = s.Remove(0, 1);
|
s = s.Remove(0, 1);
|
||||||
|
@ -65,7 +71,6 @@ Win32_NetworkAdapterConfiguration:MACAddress";
|
||||||
Console.WriteLine("Failed to read property");
|
Console.WriteLine("Failed to read property");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
else //Linux implementation. This will not work if you are using Mono on windows or do not have "uname", "lscpu" and "id" available
|
else //Linux implementation. This will not work if you are using Mono on windows or do not have "uname", "lscpu" and "id" available
|
||||||
{
|
{
|
||||||
Process p = new Process
|
Process p = new Process
|
||||||
|
@ -99,15 +104,17 @@ Win32_NetworkAdapterConfiguration:MACAddress";
|
||||||
return _fingerPrint;
|
return _fingerPrint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encrypts data using <see cref="Crypto">Crypto's</see> Encrypt and the HID
|
/// Encrypts data using <see cref="Crypto">Crypto's</see> Encrypt and the HID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="unencrypted">The data to encrypt</param>
|
/// <param name="unencrypted">The data to encrypt</param>
|
||||||
/// <returns>The encrypted data</returns>
|
/// <returns>The encrypted data</returns>
|
||||||
public static byte[] EncryptLocal(byte[] unencrypted) =>
|
public static byte[] EncryptLocal(byte[] unencrypted) =>
|
||||||
Crypto.Encrypt(unencrypted, Value);
|
Crypto.Encrypt(unencrypted, Value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decrypts data using <see cref="Crypto">Crypto's</see> Decrypt and the HID
|
/// Decrypts data using <see cref="Crypto">Crypto's</see> Decrypt and the HID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="encrypted">The data to decrypt</param>
|
/// <param name="encrypted">The data to decrypt</param>
|
||||||
/// <returns>The decrypted data</returns>
|
/// <returns>The decrypted data</returns>
|
||||||
|
|
|
@ -4,12 +4,12 @@ using System.IO;
|
||||||
namespace CC_Functions.Misc
|
namespace CC_Functions.Misc
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IO functions
|
/// IO functions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class IO
|
public static class IO
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recursively gets the size of an directory
|
/// Recursively gets the size of an directory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path of the directory</param>
|
/// <param name="path">The path of the directory</param>
|
||||||
/// <returns>The size of the directory</returns>
|
/// <returns>The size of the directory</returns>
|
||||||
|
@ -21,8 +21,9 @@ namespace CC_Functions.Misc
|
||||||
size += new FileInfo(t).Length;
|
size += new FileInfo(t).Length;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check whether the paths are equivalent (ignores case)
|
/// Check whether the paths are equivalent (ignores case)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path1">The first path to check</param>
|
/// <param name="path1">The first path to check</param>
|
||||||
/// <param name="path2">The second path to check</param>
|
/// <param name="path2">The second path to check</param>
|
||||||
|
|
|
@ -1,13 +1,156 @@
|
||||||
namespace CC_Functions.Misc
|
namespace CC_Functions.Misc
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Characters for use in CC-Functions.CommandLine
|
/// Characters for use in CC-Functions.CommandLine
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class SpecialChars
|
public static class SpecialChars
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The space character
|
/// The space character
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const char Empty = ' ';
|
public const char Empty = ' ';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with two lines
|
||||||
|
/// </summary>
|
||||||
|
public static class TwoLineSimple
|
||||||
|
{
|
||||||
|
// 1 connectors
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char Up = '║';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char Down = '║';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char Left = '═';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char Right = '═';
|
||||||
|
|
||||||
|
// 2 connectors
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpDown = '║';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char LeftRight = '═';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char DownRight = '╔';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpRight = '╚';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char DownLeft = '╗';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpLeft = '╝';
|
||||||
|
|
||||||
|
// 3 connectors
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpDownLeft = '╣';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpDownRight = '╠';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpLeftRight = '╩';
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char DownLeftRight = '╦';
|
||||||
|
|
||||||
|
// 4 connectors
|
||||||
|
/// <summary>
|
||||||
|
/// Wall with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpDownLeftRight = '╬';
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Simple line
|
||||||
|
/// </summary>
|
||||||
|
public static class OneLineSimple
|
||||||
|
{
|
||||||
|
// 1 connectors
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char Up = '╵';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char Down = '╷';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char Left = '╴';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char Right = '╶';
|
||||||
|
|
||||||
|
// 2 connectors
|
||||||
|
public const char UpDown = '│';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char LeftRight = '─';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char DownRight = '┌';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpRight = '└';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char DownLeft = '┐';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpLeft = '┘';
|
||||||
|
|
||||||
|
// 3 connectors
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpDownLeft = '┤';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpDownRight = '├';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpLeftRight = '┴';
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char DownLeftRight = '┬';
|
||||||
|
|
||||||
|
// 4 connectors
|
||||||
|
/// <summary>
|
||||||
|
/// Line with specified points
|
||||||
|
/// </summary>
|
||||||
|
public const char UpDownLeftRight = '┼';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,5 @@
|
||||||
using System;
|
using CC_Functions.W32.DCDrawer;
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using CC_Functions.Misc;
|
|
||||||
using CC_Functions.W32.Forms;
|
using CC_Functions.W32.Forms;
|
||||||
using CC_Functions.W32.DCDrawer;
|
|
||||||
using CC_Functions.W32.Hooks;
|
using CC_Functions.W32.Hooks;
|
||||||
using static CC_Functions.W32.Power;
|
using static CC_Functions.W32.Power;
|
||||||
|
|
||||||
|
@ -14,6 +9,8 @@ namespace CC_Functions.W32.Test
|
||||||
{
|
{
|
||||||
private static Wnd32 _tmpWnd32Obj;
|
private static Wnd32 _tmpWnd32Obj;
|
||||||
private static MainForm _mainF;
|
private static MainForm _mainF;
|
||||||
|
|
||||||
|
private static Wnd32 _wndSelectMouseCurrent;
|
||||||
private readonly KeyboardHook _kHook;
|
private readonly KeyboardHook _kHook;
|
||||||
private readonly MouseHook _mHook;
|
private readonly MouseHook _mHook;
|
||||||
private readonly Label[] _readerLabels;
|
private readonly Label[] _readerLabels;
|
||||||
|
@ -101,13 +98,13 @@ namespace CC_Functions.W32.Test
|
||||||
FormBorderStyle = FormBorderStyle.None,
|
FormBorderStyle = FormBorderStyle.None,
|
||||||
WindowState = FormWindowState.Maximized
|
WindowState = FormWindowState.Maximized
|
||||||
};
|
};
|
||||||
Label lab = new Label { AutoSize = true };
|
Label lab = new Label {AutoSize = true};
|
||||||
frm.Controls.Add(lab);
|
frm.Controls.Add(lab);
|
||||||
Panel pan = new Panel { BackColor = Color.Red };
|
Panel pan = new Panel {BackColor = Color.Red};
|
||||||
frm.Controls.Add(pan);
|
frm.Controls.Add(pan);
|
||||||
Wnd32[] children = TmpWnd.Children;
|
Wnd32[] children = TmpWnd.Children;
|
||||||
|
|
||||||
void UpdateGUI(Point labelPosition)
|
void UpdateGui(Point labelPosition)
|
||||||
{
|
{
|
||||||
lab.Text = $"{_wndSelectMouseCurrent.Title} ({_wndSelectMouseCurrent.HWnd})";
|
lab.Text = $"{_wndSelectMouseCurrent.Title} ({_wndSelectMouseCurrent.HWnd})";
|
||||||
lab.Location = new Point(labelPosition.X + 5, labelPosition.Y + 5);
|
lab.Location = new Point(labelPosition.X + 5, labelPosition.Y + 5);
|
||||||
|
@ -116,11 +113,11 @@ namespace CC_Functions.W32.Test
|
||||||
|
|
||||||
void MouseEventHandler(object sender1, MouseEventArgs e1)
|
void MouseEventHandler(object sender1, MouseEventArgs e1)
|
||||||
{
|
{
|
||||||
Func<Wnd32, bool> checkWnd = (s) => s.Position.Contains(e1.Location);
|
Func<Wnd32, bool> checkWnd = s => s.Position.Contains(e1.Location);
|
||||||
if (children.Any(checkWnd))
|
if (children.Any(checkWnd))
|
||||||
{
|
{
|
||||||
_wndSelectMouseCurrent = children.First(checkWnd);
|
_wndSelectMouseCurrent = children.First(checkWnd);
|
||||||
UpdateGUI(Cursor.Position);
|
UpdateGui(Cursor.Position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +148,7 @@ namespace CC_Functions.W32.Test
|
||||||
tmp = children.Length;
|
tmp = children.Length;
|
||||||
tmp--;
|
tmp--;
|
||||||
_wndSelectMouseCurrent = children[tmp];
|
_wndSelectMouseCurrent = children[tmp];
|
||||||
UpdateGUI(_wndSelectMouseCurrent.Position.Location);
|
UpdateGui(_wndSelectMouseCurrent.Position.Location);
|
||||||
break;
|
break;
|
||||||
case Keys.Down:
|
case Keys.Down:
|
||||||
case Keys.Right:
|
case Keys.Right:
|
||||||
|
@ -160,7 +157,7 @@ namespace CC_Functions.W32.Test
|
||||||
if (tmp == children.Length)
|
if (tmp == children.Length)
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
_wndSelectMouseCurrent = children[tmp];
|
_wndSelectMouseCurrent = children[tmp];
|
||||||
UpdateGUI(_wndSelectMouseCurrent.Position.Location);
|
UpdateGui(_wndSelectMouseCurrent.Position.Location);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +169,7 @@ namespace CC_Functions.W32.Test
|
||||||
pan.MouseMove += MouseEventHandler;
|
pan.MouseMove += MouseEventHandler;
|
||||||
lab.MouseMove += MouseEventHandler;
|
lab.MouseMove += MouseEventHandler;
|
||||||
frm.KeyDown += KeyEventHandler;
|
frm.KeyDown += KeyEventHandler;
|
||||||
UpdateGUI(Cursor.Position);
|
UpdateGui(Cursor.Position);
|
||||||
frm.Show();
|
frm.Show();
|
||||||
_wndSelectMouseCurrent = frm.GetWnd32();
|
_wndSelectMouseCurrent = frm.GetWnd32();
|
||||||
Cursor.Position = Cursor.Position;
|
Cursor.Position = Cursor.Position;
|
||||||
|
@ -263,7 +260,6 @@ namespace CC_Functions.W32.Test
|
||||||
|
|
||||||
private void Wnd_action_destroy_Click(object sender, EventArgs e) => TmpWnd.Destroy();
|
private void Wnd_action_destroy_Click(object sender, EventArgs e) => TmpWnd.Destroy();
|
||||||
|
|
||||||
private static Wnd32 _wndSelectMouseCurrent;
|
|
||||||
private void Wnd_select_mouse_Click(object sender, EventArgs e)
|
private void Wnd_select_mouse_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
WindowState = FormWindowState.Minimized;
|
WindowState = FormWindowState.Minimized;
|
||||||
|
@ -281,7 +277,7 @@ namespace CC_Functions.W32.Test
|
||||||
Panel pan = new Panel {BackColor = Color.Red};
|
Panel pan = new Panel {BackColor = Color.Red};
|
||||||
frm.Controls.Add(pan);
|
frm.Controls.Add(pan);
|
||||||
|
|
||||||
void UpdateGUI(Point labelPosition)
|
void UpdateGui(Point labelPosition)
|
||||||
{
|
{
|
||||||
lab.Text = $"{_wndSelectMouseCurrent.Title} ({_wndSelectMouseCurrent.HWnd})";
|
lab.Text = $"{_wndSelectMouseCurrent.Title} ({_wndSelectMouseCurrent.HWnd})";
|
||||||
lab.Location = new Point(labelPosition.X + 5, labelPosition.Y + 5);
|
lab.Location = new Point(labelPosition.X + 5, labelPosition.Y + 5);
|
||||||
|
@ -291,7 +287,7 @@ namespace CC_Functions.W32.Test
|
||||||
void MouseEventHandler(object sender1, MouseEventArgs e1)
|
void MouseEventHandler(object sender1, MouseEventArgs e1)
|
||||||
{
|
{
|
||||||
_wndSelectMouseCurrent = Wnd32.AllFromPoint(MousePosition, true).First(s => s != frm.GetWnd32());
|
_wndSelectMouseCurrent = Wnd32.AllFromPoint(MousePosition, true).First(s => s != frm.GetWnd32());
|
||||||
UpdateGUI(Cursor.Position);
|
UpdateGui(Cursor.Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandler(object sender1, EventArgs e1)
|
void EventHandler(object sender1, EventArgs e1)
|
||||||
|
@ -390,12 +386,12 @@ namespace CC_Functions.W32.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PointF MakePoint(float xPercent, float yPercent) => new PointF(
|
private static PointF MakePoint(float xPercent, float yPercent) => new PointF(
|
||||||
(Screen.PrimaryScreen.Bounds.Width * xPercent) / 100,
|
Screen.PrimaryScreen.Bounds.Width * xPercent / 100,
|
||||||
(Screen.PrimaryScreen.Bounds.Height * yPercent) / 100);
|
Screen.PrimaryScreen.Bounds.Height * yPercent / 100);
|
||||||
|
|
||||||
private static SizeF MakeSizeY(float xPercent, float yPercent) => new SizeF(
|
private static SizeF MakeSizeY(float xPercent, float yPercent) => new SizeF(
|
||||||
(Screen.PrimaryScreen.Bounds.Height * xPercent) / 100,
|
Screen.PrimaryScreen.Bounds.Height * xPercent / 100,
|
||||||
(Screen.PrimaryScreen.Bounds.Height * yPercent) / 100);
|
Screen.PrimaryScreen.Bounds.Height * yPercent / 100);
|
||||||
|
|
||||||
private void desk_set_Click(object sender, EventArgs e)
|
private void desk_set_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Test
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Test
|
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.DCDrawer
|
||||||
using System.Drawing;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.DCDrawer
|
|
||||||
{
|
{
|
||||||
public class DCBuffered : IDCDrawer
|
public class DCBuffered : IDCDrawer
|
||||||
{
|
{
|
||||||
|
@ -20,6 +16,8 @@ namespace CC_Functions.W32.DCDrawer
|
||||||
Graphics = buffer.Graphics;
|
Graphics = buffer.Graphics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Graphics Graphics { get; }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
buffer.Render(drawer.Graphics);
|
buffer.Render(drawer.Graphics);
|
||||||
|
@ -27,7 +25,5 @@ namespace CC_Functions.W32.DCDrawer
|
||||||
buffer.Dispose();
|
buffer.Dispose();
|
||||||
drawer.Dispose();
|
drawer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Graphics Graphics { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using CC_Functions.W32.Native;
|
||||||
using System.Drawing;
|
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.DCDrawer
|
namespace CC_Functions.W32.DCDrawer
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.DCDrawer
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.DCDrawer
|
|
||||||
{
|
{
|
||||||
public interface IDCDrawer : IDisposable
|
public interface IDCDrawer : IDisposable
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
using System;
|
using CC_Functions.W32.DCDrawer;
|
||||||
using System.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.IO;
|
|
||||||
using CC_Functions.W32.DCDrawer;
|
|
||||||
using CC_Functions.W32.Native;
|
using CC_Functions.W32.Native;
|
||||||
using Microsoft.Win32;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
namespace CC_Functions.W32
|
||||||
{
|
{
|
||||||
|
@ -16,10 +11,9 @@ namespace CC_Functions.W32
|
||||||
{
|
{
|
||||||
using (Bitmap bmpTemp =
|
using (Bitmap bmpTemp =
|
||||||
new Bitmap(
|
new Bitmap(
|
||||||
$@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\Microsoft\Windows\Themes\TranscodedWallpaper"))
|
$@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\Microsoft\Windows\Themes\TranscodedWallpaper")
|
||||||
{
|
)
|
||||||
return (Image) bmpTemp.Clone();
|
return (Image) bmpTemp.Clone();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Forms
|
namespace CC_Functions.W32.Forms
|
||||||
{
|
{
|
||||||
public class DataGridViewNumericUpDownCell : DataGridViewTextBoxCell
|
public class DataGridViewNumericUpDownCell : DataGridViewTextBoxCell
|
||||||
|
@ -399,7 +391,7 @@ namespace CC_Functions.W32.Forms
|
||||||
negativeSignKey = (Keys) VkKeyScan(negativeSignStr[0]);
|
negativeSignKey = (Keys) VkKeyScan(negativeSignStr[0]);
|
||||||
|
|
||||||
if ((char.IsDigit((char) e.KeyCode) ||
|
if ((char.IsDigit((char) e.KeyCode) ||
|
||||||
(e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9) ||
|
e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9 ||
|
||||||
negativeSignKey == e.KeyCode ||
|
negativeSignKey == e.KeyCode ||
|
||||||
Keys.Subtract == e.KeyCode) &&
|
Keys.Subtract == e.KeyCode) &&
|
||||||
!e.Shift && !e.Alt && !e.Control)
|
!e.Shift && !e.Alt && !e.Control)
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Forms
|
namespace CC_Functions.W32.Forms
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Forms
|
namespace CC_Functions.W32.Forms
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -86,9 +80,7 @@ namespace CC_Functions.W32.Forms
|
||||||
dataGridView.EditingPanel.BackColor = opaqueBackColor;
|
dataGridView.EditingPanel.BackColor = opaqueBackColor;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
BackColor = dataGridViewCellStyle.BackColor;
|
BackColor = dataGridViewCellStyle.BackColor;
|
||||||
}
|
|
||||||
|
|
||||||
ForeColor = dataGridViewCellStyle.ForeColor;
|
ForeColor = dataGridViewCellStyle.ForeColor;
|
||||||
TextAlign = DataGridViewNumericUpDownCell.TranslateAlignment(dataGridViewCellStyle.Alignment);
|
TextAlign = DataGridViewNumericUpDownCell.TranslateAlignment(dataGridViewCellStyle.Alignment);
|
||||||
|
@ -108,10 +100,10 @@ namespace CC_Functions.W32.Forms
|
||||||
if (textBox != null)
|
if (textBox != null)
|
||||||
// If the end of the selection is at the end of the string,
|
// If the end of the selection is at the end of the string,
|
||||||
// let the DataGridView treat the key message
|
// let the DataGridView treat the key message
|
||||||
if ((RightToLeft == RightToLeft.No &&
|
if (RightToLeft == RightToLeft.No &&
|
||||||
!(textBox.SelectionLength == 0 && textBox.SelectionStart == textBox.Text.Length)) ||
|
!(textBox.SelectionLength == 0 && textBox.SelectionStart == textBox.Text.Length) ||
|
||||||
(RightToLeft == RightToLeft.Yes &&
|
RightToLeft == RightToLeft.Yes &&
|
||||||
!(textBox.SelectionLength == 0 && textBox.SelectionStart == 0)))
|
!(textBox.SelectionLength == 0 && textBox.SelectionStart == 0))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -123,10 +115,10 @@ namespace CC_Functions.W32.Forms
|
||||||
// If the end of the selection is at the begining of the string
|
// If the end of the selection is at the begining of the string
|
||||||
// or if the entire text is selected and we did not start editing,
|
// or if the entire text is selected and we did not start editing,
|
||||||
// send this character to the dataGridView, else process the key message
|
// send this character to the dataGridView, else process the key message
|
||||||
if ((RightToLeft == RightToLeft.No &&
|
if (RightToLeft == RightToLeft.No &&
|
||||||
!(textBox.SelectionLength == 0 && textBox.SelectionStart == 0)) ||
|
!(textBox.SelectionLength == 0 && textBox.SelectionStart == 0) ||
|
||||||
(RightToLeft == RightToLeft.Yes &&
|
RightToLeft == RightToLeft.Yes &&
|
||||||
!(textBox.SelectionLength == 0 && textBox.SelectionStart == textBox.Text.Length)))
|
!(textBox.SelectionLength == 0 && textBox.SelectionStart == textBox.Text.Length))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -236,9 +228,7 @@ namespace CC_Functions.W32.Forms
|
||||||
// the negative sign is pressed.
|
// the negative sign is pressed.
|
||||||
bool notifyValueChange = false;
|
bool notifyValueChange = false;
|
||||||
if (char.IsDigit(e.KeyChar))
|
if (char.IsDigit(e.KeyChar))
|
||||||
{
|
|
||||||
notifyValueChange = true;
|
notifyValueChange = true;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NumberFormatInfo numberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
|
NumberFormatInfo numberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Forms
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Forms
|
|
||||||
{
|
{
|
||||||
public delegate void SetPropertyDelegate<TCtl, TProp>(TCtl control, Expression<Func<TCtl, TProp>> propexpr,
|
public delegate void SetPropertyDelegate<TCtl, TProp>(TCtl control, Expression<Func<TCtl, TProp>> propexpr,
|
||||||
TProp value) where TCtl : Control;
|
TProp value) where TCtl : Control;
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
using System;
|
using Timer = System.Timers.Timer;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using Timer = System.Timers.Timer;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Forms
|
namespace CC_Functions.W32.Forms
|
||||||
{
|
{
|
||||||
|
@ -15,7 +10,7 @@ namespace CC_Functions.W32.Forms
|
||||||
private const double IndicatorOffset = Math.PI / 16;
|
private const double IndicatorOffset = Math.PI / 16;
|
||||||
private const int MaximumIndicators = 6;
|
private const int MaximumIndicators = 6;
|
||||||
private const int SizeFactor = 20;
|
private const int SizeFactor = 20;
|
||||||
private const double StartAt = (2 * Math.PI) / 3;
|
private const double StartAt = 2 * Math.PI / 3;
|
||||||
private const double TimerInterval = 100.0;
|
private const double TimerInterval = 100.0;
|
||||||
private readonly Indicator[] indicators = new Indicator[MaximumIndicators];
|
private readonly Indicator[] indicators = new Indicator[MaximumIndicators];
|
||||||
private readonly Timer timer;
|
private readonly Timer timer;
|
||||||
|
@ -28,7 +23,7 @@ namespace CC_Functions.W32.Forms
|
||||||
public RotatingIndicator()
|
public RotatingIndicator()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
indicators[i] = new Indicator(StartAt + (i * IndicatorOffset));
|
indicators[i] = new Indicator(StartAt + i * IndicatorOffset);
|
||||||
SetStyle(
|
SetStyle(
|
||||||
ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
|
ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint |
|
||||||
ControlStyles.SupportsTransparentBackColor, true);
|
ControlStyles.SupportsTransparentBackColor, true);
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Windows.Forms;
|
namespace CC_Functions.W32.Forms
|
||||||
|
|
||||||
namespace CC_Functions.W32.Forms
|
|
||||||
{
|
{
|
||||||
partial class SelectBox<T>
|
partial class SelectBox<T>
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Forms
|
||||||
using System.Linq;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Forms
|
|
||||||
{
|
{
|
||||||
internal partial class SelectBox<T> : Form
|
internal partial class SelectBox<T> : Form
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
|
||||||
{
|
{
|
||||||
public static class GenericExtensions
|
public static class GenericExtensions
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
using System;
|
using CC_Functions.W32.Native;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Hooks
|
namespace CC_Functions.W32.Hooks
|
||||||
{
|
{
|
||||||
|
@ -38,9 +33,7 @@ namespace CC_Functions.W32.Hooks
|
||||||
{
|
{
|
||||||
using (Process curProcess = Process.GetCurrentProcess())
|
using (Process curProcess = Process.GetCurrentProcess())
|
||||||
using (ProcessModule curModule = curProcess.MainModule)
|
using (ProcessModule curModule = curProcess.MainModule)
|
||||||
{
|
|
||||||
return user32.SetWindowsHookEx(WH_KEYBOARD_LL, proc, kernel32.GetModuleHandle(curModule.ModuleName), 0);
|
return user32.SetWindowsHookEx(WH_KEYBOARD_LL, proc, kernel32.GetModuleHandle(curModule.ModuleName), 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Hooks
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Hooks
|
|
||||||
{
|
{
|
||||||
public sealed class KeyboardHookEventArgs : EventArgs
|
public sealed class KeyboardHookEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
using System;
|
using CC_Functions.W32.Native;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Hooks
|
namespace CC_Functions.W32.Hooks
|
||||||
{
|
{
|
||||||
|
@ -47,9 +42,7 @@ namespace CC_Functions.W32.Hooks
|
||||||
{
|
{
|
||||||
using (Process curProcess = Process.GetCurrentProcess())
|
using (Process curProcess = Process.GetCurrentProcess())
|
||||||
using (ProcessModule curModule = curProcess.MainModule)
|
using (ProcessModule curModule = curProcess.MainModule)
|
||||||
{
|
|
||||||
return user32.SetWindowsHookEx(WH_MOUSE_LL, proc, kernel32.GetModuleHandle(curModule.ModuleName), 0);
|
return user32.SetWindowsHookEx(WH_MOUSE_LL, proc, kernel32.GetModuleHandle(curModule.ModuleName), 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Hooks
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Hooks
|
|
||||||
{
|
{
|
||||||
public class MouseHookEventArgs : EventArgs
|
public class MouseHookEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Windows.Forms;
|
using CC_Functions.W32.Native;
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
namespace CC_Functions.W32
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Drawing;
|
using CC_Functions.W32.Native;
|
||||||
using System.Windows.Forms;
|
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
namespace CC_Functions.W32
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Runtime.InteropServices;
|
namespace CC_Functions.W32.Native
|
||||||
|
|
||||||
namespace CC_Functions.W32.Native
|
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct RECT
|
public struct RECT
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Native
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Native
|
|
||||||
{
|
{
|
||||||
internal static class advapi32
|
internal static class advapi32
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Native
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Native
|
|
||||||
{
|
{
|
||||||
internal static class gdi32
|
internal static class gdi32
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Native
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Native
|
|
||||||
{
|
{
|
||||||
internal static class kernel32
|
internal static class kernel32
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Native
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Native
|
|
||||||
{
|
{
|
||||||
internal static class ntdll
|
internal static class ntdll
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Native
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Native
|
|
||||||
{
|
{
|
||||||
internal static class shell32
|
internal static class shell32
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
using System;
|
namespace CC_Functions.W32.Native
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32.Native
|
|
||||||
{
|
{
|
||||||
internal static class user32
|
internal static class user32
|
||||||
{
|
{
|
||||||
public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr lParam);
|
|
||||||
public delegate bool EnumDelegate(IntPtr hWnd, int lParam);
|
public delegate bool EnumDelegate(IntPtr hWnd, int lParam);
|
||||||
|
|
||||||
|
public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr lParam);
|
||||||
|
|
||||||
public delegate IntPtr LowLevelProc(int nCode, IntPtr wParam, IntPtr lParam);
|
public delegate IntPtr LowLevelProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
|
@ -130,7 +127,7 @@ namespace CC_Functions.W32.Native
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
||||||
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
|
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
|
||||||
|
|
||||||
[DllImport("user32")]
|
[DllImport("user32")]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);
|
public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using CC_Functions.W32.Native;
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
using static CC_Functions.W32.Privileges;
|
using static CC_Functions.W32.Privileges;
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
namespace CC_Functions.W32
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
using CC_Functions.W32.Native;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
namespace CC_Functions.W32
|
||||||
{
|
{
|
||||||
|
@ -124,18 +120,14 @@ namespace CC_Functions.W32
|
||||||
new Win32Exception());
|
new Win32Exception());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
throw new InvalidOperationException("AdjustTokenPrivileges failed.",
|
throw new InvalidOperationException("AdjustTokenPrivileges failed.",
|
||||||
new Win32Exception());
|
new Win32Exception());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
string.Format(CultureInfo.InvariantCulture,
|
string.Format(CultureInfo.InvariantCulture,
|
||||||
"OpenProcessToken failed. CurrentProcess: {0}", currentProcess.ToInt32()),
|
"OpenProcessToken failed. CurrentProcess: {0}", currentProcess.ToInt32()),
|
||||||
new Win32Exception());
|
new Win32Exception());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -144,12 +136,10 @@ namespace CC_Functions.W32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
string.Format(CultureInfo.InvariantCulture,
|
string.Format(CultureInfo.InvariantCulture,
|
||||||
"LookupPrivilegeValue failed. SecurityEntityValue: {0}", securityEntityValue),
|
"LookupPrivilegeValue failed. SecurityEntityValue: {0}", securityEntityValue),
|
||||||
new Win32Exception());
|
new Win32Exception());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
using System;
|
using CC_Functions.W32.DCDrawer;
|
||||||
using System.Drawing;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using CC_Functions.W32.DCDrawer;
|
|
||||||
using CC_Functions.W32.Native;
|
using CC_Functions.W32.Native;
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
namespace CC_Functions.W32
|
||||||
|
@ -30,10 +27,7 @@ namespace CC_Functions.W32
|
||||||
|
|
||||||
public static void Draw(Image img)
|
public static void Draw(Image img)
|
||||||
{
|
{
|
||||||
using (IDCDrawer drawerBuffered = GetDrawer())
|
using (IDCDrawer drawerBuffered = GetDrawer()) drawerBuffered.Graphics.DrawImage(img, GetBounds());
|
||||||
{
|
|
||||||
drawerBuffered.Graphics.DrawImage(img, GetBounds());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IDCDrawer GetDrawer(bool buffer = true)
|
public static IDCDrawer GetDrawer(bool buffer = true)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Security.Principal;
|
namespace CC_Functions.W32
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
|
||||||
{
|
{
|
||||||
public static class MiscFunctions
|
public static class MiscFunctions
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using CC_Functions.W32.Native;
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
namespace CC_Functions.W32
|
||||||
{
|
{
|
||||||
|
|
40
W32/Wnd32.cs
40
W32/Wnd32.cs
|
@ -1,13 +1,4 @@
|
||||||
using System;
|
using CC_Functions.W32.Native;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using CC_Functions.W32.Native;
|
|
||||||
|
|
||||||
namespace CC_Functions.W32
|
namespace CC_Functions.W32
|
||||||
{
|
{
|
||||||
|
@ -16,10 +7,8 @@ namespace CC_Functions.W32
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Wnd32 : IEquatable<Wnd32>
|
public sealed class Wnd32 : IEquatable<Wnd32>
|
||||||
{
|
{
|
||||||
#region Exposed
|
#region Exposed
|
||||||
|
#region CreateInstance
|
||||||
#region CreateInstance
|
|
||||||
|
|
||||||
private Wnd32(IntPtr handle) => HWnd = handle;
|
private Wnd32(IntPtr handle) => HWnd = handle;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -61,7 +50,8 @@ namespace CC_Functions.W32
|
||||||
/// <param name="point">The point to scan</param>
|
/// <param name="point">The point to scan</param>
|
||||||
/// <param name="visible">Whether windows need to be visible</param>
|
/// <param name="visible">Whether windows need to be visible</param>
|
||||||
/// <returns>The windows</returns>
|
/// <returns>The windows</returns>
|
||||||
public static Wnd32[] AllFromPoint(Point point, bool visible = false) => All.Where(s => s.Position.Contains(point) && s.Shown || !visible).ToArray();
|
public static Wnd32[] AllFromPoint(Point point, bool visible = false) =>
|
||||||
|
All.Where(s => s.Position.Contains(point) && s.Shown || !visible).ToArray();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the window associated with the forms handle
|
/// Gets the window associated with the forms handle
|
||||||
|
@ -100,11 +90,9 @@ namespace CC_Functions.W32
|
||||||
/// The current programs console window. Do NOT use this if you are not targeting a console app or allocating a console
|
/// The current programs console window. Do NOT use this if you are not targeting a console app or allocating a console
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Wnd32 ConsoleWindow => FromHandle(kernel32.GetConsoleWindow());
|
public static Wnd32 ConsoleWindow => FromHandle(kernel32.GetConsoleWindow());
|
||||||
|
#endregion CreateInstance
|
||||||
|
|
||||||
#endregion CreateInstance
|
#region InstanceActions
|
||||||
|
|
||||||
#region InstanceActions
|
|
||||||
|
|
||||||
public Wnd32[] Children
|
public Wnd32[] Children
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -357,13 +345,10 @@ namespace CC_Functions.W32
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion InstanceActions
|
||||||
|
#endregion Exposed
|
||||||
|
|
||||||
#endregion InstanceActions
|
#region Internal
|
||||||
|
|
||||||
#endregion Exposed
|
|
||||||
|
|
||||||
#region Internal
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The windows' handle
|
/// The windows' handle
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -378,7 +363,7 @@ namespace CC_Functions.W32
|
||||||
_windowHandles.Add(hWnd);
|
_windowHandles.Add(hWnd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool EnumWindow(IntPtr hWnd, IntPtr lParam)
|
private bool EnumWindow(IntPtr hWnd, IntPtr lParam)
|
||||||
{
|
{
|
||||||
GCHandle gcChildhandlesList = GCHandle.FromIntPtr(lParam);
|
GCHandle gcChildhandlesList = GCHandle.FromIntPtr(lParam);
|
||||||
|
@ -390,7 +375,6 @@ namespace CC_Functions.W32
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endregion Internal
|
||||||
#endregion Internal
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue