From f521642df214d0ab42df6d49fa969cd5bf63b315 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 24 Jun 2014 07:17:25 +0200 Subject: [PATCH] Draw border inside control bounds. Added few more tests. --- .../Controls/BorderTests.cs | 37 ++++++++++++++++++ Perspex/Controls/Border.cs | 5 ++- Perspex/Media/Brushes.cs | 7 ++++ Perspex/Rect.cs | 11 ++++++ .../Border/Border_1px_Border.expected.png | Bin 663 -> 609 bytes .../Border/Border_2px_Border.expected.png | Bin 0 -> 611 bytes .../Controls/Border/Border_Fill.expected.png | Bin 0 -> 601 bytes 7 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 TestFiles/Direct2D1/Controls/Border/Border_2px_Border.expected.png create mode 100644 TestFiles/Direct2D1/Controls/Border/Border_Fill.expected.png diff --git a/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs b/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs index 907ef6f741..4dbf79fd74 100644 --- a/Perspex.Direct2D1.RenderTests/Controls/BorderTests.cs +++ b/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(); + } } } diff --git a/Perspex/Controls/Border.cs b/Perspex/Controls/Border.cs index 197ef18c28..8d6c3415f0 100644 --- a/Perspex/Controls/Border.cs +++ b/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); } } } diff --git a/Perspex/Media/Brushes.cs b/Perspex/Media/Brushes.cs index 7ecba5d2a4..261fcc98ca 100644 --- a/Perspex/Media/Brushes.cs +++ b/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; + } } } diff --git a/Perspex/Rect.cs b/Perspex/Rect.cs index 56c99a1f4e..514c69fde7 100644 --- a/Perspex/Rect.cs +++ b/Perspex/Rect.cs @@ -189,6 +189,17 @@ namespace Perspex p.Y >= this.y && p.Y < this.y + this.height; } + /// + /// Deflates the rectangle. + /// + /// The thickness. + /// The deflated rectangle. + /// The deflated rectangle size cannot be less than 0. + public Rect Deflate(double thickness) + { + return this.Deflate(new Thickness(thickness)); + } + /// /// Deflates the rectangle by a . /// diff --git a/TestFiles/Direct2D1/Controls/Border/Border_1px_Border.expected.png b/TestFiles/Direct2D1/Controls/Border/Border_1px_Border.expected.png index ac360079e7ad53c3d70681030eb7a17fbc856dcc..24239d5799ab3308d44bf2ab283758dc0202c9b3 100644 GIT binary patch literal 609 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VM%xNb!1@J z*w6hZk(GggiQCh~F{C2y?d6Sv%?<)A2iyM?yPcbPh2!_C+c#Ot_<%YX7!CwopH zT&&Nl(zxO3{rvlz4{$d+2yn2B5<@o(TC%sVM%xNb!1@J z*w6hZk(Ggg$c`QYyR)*F{`b4f z1k}uMz}mWZ@AG1wGq22^E$!dwOgjSeP6~ ziJ=;M1& diff --git a/TestFiles/Direct2D1/Controls/Border/Border_2px_Border.expected.png b/TestFiles/Direct2D1/Controls/Border/Border_2px_Border.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..cebe42f3dffecec76c3184b4dc3c95a3351a6ca5 GIT binary patch literal 611 zcmeAS@N?(olHy`uVBq!ia0vp^CqS5k4M?tyST_$yF%}28J29*~C-V}>VM%xNb!1@J z*w6hZk(GggiPzJ`F{C2y?bVIE4Gugk2iyNuvng7}DIQ8!+sU@)6BAGi1H+9ghSBRH zZv>hZoMV!=l|Le$Xukg4E%rtQ0S=~7Vu*%8!I^2VM%xNb!1@J z*w6hZk(GggiP_V|F{C2y?d5}<4F(J>2Q&WLuJ)K$$lYNq6T@l^)Bpr#rDy(^>}|HS vWlUjyUX$RcAi%;jN(}Wd07osue&b`j+h#Kt7)_eY2omvh^>bP0l+XkKIR;Xb literal 0 HcmV?d00001