diff --git a/samples/SharpDx2D/App.config b/samples/SharpDx2D/App.config new file mode 100644 index 0000000..d1428ad --- /dev/null +++ b/samples/SharpDx2D/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/samples/SharpDx2D/App.xaml b/samples/SharpDx2D/App.xaml new file mode 100644 index 0000000..b026861 --- /dev/null +++ b/samples/SharpDx2D/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/samples/SharpDx2D/App.xaml.cs b/samples/SharpDx2D/App.xaml.cs new file mode 100644 index 0000000..5cc7568 --- /dev/null +++ b/samples/SharpDx2D/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace SharpDx2D +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/samples/SharpDx2D/MainWindow.xaml b/samples/SharpDx2D/MainWindow.xaml new file mode 100644 index 0000000..b43a36c --- /dev/null +++ b/samples/SharpDx2D/MainWindow.xaml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/samples/SharpDx2D/MainWindow.xaml.cs b/samples/SharpDx2D/MainWindow.xaml.cs new file mode 100644 index 0000000..6321edf --- /dev/null +++ b/samples/SharpDx2D/MainWindow.xaml.cs @@ -0,0 +1,106 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using SharpDX.Direct2D1; + +namespace SharpDx2D +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + private TimeSpan lastRenderTime; + private RenderTarget renderTarget = null; + private SharpDX.DirectWrite.TextLayout textLayout; + private SharpDX.Direct2D1.Brush brush; + + public MainWindow() + { + InitializeComponent(); + Loaded += MainWindow_Loaded; + SizeChanged += MainWindow_SizeChanged; + } + + private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e) + { + Grid g = (Grid)Content; + if (g.ActualWidth > 0 && g.ActualHeight > 0) + { + InteropImage.SetPixelSize((int)g.ActualWidth, (int)g.ActualHeight); + } + else + { + Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action)MainWindow_SizeChanged, null, null); + } + } + + private void MainWindow_Loaded(object sender, RoutedEventArgs e) + { + SharpDX.DirectWrite.Factory factory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated); + SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(factory, "Arial", 30); + textLayout = new SharpDX.DirectWrite.TextLayout(factory, "Test", textFormat, 0, 0); + MainWindow_SizeChanged(null, null); + InteropImage.WindowOwner = (new System.Windows.Interop.WindowInteropHelper(this)).Handle; + InteropImage.OnRender = OnRender; + CompositionTarget.Rendering += CompositionTarget_Rendering; + } + + private void OnRender(IntPtr handle, bool isNewSurface) + { + if (isNewSurface) + { + if (brush != null) + { + brush.Dispose(); + brush = null; + } + + if (renderTarget != null) + { + renderTarget.Dispose(); + renderTarget = null; + } + + SharpDX.ComObject comObject = new SharpDX.ComObject(handle); + SharpDX.DXGI.Resource resource = comObject.QueryInterface(); + SharpDX.Direct3D10.Texture2D texture = resource.QueryInterface(); + using (var surface = texture.QueryInterface()) + { + var properties = new RenderTargetProperties(); + properties.DpiX = 96; + properties.DpiY = 96; + properties.MinLevel = FeatureLevel.Level_DEFAULT; + properties.PixelFormat = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.Unknown, AlphaMode.Premultiplied); + properties.Type = RenderTargetType.Default; + properties.Usage = RenderTargetUsage.None; + + renderTarget = new RenderTarget(new Factory(), surface, properties); + } + } + + if (brush == null) + { + brush = new SharpDX.Direct2D1.SolidColorBrush(renderTarget, new SharpDX.Color4(0.2f, 0.2f, 0.2f, 0.5f)); + } + + renderTarget.BeginDraw(); + renderTarget.DrawTextLayout(new SharpDX.Vector2(50, 50), textLayout, brush); + renderTarget.EndDraw(); + } + + private void CompositionTarget_Rendering(object sender, EventArgs e) + { + RenderingEventArgs args = (RenderingEventArgs)e; + + // It's possible for Rendering to call back twice in the same frame + // so only render when we haven't already rendered in this frame. + if (lastRenderTime != args.RenderingTime) + { + InteropImage.RequestRender(); + lastRenderTime = args.RenderingTime; + } + } + } +} diff --git a/samples/SharpDx2D/Properties/AssemblyInfo.cs b/samples/SharpDx2D/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7a63c43 --- /dev/null +++ b/samples/SharpDx2D/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 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("SharpDx2D")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SharpDx2D")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[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)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// 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/samples/SharpDx2D/Properties/Resources.Designer.cs b/samples/SharpDx2D/Properties/Resources.Designer.cs new file mode 100644 index 0000000..7c5525c --- /dev/null +++ b/samples/SharpDx2D/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SharpDx2D.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharpDx2D.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/samples/SharpDx2D/Properties/Resources.resx b/samples/SharpDx2D/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/samples/SharpDx2D/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/samples/SharpDx2D/Properties/Settings.Designer.cs b/samples/SharpDx2D/Properties/Settings.Designer.cs new file mode 100644 index 0000000..450d0fd --- /dev/null +++ b/samples/SharpDx2D/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SharpDx2D.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/samples/SharpDx2D/Properties/Settings.settings b/samples/SharpDx2D/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/samples/SharpDx2D/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/samples/SharpDx2D/README.md b/samples/SharpDx2D/README.md new file mode 100644 index 0000000..4f9c41f --- /dev/null +++ b/samples/SharpDx2D/README.md @@ -0,0 +1,10 @@ +A Direct2D SharpDX Sample + +Requires following NuGet packages + +* Microsoft.Wpf.Interop.DirectX-x86 +* SharpDX +* SharpDX.D3DCompiler +* SharpDX.Direct2D1 +* SharpDX.Direct3D10 +* SharpDX.DXGI \ No newline at end of file diff --git a/samples/SharpDx2D/SharpDx2D.csproj b/samples/SharpDx2D/SharpDx2D.csproj new file mode 100644 index 0000000..1d2c3c3 --- /dev/null +++ b/samples/SharpDx2D/SharpDx2D.csproj @@ -0,0 +1,143 @@ + + + + + Debug + AnyCPU + {64669039-1540-4220-964C-CE9B68EDDCD3} + WinExe + Properties + SharpDx2D + SharpDx2D + v4.5 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + packages\Microsoft.Wpf.Interop.DirectX-x86.0.9.0-beta-22856\lib\net45\Microsoft.Wpf.Interop.DirectX.dll + True + + + False + $(SharpDXPackageBinDir)\SharpDX.dll + + + False + $(SharpDXPackageBinDir)\SharpDX.D3DCompiler.dll + + + $(SharpDXPackageBinDir)\SharpDX.Direct2D1.dll + + + False + $(SharpDXPackageBinDir)\SharpDX.Direct3D10.dll + + + False + $(SharpDXPackageBinDir)\SharpDX.DXGI.dll + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/samples/SharpDx2D/SharpDx2D.sln b/samples/SharpDx2D/SharpDx2D.sln new file mode 100644 index 0000000..9fe7d5e --- /dev/null +++ b/samples/SharpDx2D/SharpDx2D.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpDx2D", "SharpDx2D.csproj", "{64669039-1540-4220-964C-CE9B68EDDCD3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {64669039-1540-4220-964C-CE9B68EDDCD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64669039-1540-4220-964C-CE9B68EDDCD3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64669039-1540-4220-964C-CE9B68EDDCD3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64669039-1540-4220-964C-CE9B68EDDCD3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/SharpDx2D/packages.config b/samples/SharpDx2D/packages.config new file mode 100644 index 0000000..2475409 --- /dev/null +++ b/samples/SharpDx2D/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file