Browse Source

Merge branch 'master' into fixes/10655-setcurrentvalue-with-style-2

pull/10695/head
Max Katz 3 years ago
committed by GitHub
parent
commit
c7584e03e2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 60
      samples/ControlCatalog/Pages/ClipboardPage.xaml.cs
  2. 8
      samples/ControlCatalog/Pages/CustomDrawingExampleControl.cs
  3. 2
      samples/RenderDemo/Pages/RenderTargetBitmapPage.cs
  4. 2
      src/Avalonia.Base/Media/DrawingGroup.cs
  5. 17
      src/Avalonia.Base/Platform/Storage/FileIO/StorageProviderHelpers.cs
  6. 16
      src/Avalonia.Base/Platform/Storage/StorageProviderExtensions.cs
  7. 4
      src/Avalonia.Base/Rendering/ImmediateRenderer.cs
  8. 2
      src/Avalonia.Controls/SelectableTextBlock.cs
  9. 1
      src/Avalonia.Controls/TopLevel.cs
  10. 4
      tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs
  11. 2
      tests/Avalonia.RenderTests/Media/ConicGradientBrushTests.cs
  12. 2
      tests/Avalonia.RenderTests/Media/LinearGradientBrushTests.cs
  13. 2
      tests/Avalonia.RenderTests/Media/RadialGradientBrushTests.cs
  14. 2
      tests/Avalonia.RenderTests/Media/TextFormatting/TextLayoutTests.cs
  15. 2
      tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs

60
samples/ControlCatalog/Pages/ClipboardPage.xaml.cs

@ -1,16 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
using Avalonia.Platform.Storage.FileIO;
namespace ControlCatalog.Pages
{
public partial class ClipboardPage : UserControl
{
private INotificationManager? _notificationManager;
private INotificationManager NotificationManager => _notificationManager
??= new WindowNotificationManager(TopLevel.GetTopLevel(this)!);
public ClipboardPage()
{
InitializeComponent();
@ -31,7 +38,7 @@ namespace ControlCatalog.Pages
private async void PasteText(object? sender, RoutedEventArgs args)
{
if(Application.Current!.Clipboard is { } clipboard)
if (Application.Current!.Clipboard is { } clipboard)
{
ClipboardContent.Text = await clipboard.GetTextAsync();
}
@ -59,15 +66,45 @@ namespace ControlCatalog.Pages
{
if (Application.Current!.Clipboard is { } clipboard)
{
var files = (ClipboardContent.Text ?? String.Empty)
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
if (files.Length == 0)
var storageProvider = TopLevel.GetTopLevel(this)!.StorageProvider;
var filesPath = (ClipboardContent.Text ?? string.Empty)
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
if (filesPath.Length == 0)
{
return;
}
var dataObject = new DataObject();
dataObject.Set(DataFormats.FileNames, files);
await clipboard.SetDataObjectAsync(dataObject);
List<string> invalidFile = new(filesPath.Length);
List<IStorageFile> files = new(filesPath.Length);
for (int i = 0; i < filesPath.Length; i++)
{
var file = await storageProvider.TryGetFileFromPathAsync(filesPath[i]);
if (file is null)
{
invalidFile.Add(filesPath[i]);
}
else
{
files.Add(file);
}
}
if (invalidFile.Count > 0)
{
NotificationManager.Show(new Notification("Warning", "There is one o more invalid path.", NotificationType.Warning));
}
if (files.Count > 0)
{
var dataObject = new DataObject();
dataObject.Set(DataFormats.Files, files);
await clipboard.SetDataObjectAsync(dataObject);
NotificationManager.Show(new Notification("Success", "Copy completated.", NotificationType.Success));
}
else
{
NotificationManager.Show(new Notification("Warning", "Any files to copy in Clipboard.", NotificationType.Warning));
}
}
}
@ -75,8 +112,9 @@ namespace ControlCatalog.Pages
{
if (Application.Current!.Clipboard is { } clipboard)
{
var fiels = await clipboard.GetDataAsync(DataFormats.FileNames) as IEnumerable<string>;
ClipboardContent.Text = fiels != null ? string.Join(Environment.NewLine, fiels) : string.Empty;
var files = await clipboard.GetDataAsync(DataFormats.Files) as IEnumerable<Avalonia.Platform.Storage.IStorageItem>;
ClipboardContent.Text = files != null ? string.Join(Environment.NewLine, files.Select(f => f.TryGetLocalPath() ?? f.Name)) : string.Empty;
}
}
@ -95,7 +133,7 @@ namespace ControlCatalog.Pages
{
await clipboard.ClearAsync();
}
}
}
}

8
samples/ControlCatalog/Pages/CustomDrawingExampleControl.cs

@ -133,17 +133,17 @@ namespace ControlCatalog.Pages
// 0,0 refers to the top-left of the control now. It is not prime time to draw gui stuff because it'll be under the world
var translateModifier = context.PushPreTransform(Avalonia.Matrix.CreateTranslation(new Avalonia.Vector(halfWidth, halfHeight)));
var translateModifier = context.PushTransform(Avalonia.Matrix.CreateTranslation(new Avalonia.Vector(halfWidth, halfHeight)));
// now 0,0 refers to the ViewportCenter(X,Y).
var rotationMatrix = Avalonia.Matrix.CreateRotation(Rotation);
var rotationModifier = context.PushPreTransform(rotationMatrix);
var rotationModifier = context.PushTransform(rotationMatrix);
// everything is rotated but not scaled
var scaleModifier = context.PushPreTransform(Avalonia.Matrix.CreateScale(Scale, -Scale));
var scaleModifier = context.PushTransform(Avalonia.Matrix.CreateScale(Scale, -Scale));
var mapPositionModifier = context.PushPreTransform(Matrix.CreateTranslation(new Vector(-ViewportCenterX, -ViewportCenterY)));
var mapPositionModifier = context.PushTransform(Matrix.CreateTranslation(new Vector(-ViewportCenterX, -ViewportCenterY)));
// now everything is rotated and scaled, and at the right position, now we're drawing strictly in world coordinates

2
samples/RenderDemo/Pages/RenderTargetBitmapPage.cs

@ -29,7 +29,7 @@ namespace RenderDemo.Pages
public override void Render(DrawingContext context)
{
using (var ctx = _bitmap.CreateDrawingContext())
using (ctx.PushPostTransform(Matrix.CreateTranslation(-100, -100)
using (ctx.PushTransform(Matrix.CreateTranslation(-100, -100)
* Matrix.CreateRotation(_st.Elapsed.TotalSeconds)
* Matrix.CreateTranslation(100, 100)))
{

2
src/Avalonia.Base/Media/DrawingGroup.cs

@ -73,7 +73,7 @@ namespace Avalonia.Media
{
var bounds = GetBounds();
using (context.PushPreTransform(Transform?.Value ?? Matrix.Identity))
using (context.PushTransform(Transform?.Value ?? Matrix.Identity))
using (context.PushOpacity(Opacity, bounds))
using (ClipGeometry != null ? context.PushGeometryClip(ClipGeometry) : default)
using (OpacityMask != null ? context.PushOpacityMask(OpacityMask, bounds) : default)

17
src/Avalonia.Base/Platform/Storage/FileIO/StorageProviderHelpers.cs

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
@ -23,7 +24,7 @@ internal static class StorageProviderHelpers
return null;
}
public static Uri FilePathToUri(string path)
{
var uriPath = new StringBuilder(path)
@ -35,6 +36,20 @@ internal static class StorageProviderHelpers
return new UriBuilder("file", string.Empty) { Path = uriPath }.Uri;
}
public static bool TryFilePathToUri(string path, [NotNullWhen(true)] out Uri? uri)
{
try
{
uri = FilePathToUri(path);
return true;
}
catch
{
uri = null;
return false;
}
}
public static string NameWithExtension(string path, string? defaultExtension, FilePickerFileType? filter)
{
var name = Path.GetFileName(path);

16
src/Avalonia.Base/Platform/Storage/StorageProviderExtensions.cs

@ -16,8 +16,13 @@ public static class StorageProviderExtensions
{
return Task.FromResult(StorageProviderHelpers.TryCreateBclStorageItem(filePath) as IStorageFile);
}
return provider.TryGetFileFromPathAsync(StorageProviderHelpers.FilePathToUri(filePath));
if (StorageProviderHelpers.TryFilePathToUri(filePath, out var uri))
{
return provider.TryGetFileFromPathAsync(uri);
}
return Task.FromResult<IStorageFile?>(null);
}
/// <inheritdoc cref="IStorageProvider.TryGetFolderFromPathAsync"/>
@ -29,7 +34,12 @@ public static class StorageProviderExtensions
return Task.FromResult(StorageProviderHelpers.TryCreateBclStorageItem(folderPath) as IStorageFolder);
}
return provider.TryGetFolderFromPathAsync(StorageProviderHelpers.FilePathToUri(folderPath));
if (StorageProviderHelpers.TryFilePathToUri(folderPath, out var uri))
{
return provider.TryGetFolderFromPathAsync(uri);
}
return Task.FromResult<IStorageFolder?>(null);
}
/// <summary>

4
src/Avalonia.Base/Rendering/ImmediateRenderer.cs

@ -83,7 +83,7 @@ namespace Avalonia.Rendering
}
}
using (context.PushPostTransform(m))
using (context.PushTransform(m))
using (context.PushOpacity(opacity, bounds))
using (clipToBounds
#pragma warning disable CS0618 // Type or member is obsolete
@ -95,7 +95,7 @@ namespace Avalonia.Rendering
using (visual.Clip != null ? context.PushGeometryClip(visual.Clip) : default)
using (visual.OpacityMask != null ? context.PushOpacityMask(visual.OpacityMask, bounds) : default)
using (context.PushTransformContainer())
using (context.PushTransform(Matrix.Identity))
{
visual.Render(context);

2
src/Avalonia.Controls/SelectableTextBlock.cs

@ -177,7 +177,7 @@ namespace Avalonia.Controls
var rects = TextLayout.HitTestTextRange(start, length);
using (context.PushPostTransform(Matrix.CreateTranslation(origin)))
using (context.PushTransform(Matrix.CreateTranslation(origin)))
{
foreach (var rect in rects)
{

1
src/Avalonia.Controls/TopLevel.cs

@ -15,7 +15,6 @@ using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
using Avalonia.Reactive;
using Avalonia.Rendering;
using Avalonia.Styling;
using Avalonia.Utilities;

4
tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs

@ -88,7 +88,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Height = 200,
Child = new CustomRenderer((control, context) =>
{
using (var transform = context.PushPreTransform(Matrix.CreateTranslation(100, 100)))
using (var transform = context.PushTransform(Matrix.CreateTranslation(100, 100)))
using (var clip = context.PushClip(new Rect(0, 0, 100, 100)))
{
context.FillRectangle(Brushes.Blue, new Rect(0, 0, 200, 200));
@ -112,7 +112,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Height = 200,
Child = new CustomRenderer((control, context) =>
{
using (var transform = context.PushPreTransform(Matrix.CreateTranslation(100, 100)))
using (var transform = context.PushTransform(Matrix.CreateTranslation(100, 100)))
using (var clip = context.PushClip(new Rect(0, 0, 100, 100)))
{
context.FillRectangle(Brushes.Blue, new Rect(0, 0, 200, 200));

2
tests/Avalonia.RenderTests/Media/ConicGradientBrushTests.cs

@ -200,7 +200,7 @@ namespace Avalonia.Direct2D1.RenderTests.Media
Child = new DrawnControl(c =>
{
c.DrawRectangle(brush, null, new Rect(0, 0, 100, 100));
using (c.PushPreTransform(Matrix.CreateTranslation(100, 100)))
using (c.PushTransform(Matrix.CreateTranslation(100, 100)))
c.DrawRectangle(brush, null, new Rect(0, 0, 100, 100));
}),
};

2
tests/Avalonia.RenderTests/Media/LinearGradientBrushTests.cs

@ -95,7 +95,7 @@ namespace Avalonia.Direct2D1.RenderTests.Media
{
c.DrawRectangle(brush, null, new Rect(0, 0, 100, 100));
using (c.PushPreTransform(Matrix.CreateTranslation(100, 100)))
using (c.PushTransform(Matrix.CreateTranslation(100, 100)))
c.DrawRectangle(brush, null, new Rect(0, 0, 100, 100));
}),
};

2
tests/Avalonia.RenderTests/Media/RadialGradientBrushTests.cs

@ -185,7 +185,7 @@ namespace Avalonia.Direct2D1.RenderTests.Media
Child = new DrawnControl(c =>
{
c.DrawRectangle(brush, null, new Rect(0, 0, 100, 100));
using (c.PushPreTransform(Matrix.CreateTranslation(100, 100)))
using (c.PushTransform(Matrix.CreateTranslation(100, 100)))
c.DrawRectangle(brush, null, new Rect(0, 0, 100, 100));
}),
};

2
tests/Avalonia.RenderTests/Media/TextFormatting/TextLayoutTests.cs

@ -312,7 +312,7 @@ namespace Avalonia.Direct2D1.RenderTests.Media
var rotate = Matrix.CreateTranslation(-100, -100) *
Matrix.CreateRotation(MathUtilities.Deg2Rad(90)) *
Matrix.CreateTranslation(100, 100);
using var transform = c.PushPreTransform(rotate);
using var transform = c.PushTransform(rotate);
c.DrawRectangle(Brushes.Yellow, null, rect);
t.Draw(c, rect.Position);
}),

2
tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextFormatterTests.cs

@ -792,7 +792,7 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting
public override double Baseline => 0;
public override void Draw(DrawingContext drawingContext, Point origin)
{
using (drawingContext.PushPreTransform(Matrix.CreateTranslation(new Vector(origin.X, 0))))
using (drawingContext.PushTransform(Matrix.CreateTranslation(new Vector(origin.X, 0))))
{
drawingContext.FillRectangle(_fill, _rect);
}

Loading…
Cancel
Save