Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Avalonia to 11.2.1 #159

Merged
merged 21 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<NoWarn>AVA3001</NoWarn>
</PropertyGroup>
<PropertyGroup>
<AvaloniaVersion>11.0.9</AvaloniaVersion>
<AvaloniaVersion>11.2.1</AvaloniaVersion>
</PropertyGroup>
</Project>
Binary file removed Icon.png
Binary file not shown.
1 change: 0 additions & 1 deletion src/Consolonia.Core/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Consolonia.Core.Tests")]
[assembly: InternalsVisibleTo("Consolonia.Designer")]

[assembly: CLSCompliant(false)] //todo: should we make it compliant?
10 changes: 4 additions & 6 deletions src/Consolonia.Core/Consolonia.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
<Compile Remove="Controls\FileOpen\**" />
<EmbeddedResource Remove="Controls\FileOpen\**" />
<None Remove="Controls\FileOpen\**" />
</ItemGroup>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.FreeDesktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Skia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="$(AvaloniaVersion)" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
<PackageReference Include="Unicode.net" Version="2.0.0" />
<PackageReference Include="Wcwidth" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>


</Project>
36 changes: 23 additions & 13 deletions src/Consolonia.Core/Controls/MessageBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,29 @@

InitializeComponent();

AttachedToVisualTree += (_, _) =>
{
// we don't hook this up until the dialog is shown as the visible state is driven off of the DataContext
// which is set at ShowDialogAsync() time.
if (OkButton.IsVisible)
OkButton.AttachedToVisualTree += (_, _) => OkButton.Focus();
else if (YesButton.IsVisible)
YesButton.AttachedToVisualTree += (_, _) => YesButton.Focus();
else if (CancelButton.IsVisible)
CancelButton.AttachedToVisualTree += (_, _) => CancelButton.Focus();
else if (NoButton.IsVisible)
NoButton.AttachedToVisualTree += (_, _) => NoButton.Focus();
};
AttachedToVisualTree += OnShowDialog;
}

private void OnShowDialog(object sender, VisualTreeAttachmentEventArgs e)
{
// we don't hook this up until the dialog is shown as the visible state is driven off of the DataContext
// which is set at ShowDialogAsync() time.
AttachedToVisualTree -= OnShowDialog;
if (OkButton.IsVisible)
OkButton.AttachedToVisualTree += ButtonAttached;
else if (YesButton.IsVisible)
YesButton.AttachedToVisualTree += ButtonAttached;
else if (CancelButton.IsVisible)
CancelButton.AttachedToVisualTree += ButtonAttached;
else if (NoButton.IsVisible)
NoButton.AttachedToVisualTree += ButtonAttached;
}

private void ButtonAttached(object sender, VisualTreeAttachmentEventArgs e)
{
var button = (Button)sender;
button.AttachedToVisualTree -= ButtonAttached;
button.Focus();
}

public Mode Mode
Expand Down Expand Up @@ -93,7 +103,7 @@
DataContext = new MessageBoxViewModel(Mode, Ok, Cancel, Yes, No, text, title ?? Title);
#nullable enable
var result = await ShowDialogAsync<MessageBoxResult?>(parent);
if (result.HasValue) return result.Value;

Check notice on line 106 in src/Consolonia.Core/Controls/MessageBox.axaml.cs

View workflow job for this annotation

GitHub Actions / build

"[ConvertIfStatementToReturnStatement] Convert into 'return' statement" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Controls/MessageBox.axaml.cs(106,13)
return MessageBoxResult.Cancel;
#nullable disable
}
Expand Down
12 changes: 9 additions & 3 deletions src/Consolonia.Core/Drawing/ConsoleBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ public static ConsoleBrush FromPosition(IBrush brush, int x, int y, int width, i
// Calculate the distance from the center
double dx = x - centerX;
double dy = y - centerY;
double distance = Math.Sqrt(dx * dx + dy * dy);

// Normalize the distance based on the brush radius
double normalizedDistance = distance / (Math.Min(width, height) * radialBrush.Radius);
// Calculate the distance based on separate X and Y radii
double distanceX = dx / (width * radialBrush.RadiusX.Scalar);
double distanceY = dy / (height * radialBrush.RadiusY.Scalar);
double distance = Math.Sqrt(distanceX * distanceX + distanceY * distanceY);

// Normalize the distance
double normalizedDistance = distance /
Math.Sqrt(radialBrush.RadiusX.Scalar * radialBrush.RadiusX.Scalar +
radialBrush.RadiusY.Scalar * radialBrush.RadiusY.Scalar);

// Clamp the normalized distance to [0, 1]
normalizedDistance = Math.Min(Math.Max(normalizedDistance, 0), 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Avalonia;
using Avalonia.Platform;

namespace Consolonia.Core.Drawing
Expand All @@ -20,6 +21,13 @@
return new RenderTarget(surfaces);
}

public IDrawingContextLayerImpl CreateOffscreenRenderTarget(PixelSize pixelSize, double scaling)
{
throw new NotImplementedException();
}
tomlm marked this conversation as resolved.
Show resolved Hide resolved

public bool IsLost => false;

public IReadOnlyDictionary<Type, object> PublicFeatures { get; private set; } = new Dictionary<Type, object>();

Check notice on line 31 in src/Consolonia.Core/Drawing/ConsoloniaPlatformRenderInterfaceContext.cs

View workflow job for this annotation

GitHub Actions / build

"[AutoPropertyCanBeMadeGetOnly.Local] Auto-property can be made get-only" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/ConsoloniaPlatformRenderInterfaceContext.cs(31,72)
}
}
7 changes: 7 additions & 0 deletions src/Consolonia.Core/Drawing/ConsoloniaRenderInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,17 @@ public bool IsSupportedBitmapPixelFormat(PixelFormat format)
throw new NotImplementedException();
}

public IPlatformRenderInterfaceRegion CreateRegion()
{
throw new NotImplementedException();
}

public bool SupportsIndividualRoundRects => false;

public AlphaFormat DefaultAlphaFormat => throw new NotImplementedException();

public PixelFormat DefaultPixelFormat => throw new NotImplementedException();

public bool SupportsRegions => false;
}
}
138 changes: 61 additions & 77 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
private readonly Matrix _postTransform = Matrix.Identity;
private Matrix _transform = Matrix.Identity;

public DrawingContextImpl(ConsoleWindow consoleWindow)
public DrawingContextImpl(ConsoleWindow consoleWindow, PixelBuffer pixelBuffer)
{
_consoleWindow = consoleWindow;
_pixelBuffer = consoleWindow.PixelBuffer;
_clipStack.Push(_pixelBuffer.Size);
_pixelBuffer = pixelBuffer;
_clipStack.Push(pixelBuffer.Size);
RenderOptions = new RenderOptions();
}

private Rect CurrentClip => _clipStack.Peek();

public RenderOptions RenderOptions { get; set; }

Check warning on line 47 in src/Consolonia.Core/Drawing/DrawingContextImpl.cs

View workflow job for this annotation

GitHub Actions / build

"[UnusedAutoPropertyAccessor.Global] Auto-property accessor 'RenderOptions.get' is never used" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/DrawingContextImpl.cs(47,46)

tomlm marked this conversation as resolved.
Show resolved Hide resolved
public void Dispose()
{
}
Expand Down Expand Up @@ -101,7 +104,7 @@
() =>
{
_pixelBuffer.Set(new PixelBufferCoordinate((ushort)px, (ushort)py),
existingPixel => existingPixel.Blend(imagePixel));
(existingPixel, _) => existingPixel.Blend(imagePixel), imagePixel.Background.Color);
});
}
}
Expand Down Expand Up @@ -175,8 +178,8 @@
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))));
(pixel, bb) => pixel.Blend(new Pixel(new PixelBackground(bb.Mode, bb.Color))),
backgroundBrush);
});
}
}
Expand Down Expand Up @@ -215,7 +218,7 @@
DrawStringInternal(foreground, text, glyphRun.GlyphTypeface);
}

public IDrawingContextLayerImpl CreateLayer(Size size)
public IDrawingContextLayerImpl CreateLayer(PixelSize size)
{
return new RenderTarget(_consoleWindow);
}
tomlm marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -234,6 +237,11 @@
PushClip(clip.Rect);
}

public void PushClip(IPlatformRenderInterfaceRegion region)
{
throw new NotImplementedException();
}

tomlm marked this conversation as resolved.
Show resolved Hide resolved
public void PopClip()
{
_clipStack.Pop();
Expand Down Expand Up @@ -286,47 +294,69 @@
throw new NotImplementedException();
}

public RenderOptions RenderOptions { get; set; }

public Matrix Transform
{
get => _transform;
set => _transform = value * _postTransform;
}

public void DrawRegion(IBrush brush, IPen pen, IPlatformRenderInterfaceRegion region)
{
throw new NotImplementedException();
}

tomlm marked this conversation as resolved.
Show resolved Hide resolved
public void PushLayer(Rect bounds)
{
throw new NotImplementedException();
}

public void PopLayer()
{
throw new NotImplementedException();
}

tomlm marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Draw a straight horizontal line or vertical line
/// </summary>
/// <param name="pen">pen</param>
/// <param name="line">line</param>
private void DrawLineInternal(IPen pen, Line line)
{
if (pen.Thickness.IsNearlyEqual(0)) return;
if (pen.Thickness == 0) return;

line = TransformLineInternal(line);

if (pen.Thickness.IsNearlyEqual(UnderlineThickness) || pen.Thickness.IsNearlyEqual(StrikethroughThickness))
Point head = line.PStart;
if (pen.Brush is MoveConsoleCaretToPositionBrush)
{
if (line.Vertical)
throw new NotSupportedException(
"Vertical strikethrough or underline text decorations is not supported.");
CurrentClip.ExecuteWithClipping(head,
() => { _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); });
return;
}

if (line.Vertical == false && pen.Thickness > 1)
{
// horizontal lines with thickness larger than one are text decorations
ApplyTextDecorationLineInternal(pen, line);
ApplyTextDecorationLineInternal(ref head, pen, line);
return;
}

DrawRectangleLineInternal(pen, line);
}
var extractColorCheckPlatformSupported = ExtractColorOrNullWithPlatformCheck(pen, out var lineStyle);
if (extractColorCheckPlatformSupported == null)
return;

private void ApplyTextDecorationLineInternal(IPen pen, Line line)
{
line = TransformLineInternal(line);
var color = (Color)extractColorCheckPlatformSupported;

Point head = line.PStart;
byte pattern = (byte)(line.Vertical ? 0b1010 : 0b0101);
DrawPixelAndMoveHead(ref head, line, lineStyle, pattern, color, line.Length); //line
}

TextDecorationLocation textDecoration = pen.Thickness switch
private void ApplyTextDecorationLineInternal(ref Point head, IPen pen, Line line)
{
TextDecorationCollection textDecoration = pen.Thickness switch
{
UnderlineThickness => TextDecorationLocation.Underline,
StrikethroughThickness => TextDecorationLocation.Strikethrough,
UnderlineThickness => TextDecorations.Underline,
StrikethroughThickness => TextDecorations.Strikethrough,
_ => throw new ArgumentOutOfRangeException($"Unsupported thickness {pen.Thickness}")
};

Expand Down Expand Up @@ -508,7 +538,7 @@
CurrentClip.ExecuteWithClipping(newCharacterPoint, () =>
{
_pixelBuffer.Set((PixelBufferCoordinate)newCharacterPoint,
oldPixel => oldPixel.Blend(consolePixel));
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
});
}

Expand All @@ -524,63 +554,17 @@
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);
var consolePixel = new Pixel(symbol, foregroundColor, typeface.Style, typeface.Weight);
CurrentClip.ExecuteWithClipping(characterPoint, () =>
{
_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 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));
}
}

// 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);
});
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
});

currentXPosition += symbol.Width;
if (symbol.Width > 1)
currentXPosition += symbol.Width;
else
currentXPosition++;
}
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Consolonia.Core/Drawing/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public bool TryGetSegment(double startDistance, double stopDistance, bool startO
public IGeometryImpl SourceGeometry { get; }
public Matrix Transform { get; }

public IGeometryImpl GetWidenedGeometry(IPen pen)
{
throw new NotImplementedException();
}
tomlm marked this conversation as resolved.
Show resolved Hide resolved

public static Line CreateMyLine(Point p1, Point p2)
{
(double x, double y) = p2 - p1;
Expand Down
Loading
Loading