From aaf951ab9426cb86b66d6142381a53558c49d470 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:11:59 +0000 Subject: [PATCH] Automated JetBrains cleanup Co-authored-by: <+@users.noreply.github.com> --- .../Drawing/DrawingContextImpl.cs | 347 +++++++++--------- 1 file changed, 175 insertions(+), 172 deletions(-) diff --git a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs index e8eb149a..5714df4c 100644 --- a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs +++ b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs @@ -96,37 +96,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 represent the 4 pixels - char quadPixel = GetQuadPixelCharacter(quadColors); + // map it to a single char to represent 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(quadPixel), foreground), - new PixelBackground(background)); - CurrentClip.ExecuteWithClipping(new Point(px, py), - () => - { - _pixelBuffer.Set(new PixelBufferCoordinate((ushort)px, (ushort)py), - existingPixel => existingPixel.Blend(imagePixel)); - }); - } + var imagePixel = new Pixel( + new PixelForeground(new SimpleSymbol(quadPixel), foreground), + new PixelBackground(background)); + CurrentClip.ExecuteWithClipping(new Point(px, py), + () => + { + _pixelBuffer.Set(new PixelBufferCoordinate((ushort)px, (ushort)py), + existingPixel => existingPixel.Blend(imagePixel)); + }); + } } public void DrawBitmap(IBitmapImpl source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect) @@ -150,83 +150,83 @@ public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry) DrawLineInternal(pen, myLine); break; case StreamGeometryImpl streamGeometry: - { - pen = pen ?? new Pen(brush); + { + pen = pen ?? new Pen(brush); - var extractColorCheckPlatformSupported = - ExtractColorOrNullWithPlatformCheck(pen, out var lineStyle); - if (extractColorCheckPlatformSupported == null) - return; + var extractColorCheckPlatformSupported = + ExtractColorOrNullWithPlatformCheck(pen, out var lineStyle); + if (extractColorCheckPlatformSupported == null) + return; - var color = (Color)extractColorCheckPlatformSupported; + var color = (Color)extractColorCheckPlatformSupported; - lineStyle ??= LineStyle.SingleLine; + lineStyle ??= LineStyle.SingleLine; - var strokePositions = InferStrokePositions(streamGeometry); + var strokePositions = InferStrokePositions(streamGeometry); - bool hasTop = strokePositions.Contains(RectangleLinePosition.Top); - bool hasRight = strokePositions.Contains(RectangleLinePosition.Right); - bool hasBottom = strokePositions.Contains(RectangleLinePosition.Bottom); - bool hasLeft = strokePositions.Contains(RectangleLinePosition.Left); + bool hasTop = strokePositions.Contains(RectangleLinePosition.Top); + bool hasRight = strokePositions.Contains(RectangleLinePosition.Right); + bool hasBottom = strokePositions.Contains(RectangleLinePosition.Bottom); + bool hasLeft = strokePositions.Contains(RectangleLinePosition.Left); - if (lineStyle == LineStyle.Edge || lineStyle == LineStyle.EdgeWide) + if (lineStyle == LineStyle.Edge || lineStyle == LineStyle.EdgeWide) + { + for (int iStroke = 0; iStroke < streamGeometry.Strokes.Count; iStroke++) { - for (int iStroke = 0; iStroke < streamGeometry.Strokes.Count; iStroke++) - { - Line stroke = TransformLineInternal(streamGeometry.Strokes[iStroke]); + Line stroke = TransformLineInternal(streamGeometry.Strokes[iStroke]); - if (stroke.Bounds.Width > 0 || stroke.Bounds.Height > 0) - { - if (stroke.Vertical) - DrawEdgeLine(stroke, strokePositions[iStroke], lineStyle.Value, color, hasTop, - hasBottom); - else - DrawEdgeLine(stroke, strokePositions[iStroke], lineStyle.Value, color, hasLeft, - hasRight); - } + if (stroke.Bounds.Width > 0 || stroke.Bounds.Height > 0) + { + if (stroke.Vertical) + DrawEdgeLine(stroke, strokePositions[iStroke], lineStyle.Value, color, hasTop, + hasBottom); + else + DrawEdgeLine(stroke, strokePositions[iStroke], lineStyle.Value, color, hasLeft, + hasRight); } } - else + } + else + { + Line strokeTop = null; + Line strokeLeft = null; + Line strokeRight = null; + Line strokeBottom = null; + for (int iStroke = 0; iStroke < streamGeometry.Strokes.Count; iStroke++) { - Line strokeTop = null; - Line strokeLeft = null; - Line strokeRight = null; - Line strokeBottom = null; - for (int iStroke = 0; iStroke < streamGeometry.Strokes.Count; iStroke++) - { - Line stroke = streamGeometry.Strokes[iStroke]; - RectangleLinePosition strokePosition = strokePositions[iStroke]; - if (strokePosition == RectangleLinePosition.Left) - strokeLeft = stroke; - else if (strokePosition == RectangleLinePosition.Right) - strokeRight = stroke; - else if (strokePosition == RectangleLinePosition.Top) - strokeTop = stroke; - else if (strokePosition == RectangleLinePosition.Bottom) - strokeBottom = stroke; - } - - if (strokeLeft != null) - //if (strokeBottom != null) - // strokeLeft = new Line(strokeLeft.PStart, strokeBottom.PStart, strokeLeft.SourceGeometry, strokeLeft.Transform); - DrawBoxLineInternal(pen, strokeLeft, RectangleLinePosition.Left); - - if (strokeTop != null) - //if (strokeRight != null) - // strokeTop = new Line(strokeTop.PStart, strokeRight.PStart, strokeTop.SourceGeometry, strokeTop.Transform); - DrawBoxLineInternal(pen, strokeTop, RectangleLinePosition.Top); - - if (strokeRight != null) - //if (strokeBottom != null) - // strokeRight = new Line(strokeRight.PStart, strokeBottom.PEnd, strokeRight.SourceGeometry, strokeRight.Transform); - DrawBoxLineInternal(pen, strokeRight, RectangleLinePosition.Right); - - if (strokeBottom != null) - //if (strokeLeft != null) - // strokeBottom = new Line(strokeLeft.PEnd, strokeBottom.PEnd, strokeBottom.SourceGeometry, strokeBottom.Transform); - DrawBoxLineInternal(pen, strokeBottom, RectangleLinePosition.Bottom); + Line stroke = streamGeometry.Strokes[iStroke]; + RectangleLinePosition strokePosition = strokePositions[iStroke]; + if (strokePosition == RectangleLinePosition.Left) + strokeLeft = stroke; + else if (strokePosition == RectangleLinePosition.Right) + strokeRight = stroke; + else if (strokePosition == RectangleLinePosition.Top) + strokeTop = stroke; + else if (strokePosition == RectangleLinePosition.Bottom) + strokeBottom = stroke; } + + if (strokeLeft != null) + //if (strokeBottom != null) + // strokeLeft = new Line(strokeLeft.PStart, strokeBottom.PStart, strokeLeft.SourceGeometry, strokeLeft.Transform); + DrawBoxLineInternal(pen, strokeLeft, RectangleLinePosition.Left); + + if (strokeTop != null) + //if (strokeRight != null) + // strokeTop = new Line(strokeTop.PStart, strokeRight.PStart, strokeTop.SourceGeometry, strokeTop.Transform); + DrawBoxLineInternal(pen, strokeTop, RectangleLinePosition.Top); + + if (strokeRight != null) + //if (strokeBottom != null) + // strokeRight = new Line(strokeRight.PStart, strokeBottom.PEnd, strokeRight.SourceGeometry, strokeRight.Transform); + DrawBoxLineInternal(pen, strokeRight, RectangleLinePosition.Right); + + if (strokeBottom != null) + //if (strokeLeft != null) + // strokeBottom = new Line(strokeLeft.PEnd, strokeBottom.PEnd, strokeBottom.SourceGeometry, strokeBottom.Transform); + DrawBoxLineInternal(pen, strokeBottom, RectangleLinePosition.Bottom); } + } break; default: ConsoloniaPlatform.RaiseNotSupported(5); @@ -256,18 +256,21 @@ 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; + } case MoveConsoleCaretToPositionBrush: - { - var head = r.TopLeft.Transform(Transform); - CurrentClip.ExecuteWithClipping(head, - () => { _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); }); - return; - } + { + Point head = r.TopLeft.Transform(Transform); + CurrentClip.ExecuteWithClipping(head, + () => + { + _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); + }); + return; + } } FillRectangleWithBrush(brush, pen, r); @@ -467,7 +470,7 @@ private void DrawLineInternal(IPen pen, Line line) if (pen.Brush is MoveConsoleCaretToPositionBrush) { - var head = line.PStart.Transform(Transform); + Point head = line.PStart.Transform(Transform); CurrentClip.ExecuteWithClipping(head, () => { _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); }); return; @@ -518,19 +521,19 @@ private void FillRectangleWithBrush(IBrush brush, IPen pen, Rect r) 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 => pixel.Blend(new Pixel(new PixelBackground(backgroundBrush.Mode, - backgroundBrush.Color)))); - }); - } + 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 => pixel.Blend(new Pixel(new PixelBackground(backgroundBrush.Mode, + backgroundBrush.Color)))); + }); + } } /// @@ -751,21 +754,21 @@ private void DrawLineSymbolAndMoveHead(ref Point head, bool isVertical, ISymbol switch (glyph) { case "\t": + { + const int tabSize = 8; + var consolePixel = new Pixel(new SimpleSymbol(' '), foregroundColor); + for (int j = 0; j < tabSize; j++) { - const int tabSize = 8; - var consolePixel = new Pixel(new SimpleSymbol(' '), 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 => oldPixel.Blend(consolePixel)); - }); - } - - currentXPosition += tabSize - 1; + _pixelBuffer.Set((PixelBufferCoordinate)newCharacterPoint, + oldPixel => oldPixel.Blend(consolePixel)); + }); } + + currentXPosition += tabSize - 1; + } break; case "\r": case "\f": @@ -774,66 +777,66 @@ private void DrawLineSymbolAndMoveHead(ref Point head, bool isVertical, ISymbol currentYPosition++; break; default: + { + var symbol = new SimpleSymbol(glyph); + // if we are attempting to draw a wide glyph we need to make sure that the clipping point + // is for the last physical char. Aka a double char should be clipped if it's second rendered + // char would break the boundary of the clip. + // var clippingPoint = new Point(characterPoint.X + symbol.Width - 1, characterPoint.Y); + var newPixel = new Pixel(symbol, foregroundColor, typeface.Style, typeface.Weight); + CurrentClip.ExecuteWithClipping(characterPoint, () => { - var symbol = new SimpleSymbol(glyph); - // if we are attempting to draw a wide glyph we need to make sure that the clipping point - // is for the last physical char. Aka a double char should be clipped if it's second rendered - // char would break the boundary of the clip. - // var clippingPoint = new Point(characterPoint.X + symbol.Width - 1, characterPoint.Y); - var newPixel = new Pixel(symbol, foregroundColor, typeface.Style, typeface.Weight); - CurrentClip.ExecuteWithClipping(characterPoint, () => - { - _pixelBuffer.Set((PixelBufferCoordinate)characterPoint, - oldPixel => + _pixelBuffer.Set((PixelBufferCoordinate)characterPoint, + oldPixel => + { + if (oldPixel.Width == 0) + { + // if the oldPixel was empty, we need to set the previous pixel to space + double targetX = characterPoint.X - 1; + if (targetX >= 0) + _pixelBuffer.Set( + (PixelBufferCoordinate)new Point(targetX, characterPoint.Y), + oldPixel2 => + new Pixel( + new PixelForeground(new SimpleSymbol(' '), Colors.Transparent), + oldPixel2.Background)); + } + else if (oldPixel.Width > 1) { - if (oldPixel.Width == 0) + // if oldPixel was wide we need to reset overlapped symbols from empty to space + for (ushort i = 1; i < oldPixel.Width; i++) { - // if the oldPixel was empty, we need to set the previous pixel to space - double targetX = characterPoint.X - 1; - if (targetX >= 0) + double targetX = characterPoint.X + i; + if (targetX < _pixelBuffer.Size.Width) _pixelBuffer.Set( (PixelBufferCoordinate)new Point(targetX, characterPoint.Y), oldPixel2 => new Pixel( - new PixelForeground(new SimpleSymbol(' '), Colors.Transparent), - oldPixel2.Background)); + new PixelForeground(new SimpleSymbol(' '), + Colors.Transparent), oldPixel2.Background)); } - else if (oldPixel.Width > 1) + } + + // if the pixel was a wide character, we need to set the overlapped pixels to empty pixels. + if (newPixel.Width > 1) + for (int i = 1; i < symbol.Width; i++) { - // if oldPixel was wide we need to reset overlapped symbols from empty to space - for (ushort i = 1; i < oldPixel.Width; i++) - { - double targetX = characterPoint.X + i; - if (targetX < _pixelBuffer.Size.Width) - _pixelBuffer.Set( - (PixelBufferCoordinate)new Point(targetX, characterPoint.Y), - oldPixel2 => - new Pixel( - new PixelForeground(new SimpleSymbol(' '), - Colors.Transparent), oldPixel2.Background)); - } + double targetX = characterPoint.X + i; + if (targetX < _pixelBuffer.Size.Width) + _pixelBuffer.Set( + (PixelBufferCoordinate)new Point(targetX, characterPoint.Y), + oldPixel2 => + new Pixel( + new PixelForeground(new SimpleSymbol(), Colors.Transparent), + oldPixel2.Background)); } - // if the pixel was a wide character, we need to set the overlapped pixels to empty pixels. - if (newPixel.Width > 1) - for (int i = 1; i < symbol.Width; i++) - { - double targetX = characterPoint.X + i; - if (targetX < _pixelBuffer.Size.Width) - _pixelBuffer.Set( - (PixelBufferCoordinate)new Point(targetX, characterPoint.Y), - oldPixel2 => - new Pixel( - new PixelForeground(new SimpleSymbol(), Colors.Transparent), - oldPixel2.Background)); - } - - return oldPixel.Blend(newPixel); - }); - }); + return oldPixel.Blend(newPixel); + }); + }); - currentXPosition += symbol.Width; - } + currentXPosition += symbol.Width; + } break; } }