From adb599590a2ed50c58017725bae3f477713b0d73 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:21:41 +0000 Subject: [PATCH] Automated JetBrains cleanup Co-authored-by: <+@users.noreply.github.com> --- src/Consolonia.Core/Drawing/CaretStyle.cs | 2 +- .../Drawing/DrawingContextImpl.cs | 350 +++++++++--------- .../MoveConsoleCaretToPositionBrush.cs | 12 +- .../InputLessDefaultNetConsole.cs | 7 +- .../Templates/Controls/CaretControl.axaml | 2 +- .../Templates/Controls/ComboBoxItem.axaml | 3 +- 6 files changed, 186 insertions(+), 190 deletions(-) diff --git a/src/Consolonia.Core/Drawing/CaretStyle.cs b/src/Consolonia.Core/Drawing/CaretStyle.cs index 2bbaba78..c3467803 100644 --- a/src/Consolonia.Core/Drawing/CaretStyle.cs +++ b/src/Consolonia.Core/Drawing/CaretStyle.cs @@ -7,6 +7,6 @@ public enum CaretStyle BlinkingBlock, SteadyBlock, BlinkingUnderline, - SteadyUnderline, + SteadyUnderline } } \ No newline at end of file diff --git a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs index ff5788a2..3582dee6 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,22 +256,22 @@ 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 moveBrush: - { - Point head = r.TopLeft.Transform(Transform); - _pixelBuffer.CaretStyle = moveBrush.CaretStyle; - CurrentClip.ExecuteWithClipping(head, - () => - { - _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); - }); - return; - } + { + Point head = r.TopLeft.Transform(Transform); + _pixelBuffer.CaretStyle = moveBrush.CaretStyle; + CurrentClip.ExecuteWithClipping(head, + () => + { + _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); + }); + return; + } } FillRectangleWithBrush(brush, pen, r); @@ -523,19 +523,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)))); + }); + } } /// @@ -756,21 +756,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": @@ -779,66 +779,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; } } diff --git a/src/Consolonia.Core/Drawing/MoveConsoleCaretToPositionBrush.cs b/src/Consolonia.Core/Drawing/MoveConsoleCaretToPositionBrush.cs index eceb0f87..d91a2c57 100644 --- a/src/Consolonia.Core/Drawing/MoveConsoleCaretToPositionBrush.cs +++ b/src/Consolonia.Core/Drawing/MoveConsoleCaretToPositionBrush.cs @@ -8,18 +8,18 @@ public class MoveConsoleCaretToPositionBrush : AvaloniaObject, IImmutableBrush public static readonly StyledProperty CaretStyleProperty = AvaloniaProperty.Register(nameof(CaretStyle)); - //todo: Search for B75ABC91-2CDD-4557-9201-16AC483C8D7B - public double Opacity => 1; - public ITransform Transform => null; - public RelativePoint TransformOrigin => RelativePoint.TopLeft; - /// - /// style of caret + /// style of caret /// public CaretStyle CaretStyle { get => GetValue(CaretStyleProperty); set => SetValue(CaretStyleProperty, value); } + + //todo: Search for B75ABC91-2CDD-4557-9201-16AC483C8D7B + public double Opacity => 1; + public ITransform Transform => null; + public RelativePoint TransformOrigin => RelativePoint.TopLeft; } } \ No newline at end of file diff --git a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs index eb76edcb..dff6c716 100644 --- a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs +++ b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs @@ -14,7 +14,6 @@ namespace Consolonia.Core.Infrastructure public abstract class InputLessDefaultNetConsole : IConsole { private const string TestEmoji = "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"; - private bool _caretVisible; private PixelBufferCoordinate _headBufferPoint; private bool? _supportEmoji; @@ -32,11 +31,7 @@ protected InputLessDefaultNetConsole() protected Task PauseTask { get; private set; } - public bool CaretVisible - { - get => _caretVisible; - set => _caretVisible = value; - } + public bool CaretVisible { get; set; } public PixelBufferSize Size { get; private set; } diff --git a/src/Consolonia.Themes/Templates/Controls/CaretControl.axaml b/src/Consolonia.Themes/Templates/Controls/CaretControl.axaml index 81e9b55c..0c2e4f84 100644 --- a/src/Consolonia.Themes/Templates/Controls/CaretControl.axaml +++ b/src/Consolonia.Themes/Templates/Controls/CaretControl.axaml @@ -18,7 +18,7 @@ IsHitTestVisible="False" IsVisible="{TemplateBinding IsCaretShown}"> - + - +