Browse Source

Rectangle stuff.

pull/4/head
Steven Kirk 12 years ago
parent
commit
da75a6bfdf
  1. 1
      Perspex.Direct2D1.RenderTests/Perspex.Direct2D1.RenderTests.csproj
  2. 80
      Perspex.Direct2D1.RenderTests/Shapes/RectangleTests.cs
  3. 12
      Perspex/Controls/Control.cs
  4. 20
      Perspex/Shapes/Rectangle.cs
  5. 22
      Perspex/Size.cs
  6. BIN
      TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_1px_Stroke.expected.png
  7. BIN
      TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_2px_Stroke.expected.png
  8. BIN
      TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_Stroke_Fill.expected.png

1
Perspex.Direct2D1.RenderTests/Perspex.Direct2D1.RenderTests.csproj

@ -59,6 +59,7 @@
</Choose>
<ItemGroup>
<Compile Include="Controls\BorderTests.cs" />
<Compile Include="Shapes\RectangleTests.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

80
Perspex.Direct2D1.RenderTests/Shapes/RectangleTests.cs

@ -0,0 +1,80 @@
// -----------------------------------------------------------------------
// <copyright file="BorderTests.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1.RenderTests.Shapes
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Controls;
using Perspex.Media;
using Perspex.Shapes;
[TestClass]
public class RectangleTests : TestBase
{
public RectangleTests()
: base(@"Shapes\Rectangle")
{
}
[TestMethod]
public void Rectangle_1px_Stroke()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 200,
Content = new Rectangle
{
Stroke = Brushes.Black,
StrokeThickness = 1,
}
};
this.RenderToFile(target);
this.CompareImages();
}
[TestMethod]
public void Rectangle_2px_Stroke()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 200,
Content = new Rectangle
{
Stroke = Brushes.Black,
StrokeThickness = 2,
}
};
this.RenderToFile(target);
this.CompareImages();
}
[TestMethod]
public void Rectangle_Stroke_Fill()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 200,
Content = new Rectangle
{
Stroke = Brushes.Black,
StrokeThickness = 2,
Fill = Brushes.Red,
}
};
this.RenderToFile(target);
this.CompareImages();
}
}
}

12
Perspex/Controls/Control.cs

@ -425,8 +425,16 @@ namespace Perspex.Controls
protected virtual Size MeasureCore(Size availableSize)
{
availableSize = availableSize.Deflate(this.Margin);
return this.MeasureOverride(availableSize);
Size measuredSize = this.MeasureOverride(availableSize.Deflate(this.Margin));
double width = (this.Width > 0) ? this.Width : measuredSize.Width;
double height = (this.Height > 0) ? this.Height : measuredSize.Height;
width = Math.Min(width, this.MaxWidth);
width = Math.Max(width, this.MinWidth);
height = Math.Min(height, this.MaxHeight);
height = Math.Max(height, this.MinHeight);
return new Size(width, height);
}
protected virtual Size MeasureOverride(Size availableSize)

20
Perspex/Shapes/Rectangle.cs

@ -10,9 +10,27 @@ namespace Perspex.Shapes
public class Rectangle : Shape
{
private Geometry geometry;
private Size geometrySize;
public override Geometry DefiningGeometry
{
get { return new RectangleGeometry(new Rect(0, 0, this.Width, this.Height)); }
get
{
if (this.geometry == null || this.geometrySize != this.ActualSize)
{
this.geometry = new RectangleGeometry(new Rect(0, 0, this.ActualSize.Width, this.ActualSize.Height));
this.geometrySize = this.ActualSize;
}
return this.geometry;
}
}
protected override Size MeasureOverride(Size availableSize)
{
return new Size(this.StrokeThickness, this.StrokeThickness);
}
}
}

22
Perspex/Size.cs

@ -51,6 +51,28 @@ namespace Perspex
get { return this.height; }
}
/// <summary>
/// Checks for equality between two <see cref="Size"/>s.
/// </summary>
/// <param name="left">The first size.</param>
/// <param name="right">The second size.</param>
/// <returns>True if the sizes are equal; otherwise false.</returns>
public static bool operator ==(Size left, Size right)
{
return left.width == right.width && left.height == right.height;
}
/// <summary>
/// Checks for unequality between two <see cref="Size"/>s.
/// </summary>
/// <param name="left">The first size.</param>
/// <param name="right">The second size.</param>
/// <returns>True if the sizes are unequal; otherwise false.</returns>
public static bool operator !=(Size left, Size right)
{
return !(left == right);
}
/// <summary>
/// Constrains the size.
/// </summary>

BIN
TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_1px_Stroke.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

BIN
TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_2px_Stroke.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

BIN
TestFiles/Direct2D1/Shapes/Rectangle/Rectangle_Stroke_Fill.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

Loading…
Cancel
Save