Skip to content

Commit

Permalink
Automated JetBrains cleanup
Browse files Browse the repository at this point in the history
Co-authored-by:  <[email protected]>
  • Loading branch information
github-actions[bot] committed Nov 6, 2024
1 parent 637747c commit 559fe7b
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 135 deletions.
135 changes: 68 additions & 67 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,37 @@ public void DrawBitmap(IBitmapImpl source, double opacity, Rect sourceRect, Rect
new SKPaint { FilterQuality = SKFilterQuality.Medium });

for (int y = 0; y < bitmap.Info.Height; y += 2)
for (int x = 0; x < bitmap.Info.Width; x += 2)
{
// NOTE: we divide by 2 because we are working with quad pixels,
// // the bitmap has twice the horizontal and twice the vertical of the target rect.
int px = (int)targetRect.TopLeft.X + x / 2;
int py = (int)targetRect.TopLeft.Y + y / 2;
for (int x = 0; x < bitmap.Info.Width; x += 2)
{
// NOTE: we divide by 2 because we are working with quad pixels,
// // the bitmap has twice the horizontal and twice the vertical of the target rect.
int px = (int)targetRect.TopLeft.X + x / 2;
int py = (int)targetRect.TopLeft.Y + y / 2;

// get the quad pixel the bitmap
var quadColors = new[]
{
// get the quad pixel the bitmap
var quadColors = new[]
{
bitmap.GetPixel(x, y), bitmap.GetPixel(x + 1, y),
bitmap.GetPixel(x, y + 1), bitmap.GetPixel(x + 1, y + 1)
};

// map it to a single char to represet the 4 pixels
char quadPixel = GetQuadPixelCharacter(quadColors);
// map it to a single char to represet the 4 pixels
char quadPixel = GetQuadPixelCharacter(quadColors);

// get the combined colors for the quad pixel
Color foreground = GetForegroundColorForQuadPixel(quadColors, quadPixel);
Color background = GetBackgroundColorForQuadPixel(quadColors, quadPixel);
// get the combined colors for the quad pixel
Color foreground = GetForegroundColorForQuadPixel(quadColors, quadPixel);
Color background = GetBackgroundColorForQuadPixel(quadColors, quadPixel);

var imagePixel = new Pixel(new PixelForeground(new SimpleSymbol(new Rune(quadPixel)), color: foreground),
new PixelBackground(background));
CurrentClip.ExecuteWithClipping(new Point(px, py),
() =>
{
_pixelBuffer.Set(new PixelBufferCoordinate((ushort)px, (ushort)py),
(existingPixel, _) => existingPixel.Blend(imagePixel), imagePixel.Background.Color);
});
}
var imagePixel = new Pixel(
new PixelForeground(new SimpleSymbol(new Rune(quadPixel)), color: foreground),
new PixelBackground(background));
CurrentClip.ExecuteWithClipping(new Point(px, py),
() =>
{
_pixelBuffer.Set(new PixelBufferCoordinate((ushort)px, (ushort)py),
(existingPixel, _) => existingPixel.Blend(imagePixel), imagePixel.Background.Color);
});
}
}

public void DrawBitmap(IBitmapImpl source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
Expand Down Expand Up @@ -150,31 +151,31 @@ public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry)
case VisualBrush:
throw new NotImplementedException();
case ISceneBrush sceneBrush:
{
ISceneBrushContent sceneBrushContent = sceneBrush.CreateContent();
if (sceneBrushContent != null) sceneBrushContent.Render(this, Matrix.Identity);
return;
}
{
ISceneBrushContent sceneBrushContent = sceneBrush.CreateContent();
if (sceneBrushContent != null) sceneBrushContent.Render(this, Matrix.Identity);
return;
}
}

Rect r2 = r.TransformToAABB(Transform);

double width = r2.Width + (pen?.Thickness ?? 0);
double height = r2.Height + (pen?.Thickness ?? 0);
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
{
int px = (int)(r2.TopLeft.X + x);
int py = (int)(r2.TopLeft.Y + y);
for (int y = 0; y < height; y++)
{
int px = (int)(r2.TopLeft.X + x);
int py = (int)(r2.TopLeft.Y + y);

ConsoleBrush backgroundBrush = ConsoleBrush.FromPosition(brush, x, y, (int)width, (int)height);
CurrentClip.ExecuteWithClipping(new Point(px, py), () =>
{
_pixelBuffer.Set(new PixelBufferCoordinate((ushort)px, (ushort)py),
(pixel, bb) => pixel.Blend(new Pixel(new PixelBackground(bb.Mode, bb.Color))),
backgroundBrush);
});
}
ConsoleBrush backgroundBrush = ConsoleBrush.FromPosition(brush, x, y, (int)width, (int)height);
CurrentClip.ExecuteWithClipping(new Point(px, py), () =>
{
_pixelBuffer.Set(new PixelBufferCoordinate((ushort)px, (ushort)py),
(pixel, bb) => pixel.Blend(new Pixel(new PixelBackground(bb.Mode, bb.Color))),
backgroundBrush);
});
}
}

if (pen is null or { Thickness: 0 }
Expand Down Expand Up @@ -207,7 +208,7 @@ public void DrawGlyphRun(IBrush foreground, IGlyphRunImpl glyphRun)
}

string charactersDoDraw =
string.Concat(glyphRunImpl.GlyphIndices.Select(us => (char)us).ToArray());
string.Concat(glyphRunImpl.GlyphIndices.Select(us => (char)us).ToArray());
DrawStringInternal(foreground, charactersDoDraw, glyphRun.GlyphTypeface);
}

Expand Down Expand Up @@ -500,51 +501,51 @@ private void DrawPixelAndMoveHead(ref Point head, Line line, LineStyle? lineStyl
int currentXPosition = 0;

// Each rune maps to a pixel
foreach(var rune in text.EnumerateRunes())
foreach (Rune rune in text.EnumerateRunes())
{
Point characterPoint = whereToDraw.Transform(Matrix.CreateTranslation(currentXPosition++, 0));
Color foregroundColor = consoleBrush.Color;

switch (rune.Value)
{
case '\t':
{
const int tabSize = 8;
var consolePixel = new Pixel(new Rune(' '), foregroundColor);
for (int j = 0; j < tabSize; j++)
{
const int tabSize = 8;
var consolePixel = new Pixel(new Rune(' '), foregroundColor);
for (int j = 0; j < tabSize; j++)
Point newCharacterPoint = characterPoint.WithX(characterPoint.X + j);
CurrentClip.ExecuteWithClipping(newCharacterPoint, () =>
{
Point newCharacterPoint = characterPoint.WithX(characterPoint.X + j);
CurrentClip.ExecuteWithClipping(newCharacterPoint, () =>
{
_pixelBuffer.Set((PixelBufferCoordinate)newCharacterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
});
}

currentXPosition += tabSize - 1;
_pixelBuffer.Set((PixelBufferCoordinate)newCharacterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
});
}

currentXPosition += tabSize - 1;
}
break;
case '\n':
{
/* it's not clear if we need to draw anything. Cursor can be placed at the end of the line
var consolePixel = new Pixel(' ', foregroundColor);
{
/* it's not clear if we need to draw anything. Cursor can be placed at the end of the line
var consolePixel = new Pixel(' ', foregroundColor);
_pixelBuffer.Set((PixelBufferCoordinate)characterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);*/
}
_pixelBuffer.Set((PixelBufferCoordinate)characterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);*/
}
break;
case '\u200B':
currentXPosition--;
break;
default:
{
var consolePixel = new Pixel(rune, foregroundColor, typeface.Style, typeface.Weight);
CurrentClip.ExecuteWithClipping(characterPoint, () =>
{
var consolePixel = new Pixel(rune, foregroundColor, typeface.Style, typeface.Weight);
CurrentClip.ExecuteWithClipping(characterPoint, () =>
{
_pixelBuffer.Set((PixelBufferCoordinate)characterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
});
}
_pixelBuffer.Set((PixelBufferCoordinate)characterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
});
}
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public DrawingBoxSymbol(byte upRightDownLeft)

private byte _upRightDownLeft;

public Rune Rune => new Rune(GetBoxSymbol());
public Rune Rune => new(GetBoxSymbol());

/// <summary>
/// https://en.wikipedia.org/wiki/Code_page_437
Expand Down Expand Up @@ -54,46 +54,46 @@ private char GetBoxSymbol()
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()
};
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace Consolonia.Core.Drawing.PixelBufferImplementation
public interface ISymbol
{
/// <summary>
/// The rune for the symbol
/// The rune for the symbol
/// </summary>
Rune Rune { get; }

bool IsWhiteSpace();

/// <summary>
/// Blend 2 symbols together
/// Blend 2 symbols together
/// </summary>
/// <param name="symbolAbove"></param>
/// <returns></returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public Pixel Blend(Pixel pixelAbove)

case PixelBackgroundMode.Transparent:
// if the foreground is transparent, ignore pixelAbove foreground.
newForeground = pixelAbove.Foreground.Color != Colors.Transparent ? Foreground.Blend(pixelAbove.Foreground) : Foreground;

newForeground = pixelAbove.Foreground.Color != Colors.Transparent
? Foreground.Blend(pixelAbove.Foreground)
: Foreground;

// background is transparent, ignore pixelAbove background.
newBackground = Background;
newBackground = Background;
break;
case PixelBackgroundMode.Shaded:
(newForeground, newBackground) = Shade();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ public void Set<TUserObject>(PixelBufferCoordinate point, Func<Pixel, TUserObjec
}

/// <summary>
/// Clears old pixel caret position and sets new caret position
/// Clears old pixel caret position and sets new caret position
/// </summary>
/// <param name="point"></param>
public void SetCaretPosition(PixelBufferCoordinate point)
{
var oldCaretPixel = _buffer[_caretPosition.X, _caretPosition.Y];
_buffer[_caretPosition.X, _caretPosition.Y] = new Pixel(oldCaretPixel.Foreground, oldCaretPixel.Background, isCaret: false);
Pixel oldCaretPixel = _buffer[_caretPosition.X, _caretPosition.Y];
_buffer[_caretPosition.X, _caretPosition.Y] =
new Pixel(oldCaretPixel.Foreground, oldCaretPixel.Background, false);

Check warning on line 81 in src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBuffer.cs

View workflow job for this annotation

GitHub Actions / build

"[RedundantArgumentDefaultValue] The parameter 'isCaret' has the same default value" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBuffer.cs(81,79)

_caretPosition = point;
var newCaretPixel = _buffer[_caretPosition.X, _caretPosition.Y];
_buffer[_caretPosition.X, _caretPosition.Y] = new Pixel(newCaretPixel.Foreground, newCaretPixel.Background, isCaret: true);
Pixel newCaretPixel = _buffer[_caretPosition.X, _caretPosition.Y];
_buffer[_caretPosition.X, _caretPosition.Y] =
new Pixel(newCaretPixel.Foreground, newCaretPixel.Background, true);
}

public void Foreach(Func<PixelBufferCoordinate, Pixel, Pixel> replaceAction)
Expand All @@ -97,11 +99,11 @@ public void Foreach(Func<PixelBufferCoordinate, Pixel, Pixel> replaceAction)
public void ForeachReadonly(Action<PixelBufferCoordinate, Pixel> action)
{
for (ushort j = 0; j < Height; j++)
for (ushort i = 0; i < Width; i++)
{
Pixel pixel = this[(PixelBufferCoordinate)(i, j)];
action(new PixelBufferCoordinate(i, j), pixel);
}
for (ushort i = 0; i < Width; i++)
{
Pixel pixel = this[(PixelBufferCoordinate)(i, j)];
action(new PixelBufferCoordinate(i, j), pixel);
}
}

private (ushort x, ushort y) ToXY(int i)
Expand Down
Loading

0 comments on commit 559fe7b

Please sign in to comment.