Browse Source

Draw border inside control bounds.

Added few more tests.
pull/4/head
Steven Kirk 12 years ago
parent
commit
f521642df2
  1. 37
      Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs
  2. 5
      Perspex/Controls/Border.cs
  3. 7
      Perspex/Media/Brushes.cs
  4. 11
      Perspex/Rect.cs
  5. BIN
      TestFiles/Direct2D1/Controls/Border/Border_1px_Border.expected.png
  6. BIN
      TestFiles/Direct2D1/Controls/Border/Border_2px_Border.expected.png
  7. BIN
      TestFiles/Direct2D1/Controls/Border/Border_Fill.expected.png

37
Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs

@ -36,5 +36,42 @@ namespace Perspex.Direct2D1.RenderTests.Controls
this.RenderToFile(target);
this.CompareImages();
}
[TestMethod]
public void Border_2px_Border()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 200,
Content = new Border
{
BorderBrush = Brushes.Black,
BorderThickness = 2,
}
};
this.RenderToFile(target);
this.CompareImages();
}
[TestMethod]
public void Border_Fill()
{
Decorator target = new Decorator
{
Padding = new Thickness(8),
Width = 200,
Height = 200,
Content = new Border
{
Background = Brushes.Red,
}
};
this.RenderToFile(target);
this.CompareImages();
}
}
}

5
Perspex/Controls/Border.cs

@ -27,15 +27,16 @@ namespace Perspex.Controls
Brush background = this.Background;
Brush borderBrush = this.BorderBrush;
double borderThickness = this.BorderThickness;
Rect rect = new Rect(this.Bounds.Size).Deflate(BorderThickness / 2);
if (background != null)
{
context.FillRectange(background, new Rect(this.Bounds.Size));
context.FillRectange(background, rect);
}
if (borderBrush != null && borderThickness > 0)
{
context.DrawRectange(new Pen(borderBrush, borderThickness), new Rect(this.Bounds.Size));
context.DrawRectange(new Pen(borderBrush, borderThickness), rect);
}
}
}

7
Perspex/Media/Brushes.cs

@ -14,6 +14,7 @@ namespace Perspex.Media
static Brushes()
{
Black = new SolidColorBrush(0xff000000);
Red = new SolidColorBrush(0xffff0000);
}
public static SolidColorBrush Black
@ -21,5 +22,11 @@ namespace Perspex.Media
get;
private set;
}
public static SolidColorBrush Red
{
get;
private set;
}
}
}

11
Perspex/Rect.cs

@ -189,6 +189,17 @@ namespace Perspex
p.Y >= this.y && p.Y < this.y + this.height;
}
/// <summary>
/// Deflates the rectangle.
/// </summary>
/// <param name="thickness">The thickness.</param>
/// <returns>The deflated rectangle.</returns>
/// <remarks>The deflated rectangle size cannot be less than 0.</remarks>
public Rect Deflate(double thickness)
{
return this.Deflate(new Thickness(thickness));
}
/// <summary>
/// Deflates the rectangle by a <see cref="Thickness"/>.
/// </summary>

BIN
TestFiles/Direct2D1/Controls/Border/Border_1px_Border.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

After

Width:  |  Height:  |  Size: 609 B

BIN
TestFiles/Direct2D1/Controls/Border/Border_2px_Border.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

BIN
TestFiles/Direct2D1/Controls/Border/Border_Fill.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

Loading…
Cancel
Save