Browse Source
And added a test that outputs an image using it (doesn't actually compare the image yet)pull/4/head
20 changed files with 477 additions and 4 deletions
@ -0,0 +1,39 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="BorderTests.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Direct2D1.RenderTests.Controls |
|||
{ |
|||
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
|
|||
[TestClass] |
|||
public class BorderTests : TestBase |
|||
{ |
|||
public BorderTests() |
|||
: base(@"Controls\Border") |
|||
{ |
|||
} |
|||
|
|||
[TestMethod] |
|||
public void Border_1px_Border() |
|||
{ |
|||
Decorator target = new Decorator |
|||
{ |
|||
Padding = new Thickness(8), |
|||
Width = 200, |
|||
Height = 200, |
|||
Content = new Border |
|||
{ |
|||
BorderBrush = Brushes.Black, |
|||
BorderThickness = 1, |
|||
} |
|||
}; |
|||
|
|||
this.RenderToFile(target); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,101 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{DABFD304-D6A4-4752-8123-C2CCF7AC7831}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Direct2D1.RenderTests</RootNamespace> |
|||
<AssemblyName>Perspex.Direct2D1.RenderTests</AssemblyName> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> |
|||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
|||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> |
|||
<IsCodedUITest>False</IsCodedUITest> |
|||
<TestProjectType>UnitTest</TestProjectType> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Splat, Version=1.1.1.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<SpecificVersion>False</SpecificVersion> |
|||
<HintPath>..\packages\Splat.1.1.1\lib\Net45\Splat.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> |
|||
</ItemGroup> |
|||
</When> |
|||
<Otherwise> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" /> |
|||
</ItemGroup> |
|||
</Otherwise> |
|||
</Choose> |
|||
<ItemGroup> |
|||
<Compile Include="Controls\BorderTests.cs" /> |
|||
<Compile Include="TestBase.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Perspex.Direct2D1\Perspex.Direct2D1.csproj"> |
|||
<Project>{3e908f67-5543-4879-a1dc-08eace79b3cd}</Project> |
|||
<Name>Perspex.Direct2D1</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex\Perspex.csproj"> |
|||
<Project>{3c9f40da-d2a5-43a1-a272-e965876c6d46}</Project> |
|||
<Name>Perspex</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
</ItemGroup> |
|||
</When> |
|||
</Choose> |
|||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Perspex.Direct2D1.RenderTests")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.Direct2D1.RenderTests")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("21fcc0e6-150b-43c4-a658-23a354ec33d9")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,49 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="TestBase.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Direct2D1.RenderTests |
|||
{ |
|||
using System.IO; |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using Perspex.Controls; |
|||
using Perspex.Media; |
|||
|
|||
public class TestBase |
|||
{ |
|||
static TestBase() |
|||
{ |
|||
Direct2D1Platform.Initialize(); |
|||
} |
|||
|
|||
public TestBase(string outputPath) |
|||
{ |
|||
string testFiles = Path.GetFullPath(@"..\..\..\TestFiles\Direct2D1"); |
|||
this.OutputPath = Path.Combine(testFiles, outputPath); |
|||
} |
|||
|
|||
public string OutputPath |
|||
{ |
|||
get; |
|||
private set; |
|||
} |
|||
|
|||
protected void RenderToFile(Control target, [CallerMemberName] string testName = "") |
|||
{ |
|||
string path = Path.Combine(this.OutputPath, testName + ".out.png"); |
|||
|
|||
RenderTargetBitmap bitmap = new RenderTargetBitmap( |
|||
(int)target.Width, |
|||
(int)target.Height); |
|||
|
|||
Size size = new Size(target.Width, target.Height); |
|||
target.Measure(size); |
|||
target.Arrange(new Rect(size)); |
|||
bitmap.Render(target); |
|||
bitmap.Save(path); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="Splat" version="1.1.1" targetFramework="net45" /> |
|||
</packages> |
|||
@ -0,0 +1,56 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="BitmapImpl.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Direct2D1.Media |
|||
{ |
|||
using System; |
|||
using System.IO; |
|||
using Perspex.Platform; |
|||
using SharpDX.WIC; |
|||
|
|||
public class BitmapImpl : IBitmapImpl |
|||
{ |
|||
private ImagingFactory factory; |
|||
|
|||
public BitmapImpl(ImagingFactory factory, int width, int height) |
|||
{ |
|||
this.factory = factory; |
|||
this.WicImpl = new Bitmap( |
|||
factory, |
|||
width, |
|||
height, |
|||
PixelFormat.Format32bppPBGRA, |
|||
BitmapCreateCacheOption.CacheOnLoad); |
|||
} |
|||
|
|||
public Bitmap WicImpl |
|||
{ |
|||
get; |
|||
private set; |
|||
} |
|||
|
|||
public void Save(string fileName) |
|||
{ |
|||
if (Path.GetExtension(fileName) != ".png") |
|||
{ |
|||
// Yeah, we need to support other formats.
|
|||
throw new NotSupportedException("Use PNG, stoopid."); |
|||
} |
|||
|
|||
using (FileStream s = new FileStream(fileName, FileMode.Create)) |
|||
{ |
|||
PngBitmapEncoder encoder = new PngBitmapEncoder(factory); |
|||
encoder.Initialize(s); |
|||
|
|||
BitmapFrameEncode frame = new BitmapFrameEncode(encoder); |
|||
frame.Initialize(); |
|||
frame.WriteSource(this.WicImpl); |
|||
frame.Commit(); |
|||
encoder.Commit(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="RenderTargetBitmapImpl.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Direct2D1.Media |
|||
{ |
|||
using System; |
|||
using Perspex.Platform; |
|||
using SharpDX.Direct2D1; |
|||
using SharpDX.WIC; |
|||
|
|||
public class RenderTargetBitmapImpl : BitmapImpl, IRenderTargetBitmapImpl |
|||
{ |
|||
private WicRenderTarget target; |
|||
|
|||
public RenderTargetBitmapImpl( |
|||
ImagingFactory imagingFactory, |
|||
Factory d2dFactory, |
|||
int width, |
|||
int height) |
|||
: base(imagingFactory, width, height) |
|||
{ |
|||
this.target = new WicRenderTarget( |
|||
d2dFactory, |
|||
this.WicImpl, |
|||
new RenderTargetProperties |
|||
{ |
|||
DpiX = 96, |
|||
DpiY = 96, |
|||
}); |
|||
} |
|||
|
|||
public void Render(IVisual visual) |
|||
{ |
|||
Renderer renderer = new Renderer(this.target); |
|||
renderer.Render(visual); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Bitmap.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
using Perspex.Platform; |
|||
using Splat; |
|||
|
|||
public class Bitmap |
|||
{ |
|||
public Bitmap(int width, int height) |
|||
{ |
|||
IPlatformFactory factory = Locator.Current.GetService<IPlatformFactory>(); |
|||
this.PlatformImpl = factory.CreateBitmap(width, height); |
|||
} |
|||
|
|||
protected Bitmap(IBitmapImpl impl) |
|||
{ |
|||
this.PlatformImpl = impl; |
|||
} |
|||
|
|||
public IBitmapImpl PlatformImpl |
|||
{ |
|||
get; |
|||
private set; |
|||
} |
|||
|
|||
public void Save(string fileName) |
|||
{ |
|||
this.PlatformImpl.Save(fileName); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="RenderTargetBitmap.cs" company="Steven Kirk">
|
|||
// Copyright 2013 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Media |
|||
{ |
|||
using Perspex.Platform; |
|||
using Splat; |
|||
|
|||
public class RenderTargetBitmap : Bitmap |
|||
{ |
|||
public RenderTargetBitmap(int width, int height) |
|||
: base(CreateImpl(width, height)) |
|||
{ |
|||
} |
|||
|
|||
public new IRenderTargetBitmapImpl PlatformImpl |
|||
{ |
|||
get { return (IRenderTargetBitmapImpl)base.PlatformImpl; } |
|||
} |
|||
|
|||
public void Render(IVisual visual) |
|||
{ |
|||
this.PlatformImpl.Render(visual); |
|||
} |
|||
|
|||
private static IBitmapImpl CreateImpl(int width, int height) |
|||
{ |
|||
IPlatformFactory factory = Locator.Current.GetService<IPlatformFactory>(); |
|||
return factory.CreateRenderTargetBitmap(width, height); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="IBitmapImpl.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Platform |
|||
{ |
|||
public interface IBitmapImpl |
|||
{ |
|||
void Save(string fileName); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="IRenderTargetBitmapImpl.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Platform |
|||
{ |
|||
public interface IRenderTargetBitmapImpl : IBitmapImpl |
|||
{ |
|||
void Render(IVisual visual); |
|||
} |
|||
} |
|||
|
After Width: | Height: | Size: 663 B |
Loading…
Reference in new issue