Browse Source

Separate Windows and D2D assemblies.

pull/4/head
Steven Kirk 12 years ago
parent
commit
bdb9d44f55
  1. 28
      Perspex.Direct2D1/Direct2D1Platform.cs
  2. 3
      Perspex.Direct2D1/DrawingContext.cs
  3. 88
      Perspex.Direct2D1/Perspex.Direct2D1.csproj
  4. 36
      Perspex.Direct2D1/Properties/AssemblyInfo.cs
  5. 14
      Perspex.Direct2D1/Renderer.cs
  6. 2
      Perspex.Direct2D1/TextService.cs
  7. 10
      Perspex.Direct2D1/packages.config
  8. 12
      Perspex.Windows/Perspex.Windows.csproj
  9. 6
      Perspex.Windows/Window.cs
  10. 3
      Perspex.Windows/packages.config
  11. 8
      Perspex.sln
  12. 10
      Perspex/Application.cs
  13. 1
      Perspex/Perspex.csproj
  14. 37
      Perspex/Platform/IRenderer.cs
  15. 16
      TestApplication/App.cs
  16. 14
      TestApplication/Program.cs
  17. 5
      TestApplication/TestApplication.csproj
  18. 1
      packages/repositories.config

28
Perspex.Direct2D1/Direct2D1Platform.cs

@ -0,0 +1,28 @@
// -----------------------------------------------------------------------
// <copyright file="Direct2D1Initialize.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Direct2D1
{
using Perspex.Media;
using Perspex.Platform;
using Splat;
public static class Direct2D1Platform
{
public static void Initialize()
{
SharpDX.Direct2D1.Factory d2d1Factory = new SharpDX.Direct2D1.Factory();
SharpDX.DirectWrite.Factory dwFactory = new SharpDX.DirectWrite.Factory();
TextService textService = new TextService(dwFactory);
var locator = Locator.CurrentMutable;
locator.Register(() => d2d1Factory, typeof(SharpDX.Direct2D1.Factory));
locator.Register(() => dwFactory, typeof(SharpDX.DirectWrite.Factory));
locator.Register(() => textService, typeof(ITextService));
locator.Register(() => new Renderer(), typeof(IRenderer));
}
}
}

3
Perspex.Windows/DrawingContext.cs → Perspex.Direct2D1/DrawingContext.cs

@ -4,12 +4,11 @@
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Windows
namespace Perspex.Direct2D1
{
using System;
using System.Reactive.Disposables;
using Perspex.Media;
using Perspex.Windows.Media;
using SharpDX;
using SharpDX.Direct2D1;
using Matrix = Perspex.Media.Matrix;

88
Perspex.Direct2D1/Perspex.Direct2D1.csproj

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3E908F67-5543-4879-A1DC-08EACE79B3CD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Perspex.Direct2D1</RootNamespace>
<AssemblyName>Perspex.Direct2D1</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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="SharpDX">
<HintPath>..\packages\SharpDX.2.5.0\lib\net40\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Direct2D1">
<HintPath>..\packages\SharpDX.Direct2D1.2.5.0\lib\net40\SharpDX.Direct2D1.dll</HintPath>
</Reference>
<Reference Include="SharpDX.DXGI">
<HintPath>..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll</HintPath>
</Reference>
<Reference Include="Splat">
<HintPath>..\packages\Splat.1.1.1\lib\Net45\Splat.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Reactive.Core">
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Net45\System.Reactive.Core.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Interfaces">
<HintPath>..\packages\Rx-Interfaces.2.1.30214.0\lib\Net45\System.Reactive.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.PlatformServices">
<HintPath>..\packages\Rx-PlatformServices.2.1.30214.0\lib\Net45\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Direct2D1Platform.cs" />
<Compile Include="DrawingContext.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderer.cs" />
<Compile Include="TextService.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Perspex\Perspex.csproj">
<Project>{3c9f40da-d2a5-43a1-a272-e965876c6d46}</Project>
<Name>Perspex</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<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>

36
Perspex.Direct2D1/Properties/AssemblyInfo.cs

@ -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")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Perspex.Direct2D1")]
[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("6fb97e2a-0259-435b-b805-478fbab3cbbf")]
// 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")]

14
Perspex.Windows/Renderer.cs → Perspex.Direct2D1/Renderer.cs

@ -4,9 +4,10 @@
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Windows
namespace Perspex.Direct2D1
{
using System;
using Perspex.Platform;
using SharpDX;
using SharpDX.Direct2D1;
using DwFactory = SharpDX.DirectWrite.Factory;
@ -15,7 +16,7 @@ namespace Perspex.Windows
/// <summary>
/// Renders a <see cref="Canvas"/>.
/// </summary>
public class Renderer
public class Renderer : IRenderer
{
/// <summary>
/// The render target.
@ -28,8 +29,13 @@ namespace Perspex.Windows
/// <param name="hwnd">The window handle.</param>
/// <param name="width">The width of the window.</param>
/// <param name="height">The height of the window.</param>
public Renderer(IntPtr hwnd, int width, int height)
public void Initialize(IntPtr hwnd, double width, double height)
{
if (this.renderTarget != null)
{
throw new InvalidOperationException("Cannot initialize Renderer more than once.");
}
this.Direct2DFactory = new Factory();
this.DirectWriteFactory = new DwFactory();
@ -40,7 +46,7 @@ namespace Perspex.Windows
HwndRenderTargetProperties hwndProperties = new HwndRenderTargetProperties
{
Hwnd = hwnd,
PixelSize = new Size2(width, height),
PixelSize = new Size2((int)width, (int)height),
};
this.renderTarget = new WindowRenderTarget(

2
Perspex.Windows/Media/TextService.cs → Perspex.Direct2D1/TextService.cs

@ -4,7 +4,7 @@
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Windows.Media
namespace Perspex.Direct2D1
{
using Perspex.Media;
using SharpDX.DirectWrite;

10
Perspex.Direct2D1/packages.config

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Rx-Core" version="2.1.30214.0" targetFramework="net45" />
<package id="Rx-Interfaces" version="2.1.30214.0" targetFramework="net45" />
<package id="Rx-PlatformServices" version="2.1.30214.0" targetFramework="net45" />
<package id="SharpDX" version="2.5.0" targetFramework="net45" />
<package id="SharpDX.Direct2D1" version="2.5.0" targetFramework="net45" />
<package id="SharpDX.DXGI" version="2.5.0" targetFramework="net45" />
<package id="Splat" version="1.1.1" targetFramework="net45" />
</packages>

12
Perspex.Windows/Perspex.Windows.csproj

@ -30,15 +30,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpDX">
<HintPath>..\packages\SharpDX.2.5.0\lib\net40\SharpDX.dll</HintPath>
</Reference>
<Reference Include="SharpDX.Direct2D1">
<HintPath>..\packages\SharpDX.Direct2D1.2.5.0\lib\net40\SharpDX.Direct2D1.dll</HintPath>
</Reference>
<Reference Include="SharpDX.DXGI">
<HintPath>..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll</HintPath>
</Reference>
<Reference Include="Splat">
<HintPath>..\packages\Splat.1.1.1\lib\Net45\Splat.dll</HintPath>
</Reference>
@ -65,10 +56,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DrawingContext.cs" />
<Compile Include="Input\MouseDevice.cs" />
<Compile Include="Media\TextService.cs" />
<Compile Include="Renderer.cs" />
<Compile Include="Threading\Dispatcher.cs" />
<Compile Include="Threading\DispatcherFrame.cs" />
<Compile Include="Threading\DispatcherOperation.cs" />

6
Perspex.Windows/Window.cs

@ -15,6 +15,7 @@ namespace Perspex.Windows
using Perspex.Input;
using Perspex.Input.Raw;
using Perspex.Layout;
using Perspex.Platform;
using Perspex.Windows.Input;
using Perspex.Windows.Interop;
using Perspex.Windows.Threading;
@ -29,7 +30,7 @@ namespace Perspex.Windows
private string className;
private Renderer renderer;
private IRenderer renderer;
private IInputManager inputManager;
@ -43,7 +44,8 @@ namespace Perspex.Windows
this.CreateWindow();
Size clientSize = this.ClientSize;
this.LayoutManager = new LayoutManager();
this.renderer = new Renderer(this.Handle, (int)clientSize.Width, (int)clientSize.Height);
this.renderer = Locator.Current.GetService<IRenderer>();
this.renderer.Initialize(this.Handle, (int)clientSize.Width, (int)clientSize.Height);
this.inputManager = Locator.Current.GetService<IInputManager>();
this.Template = ControlTemplate.Create<Window>(this.DefaultTemplate);

3
Perspex.Windows/packages.config

@ -5,9 +5,6 @@
<package id="Rx-Linq" version="2.1.30214.0" targetFramework="net45" />
<package id="Rx-Main" version="2.1.30214.0" targetFramework="net45" />
<package id="Rx-PlatformServices" version="2.1.30214.0" targetFramework="net45" />
<package id="SharpDX" version="2.5.0" targetFramework="net45" />
<package id="SharpDX.Direct2D1" version="2.5.0" targetFramework="net45" />
<package id="SharpDX.DXGI" version="2.5.0" targetFramework="net45" />
<package id="Splat" version="1.1.1" targetFramework="net45" />
<package id="StyleCop.MSBuild" version="4.7.46.0" targetFramework="net45" />
</packages>

8
Perspex.sln

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex", "Perspex\Perspex.csproj", "{3C9F40DA-D2A5-43A1-A272-E965876C6D46}"
EndProject
@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication", "TestAppl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.UnitTests", "Perspex.UnitTests\Perspex.UnitTests.csproj", "{2905FF23-53FB-45E6-AA49-6AF47A172056}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Direct2D1", "Perspex.Direct2D1\Perspex.Direct2D1.csproj", "{3E908F67-5543-4879-A1DC-08EACE79B3CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -33,6 +35,10 @@ Global
{2905FF23-53FB-45E6-AA49-6AF47A172056}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2905FF23-53FB-45E6-AA49-6AF47A172056}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2905FF23-53FB-45E6-AA49-6AF47A172056}.Release|Any CPU.Build.0 = Release|Any CPU
{3E908F67-5543-4879-A1DC-08EACE79B3CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E908F67-5543-4879-A1DC-08EACE79B3CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E908F67-5543-4879-A1DC-08EACE79B3CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E908F67-5543-4879-A1DC-08EACE79B3CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

10
Perspex/Application.cs

@ -6,7 +6,11 @@
namespace Perspex
{
using System.Reflection;
using Perspex.Input;
using Perspex.Platform;
using Perspex.Styling;
using Splat;
public class Application
{
@ -40,5 +44,11 @@ namespace Perspex
this.styles = value;
}
}
public static void RegisterPortableServices()
{
InputManager inputManager = new InputManager();
Locator.CurrentMutable.Register(() => inputManager, typeof(IInputManager));
}
}
}

1
Perspex/Perspex.csproj

@ -82,6 +82,7 @@
<Compile Include="Input\InputManager.cs" />
<Compile Include="Input\Raw\RawInputEventArgs.cs" />
<Compile Include="Input\Raw\RawMouseEventArgs.cs" />
<Compile Include="Platform\IRenderer.cs" />
<Compile Include="Styling\StyleBinding.cs" />
<Compile Include="Classes.cs" />
<Compile Include="Contract.cs" />

37
Perspex/Platform/IRenderer.cs

@ -0,0 +1,37 @@
// -----------------------------------------------------------------------
// <copyright file="IRenderer.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Platform
{
using System;
public interface IRenderer
{
/// <summary>
/// Initializes the renderer to draw to the specified handle.
/// </summary>
/// <param name="handle">The window etc handle</param>
/// <param name="width">The initial viewport width.</param>
/// <param name="height">The initial viewport height.</param>
/// <remarks>
/// TODO: This probably should be somewhere else...
/// </remarks>
void Initialize(IntPtr handle, double width, double height);
/// <summary>
/// Renders the specified visual.
/// </summary>
/// <param name="visual">The visual to render.</param>
void Render(IVisual visual);
/// <summary>
/// Resizes the rendered viewport.
/// </summary>
/// <param name="width">The new width.</param>
/// <param name="height">The new height.</param>
void Resize(int width, int height);
}
}

16
TestApplication/App.cs

@ -0,0 +1,16 @@
namespace TestApplication
{
using Perspex;
using Perspex.Direct2D1;
using Perspex.Themes.Default;
public class App : Application
{
public App()
{
RegisterPortableServices();
Direct2D1Platform.Initialize();
this.Styles = new DefaultTheme();
}
}
}

14
TestApplication/Program.cs

@ -12,7 +12,6 @@ using Perspex.Media;
using Perspex.Styling;
using Perspex.Themes.Default;
using Perspex.Windows;
using Perspex.Windows.Media;
using Perspex.Windows.Threading;
using Splat;
@ -37,21 +36,10 @@ namespace TestApplication
{
static void Main(string[] args)
{
TextService textService = new TextService(new SharpDX.DirectWrite.Factory());
InputManager inputManager = new InputManager();
Locator.CurrentMutable.Register(() => inputManager, typeof(IInputManager));
Locator.CurrentMutable.Register(() => textService, typeof(ITextService));
Locator.CurrentMutable.Register(() => new Styler(), typeof(IStyler));
Locator.CurrentMutable.Register(() => new TestLogger(), typeof(ILogger));
Application application = new Application
{
Styles = new Styles
{
new DefaultTheme(),
}
};
App application = new App();
Window window = new Window
{

5
TestApplication/TestApplication.csproj

@ -73,6 +73,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -81,6 +82,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Perspex.Direct2D1\Perspex.Direct2D1.csproj">
<Project>{3e908f67-5543-4879-a1dc-08eace79b3cd}</Project>
<Name>Perspex.Direct2D1</Name>
</ProjectReference>
<ProjectReference Include="..\Perspex.Windows\Perspex.Windows.csproj">
<Project>{811a76cf-1cf6-440f-963b-bbe31bd72a82}</Project>
<Name>Perspex.Windows</Name>

1
packages/repositories.config

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\Perspex.Direct2D1\packages.config" />
<repository path="..\Perspex.UnitTests\packages.config" />
<repository path="..\Perspex.Windows\packages.config" />
<repository path="..\Perspex\packages.config" />

Loading…
Cancel
Save