From bdb9d44f55c249bab758cb12addb02d8fe100c47 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 11 Jun 2014 01:39:20 +0200 Subject: [PATCH] Separate Windows and D2D assemblies. --- Perspex.Direct2D1/Direct2D1Platform.cs | 28 ++++++ .../DrawingContext.cs | 3 +- Perspex.Direct2D1/Perspex.Direct2D1.csproj | 88 +++++++++++++++++++ Perspex.Direct2D1/Properties/AssemblyInfo.cs | 36 ++++++++ .../Renderer.cs | 14 ++- .../TextService.cs | 2 +- Perspex.Direct2D1/packages.config | 10 +++ Perspex.Windows/Perspex.Windows.csproj | 12 --- Perspex.Windows/Window.cs | 6 +- Perspex.Windows/packages.config | 3 - Perspex.sln | 8 +- Perspex/Application.cs | 10 +++ Perspex/Perspex.csproj | 1 + Perspex/Platform/IRenderer.cs | 37 ++++++++ TestApplication/App.cs | 16 ++++ TestApplication/Program.cs | 14 +-- TestApplication/TestApplication.csproj | 5 ++ packages/repositories.config | 1 + 18 files changed, 256 insertions(+), 38 deletions(-) create mode 100644 Perspex.Direct2D1/Direct2D1Platform.cs rename {Perspex.Windows => Perspex.Direct2D1}/DrawingContext.cs (99%) create mode 100644 Perspex.Direct2D1/Perspex.Direct2D1.csproj create mode 100644 Perspex.Direct2D1/Properties/AssemblyInfo.cs rename {Perspex.Windows => Perspex.Direct2D1}/Renderer.cs (89%) rename {Perspex.Windows/Media => Perspex.Direct2D1}/TextService.cs (97%) create mode 100644 Perspex.Direct2D1/packages.config create mode 100644 Perspex/Platform/IRenderer.cs create mode 100644 TestApplication/App.cs diff --git a/Perspex.Direct2D1/Direct2D1Platform.cs b/Perspex.Direct2D1/Direct2D1Platform.cs new file mode 100644 index 0000000000..fb98483edd --- /dev/null +++ b/Perspex.Direct2D1/Direct2D1Platform.cs @@ -0,0 +1,28 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +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)); + } + } +} diff --git a/Perspex.Windows/DrawingContext.cs b/Perspex.Direct2D1/DrawingContext.cs similarity index 99% rename from Perspex.Windows/DrawingContext.cs rename to Perspex.Direct2D1/DrawingContext.cs index 048d3056c2..d9bc460485 100644 --- a/Perspex.Windows/DrawingContext.cs +++ b/Perspex.Direct2D1/DrawingContext.cs @@ -4,12 +4,11 @@ // // ----------------------------------------------------------------------- -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; diff --git a/Perspex.Direct2D1/Perspex.Direct2D1.csproj b/Perspex.Direct2D1/Perspex.Direct2D1.csproj new file mode 100644 index 0000000000..a1a28b4ff7 --- /dev/null +++ b/Perspex.Direct2D1/Perspex.Direct2D1.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {3E908F67-5543-4879-A1DC-08EACE79B3CD} + Library + Properties + Perspex.Direct2D1 + Perspex.Direct2D1 + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\SharpDX.2.5.0\lib\net40\SharpDX.dll + + + ..\packages\SharpDX.Direct2D1.2.5.0\lib\net40\SharpDX.Direct2D1.dll + + + ..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll + + + ..\packages\Splat.1.1.1\lib\Net45\Splat.dll + + + + + + ..\packages\Rx-Core.2.1.30214.0\lib\Net45\System.Reactive.Core.dll + + + ..\packages\Rx-Interfaces.2.1.30214.0\lib\Net45\System.Reactive.Interfaces.dll + + + ..\packages\Rx-PlatformServices.2.1.30214.0\lib\Net45\System.Reactive.PlatformServices.dll + + + + + + + + + + + + + + + + + + {3c9f40da-d2a5-43a1-a272-e965876c6d46} + Perspex + + + + + + + + \ No newline at end of file diff --git a/Perspex.Direct2D1/Properties/AssemblyInfo.cs b/Perspex.Direct2D1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..76d8cce9ff --- /dev/null +++ b/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")] diff --git a/Perspex.Windows/Renderer.cs b/Perspex.Direct2D1/Renderer.cs similarity index 89% rename from Perspex.Windows/Renderer.cs rename to Perspex.Direct2D1/Renderer.cs index dd97d0b05a..6ced852b45 100644 --- a/Perspex.Windows/Renderer.cs +++ b/Perspex.Direct2D1/Renderer.cs @@ -4,9 +4,10 @@ // // ----------------------------------------------------------------------- -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 /// /// Renders a . /// - public class Renderer + public class Renderer : IRenderer { /// /// The render target. @@ -28,8 +29,13 @@ namespace Perspex.Windows /// The window handle. /// The width of the window. /// The height of the window. - 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( diff --git a/Perspex.Windows/Media/TextService.cs b/Perspex.Direct2D1/TextService.cs similarity index 97% rename from Perspex.Windows/Media/TextService.cs rename to Perspex.Direct2D1/TextService.cs index c7b9bb3065..5d5b2ed209 100644 --- a/Perspex.Windows/Media/TextService.cs +++ b/Perspex.Direct2D1/TextService.cs @@ -4,7 +4,7 @@ // // ----------------------------------------------------------------------- -namespace Perspex.Windows.Media +namespace Perspex.Direct2D1 { using Perspex.Media; using SharpDX.DirectWrite; diff --git a/Perspex.Direct2D1/packages.config b/Perspex.Direct2D1/packages.config new file mode 100644 index 0000000000..fd261d2b22 --- /dev/null +++ b/Perspex.Direct2D1/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Perspex.Windows/Perspex.Windows.csproj b/Perspex.Windows/Perspex.Windows.csproj index ba75d8f5d9..7eacbfc990 100644 --- a/Perspex.Windows/Perspex.Windows.csproj +++ b/Perspex.Windows/Perspex.Windows.csproj @@ -30,15 +30,6 @@ 4 - - ..\packages\SharpDX.2.5.0\lib\net40\SharpDX.dll - - - ..\packages\SharpDX.Direct2D1.2.5.0\lib\net40\SharpDX.Direct2D1.dll - - - ..\packages\SharpDX.DXGI.2.5.0\lib\net40\SharpDX.DXGI.dll - ..\packages\Splat.1.1.1\lib\Net45\Splat.dll @@ -65,10 +56,7 @@ - - - diff --git a/Perspex.Windows/Window.cs b/Perspex.Windows/Window.cs index 96c26c9038..8a65c93720 100644 --- a/Perspex.Windows/Window.cs +++ b/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(); + this.renderer.Initialize(this.Handle, (int)clientSize.Width, (int)clientSize.Height); this.inputManager = Locator.Current.GetService(); this.Template = ControlTemplate.Create(this.DefaultTemplate); diff --git a/Perspex.Windows/packages.config b/Perspex.Windows/packages.config index b2cc097609..c6bacea064 100644 --- a/Perspex.Windows/packages.config +++ b/Perspex.Windows/packages.config @@ -5,9 +5,6 @@ - - - \ No newline at end of file diff --git a/Perspex.sln b/Perspex.sln index 3a84b3a0da..64cb4832b4 100644 --- a/Perspex.sln +++ b/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 diff --git a/Perspex/Application.cs b/Perspex/Application.cs index 24ef9105ce..96cbadbb3e 100644 --- a/Perspex/Application.cs +++ b/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)); + } } } diff --git a/Perspex/Perspex.csproj b/Perspex/Perspex.csproj index ab1013d402..98cff42cc4 100644 --- a/Perspex/Perspex.csproj +++ b/Perspex/Perspex.csproj @@ -82,6 +82,7 @@ + diff --git a/Perspex/Platform/IRenderer.cs b/Perspex/Platform/IRenderer.cs new file mode 100644 index 0000000000..9d69b77ed8 --- /dev/null +++ b/Perspex/Platform/IRenderer.cs @@ -0,0 +1,37 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Platform +{ + using System; + + public interface IRenderer + { + /// + /// Initializes the renderer to draw to the specified handle. + /// + /// The window etc handle + /// The initial viewport width. + /// The initial viewport height. + /// + /// TODO: This probably should be somewhere else... + /// + void Initialize(IntPtr handle, double width, double height); + + /// + /// Renders the specified visual. + /// + /// The visual to render. + void Render(IVisual visual); + + /// + /// Resizes the rendered viewport. + /// + /// The new width. + /// The new height. + void Resize(int width, int height); + } +} diff --git a/TestApplication/App.cs b/TestApplication/App.cs new file mode 100644 index 0000000000..ff715409fd --- /dev/null +++ b/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(); + } + } +} diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index 13acad45ca..3c1efc29a2 100644 --- a/TestApplication/Program.cs +++ b/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 { diff --git a/TestApplication/TestApplication.csproj b/TestApplication/TestApplication.csproj index 84342f5b53..7c587efdab 100644 --- a/TestApplication/TestApplication.csproj +++ b/TestApplication/TestApplication.csproj @@ -73,6 +73,7 @@ + @@ -81,6 +82,10 @@ + + {3e908f67-5543-4879-a1dc-08eace79b3cd} + Perspex.Direct2D1 + {811a76cf-1cf6-440f-963b-bbe31bd72a82} Perspex.Windows diff --git a/packages/repositories.config b/packages/repositories.config index c3ec62a63c..4385439ce2 100644 --- a/packages/repositories.config +++ b/packages/repositories.config @@ -1,5 +1,6 @@  +