diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/DrawingBoxSymbol.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/DrawingBoxSymbol.cs index 5f660636..e6dd1ab4 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/DrawingBoxSymbol.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/DrawingBoxSymbol.cs @@ -56,46 +56,46 @@ private static char GetBoxSymbol(byte upRightDownLeft) return horizontal ? '╪' : '╫'; default: + { + return upRightDownLeft switch { - return upRightDownLeft switch - { - EmptySymbol => char.MinValue, - BoldSymbol => '█', - 0b0000_1001 => '┘', - 0b1000_1001 => '╜', - 0b0001_1001 => '╛', - 0b1001_1001 => '╝', - 0b0000_0011 => '┐', - 0b0010_0011 => '╖', - 0b0001_0011 => '╕', - 0b0011_0011 => '╗', - 0b0000_0110 => '┌', - 0b0100_0110 => '╒', - 0b0010_0110 => '╓', - 0b0110_0110 => '╔', - 0b0000_1100 => '└', - 0b0100_1100 => '╘', - 0b1000_1100 => '╙', - 0b1100_1100 => '╚', - 0b0000_1110 => '├', - 0b1000_1110 or 0b0010_1110 or 0b1010_1110 => '╟', - 0b0100_1110 => '╞', - 0b1100_1110 or 0b0110_1110 or 0b1110_1110 => '╠', - 0b0000_1011 => '┤', - 0b1000_1011 or 0b0010_1011 or 0b1010_1011 => '╢', - 0b0001_1011 => '╡', - 0b1001_1011 or 0b0011_1011 or 0b1011_1011 => '╣', - 0b0000_1101 => '┴', - 0b1000_1101 => '╨', - 0b0100_1101 or 0b0001_1101 or 0b0101_1101 => '╧', - 0b1100_1101 or 0b1001_1101 or 0b1101_1101 => '╩', - 0b0000_0111 => '┬', - 0b0010_0111 => '╥', - 0b0100_0111 or 0b0001_0111 or 0b0101_0111 => '╤', - 0b0110_0111 or 0b0011_0111 or 0b0111_0111 => '╦', - _ => throw new InvalidOperationException() - }; - } + EmptySymbol => char.MinValue, + BoldSymbol => '█', + 0b0000_1001 => '┘', + 0b1000_1001 => '╜', + 0b0001_1001 => '╛', + 0b1001_1001 => '╝', + 0b0000_0011 => '┐', + 0b0010_0011 => '╖', + 0b0001_0011 => '╕', + 0b0011_0011 => '╗', + 0b0000_0110 => '┌', + 0b0100_0110 => '╒', + 0b0010_0110 => '╓', + 0b0110_0110 => '╔', + 0b0000_1100 => '└', + 0b0100_1100 => '╘', + 0b1000_1100 => '╙', + 0b1100_1100 => '╚', + 0b0000_1110 => '├', + 0b1000_1110 or 0b0010_1110 or 0b1010_1110 => '╟', + 0b0100_1110 => '╞', + 0b1100_1110 or 0b0110_1110 or 0b1110_1110 => '╠', + 0b0000_1011 => '┤', + 0b1000_1011 or 0b0010_1011 or 0b1010_1011 => '╢', + 0b0001_1011 => '╡', + 0b1001_1011 or 0b0011_1011 or 0b1011_1011 => '╣', + 0b0000_1101 => '┴', + 0b1000_1101 => '╨', + 0b0100_1101 or 0b0001_1101 or 0b0101_1101 => '╧', + 0b1100_1101 or 0b1001_1101 or 0b1101_1101 => '╩', + 0b0000_0111 => '┬', + 0b0010_0111 => '╥', + 0b0100_0111 or 0b0001_0111 or 0b0101_0111 => '╤', + 0b0110_0111 or 0b0011_0111 or 0b0111_0111 => '╦', + _ => throw new InvalidOperationException() + }; + } } } @@ -135,18 +135,28 @@ public static DrawingBoxSymbol UpRightDownLeftFromPattern(byte pattern, LineStyl } public bool Equals(DrawingBoxSymbol other) - => _upRightDownLeft == other._upRightDownLeft; + { + return _upRightDownLeft == other._upRightDownLeft; + } public override bool Equals([NotNullWhen(true)] object obj) - => obj is DrawingBoxSymbol other && this.Equals(other); + { + return obj is DrawingBoxSymbol other && Equals(other); + } public override int GetHashCode() - => _upRightDownLeft.GetHashCode(); + { + return _upRightDownLeft.GetHashCode(); + } public static bool operator ==(DrawingBoxSymbol left, DrawingBoxSymbol right) - => left.Equals(right); - + { + return left.Equals(right); + } + public static bool operator !=(DrawingBoxSymbol left, DrawingBoxSymbol right) - => !left.Equals(right); + { + return !left.Equals(right); + } } } \ No newline at end of file diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs index a60d0893..0f5ae2a3 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/Pixel.cs @@ -125,20 +125,30 @@ private static Color MergeColors(Color target, Color source) } public bool Equals(Pixel other) - => Foreground.Equals(other.Foreground) && - Background.Equals(other.Background) && - IsCaret.Equals(IsCaret); + { + return Foreground.Equals(other.Foreground) && + Background.Equals(other.Background) && + IsCaret.Equals(IsCaret); + } public override bool Equals([NotNullWhen(true)] object obj) - => obj is Pixel other && this.Equals(other); + { + return obj is Pixel other && Equals(other); + } public override int GetHashCode() - => HashCode.Combine(Foreground, Background, IsCaret); + { + return HashCode.Combine(Foreground, Background, IsCaret); + } public static bool operator ==(Pixel left, Pixel right) - => left.Equals(right); + { + return left.Equals(right); + } public static bool operator !=(Pixel left, Pixel right) - => !left.Equals(right); + { + return !left.Equals(right); + } } } \ No newline at end of file diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBackground.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBackground.cs index f2584faf..f2865c43 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBackground.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBackground.cs @@ -45,20 +45,30 @@ public PixelBackground Shade() return new PixelBackground(newMode, newColor); } - + public bool Equals(PixelBackground other) - => Color.Equals(other.Color) && Mode == other.Mode; + { + return Color.Equals(other.Color) && Mode == other.Mode; + } public override bool Equals([NotNullWhen(true)] object obj) - => obj is PixelBackground other && this.Equals(other); + { + return obj is PixelBackground other && Equals(other); + } public override int GetHashCode() - => HashCode.Combine(Color, Mode); + { + return HashCode.Combine(Color, Mode); + } public static bool operator ==(PixelBackground left, PixelBackground right) - => left.Equals(right); + { + return left.Equals(right); + } public static bool operator !=(PixelBackground left, PixelBackground right) - => !left.Equals(right); + { + return !left.Equals(right); + } } } \ No newline at end of file diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelForeground.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelForeground.cs index c1b51426..2a89eca4 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelForeground.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelForeground.cs @@ -49,22 +49,32 @@ public PixelForeground Blend(PixelForeground pixelAboveForeground) } public bool Equals(PixelForeground other) - => Symbol.Equals(other.Symbol) && - Color.Equals(other.Color) && - Weight == other.Weight && - Style == other.Style && - Equals(TextDecorations, other.TextDecorations); + { + return Symbol.Equals(other.Symbol) && + Color.Equals(other.Color) && + Weight == other.Weight && + Style == other.Style && + Equals(TextDecorations, other.TextDecorations); + } public override bool Equals([NotNullWhen(true)] object obj) - => obj is PixelForeground other && this.Equals(other); + { + return obj is PixelForeground other && Equals(other); + } public override int GetHashCode() - => HashCode.Combine(Symbol, Color, (int)Weight, (int)Style, TextDecorations); + { + return HashCode.Combine(Symbol, Color, (int)Weight, (int)Style, TextDecorations); + } public static bool operator ==(PixelForeground left, PixelForeground right) - => left.Equals(right); + { + return left.Equals(right); + } public static bool operator !=(PixelForeground left, PixelForeground right) - => !left.Equals(right); + { + return !left.Equals(right); + } } } \ No newline at end of file diff --git a/src/Consolonia.Core/Drawing/PixelBufferImplementation/SimpleSymbol.cs b/src/Consolonia.Core/Drawing/PixelBufferImplementation/SimpleSymbol.cs index d19fd456..bb9da67b 100644 --- a/src/Consolonia.Core/Drawing/PixelBufferImplementation/SimpleSymbol.cs +++ b/src/Consolonia.Core/Drawing/PixelBufferImplementation/SimpleSymbol.cs @@ -48,18 +48,28 @@ public ISymbol Blend(ref ISymbol symbolAbove) } public bool Equals(SimpleSymbol other) - => Text.Equals(other.Text, StringComparison.Ordinal); + { + return Text.Equals(other.Text, StringComparison.Ordinal); + } public override bool Equals([NotNullWhen(true)] object obj) - => obj is SimpleSymbol other && this.Equals(other); + { + return obj is SimpleSymbol other && Equals(other); + } public override int GetHashCode() - => Text.GetHashCode(StringComparison.Ordinal); + { + return Text.GetHashCode(StringComparison.Ordinal); + } public static bool operator ==(SimpleSymbol left, SimpleSymbol right) - => left.Equals(right); + { + return left.Equals(right); + } public static bool operator !=(SimpleSymbol left, SimpleSymbol right) - => !left.Equals(right); + { + return !left.Equals(right); + } } -} +} \ No newline at end of file diff --git a/src/Consolonia.Core/Drawing/RenderTarget.cs b/src/Consolonia.Core/Drawing/RenderTarget.cs index 17d9c88e..680eab71 100644 --- a/src/Consolonia.Core/Drawing/RenderTarget.cs +++ b/src/Consolonia.Core/Drawing/RenderTarget.cs @@ -109,38 +109,38 @@ private void RenderToDevice() var flushingBuffer = new FlushingBuffer(_console); for (ushort y = 0; y < pixelBuffer.Height; y++) - for (ushort x = 0; x < pixelBuffer.Width;) - { - Pixel pixel = pixelBuffer[(PixelBufferCoordinate)(x, y)]; + for (ushort x = 0; x < pixelBuffer.Width;) + { + Pixel pixel = pixelBuffer[(PixelBufferCoordinate)(x, y)]; - if (pixel.IsCaret) - { - if (caretPosition != null) - throw new InvalidOperationException("Caret is already shown"); - caretPosition = new PixelBufferCoordinate(x, y); - } + if (pixel.IsCaret) + { + if (caretPosition != null) + throw new InvalidOperationException("Caret is already shown"); + caretPosition = new PixelBufferCoordinate(x, y); + } - /* todo: There is not IWindowImpl.Invalidate anymore. - if (!_consoleWindow.InvalidatedRects.Any(rect => - rect.ContainsExclusive(new Point(x, y)))) continue;*/ - if (pixel.Background.Mode != PixelBackgroundMode.Colored) - throw new InvalidOperationException( - "All pixels in the buffer must have exact console color before rendering"); + /* todo: There is not IWindowImpl.Invalidate anymore. + if (!_consoleWindow.InvalidatedRects.Any(rect => + rect.ContainsExclusive(new Point(x, y)))) continue;*/ + if (pixel.Background.Mode != PixelBackgroundMode.Colored) + throw new InvalidOperationException( + "All pixels in the buffer must have exact console color before rendering"); - //todo: indexOutOfRange during resize - if (_cache[x, y] == pixel) - { - x++; - continue; - } + //todo: indexOutOfRange during resize + if (_cache[x, y] == pixel) + { + x++; + continue; + } - _cache[x, y] = pixel; + _cache[x, y] = pixel; - flushingBuffer.WritePixel(new PixelBufferCoordinate(x, y), pixel); + flushingBuffer.WritePixel(new PixelBufferCoordinate(x, y), pixel); - x += pixel.Foreground.Symbol.Width; - } + x += pixel.Foreground.Symbol.Width; + } flushingBuffer.Flush(); diff --git a/src/Tests/Consolonia.Core.Tests/DrawingBoxSymbolTests.cs b/src/Tests/Consolonia.Core.Tests/DrawingBoxSymbolTests.cs index 54a57a18..9e4b5dcc 100644 --- a/src/Tests/Consolonia.Core.Tests/DrawingBoxSymbolTests.cs +++ b/src/Tests/Consolonia.Core.Tests/DrawingBoxSymbolTests.cs @@ -50,15 +50,15 @@ public void BlendAllSymbols() }; foreach ((byte code1, string _) in symbols) - foreach ((byte code2, string _) in symbols) - { - ISymbol symbol1 = new DrawingBoxSymbol(code1); - ISymbol symbol2 = new DrawingBoxSymbol(code2); - ISymbol blendedSymbol = symbol1.Blend(ref symbol2); - if (symbol1.Text != symbol2.Text) - Debug.WriteLine($"{symbol1.Text} + {symbol2.Text} => {blendedSymbol.Text}"); - Assert.That(blendedSymbol.Text, Is.Not.Null); - } + foreach ((byte code2, string _) in symbols) + { + ISymbol symbol1 = new DrawingBoxSymbol(code1); + ISymbol symbol2 = new DrawingBoxSymbol(code2); + ISymbol blendedSymbol = symbol1.Blend(ref symbol2); + if (symbol1.Text != symbol2.Text) + Debug.WriteLine($"{symbol1.Text} + {symbol2.Text} => {blendedSymbol.Text}"); + Assert.That(blendedSymbol.Text, Is.Not.Null); + } } [Test] @@ -112,6 +112,5 @@ public void Hash() set2.Add(new DrawingBoxSymbol(0b0000_1111)); Assert.That(set2.Count, Is.EqualTo(1)); } - } } \ No newline at end of file diff --git a/src/Tests/Consolonia.Core.Tests/PixelForegroundTests.cs b/src/Tests/Consolonia.Core.Tests/PixelForegroundTests.cs index bb8a39ec..029315e7 100644 --- a/src/Tests/Consolonia.Core.Tests/PixelForegroundTests.cs +++ b/src/Tests/Consolonia.Core.Tests/PixelForegroundTests.cs @@ -85,14 +85,14 @@ public void Equality() public void Inequality() { var pixelForeground = new PixelForeground(new SimpleSymbol('a'), Colors.Red); - foreach (var variation in new PixelForeground[] - { - new(new SimpleSymbol('b'), Colors.Red), - new(new SimpleSymbol('a'), Colors.Blue), - new(new SimpleSymbol('a'), Colors.Red, FontWeight.Bold), - new(new SimpleSymbol('a'), Colors.Red, style: FontStyle.Italic), - new(new SimpleSymbol('a'), Colors.Red, textDecorations: TextDecorations.Underline), - }) + foreach (PixelForeground variation in new PixelForeground[] + { + new(new SimpleSymbol('b'), Colors.Red), + new(new SimpleSymbol('a'), Colors.Blue), + new(new SimpleSymbol('a'), Colors.Red, FontWeight.Bold), + new(new SimpleSymbol('a'), Colors.Red, style: FontStyle.Italic), + new(new SimpleSymbol('a'), Colors.Red, textDecorations: TextDecorations.Underline) + }) { Assert.That(!pixelForeground.Equals((object)variation)); Assert.That(!pixelForeground.Equals(variation)); @@ -151,7 +151,7 @@ public void HashCode() pixelForeground = new PixelForeground(new SimpleSymbol('a'), Colors.Red); pixelForeground2 = new PixelForeground(new SimpleSymbol('b'), Colors.Red); Assert.That(pixelForeground.GetHashCode(), Is.Not.EqualTo(pixelForeground2.GetHashCode())); - + pixelForeground = new PixelForeground(new SimpleSymbol('a'), Colors.Red); pixelForeground2 = new PixelForeground(new SimpleSymbol('a'), Colors.Blue); Assert.That(pixelForeground.GetHashCode(), Is.Not.EqualTo(pixelForeground2.GetHashCode())); diff --git a/src/Tests/Consolonia.Core.Tests/PixelTests.cs b/src/Tests/Consolonia.Core.Tests/PixelTests.cs index ea72de9e..887b403f 100644 --- a/src/Tests/Consolonia.Core.Tests/PixelTests.cs +++ b/src/Tests/Consolonia.Core.Tests/PixelTests.cs @@ -72,17 +72,17 @@ public void Equality() public void NotEqual() { var pixel = new Pixel(new PixelForeground(new SimpleSymbol('a'), Colors.Red), - new PixelBackground(Colors.Blue)); + new PixelBackground(Colors.Blue)); var pixel2 = new Pixel(new PixelForeground(new SimpleSymbol('b'), Colors.Red), - new PixelBackground(Colors.Blue)); + new PixelBackground(Colors.Blue)); Assert.That(!pixel.Equals((object)pixel2)); Assert.That(!pixel.Equals(pixel2)); Assert.That(pixel != pixel2); pixel = new Pixel(new PixelForeground(new SimpleSymbol('a'), Colors.Red), - new PixelBackground(Colors.Blue)); + new PixelBackground(Colors.Blue)); pixel2 = new Pixel(new PixelForeground(new SimpleSymbol('a'), Colors.Blue), - new PixelBackground(Colors.Blue)); + new PixelBackground(Colors.Blue)); Assert.That(!pixel.Equals((object)pixel2)); Assert.That(!pixel.Equals(pixel2)); Assert.That(pixel != pixel2); diff --git a/src/Tests/Consolonia.Core.Tests/SimpleSymbolTests.cs b/src/Tests/Consolonia.Core.Tests/SimpleSymbolTests.cs index 965eba6f..db91c5cb 100644 --- a/src/Tests/Consolonia.Core.Tests/SimpleSymbolTests.cs +++ b/src/Tests/Consolonia.Core.Tests/SimpleSymbolTests.cs @@ -87,7 +87,7 @@ public void InequalityISymbol() Assert.That(!symbol.Equals(symbol2)); Assert.That(!symbol.Equals(symbol2)); } - + [Test] public void HashCode() { @@ -95,7 +95,7 @@ public void HashCode() set.Add(new SimpleSymbol("a")); set.Add(new SimpleSymbol("a")); Assert.That(set.Count, Is.EqualTo(1)); - + var set2 = new HashSet(); set2.Add(new SimpleSymbol("a")); set2.Add(new SimpleSymbol("a"));