Browse Source

Merge branch 'master' into fixes/2435

pull/2444/head
Steven Kirk 8 years ago
committed by GitHub
parent
commit
a30a32c878
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      azure-pipelines.yml
  2. 2
      nukebuild/Numerge
  3. 4
      src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs
  4. 3
      src/Avalonia.Controls.DataGrid/Properties/AssemblyInfo.cs
  5. 21
      src/Avalonia.Controls/Grid.cs
  6. 5
      src/Avalonia.Controls/Platform/InProcessDragSource.cs
  7. 72
      src/Avalonia.Controls/Shapes/Shape.cs
  8. 11
      src/Avalonia.Controls/Window.cs
  9. 10
      src/Avalonia.Visuals/Media/BrushExtensions.cs
  10. 72
      src/Avalonia.Visuals/Media/Pen.cs
  11. 3
      src/Avalonia.Visuals/Media/PenLineCap.cs
  12. 19
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  13. 8
      src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs
  14. 45
      tests/Avalonia.Controls.UnitTests/WindowTests.cs
  15. 8
      tests/Avalonia.RenderTests/Shapes/PathTests.cs
  16. 3
      tests/Avalonia.RenderTests/Shapes/PolylineTests.cs
  17. BIN
      tests/TestFiles/Direct2D1/Shapes/Path/Path_With_PenLineCap.expected.png
  18. BIN
      tests/TestFiles/Skia/Shapes/Path/Path_With_PenLineCap.expected.png

4
azure-pipelines.yml

@ -32,7 +32,7 @@ jobs:
- job: macOS
pool:
vmImage: 'xcode9-macos10.13'
vmImage: 'macOS-10.14'
steps:
- task: DotNetCoreInstaller@0
inputs:
@ -49,7 +49,7 @@ jobs:
inputs:
actions: 'build'
scheme: ''
sdk: 'macosx10.13'
sdk: 'macosx10.14'
configuration: 'Release'
xcWorkspacePath: '**/*.xcodeproj/project.xcworkspace'
xcodeVersion: 'default' # Options: 8, 9, default, specifyPath

2
nukebuild/Numerge

@ -1 +1 @@
Subproject commit 4464343aef5c8ab7a42fcb20a483a6058199f8b8
Subproject commit aef10ae67dc55c95f49b52a505a0be33bfa297a5

4
src/Avalonia.Controls.DataGrid/Collections/DataGridCollectionView.cs

@ -927,7 +927,7 @@ namespace Avalonia.Collections
/// <remarks>
/// <p>
/// Clear a sort criteria by assigning SortDescription.Empty to this property.
/// One or more sort criteria in form of <seealso cref="SortDescription"/>
/// One or more sort criteria in form of <seealso cref="DataGridSortDescription"/>
/// can be used, each specifying a property and direction to sort by.
/// </p>
/// </remarks>
@ -4312,4 +4312,4 @@ namespace Avalonia.Collections
}
}
}
}
}

3
src/Avalonia.Controls.DataGrid/Properties/AssemblyInfo.cs

@ -8,7 +8,6 @@ using Avalonia.Metadata;
[assembly: InternalsVisibleTo("Avalonia.Controls.UnitTests")]
[assembly: InternalsVisibleTo("Avalonia.DesignerSupport")]
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia")]
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls")]
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.Primitives")]
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.Collections")]
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Controls.Primitives")]

21
src/Avalonia.Controls/Grid.cs

@ -177,6 +177,17 @@ namespace Avalonia.Controls
return element.GetValue(RowSpanProperty);
}
/// <summary>
/// Gets the value of the IsSharedSizeScope attached property for a control.
/// </summary>
/// <param name="element">The control.</param>
/// <returns>The control's IsSharedSizeScope value.</returns>
public static bool GetIsSharedSizeScope(AvaloniaObject element)
{
return element.GetValue(IsSharedSizeScopeProperty);
}
/// <summary>
/// Sets the value of the Column attached property for a control.
/// </summary>
@ -217,6 +228,16 @@ namespace Avalonia.Controls
element.SetValue(RowSpanProperty, value);
}
/// <summary>
/// Sets the value of IsSharedSizeScope property for a control.
/// </summary>
/// <param name="element">The control.</param>
/// <param name="value">The IsSharedSizeScope value.</param>
public static void SetIsSharedSizeScope(AvaloniaObject element, bool value)
{
element.SetValue(IsSharedSizeScopeProperty, value);
}
/// <summary>
/// Gets the result of the last column measurement.
/// Use this result to reduce the arrange calculation.

5
src/Avalonia.Controls/Platform/InProcessDragSource.cs

@ -147,7 +147,10 @@ namespace Avalonia.Platform
e.Handled = true;
}
else if (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl || e.Key == Key.LeftAlt || e.Key == Key.RightAlt)
RaiseEventAndUpdateCursor(RawDragEventType.DragOver, _lastRoot, _lastPosition, e.Modifiers);
{
if (_lastRoot != null)
RaiseEventAndUpdateCursor(RawDragEventType.DragOver, _lastRoot, _lastPosition, e.Modifiers);
}
}
private void ProcessMouseEvents(RawMouseEventArgs e)

72
src/Avalonia.Controls/Shapes/Shape.cs

@ -21,13 +21,19 @@ namespace Avalonia.Controls.Shapes
public static readonly StyledProperty<AvaloniaList<double>> StrokeDashArrayProperty =
AvaloniaProperty.Register<Shape, AvaloniaList<double>>(nameof(StrokeDashArray));
public static readonly StyledProperty<double> StrokeDashOffsetProperty =
AvaloniaProperty.Register<Shape, double>(nameof(StrokeDashOffset));
public static readonly StyledProperty<double> StrokeThicknessProperty =
AvaloniaProperty.Register<Shape, double>(nameof(StrokeThickness));
public static readonly StyledProperty<PenLineCap> StrokeLineCapProperty =
AvaloniaProperty.Register<Shape, PenLineCap>(nameof(StrokeLineCap), PenLineCap.Flat);
public static readonly StyledProperty<PenLineJoin> StrokeJoinProperty =
AvaloniaProperty.Register<Shape, PenLineJoin>(nameof(StrokeJoin), PenLineJoin.Miter);
private Matrix _transform = Matrix.Identity;
private Geometry _definingGeometry;
private Geometry _renderedGeometry;
@ -36,7 +42,9 @@ namespace Avalonia.Controls.Shapes
static Shape()
{
AffectsMeasure<Shape>(StretchProperty, StrokeThicknessProperty);
AffectsRender<Shape>(FillProperty, StrokeProperty, StrokeDashArrayProperty);
AffectsRender<Shape>(FillProperty, StrokeProperty, StrokeDashArrayProperty, StrokeDashOffsetProperty,
StrokeThicknessProperty, StrokeLineCapProperty, StrokeJoinProperty);
}
public Geometry DefiningGeometry
@ -106,7 +114,7 @@ namespace Avalonia.Controls.Shapes
get { return GetValue(StrokeDashArrayProperty); }
set { SetValue(StrokeDashArrayProperty, value); }
}
public double StrokeDashOffset
{
get { return GetValue(StrokeDashOffsetProperty); }
@ -119,13 +127,17 @@ namespace Avalonia.Controls.Shapes
set { SetValue(StrokeThicknessProperty, value); }
}
public PenLineCap StrokeDashCap { get; set; } = PenLineCap.Flat;
public PenLineCap StrokeStartLineCap { get; set; } = PenLineCap.Flat;
public PenLineCap StrokeEndLineCap { get; set; } = PenLineCap.Flat;
public PenLineCap StrokeLineCap
{
get { return GetValue(StrokeLineCapProperty); }
set { SetValue(StrokeLineCapProperty, value); }
}
public PenLineJoin StrokeJoin { get; set; } = PenLineJoin.Miter;
public PenLineJoin StrokeJoin
{
get { return GetValue(StrokeJoinProperty); }
set { SetValue(StrokeJoinProperty, value); }
}
public override void Render(DrawingContext context)
{
@ -133,8 +145,8 @@ namespace Avalonia.Controls.Shapes
if (geometry != null)
{
var pen = new Pen(Stroke, StrokeThickness, new DashStyle(StrokeDashArray, StrokeDashOffset),
StrokeDashCap, StrokeStartLineCap, StrokeEndLineCap, StrokeJoin);
var pen = new Pen(Stroke, StrokeThickness, new DashStyle(StrokeDashArray, StrokeDashOffset),
StrokeLineCap, StrokeJoin);
context.DrawGeometry(Fill, pen, geometry);
}
}
@ -169,11 +181,11 @@ namespace Avalonia.Controls.Shapes
protected void InvalidateGeometry()
{
this._renderedGeometry = null;
this._definingGeometry = null;
_renderedGeometry = null;
_definingGeometry = null;
InvalidateMeasure();
}
protected override Size MeasureOverride(Size availableSize)
{
bool deferCalculateTransform;
@ -203,10 +215,10 @@ namespace Avalonia.Controls.Shapes
return CalculateShapeSizeAndSetTransform(availableSize);
}
}
protected override Size ArrangeOverride(Size finalSize)
{
if(_calculateTransformOnArrange)
if (_calculateTransformOnArrange)
{
_calculateTransformOnArrange = false;
CalculateShapeSizeAndSetTransform(finalSize);
@ -312,25 +324,25 @@ namespace Avalonia.Controls.Shapes
private static void AffectsGeometryInvalidate(AvaloniaPropertyChangedEventArgs e)
{
var control = e.Sender as Shape;
if (!(e.Sender is Shape control))
{
return;
}
if (control != null)
// If the geometry is invalidated when Bounds changes, only invalidate when the Size
// portion changes.
if (e.Property == BoundsProperty)
{
// If the geometry is invalidated when Bounds changes, only invalidate when the Size
// portion changes.
if (e.Property == BoundsProperty)
{
var oldBounds = (Rect)e.OldValue;
var newBounds = (Rect)e.NewValue;
var oldBounds = (Rect)e.OldValue;
var newBounds = (Rect)e.NewValue;
if (oldBounds.Size == newBounds.Size)
{
return;
}
if (oldBounds.Size == newBounds.Size)
{
return;
}
control.InvalidateGeometry();
}
control.InvalidateGeometry();
}
}
}

11
src/Avalonia.Controls/Window.cs

@ -371,8 +371,16 @@ namespace Avalonia.Controls
/// <summary>
/// Shows the window.
/// </summary>
/// <exception cref="InvalidOperationException">
/// The window has already been closed.
/// </exception>
public override void Show()
{
if (PlatformImpl == null)
{
throw new InvalidOperationException("Cannot re-show a closed window.");
}
if (IsVisible)
{
return;
@ -397,6 +405,9 @@ namespace Avalonia.Controls
/// Shows the window as a dialog.
/// </summary>
/// <param name="owner">The dialog's owner window.</param>
/// <exception cref="InvalidOperationException">
/// The window has already been closed.
/// </exception>
/// <returns>
/// A task that can be used to track the lifetime of the dialog.
/// </returns>

10
src/Avalonia.Visuals/Media/BrushExtensions.cs

@ -34,16 +34,14 @@ namespace Avalonia.Media
{
Contract.Requires<ArgumentNullException>(pen != null);
var brush = pen?.Brush?.ToImmutable();
return pen == null || ReferenceEquals(pen?.Brush, brush) ?
var brush = pen.Brush?.ToImmutable();
return ReferenceEquals(pen.Brush, brush) ?
pen :
new Pen(
brush,
thickness: pen.Thickness,
dashStyle: pen.DashStyle,
dashCap: pen.DashCap,
startLineCap: pen.StartLineCap,
endLineCap: pen.EndLineCap,
dashStyle: pen.DashStyle,
lineCap: pen.LineCap,
lineJoin: pen.LineJoin,
miterLimit: pen.MiterLimit);
}

72
src/Avalonia.Visuals/Media/Pen.cs

@ -11,63 +11,45 @@ namespace Avalonia.Media
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="brush">The brush used to draw.</param>
/// <param name="color">The stroke color.</param>
/// <param name="thickness">The stroke thickness.</param>
/// <param name="dashStyle">The dash style.</param>
/// <param name="dashCap">The dash cap.</param>
/// <param name="startLineCap">The start line cap.</param>
/// <param name="endLineCap">The end line cap.</param>
/// <param name="lineCap">Specifies the type of graphic shape to use on both ends of a line.</param>
/// <param name="lineJoin">The line join.</param>
/// <param name="miterLimit">The miter limit.</param>
public Pen(
IBrush brush,
uint color,
double thickness = 1.0,
DashStyle dashStyle = null,
PenLineCap dashCap = PenLineCap.Flat,
PenLineCap startLineCap = PenLineCap.Flat,
PenLineCap endLineCap = PenLineCap.Flat,
PenLineJoin lineJoin = PenLineJoin.Miter,
double miterLimit = 10.0)
DashStyle dashStyle = null,
PenLineCap lineCap = PenLineCap.Flat,
PenLineJoin lineJoin = PenLineJoin.Miter,
double miterLimit = 10.0) : this(new SolidColorBrush(color), thickness, dashStyle, lineCap, lineJoin, miterLimit)
{
Brush = brush;
Thickness = thickness;
DashCap = dashCap;
StartLineCap = startLineCap;
EndLineCap = endLineCap;
LineJoin = lineJoin;
MiterLimit = miterLimit;
DashStyle = dashStyle;
}
/// <summary>
/// Initializes a new instance of the <see cref="Pen"/> class.
/// </summary>
/// <param name="color">The stroke color.</param>
/// <param name="brush">The brush used to draw.</param>
/// <param name="thickness">The stroke thickness.</param>
/// <param name="dashStyle">The dash style.</param>
/// <param name="dashCap">The dash cap.</param>
/// <param name="startLineCap">The start line cap.</param>
/// <param name="endLineCap">The end line cap.</param>
/// <param name="lineCap">The line cap.</param>
/// <param name="lineJoin">The line join.</param>
/// <param name="miterLimit">The miter limit.</param>
public Pen(
uint color,
IBrush brush,
double thickness = 1.0,
DashStyle dashStyle = null,
PenLineCap dashCap = PenLineCap.Flat,
PenLineCap startLineCap = PenLineCap.Flat,
PenLineCap endLineCap = PenLineCap.Flat,
PenLineJoin lineJoin = PenLineJoin.Miter,
DashStyle dashStyle = null,
PenLineCap lineCap = PenLineCap.Flat,
PenLineJoin lineJoin = PenLineJoin.Miter,
double miterLimit = 10.0)
{
Brush = new SolidColorBrush(color);
Brush = brush;
Thickness = thickness;
StartLineCap = startLineCap;
EndLineCap = endLineCap;
LineCap = lineCap;
LineJoin = lineJoin;
MiterLimit = miterLimit;
DashStyle = dashStyle;
DashCap = dashCap;
}
/// <summary>
@ -78,18 +60,26 @@ namespace Avalonia.Media
/// <summary>
/// Gets the stroke thickness.
/// </summary>
public double Thickness { get; } = 1.0;
public double Thickness { get; }
/// <summary>
/// Specifies the style of dashed lines drawn with a <see cref="Pen"/> object.
/// </summary>
public DashStyle DashStyle { get; }
public PenLineCap DashCap { get; }
public PenLineCap StartLineCap { get; } = PenLineCap.Flat;
public PenLineCap EndLineCap { get; } = PenLineCap.Flat;
/// <summary>
/// Specifies the type of graphic shape to use on both ends of a line.
/// </summary>
public PenLineCap LineCap { get; }
public PenLineJoin LineJoin { get; } = PenLineJoin.Miter;
/// <summary>
/// Specifies how to join consecutive line or curve segments in a <see cref="PathFigure"/> (subpath) contained in a <see cref="PathGeometry"/> object.
/// </summary>
public PenLineJoin LineJoin { get; }
public double MiterLimit { get; } = 10.0;
/// <summary>
/// The limit on the ratio of the miter length to half this pen's Thickness.
/// </summary>
public double MiterLimit { get; }
}
}

3
src/Avalonia.Visuals/Media/PenLineCap.cs

@ -4,7 +4,6 @@ namespace Avalonia.Media
{
Flat,
Round,
Square,
Triangle
Square
}
}

19
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -578,25 +578,17 @@ namespace Avalonia.Skia
// Need to modify dashes due to Skia modifying their lengths
// https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/paths/dots
// TODO: Still something is off, dashes are now present, but don't look the same as D2D ones.
float dashLengthModifier;
float gapLengthModifier;
switch (pen.StartLineCap)
switch (pen.LineCap)
{
case PenLineCap.Round:
paint.StrokeCap = SKStrokeCap.Round;
dashLengthModifier = -paint.StrokeWidth;
gapLengthModifier = paint.StrokeWidth;
break;
case PenLineCap.Square:
paint.StrokeCap = SKStrokeCap.Square;
dashLengthModifier = -paint.StrokeWidth;
gapLengthModifier = paint.StrokeWidth;
break;
default:
paint.StrokeCap = SKStrokeCap.Butt;
dashLengthModifier = 0.0f;
gapLengthModifier = 0.0f;
break;
}
@ -622,13 +614,12 @@ namespace Avalonia.Skia
for (var i = 0; i < srcDashes.Count; ++i)
{
var lengthModifier = i % 2 == 0 ? dashLengthModifier : gapLengthModifier;
// Avalonia dash lengths are relative, but Skia takes absolute sizes - need to scale
dashesArray[i] = (float) srcDashes[i] * paint.StrokeWidth + lengthModifier;
dashesArray[i] = (float) srcDashes[i] * paint.StrokeWidth;
}
var pe = SKPathEffect.CreateDash(dashesArray, (float) pen.DashStyle.Offset);
var offset = (float)(pen.DashStyle.Offset * pen.Thickness);
var pe = SKPathEffect.CreateDash(dashesArray, offset);
paint.PathEffect = pe;
rv.AddDisposable(pe);

8
src/Windows/Avalonia.Direct2D1/PrimitiveExtensions.cs

@ -122,14 +122,16 @@ namespace Avalonia.Direct2D1
/// <returns>The Direct2D brush.</returns>
public static StrokeStyle ToDirect2DStrokeStyle(this Avalonia.Media.Pen pen, Factory factory)
{
var d2dLineCap = pen.LineCap.ToDirect2D();
var properties = new StrokeStyleProperties
{
DashStyle = DashStyle.Solid,
MiterLimit = (float)pen.MiterLimit,
LineJoin = pen.LineJoin.ToDirect2D(),
StartCap = pen.StartLineCap.ToDirect2D(),
EndCap = pen.EndLineCap.ToDirect2D(),
DashCap = pen.DashCap.ToDirect2D()
StartCap = d2dLineCap,
EndCap = d2dLineCap,
DashCap = d2dLineCap
};
float[] dashes = null;
if (pen.DashStyle?.Dashes != null && pen.DashStyle.Dashes.Count > 0)

45
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -292,6 +292,51 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void Calling_Show_On_Closed_Window_Should_Throw()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var windowImpl = Mock.Of<IWindowImpl>(x => x.Scaling == 1);
var target = new Window(windowImpl);
target.Show();
target.Close();
var openedRaised = false;
target.Opened += (s, e) => openedRaised = true;
var ex = Assert.Throws<InvalidOperationException>(() => target.Show());
Assert.Equal("Cannot re-show a closed window.", ex.Message);
Assert.False(openedRaised);
}
}
[Fact]
public async Task Calling_ShowDialog_On_Closed_Window_Should_Throw()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var parent = new Mock<IWindowImpl>();
var windowImpl = new Mock<IWindowImpl>();
windowImpl.SetupProperty(x => x.Closed);
windowImpl.Setup(x => x.Scaling).Returns(1);
var target = new Window(windowImpl.Object);
var task = target.ShowDialog<bool>(parent.Object);
windowImpl.Object.Closed();
await task;
var openedRaised = false;
target.Opened += (s, e) => openedRaised = true;
var ex = await Assert.ThrowsAsync<InvalidOperationException>(() => target.ShowDialog<bool>(parent.Object));
Assert.Equal("Cannot re-show a closed window.", ex.Message);
Assert.False(openedRaised);
}
}
[Fact]
public void Window_Should_Be_Centered_When_WindowStartupLocation_Is_CenterScreen()
{

8
tests/Avalonia.RenderTests/Shapes/PathTests.cs

@ -334,11 +334,7 @@ namespace Avalonia.Direct2D1.RenderTests.Shapes
CompareImages();
}
#if AVALONIA_SKIA_SKIP_FAIL
[Fact(Skip = "FIXME")]
#else
[Fact]
#endif
public async Task Path_With_PenLineCap()
{
Decorator target = new Decorator
@ -351,10 +347,8 @@ namespace Avalonia.Direct2D1.RenderTests.Shapes
StrokeThickness = 10,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
StrokeDashCap = PenLineCap.Triangle,
StrokeDashArray = new AvaloniaList<double>(3, 1),
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Square,
StrokeLineCap = PenLineCap.Round,
Data = StreamGeometry.Parse("M 20,20 L 180,180"),
}
};

3
tests/Avalonia.RenderTests/Shapes/PolylineTests.cs

@ -61,8 +61,7 @@ namespace Avalonia.Direct2D1.RenderTests.Shapes
Points = polylinePoints,
Stretch = Stretch.Uniform,
StrokeJoin = PenLineJoin.Round,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
StrokeLineCap = PenLineCap.Round,
StrokeThickness = 10
}
};

BIN
tests/TestFiles/Direct2D1/Shapes/Path/Path_With_PenLineCap.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
tests/TestFiles/Skia/Shapes/Path/Path_With_PenLineCap.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Loading…
Cancel
Save