This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
CC-Functions/Commandline/TUI/Pixel.cs

60 lines
1.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
namespace CC_Functions.Commandline.TUI
{
public class Pixel
{
private sealed class ColorContentEqualityComparer : IEqualityComparer<Pixel>
{
public bool Equals(Pixel x, Pixel y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
return x.GetHashCode().Equals(y.GetHashCode());
}
public int GetHashCode(Pixel obj) => obj.GetHashCode();
}
public static IEqualityComparer<Pixel> ColorContentComparer { get; } = new ColorContentEqualityComparer();
protected bool Equals(Pixel other) => ColorContentComparer.Equals(this, other);
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);
}
public override int GetHashCode() => HashCode.Combine((int) BackColor, (int) ForeColor, Content);
public ConsoleColor BackColor;
public ConsoleColor ForeColor;
public char Content;
public Pixel(ConsoleColor backColor, ConsoleColor foreColor, char content)
{
BackColor = backColor;
ForeColor = foreColor;
Content = content;
}
public Pixel(char content) : this(Console.BackgroundColor, Console.ForegroundColor, content)
{
}
public Pixel() : this(' ')
{
}
public static bool operator ==(Pixel a, Pixel b) => a.Equals(b);
public static bool operator !=(Pixel a, Pixel b) => !a.Equals(b);
public override string ToString() => Content.ToString();
}
}