diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 0db3f66..968a9b3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -110,7 +110,7 @@ Finally, push your commits: `git push` ## Merging -When the PR is submitted, Appveyor will build the code and report if the build was successful. +When the PR is submitted, GitHub will build the code and report if the build was successful. A team member will then review the PR, and merge the branch if everything looks OK. If there are some issues with the PR, you must diff --git a/CHANGELOG.md b/CHANGELOG.md index 4474349..a7be706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,21 @@ All notable changes to this project will be documented in this file. ### Added ### Changed +Updated SharpDX nuget packages to version 4.2.0 +Updated OxyPlot nuget packages from MyGet to version 2.0.0 stable +Migrated OxyPlot.SharpDX to .NET Standard 1.1 +Update project files to VS2019 format +OxyPlot.SharpDX.WPF: Dual-target .NET Framework 4.5.2 and .NET Core 3.1 +SimpleDemo: Target .NET Core 3.1 ### Removed ### Fixed - Clipping - Text rotation (#1075) +- Polygon geometry fill rendering (#6) +- Image Annotations (#7) +- MeasureText fixed in cases where string is null or empty +- Fixed render extent not being set in ArrangeOverride step on WPF (#12) +- Fixed zero dimensions crashing plot (#14) +- Zooming via MouseWheel not working (#24) \ No newline at end of file diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..9b367db --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,26 @@ +# This is the official list of people who have contributed +# to the OxyPlot repository. +# The AUTHORS file lists the copyright holders; this file +# lists people. + +# People submitting code should be listed in this file (by email address). + +# Names should be added to this file like so: +# Name + +# Please keep the list sorted. + +Benoît Blanchon +Brannon King +bszypelow +Dan Aizenstros +David Wong +Don Syme +lsowen +jeremyiverson +Jonathan Arweck +Just Slon +Oystein Bjorke +Thomas Ibel +twsl <45483159+twsI@users.noreply.github.com> +Soarc \ No newline at end of file diff --git a/README.md b/README.md index 8a935cb..dc5b79e 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,6 @@ OxyPlot is a cross-platform plotting library for .NET. This repository contains the SharpDX/WPF implementation. -- [Web page](http://oxyplot.org) -- [Documentation](http://docs.oxyplot.org/) -- [Announcements](http://oxyplot.org/announcements) / [atom](http://oxyplot.org/atom.xml) -- [Discussion forum](http://discussion.oxyplot.org) -- [Source repository](http://github.com/oxyplot/oxyplot) -- [Issue tracker](http://github.com/oxyplot/oxyplot/issues) -- [NuGet packages](http://www.nuget.org/packages?q=oxyplot) -- [Stack Overflow](http://stackoverflow.com/questions/tagged/oxyplot) -- [Twitter](https://twitter.com/hashtag/oxyplot) -- [Gitter](https://gitter.im/oxyplot/oxyplot) (chat) - -![License](https://img.shields.io/badge/license-MIT-red.svg) -[![Build status](https://ci.appveyor.com/api/projects/status/txt1u9ceqtbsoxhs?svg=true)](https://ci.appveyor.com/project/objorke/oxyplot-sharpdx) - -![Plot](http://oxyplot.org/public/images/normal-distributions.png) - #### Getting started 1. Use the NuGet package manager to add a reference to `OxyPlot.SharpDX.WPF` (see details below if you want to use pre-release packages) @@ -31,7 +15,7 @@ You can find examples in the `/Source/Examples` folder in the code repository. #### NuGet packages -The latest pre-release packages are pushed by AppVeyor CI to [myget.org](https://www.myget.org/) +The latest pre-release packages are pushed to [myget.org](https://www.myget.org/) To install these packages, set the myget.org package source `https://www.myget.org/F/oxyplot` and remember the "-pre" flag. The stable release packages are pushed to [nuget.org](https://www.nuget.org/packages?q=oxyplot). diff --git a/Source/AssemblyInfo.cs b/Source/AssemblyInfo.cs index be76e5d..590794a 100644 --- a/Source/AssemblyInfo.cs +++ b/Source/AssemblyInfo.cs @@ -13,7 +13,6 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// The version numbers are updated by the build script. See ~/appveyor.yml [assembly: AssemblyVersion("0.0.1")] [assembly: AssemblyInformationalVersion("0.0.1-alpha")] [assembly: AssemblyFileVersion("0.0.1")] \ No newline at end of file diff --git a/Source/Examples/SharpDX.Wpf/SimpleDemo/MainViewModel.cs b/Source/Examples/SharpDX.Wpf/SimpleDemo/MainViewModel.cs index 1195cb4..bd35a83 100644 --- a/Source/Examples/SharpDX.Wpf/SimpleDemo/MainViewModel.cs +++ b/Source/Examples/SharpDX.Wpf/SimpleDemo/MainViewModel.cs @@ -22,6 +22,6 @@ public MainViewModel() this.Model = model; } - public PlotModel Model { get; private set; } + public PlotModel Model { get; } } } diff --git a/Source/Examples/SharpDX.Wpf/SimpleDemo/Properties/AssemblyInfo.cs b/Source/Examples/SharpDX.Wpf/SimpleDemo/Properties/AssemblyInfo.cs deleted file mode 100644 index 8af1a6a..0000000 --- a/Source/Examples/SharpDX.Wpf/SimpleDemo/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Reflection; -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("SimpleDemo")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SimpleDemo")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[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/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj b/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj index fee4912..d37baa7 100644 --- a/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj +++ b/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj @@ -1,126 +1,14 @@ - - - + + - Debug - AnyCPU - {48C8FBE0-C817-43BE-AC11-895A69100A86} WinExe - Properties - SimpleDemo - SimpleDemo - v4.6.1 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - true - + netcoreapp3.1 + true - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\..\packages\OxyPlot.Core.1.0.0\lib\net45\OxyPlot.dll - - - ..\..\..\packages\SharpDX.3.0.2\lib\net45\SharpDX.dll - True - - - ..\..\..\packages\SharpDX.DXGI.3.0.2\lib\net45\SharpDX.DXGI.dll - True - - - - - - - - - - - 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 - - - - - - + - - {92129d21-61e9-4952-ab75-6e5b27c8d3f7} - OxyPlot.SharpDX.Wpf - + + - - + \ No newline at end of file diff --git a/Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config b/Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config deleted file mode 100644 index d452220..0000000 --- a/Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX.Wpf/Converters/OxyColorConverter.cs b/Source/OxyPlot.SharpDX.Wpf/Converters/OxyColorConverter.cs index 61185c5..cc931e2 100644 --- a/Source/OxyPlot.SharpDX.Wpf/Converters/OxyColorConverter.cs +++ b/Source/OxyPlot.SharpDX.Wpf/Converters/OxyColorConverter.cs @@ -63,14 +63,12 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu return null; } - if (value is Color) + if (value is Color color1) { - var color = (Color)value; - return OxyColor.FromArgb(color.A, color.R, color.G, color.B); + return OxyColor.FromArgb(color1.A, color1.R, color1.G, color1.B); } - var scb = value as SolidColorBrush; - if (scb != null) + if (value is SolidColorBrush scb) { var color = scb.Color; return OxyColor.FromArgb(color.A, color.R, color.G, color.B); diff --git a/Source/OxyPlot.SharpDX.Wpf/Converters/ThicknessConverter.cs b/Source/OxyPlot.SharpDX.Wpf/Converters/ThicknessConverter.cs index 34482a6..d3b699a 100644 --- a/Source/OxyPlot.SharpDX.Wpf/Converters/ThicknessConverter.cs +++ b/Source/OxyPlot.SharpDX.Wpf/Converters/ThicknessConverter.cs @@ -31,13 +31,9 @@ public class ThicknessConverter : IValueConverter /// The maximum value of the thickness. public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is Thickness) + if (value is Thickness t && targetType == typeof(double)) { - var t = (Thickness)value; - if (targetType == typeof(double)) - { - return Math.Max(Math.Max(t.Left, t.Right), Math.Max(t.Top, t.Bottom)); - } + return Math.Max(Math.Max(t.Left, t.Right), Math.Max(t.Top, t.Bottom)); } return null; diff --git a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj index 458e674..61a34e5 100644 --- a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj +++ b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj @@ -1,120 +1,32 @@ - - - + + - Debug - AnyCPU - {92129D21-61E9-4952-AB75-6E5B27C8D3F7} Library - Properties - OxyPlot.SharpDX.Wpf - OxyPlot.SharpDX.Wpf - v4.5.2 - 512 - + netcoreapp3.1;net452 + true + OxyPlot.SharpDX.Wpf + OxyPlot controls for WPF with SharpDX based renderer + + + 2.0.0 + Oystein Bjorke + OxyPlot + https://oxyplot.github.io/ + https://github.com/oxyplot/oxyplot-sharpdx + true + 8 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - AnyCPU - true - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - bin\Release\OxyPlot.SharpDX.Wpf.XML - true - - - true - - - OxyPlot.SharpDX.Wpf.snk - - - - ..\packages\OxyPlot.Core.1.0.0\lib\net45\OxyPlot.dll - - - - - ..\packages\SharpDX.3.0.2\lib\net45\SharpDX.dll - True - - - ..\packages\SharpDX.Direct2D1.3.0.2\lib\net45\SharpDX.Direct2D1.dll - True - - - ..\packages\SharpDX.Direct3D11.3.0.2\lib\net45\SharpDX.Direct3D11.dll - True - - - ..\packages\SharpDX.Direct3D9.3.0.2\lib\net45\SharpDX.Direct3D9.dll - True - - - ..\packages\SharpDX.DXGI.3.0.2\lib\net45\SharpDX.DXGI.dll - True - - - ..\packages\SharpDX.Mathematics.3.0.2\lib\net45\SharpDX.Mathematics.dll - True - - - - - - - - - - - - - - - - - Properties\AssemblyInfo.cs - - - - - - - - - - - Designer - - + - + + + + + + - - MSBuild:Compile - Designer - + - - - + \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj.DotSettings b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj.DotSettings deleted file mode 100644 index 75ca351..0000000 --- a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj.DotSettings +++ /dev/null @@ -1,6 +0,0 @@ - - True - True - True - True - True \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.nuspec b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.nuspec deleted file mode 100644 index 9476ade..0000000 --- a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.nuspec +++ /dev/null @@ -1,31 +0,0 @@ - - - - OxyPlot.SharpDX.Wpf - OxyPlot for WPF with SharpDX based renderer - $version$ - Oystein Bjorke - OxyPlot is a plotting library for .NET. This package targets WPF applications. - - https://raw.githubusercontent.com/oxyplot/oxyplot/master/LICENSE - http://oxyplot.org/ - https://raw.githubusercontent.com/oxyplot/oxyplot/develop/Icons/OxyPlot_128.png - false - wpf plotting plot charting chart sharpdx - - - - - - - - - - - - - - - - - diff --git a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.snk b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.snk deleted file mode 100644 index 0133abf..0000000 Binary files a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.snk and /dev/null differ diff --git a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs index 6f9c780..2347d34 100644 --- a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs +++ b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs @@ -12,7 +12,7 @@ namespace OxyPlot.SharpDX.Wpf using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; - using OxyPlot.SharpDX; + using SharpDX; using global::SharpDX; using global::SharpDX.Direct3D; using global::SharpDX.Direct3D11; @@ -26,7 +26,6 @@ namespace OxyPlot.SharpDX.Wpf using D3D9PresentParameters = global::SharpDX.Direct3D9.PresentParameters; using D3D9SwapEffect = global::SharpDX.Direct3D9.SwapEffect; using Direct3D = global::SharpDX.Direct3D9.Direct3DEx; - using DXGIResource = global::SharpDX.DXGI.Resource; using PixelFormat = global::SharpDX.Direct2D1.PixelFormat; using RenderTarget = global::SharpDX.Direct2D1.RenderTarget; using RenderTargetProperties = global::SharpDX.Direct2D1.RenderTargetProperties; @@ -119,6 +118,11 @@ public class PlotImage : FrameworkElement, System.Windows.Controls.Primitives.IS /// private BitmapImage designModeImage; + /// + /// The back buffer. + /// + private Texture2D backBuffer; + /// /// Initializes a new instance of the class. /// @@ -143,8 +147,8 @@ public PlotImage() /// public IPlotModel PlotModel { - get { return (IPlotModel)this.GetValue(PlotModelProperty); } - set { this.SetValue(PlotModelProperty, value); } + get => (IPlotModel)this.GetValue(PlotModelProperty); + set => this.SetValue(PlotModelProperty, value); } /// @@ -152,8 +156,8 @@ public IPlotModel PlotModel /// public double PlotHeight { - get { return (double)this.GetValue(PlotHeightProperty); } - set { this.SetValue(PlotHeightProperty, value); } + get => (double)this.GetValue(PlotHeightProperty); + set => this.SetValue(PlotHeightProperty, value); } /// @@ -161,25 +165,19 @@ public double PlotHeight /// public double PlotWidth { - get { return (double)this.GetValue(PlotWidthProperty); } - set { this.SetValue(PlotWidthProperty, value); } + get => (double)this.GetValue(PlotWidthProperty); + set => this.SetValue(PlotWidthProperty, value); } /// /// Gets or sets a value indicating whether scrolling on the vertical axis is possible. /// - public bool CanVerticallyScroll - { - get; set; - } + public bool CanVerticallyScroll { get; set; } /// /// Gets or sets a value indicating whether scrolling on the vertical axis is possible. /// - public bool CanHorizontallyScroll - { - get; set; - } + public bool CanHorizontallyScroll { get; set; } /// /// Gets the horizontal size of the extent. @@ -276,7 +274,7 @@ public void Render(bool invalidateSurface, bool invalidateUnits) } this.renderTarget.BeginDraw(); - this.renderTarget.Clear(backColor.ToDXColor()); + this.renderTarget.Clear(backColor.ToDxColor()); this.oxyRenderContext.Render(new RectangleF((float)this.offset.X, (float)this.offset.Y, (float)this.viewport.Width, (float)this.viewport.Height)); // TODO: add clip rectangle this.renderTarget.EndDraw(); @@ -392,20 +390,20 @@ public void MouseWheelRight() /// /// Sets the amount of horizontal offset. /// - /// The degree to which content is horizontally offset from the containing viewport. - public void SetHorizontalOffset(double offset) + /// The degree to which content is horizontally offset from the containing viewport. + public void SetHorizontalOffset(double hoffset) { - this.offset.X = offset; + this.offset.X = hoffset; this.InvalidateVisual(); } /// /// Sets the amount of vertical offset. /// - /// The degree to which content is vertically offset from the containing viewport. - public void SetVerticalOffset(double offset) + /// The degree to which content is vertically offset from the containing viewport. + public void SetVerticalOffset(double voffset) { - this.offset.Y = offset; + this.offset.Y = voffset; this.InvalidateVisual(); } @@ -520,10 +518,7 @@ protected override Size MeasureOverride(Size availableSize) var desired = new Size(desiredWidth, desiredHeight); this.Overlay.Measure(desired); - if (this.ScrollOwner != null) - { - this.ScrollOwner.InvalidateScrollInfo(); - } + this.ScrollOwner?.InvalidateScrollInfo(); return desired; } @@ -563,9 +558,15 @@ protected override Size ArrangeOverride(Size finalSize) this.Overlay.Arrange(new Rect(overlaySize)); - bool sizeChanged = this.viewport != finalSize; + var width = (int)(finalSize.Width < 1 ? 1 : finalSize.Width); + var height = (int)(finalSize.Height < 1 ? 1 : finalSize.Height); + + var renderSize = new Size(width, height); + + var sizeChanged = this.viewport != renderSize; - this.viewport = finalSize; + this.viewport = renderSize; + this.extent = renderSize; if (this.ScrollOwner != null) { @@ -582,18 +583,17 @@ protected override Size ArrangeOverride(Size finalSize) /// private void InitRendering() { - double dpiScale = 1.0; // default value for 96 dpi + var dpiScale = 1.0; // default value for 96 dpi - var hwndTarget = PresentationSource.FromVisual(this).CompositionTarget as HwndTarget; - if (hwndTarget != null) + if (PresentationSource.FromVisual(this)?.CompositionTarget is HwndTarget hwndTarget) { dpiScale = hwndTarget.TransformToDevice.M11; } - int surfWidth = (int)(this.viewport.Width < 0 ? 0 : Math.Ceiling(this.viewport.Width * dpiScale)); - int surfHeight = (int)(this.viewport.Height < 0 ? 0 : Math.Ceiling(this.viewport.Height * dpiScale)); + var surfWidth = (int)(this.viewport.Width <= 0 ? 1 : Math.Ceiling(this.viewport.Width * dpiScale)); + var surfHeight = (int)(this.viewport.Height <= 0 ? 1 : Math.Ceiling(this.viewport.Height * dpiScale)); - var windowHandle = (new WindowInteropHelper(Window.GetWindow(this))).Handle; + var windowHandle = new WindowInteropHelper(Window.GetWindow(this)).Handle; this.d3d11Device = new D3D11Device( DriverType.Hardware, @@ -605,7 +605,7 @@ private void InitRendering() FeatureLevel.Level_9_2, FeatureLevel.Level_9_1); - var backBuffer = new Texture2D( + this.backBuffer = new Texture2D( this.d3d11Device, new Texture2DDescription { @@ -621,7 +621,7 @@ private void InitRendering() CpuAccessFlags = 0 }); - var surface = backBuffer.QueryInterface(); + var surface = this.backBuffer.QueryInterface(); this.renderTarget = new RenderTarget( this.oxyRenderContext.D2DFactory, surface, @@ -641,7 +641,7 @@ private void InitRendering() Windowed = true }); - this.imageSource = new D3D11Image(this.d3d9Device, backBuffer); + this.imageSource = new D3D11Image(this.d3d9Device, this.backBuffer); this.oxyRenderContext.ResetRenderTarget(this.renderTarget); } @@ -660,7 +660,9 @@ private void CleanResources() this.d3d9Device?.Dispose(); this.renderTarget?.Dispose(); this.d3d11Device?.Dispose(); + this.backBuffer?.Dispose(); + this.backBuffer = null; this.imageSource = null; this.d3d9Device = null; this.renderTarget = null; diff --git a/Source/OxyPlot.SharpDX.Wpf/PlotView.cs b/Source/OxyPlot.SharpDX.Wpf/PlotView.cs index ccdc78e..b150959 100644 --- a/Source/OxyPlot.SharpDX.Wpf/PlotView.cs +++ b/Source/OxyPlot.SharpDX.Wpf/PlotView.cs @@ -24,51 +24,51 @@ public class PlotView : Control, IPlotView /// Identifies the dependency property. /// public static readonly DependencyProperty ControllerProperty = - DependencyProperty.Register("Controller", typeof(IPlotController), typeof(PlotView), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(Controller), typeof(IPlotController), typeof(PlotView), new PropertyMetadata(null)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty DefaultTrackerTemplateProperty = DependencyProperty.Register( - "DefaultTrackerTemplate", typeof(ControlTemplate), typeof(PlotView), new PropertyMetadata(null)); + nameof(DefaultTrackerTemplate), typeof(ControlTemplate), typeof(PlotView), new PropertyMetadata(null)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty HandleRightClicksProperty = - DependencyProperty.Register("HandleRightClicks", typeof(bool), typeof(PlotView), new PropertyMetadata(true)); + DependencyProperty.Register(nameof(HandleRightClicks), typeof(bool), typeof(PlotView), new PropertyMetadata(true)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty IsMouseWheelEnabledProperty = - DependencyProperty.Register("IsMouseWheelEnabled", typeof(bool), typeof(PlotView), new PropertyMetadata(true)); + DependencyProperty.Register(nameof(IsMouseWheelEnabled), typeof(bool), typeof(PlotView), new PropertyMetadata(true)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty ModelProperty = DependencyProperty.Register( - "Model", typeof(PlotModel), typeof(PlotView), new PropertyMetadata(null, ModelChanged)); + nameof(Model), typeof(PlotModel), typeof(PlotView), new PropertyMetadata(null, ModelChanged)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty ZoomRectangleTemplateProperty = DependencyProperty.Register( - "ZoomRectangleTemplate", typeof(ControlTemplate), typeof(PlotView), new PropertyMetadata(null)); + nameof(ZoomRectangleTemplate), typeof(ControlTemplate), typeof(PlotView), new PropertyMetadata(null)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty PlotHeightProperty = - DependencyProperty.Register("PlotHeight", typeof(double), typeof(PlotView), new PropertyMetadata(double.NaN)); + DependencyProperty.Register(nameof(PlotHeight), typeof(double), typeof(PlotView), new PropertyMetadata(double.NaN)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty PlotWidthProperty = - DependencyProperty.Register("PlotWidth", typeof(double), typeof(PlotView), new PropertyMetadata(double.NaN)); + DependencyProperty.Register(nameof(PlotWidth), typeof(double), typeof(PlotView), new PropertyMetadata(double.NaN)); /// /// The Grid PART constant. @@ -80,21 +80,11 @@ public class PlotView : Control, IPlotView /// private readonly object modelLock = new object(); - /// - /// The tracker definitions. - /// - private readonly ObservableCollection trackerDefinitions; - /// /// The mouse down point. /// private ScreenPoint mouseDownPoint; - /// - /// The current model. - /// - private PlotModel currentModel; - /// /// The current tracker. /// @@ -127,9 +117,6 @@ static PlotView() { DefaultStyleKeyProperty.OverrideMetadata(typeof(PlotView), new FrameworkPropertyMetadata(typeof(PlotView))); global::SharpDX.Configuration.EnableReleaseOnFinalizer = true; -#if DEBUG - // global::SharpDX.Configuration.EnableReleaseOnFinalizer EnableObjectTracking = true; -#endif } /// @@ -138,8 +125,6 @@ static PlotView() public PlotView() { this.DefaultStyleKey = typeof(PlotView); - - this.trackerDefinitions = new ObservableCollection(); } /// @@ -147,8 +132,8 @@ public PlotView() /// public double PlotHeight { - get { return (double)this.GetValue(PlotHeightProperty); } - set { this.SetValue(PlotHeightProperty, value); } + get => (double)this.GetValue(PlotHeightProperty); + set => this.SetValue(PlotHeightProperty, value); } /// @@ -156,8 +141,8 @@ public double PlotHeight /// public double PlotWidth { - get { return (double)this.GetValue(PlotWidthProperty); } - set { this.SetValue(PlotWidthProperty, value); } + get => (double)this.GetValue(PlotWidthProperty); + set => this.SetValue(PlotWidthProperty, value); } /// @@ -166,8 +151,8 @@ public double PlotWidth /// The PlotView controller. public IPlotController Controller { - get { return (IPlotController)this.GetValue(ControllerProperty); } - set { this.SetValue(ControllerProperty, value); } + get => (IPlotController)this.GetValue(ControllerProperty); + set => this.SetValue(ControllerProperty, value); } /// @@ -175,15 +160,8 @@ public IPlotController Controller /// public ControlTemplate DefaultTrackerTemplate { - get - { - return (ControlTemplate)this.GetValue(DefaultTrackerTemplateProperty); - } - - set - { - this.SetValue(DefaultTrackerTemplateProperty, value); - } + get => (ControlTemplate)this.GetValue(DefaultTrackerTemplateProperty); + set => this.SetValue(DefaultTrackerTemplateProperty, value); } /// @@ -191,15 +169,8 @@ public ControlTemplate DefaultTrackerTemplate /// public bool HandleRightClicks { - get - { - return (bool)this.GetValue(HandleRightClicksProperty); - } - - set - { - this.SetValue(HandleRightClicksProperty, value); - } + get => (bool)this.GetValue(HandleRightClicksProperty); + set => this.SetValue(HandleRightClicksProperty, value); } /// @@ -207,15 +178,8 @@ public bool HandleRightClicks /// public bool IsMouseWheelEnabled { - get - { - return (bool)this.GetValue(IsMouseWheelEnabledProperty); - } - - set - { - this.SetValue(IsMouseWheelEnabledProperty, value); - } + get => (bool)this.GetValue(IsMouseWheelEnabledProperty); + set => this.SetValue(IsMouseWheelEnabledProperty, value); } /// @@ -224,15 +188,8 @@ public bool IsMouseWheelEnabled /// The . public PlotModel Model { - get - { - return (PlotModel)this.GetValue(ModelProperty); - } - - set - { - this.SetValue(ModelProperty, value); - } + get => (PlotModel)this.GetValue(ModelProperty); + set => this.SetValue(ModelProperty, value); } /// @@ -241,28 +198,15 @@ public PlotModel Model /// The zoom rectangle template. public ControlTemplate ZoomRectangleTemplate { - get - { - return (ControlTemplate)this.GetValue(ZoomRectangleTemplateProperty); - } - - set - { - this.SetValue(ZoomRectangleTemplateProperty, value); - } + get => (ControlTemplate)this.GetValue(ZoomRectangleTemplateProperty); + set => this.SetValue(ZoomRectangleTemplateProperty, value); } /// /// Gets the tracker definitions. /// /// The tracker definitions. - public ObservableCollection TrackerDefinitions - { - get - { - return this.trackerDefinitions; - } - } + public ObservableCollection TrackerDefinitions { get; } = new ObservableCollection(); /// /// Gets the actual model in the view. @@ -270,25 +214,13 @@ public ObservableCollection TrackerDefinitions /// /// The actual model. /// - Model IView.ActualModel - { - get - { - return this.Model; - } - } + Model IView.ActualModel => this.Model; /// /// Gets the actual model. /// /// The actual model. - public PlotModel ActualModel - { - get - { - return this.currentModel; - } - } + public PlotModel ActualModel { get; private set; } /// /// Gets the actual controller. @@ -296,36 +228,18 @@ public PlotModel ActualModel /// /// The actual . /// - IController IView.ActualController - { - get - { - return this.ActualController; - } - } + IController IView.ActualController => this.ActualController; /// /// Gets the coordinates of the client area of the view. /// - public OxyRect ClientArea - { - get - { - return new OxyRect(0, 0, this.ActualWidth, this.ActualHeight); - } - } + public OxyRect ClientArea => new OxyRect(0, 0, this.ActualWidth, this.ActualHeight); /// /// Gets the actual PlotView controller. /// /// The actual PlotView controller. - public IPlotController ActualController - { - get - { - return this.Controller ?? (this.defaultController ?? (this.defaultController = new PlotController())); - } - } + public IPlotController ActualController => this.Controller ?? (this.defaultController ??= new PlotController()); /// /// Hides the tracker. @@ -459,20 +373,11 @@ public void ShowZoomRectangle(OxyRect r) this.zoomRectangle.Visibility = Visibility.Visible; } - /// - /// Renders the PlotView to a bitmap. - /// - /// A bitmap. - public WriteableBitmap ToBitmap() - { - throw new NotImplementedException(); - } - /// /// Stores text on the clipboard. /// /// The text. - void IPlotView.SetClipboardText(string text) + public void SetClipboardText(string text) { Clipboard.SetText(text); } @@ -496,7 +401,7 @@ public override void OnApplyTemplate() } /// - /// Called before the event occurs. + /// Called before the event occurs. /// /// The data for the event. protected override void OnKeyDown(KeyEventArgs e) @@ -512,7 +417,7 @@ protected override void OnKeyDown(KeyEventArgs e) } /// - /// Called when the event occurs. + /// Called when the event occurs. /// /// The data for the event. protected override void OnManipulationStarted(ManipulationStartedEventArgs e) @@ -527,7 +432,7 @@ protected override void OnManipulationStarted(ManipulationStartedEventArgs e) } /// - /// Called when the event occurs. + /// Called when the event occurs. /// /// The data for the event. protected override void OnManipulationDelta(ManipulationDeltaEventArgs e) @@ -542,7 +447,7 @@ protected override void OnManipulationDelta(ManipulationDeltaEventArgs e) } /// - /// Called when the event occurs. + /// Called when the event occurs. /// /// The data for the event. protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e) @@ -557,9 +462,9 @@ protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e } /// - /// Called before the event occurs to provide handling for the event in a derived class without attaching a delegate. + /// Called before the event occurs to provide handling for the event in a derived class without attaching a delegate. /// - /// A that contains the event data. + /// A that contains the event data. protected override void OnMouseWheel(MouseWheelEventArgs e) { base.OnMouseWheel(e); @@ -574,7 +479,7 @@ protected override void OnMouseWheel(MouseWheelEventArgs e) /// /// Invoked when an unhandled MouseDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. /// - /// The that contains the event data. This event data reports details about the mouse button that was pressed and the handled state. + /// The that contains the event data. This event data reports details about the mouse button that was pressed and the handled state. protected override void OnMouseDown(MouseButtonEventArgs e) { base.OnMouseDown(e); @@ -595,7 +500,7 @@ protected override void OnMouseDown(MouseButtonEventArgs e) /// /// Invoked when an unhandled MouseMove attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. /// - /// The that contains the event data. + /// The that contains the event data. protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); @@ -610,7 +515,7 @@ protected override void OnMouseMove(MouseEventArgs e) /// /// Invoked when an unhandled MouseUp routed event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. /// - /// The that contains the event data. The event data reports that the mouse button was released. + /// The that contains the event data. The event data reports that the mouse button was released. protected override void OnMouseUp(MouseButtonEventArgs e) { base.OnMouseUp(e); @@ -646,9 +551,9 @@ protected override void OnMouseUp(MouseButtonEventArgs e) } /// - /// Invoked when an unhandled  attached event is raised on this element. Implement this method to add class handling for this event. + /// Invoked when an unhandled MouseEnter attached event is raised on this element. Implement this method to add class handling for this event. /// - /// The that contains the event data. + /// The that contains the event data. protected override void OnMouseEnter(MouseEventArgs e) { base.OnMouseEnter(e); @@ -661,9 +566,9 @@ protected override void OnMouseEnter(MouseEventArgs e) } /// - /// Invoked when an unhandled  attached event is raised on this element. Implement this method to add class handling for this event. + /// Invoked when an unhandled MouseLeave attached event is raised on this element. Implement this method to add class handling for this event. /// - /// The that contains the event data. + /// The that contains the event data. protected override void OnMouseLeave(MouseEventArgs e) { base.OnMouseEnter(e); @@ -684,35 +589,6 @@ private static void ModelChanged(DependencyObject sender, DependencyPropertyChan { ((PlotView)sender).OnModelChanged(); } - - /// - /// Invokes the specified action on the UI Thread (without blocking the calling thread). - /// - /// The action. - private void BeginInvoke(Action action) - { - this.Dispatcher.InvokeAsync(action, System.Windows.Threading.DispatcherPriority.Background); - } - - /// - /// Called when the control is loaded. - /// - /// The sender. - /// The instance containing the event data. - private void OnLoaded(object sender, RoutedEventArgs e) - { - this.InvalidatePlot(); - } - - /// - /// Called when the size of the control is changed. - /// - /// The sender. - /// The instance containing the event data. - private void OnSizeChanged(object sender, SizeChangedEventArgs e) - { - this.InvalidatePlot(false); - } /// /// Called when the model is changed. @@ -721,16 +597,16 @@ private void OnModelChanged() { lock (this.modelLock) { - if (this.currentModel != null) + if (this.ActualModel != null) { - ((IPlotModel)this.currentModel).AttachPlotView(null); - this.currentModel = null; + ((IPlotModel)this.ActualModel).AttachPlotView(null); + this.ActualModel = null; } if (this.Model != null) { ((IPlotModel)this.Model).AttachPlotView(this); - this.currentModel = this.Model; + this.ActualModel = this.Model; } } @@ -743,10 +619,7 @@ private void OnModelChanged() /// if set to true, the data collections will be updated. private void UpdateModel(bool update) { - if (this.ActualModel != null) - { - ((IPlotModel)this.ActualModel).Update(update); - } + ((IPlotModel)this.ActualModel)?.Update(update); } } } \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX.Wpf/Properties/AssemblyDescription.cs b/Source/OxyPlot.SharpDX.Wpf/Properties/AssemblyDescription.cs index ec1d56b..5184b51 100644 --- a/Source/OxyPlot.SharpDX.Wpf/Properties/AssemblyDescription.cs +++ b/Source/OxyPlot.SharpDX.Wpf/Properties/AssemblyDescription.cs @@ -5,13 +5,10 @@ // -------------------------------------------------------------------------------------------------------------------- using System; -using System.Reflection; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Markup; -[assembly: AssemblyTitle("OxyPlot for WPF with SharpDX based renderer")] -[assembly: AssemblyDescription("OxyPlot controls for WPF with SharpDX based renderer")] [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)] [assembly: CLSCompliant(false)] diff --git a/Source/OxyPlot.SharpDX.Wpf/Themes/Generic.xaml b/Source/OxyPlot.SharpDX.Wpf/Themes/Generic.xaml index c31b8db..a194ec3 100644 --- a/Source/OxyPlot.SharpDX.Wpf/Themes/Generic.xaml +++ b/Source/OxyPlot.SharpDX.Wpf/Themes/Generic.xaml @@ -59,9 +59,7 @@ - - - + diff --git a/Source/OxyPlot.SharpDX.Wpf/Tracker/TrackerControl.cs b/Source/OxyPlot.SharpDX.Wpf/Tracker/TrackerControl.cs index 9051a67..9c57496 100644 --- a/Source/OxyPlot.SharpDX.Wpf/Tracker/TrackerControl.cs +++ b/Source/OxyPlot.SharpDX.Wpf/Tracker/TrackerControl.cs @@ -22,7 +22,7 @@ public class TrackerControl : ContentControl /// public static readonly DependencyProperty HorizontalLineVisibilityProperty = DependencyProperty.Register( - "HorizontalLineVisibility", + nameof(HorizontalLineVisibility), typeof(Visibility), typeof(TrackerControl), new PropertyMetadata(Visibility.Visible)); @@ -32,7 +32,7 @@ public class TrackerControl : ContentControl /// public static readonly DependencyProperty VerticalLineVisibilityProperty = DependencyProperty.Register( - "VerticalLineVisibility", + nameof(VerticalLineVisibility), typeof(Visibility), typeof(TrackerControl), new PropertyMetadata(Visibility.Visible)); @@ -41,63 +41,63 @@ public class TrackerControl : ContentControl /// Identifies the dependency property. /// public static readonly DependencyProperty LineStrokeProperty = DependencyProperty.Register( - "LineStroke", typeof(Brush), typeof(TrackerControl), new PropertyMetadata(null)); + nameof(LineStroke), typeof(Brush), typeof(TrackerControl), new PropertyMetadata(null)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty LineExtentsProperty = DependencyProperty.Register( - "LineExtents", typeof(OxyRect), typeof(TrackerControl), new PropertyMetadata(new OxyRect())); + nameof(LineExtents), typeof(OxyRect), typeof(TrackerControl), new PropertyMetadata(new OxyRect())); /// /// Identifies the dependency property. /// public static readonly DependencyProperty LineDashArrayProperty = DependencyProperty.Register( - "LineDashArray", typeof(DoubleCollection), typeof(TrackerControl), new PropertyMetadata(null)); + nameof(LineDashArray), typeof(DoubleCollection), typeof(TrackerControl), new PropertyMetadata(null)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty BorderEdgeModeProperty = DependencyProperty.Register( - "BorderEdgeMode", typeof(EdgeMode), typeof(TrackerControl)); + nameof(BorderEdgeMode), typeof(EdgeMode), typeof(TrackerControl)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty ShowPointerProperty = DependencyProperty.Register( - "ShowPointer", typeof(bool), typeof(TrackerControl), new PropertyMetadata(true)); + nameof(ShowPointer), typeof(bool), typeof(TrackerControl), new PropertyMetadata(true)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register( - "CornerRadius", typeof(double), typeof(TrackerControl), new PropertyMetadata(0.0)); + nameof(CornerRadius), typeof(double), typeof(TrackerControl), new PropertyMetadata(0.0)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty DistanceProperty = DependencyProperty.Register( - "Distance", typeof(double), typeof(TrackerControl), new PropertyMetadata(7.0)); + nameof(Distance), typeof(double), typeof(TrackerControl), new PropertyMetadata(7.0)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty CanCenterHorizontallyProperty = DependencyProperty.Register( - "CanCenterHorizontally", typeof(bool), typeof(TrackerControl), new PropertyMetadata(true)); + nameof(CanCenterHorizontally), typeof(bool), typeof(TrackerControl), new PropertyMetadata(true)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty CanCenterVerticallyProperty = DependencyProperty.Register( - "CanCenterVertically", typeof(bool), typeof(TrackerControl), new PropertyMetadata(true)); + nameof(CanCenterVertically), typeof(bool), typeof(TrackerControl), new PropertyMetadata(true)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty PositionProperty = DependencyProperty.Register( - "Position", + nameof(Position), typeof(ScreenPoint), typeof(TrackerControl), new PropertyMetadata(new ScreenPoint(), PositionChanged)); @@ -166,15 +166,8 @@ static TrackerControl() /// public EdgeMode BorderEdgeMode { - get - { - return (EdgeMode)this.GetValue(BorderEdgeModeProperty); - } - - set - { - this.SetValue(BorderEdgeModeProperty, value); - } + get => (EdgeMode)this.GetValue(BorderEdgeModeProperty); + set => this.SetValue(BorderEdgeModeProperty, value); } /// @@ -182,15 +175,8 @@ public EdgeMode BorderEdgeMode /// public Visibility HorizontalLineVisibility { - get - { - return (Visibility)this.GetValue(HorizontalLineVisibilityProperty); - } - - set - { - this.SetValue(HorizontalLineVisibilityProperty, value); - } + get => (Visibility)this.GetValue(HorizontalLineVisibilityProperty); + set => this.SetValue(HorizontalLineVisibilityProperty, value); } /// @@ -198,15 +184,8 @@ public Visibility HorizontalLineVisibility /// public Visibility VerticalLineVisibility { - get - { - return (Visibility)this.GetValue(VerticalLineVisibilityProperty); - } - - set - { - this.SetValue(VerticalLineVisibilityProperty, value); - } + get => (Visibility)this.GetValue(VerticalLineVisibilityProperty); + set => this.SetValue(VerticalLineVisibilityProperty, value); } /// @@ -214,15 +193,8 @@ public Visibility VerticalLineVisibility /// public Brush LineStroke { - get - { - return (Brush)this.GetValue(LineStrokeProperty); - } - - set - { - this.SetValue(LineStrokeProperty, value); - } + get => (Brush)this.GetValue(LineStrokeProperty); + set => this.SetValue(LineStrokeProperty, value); } /// @@ -230,47 +202,22 @@ public Brush LineStroke /// public OxyRect LineExtents { - get - { - return (OxyRect)this.GetValue(LineExtentsProperty); - } - - set - { - this.SetValue(LineExtentsProperty, value); - } + get => (OxyRect)this.GetValue(LineExtentsProperty); + set => this.SetValue(LineExtentsProperty, value); } /// /// Gets or sets LineDashArray. /// - public DoubleCollection LineDashArray - { - get - { - return (DoubleCollection)this.GetValue(LineDashArrayProperty); - } - - set - { - this.SetValue(LineDashArrayProperty, value); - } - } + public DoubleCollection LineDashArray => (DoubleCollection)this.GetValue(LineDashArrayProperty); /// /// Gets or sets a value indicating whether to show a 'pointer' on the border. /// public bool ShowPointer { - get - { - return (bool)this.GetValue(ShowPointerProperty); - } - - set - { - this.SetValue(ShowPointerProperty, value); - } + get => (bool)this.GetValue(ShowPointerProperty); + set => this.SetValue(ShowPointerProperty, value); } /// @@ -278,15 +225,8 @@ public bool ShowPointer /// public double CornerRadius { - get - { - return (double)this.GetValue(CornerRadiusProperty); - } - - set - { - this.SetValue(CornerRadiusProperty, value); - } + get => (double)this.GetValue(CornerRadiusProperty); + set => this.SetValue(CornerRadiusProperty, value); } /// @@ -294,15 +234,8 @@ public double CornerRadius /// public double Distance { - get - { - return (double)this.GetValue(DistanceProperty); - } - - set - { - this.SetValue(DistanceProperty, value); - } + get => (double)this.GetValue(DistanceProperty); + set => this.SetValue(DistanceProperty, value); } /// @@ -310,15 +243,8 @@ public double Distance /// public bool CanCenterHorizontally { - get - { - return (bool)this.GetValue(CanCenterHorizontallyProperty); - } - - set - { - this.SetValue(CanCenterHorizontallyProperty, value); - } + get => (bool)this.GetValue(CanCenterHorizontallyProperty); + set => this.SetValue(CanCenterHorizontallyProperty, value); } /// @@ -326,15 +252,8 @@ public bool CanCenterHorizontally /// public bool CanCenterVertically { - get - { - return (bool)this.GetValue(CanCenterVerticallyProperty); - } - - set - { - this.SetValue(CanCenterVerticallyProperty, value); - } + get => (bool)this.GetValue(CanCenterVerticallyProperty); + set => this.SetValue(CanCenterVerticallyProperty, value); } /// @@ -342,15 +261,8 @@ public bool CanCenterVertically /// public ScreenPoint Position { - get - { - return (ScreenPoint)this.GetValue(PositionProperty); - } - - set - { - this.SetValue(PositionProperty, value); - } + get => (ScreenPoint)this.GetValue(PositionProperty); + set => this.SetValue(PositionProperty, value); } /// @@ -367,17 +279,17 @@ public override void OnApplyTemplate() if (this.contentContainer == null) { - throw new InvalidOperationException(string.Format("The TrackerControl template must contain a content container with name +'{0}'", PartContentcontainer)); + throw new InvalidOperationException($"The TrackerControl template must contain a content container with name +'{PartContentcontainer}'"); } if (this.path == null) { - throw new InvalidOperationException(string.Format("The TrackerControl template must contain a Path with name +'{0}'", PartPath)); + throw new InvalidOperationException($"The TrackerControl template must contain a Path with name +'{PartPath}'"); } if (this.content == null) { - throw new InvalidOperationException(string.Format("The TrackerControl template must contain a ContentPresenter with name +'{0}'", PartContent)); + throw new InvalidOperationException($"The TrackerControl template must contain a ContentPresenter with name +'{PartContent}'"); } this.UpdatePositionAndBorder(); @@ -427,27 +339,27 @@ private void UpdatePositionAndBorder() } // throw new InvalidOperationException("The TrackerControl must have a Canvas parent."); - double canvasWidth = parent.ActualWidth; - double canvasHeight = parent.ActualHeight; + var canvasWidth = parent.ActualWidth; + var canvasHeight = parent.ActualHeight; this.content.Measure(new Size(canvasWidth, canvasHeight)); this.content.Arrange(new Rect(0, 0, this.content.DesiredSize.Width, this.content.DesiredSize.Height)); - double contentWidth = this.content.DesiredSize.Width; - double contentHeight = this.content.DesiredSize.Height; + var contentWidth = this.content.DesiredSize.Width; + var contentHeight = this.content.DesiredSize.Height; // Minimum allowed margins around the tracker - const double MarginLimit = 10; + const double marginLimit = 10; var ha = HorizontalAlignment.Center; if (this.CanCenterHorizontally) { - if (this.Position.X - (contentWidth / 2) < MarginLimit) + if (this.Position.X - (contentWidth / 2) < marginLimit) { ha = HorizontalAlignment.Left; } - if (this.Position.X + (contentWidth / 2) > canvasWidth - MarginLimit) + if (this.Position.X + (contentWidth / 2) > canvasWidth - marginLimit) { ha = HorizontalAlignment.Right; } @@ -460,7 +372,7 @@ private void UpdatePositionAndBorder() var va = VerticalAlignment.Center; if (this.CanCenterVertically) { - if (this.Position.Y - (contentHeight / 2) < MarginLimit) + if (this.Position.Y - (contentHeight / 2) < marginLimit) { va = VerticalAlignment.Top; } @@ -468,18 +380,18 @@ private void UpdatePositionAndBorder() if (ha == HorizontalAlignment.Center) { va = VerticalAlignment.Bottom; - if (this.Position.Y - contentHeight < MarginLimit) + if (this.Position.Y - contentHeight < marginLimit) { va = VerticalAlignment.Top; } } - if (va == VerticalAlignment.Center && this.Position.Y + (contentHeight / 2) > canvasHeight - MarginLimit) + if (va == VerticalAlignment.Center && this.Position.Y + (contentHeight / 2) > canvasHeight - marginLimit) { va = VerticalAlignment.Bottom; } - if (va == VerticalAlignment.Top && this.Position.Y + contentHeight > canvasHeight - MarginLimit) + if (va == VerticalAlignment.Top && this.Position.Y + contentHeight > canvasHeight - marginLimit) { va = VerticalAlignment.Bottom; } @@ -489,18 +401,17 @@ private void UpdatePositionAndBorder() va = this.Position.Y < canvasHeight / 2 ? VerticalAlignment.Top : VerticalAlignment.Bottom; } - double dx = ha == HorizontalAlignment.Center ? -0.5 : ha == HorizontalAlignment.Left ? 0 : -1; - double dy = va == VerticalAlignment.Center ? -0.5 : va == VerticalAlignment.Top ? 0 : -1; + var dx = ha == HorizontalAlignment.Center ? -0.5 : ha == HorizontalAlignment.Left ? 0 : -1; + var dy = va == VerticalAlignment.Center ? -0.5 : va == VerticalAlignment.Top ? 0 : -1; - Thickness margin; this.path.Data = this.ShowPointer - ? this.CreatePointerBorderGeometry(ha, va, contentWidth, contentHeight, out margin) + ? this.CreatePointerBorderGeometry(ha, va, contentWidth, contentHeight, out var margin) : this.CreateBorderGeometry(ha, va, contentWidth, contentHeight, out margin); this.content.Margin = margin; this.contentContainer.Measure(new Size(canvasWidth, canvasHeight)); - Size contentSize = this.contentContainer.DesiredSize; + var contentSize = this.contentContainer.DesiredSize; this.contentContainer.RenderTransform = new TranslateTransform { @@ -508,7 +419,7 @@ private void UpdatePositionAndBorder() Y = dy * contentSize.Height }; - ScreenPoint pos = this.Position; + var pos = this.Position; if (this.horizontalLine != null) { @@ -557,7 +468,7 @@ private void UpdatePositionAndBorder() private Geometry CreateBorderGeometry( HorizontalAlignment ha, VerticalAlignment va, double width, double height, out Thickness margin) { - double m = this.Distance; + var m = this.Distance; var rect = new Rect( ha == HorizontalAlignment.Left ? m : 0, va == VerticalAlignment.Top ? m : 0, width, height); margin = new Thickness @@ -567,7 +478,7 @@ private Geometry CreateBorderGeometry( Right = ha == HorizontalAlignment.Right ? m : 0, Bottom = va == VerticalAlignment.Bottom ? m : 0 }; - return new RectangleGeometry { Rect = rect /*, RadiusX = this.CornerRadius, RadiusY = this.CornerRadius*/ }; + return new RectangleGeometry { Rect = rect }; } /// @@ -583,16 +494,16 @@ private Geometry CreatePointerBorderGeometry( HorizontalAlignment ha, VerticalAlignment va, double width, double height, out Thickness margin) { Point[] points = null; - double m = this.Distance; + var m = this.Distance; margin = new Thickness(); if (ha == HorizontalAlignment.Center && va == VerticalAlignment.Bottom) { - double x0 = 0; - double x1 = width; - double x2 = (x0 + x1) / 2; - double y0 = 0; - double y1 = height; + var x0 = 0; + var x1 = width; + var x2 = (x0 + x1) / 2; + var y0 = 0; + var y1 = height; margin = new Thickness { Bottom = m }; points = new[] { @@ -603,11 +514,11 @@ private Geometry CreatePointerBorderGeometry( if (ha == HorizontalAlignment.Center && va == VerticalAlignment.Top) { - double x0 = 0; - double x1 = width; - double x2 = (x0 + x1) / 2; - double y0 = m; - double y1 = m + height; + var x0 = 0; + var x1 = width; + var x2 = (x0 + x1) / 2; + var y0 = m; + var y1 = m + height; margin = new Thickness { Top = m }; points = new[] { @@ -618,11 +529,11 @@ private Geometry CreatePointerBorderGeometry( if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Center) { - double x0 = m; - double x1 = m + width; + var x0 = m; + var x1 = m + width; double y0 = 0; - double y1 = height; - double y2 = (y0 + y1) / 2; + var y1 = height; + var y2 = (y0 + y1) / 2; margin = new Thickness { Left = m }; points = new[] { @@ -633,11 +544,11 @@ private Geometry CreatePointerBorderGeometry( if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Center) { - double x0 = 0; - double x1 = width; - double y0 = 0; - double y1 = height; - double y2 = (y0 + y1) / 2; + var x0 = 0; + var x1 = width; + var y0 = 0; + var y1 = height; + var y2 = (y0 + y1) / 2; margin = new Thickness { Right = m }; points = new[] { @@ -649,10 +560,10 @@ private Geometry CreatePointerBorderGeometry( if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Top) { m *= 0.67; - double x0 = m; - double x1 = m + width; - double y0 = m; - double y1 = m + height; + var x0 = m; + var x1 = m + width; + var y0 = m; + var y1 = m + height; margin = new Thickness { Left = m, Top = m }; points = new[] { @@ -664,10 +575,10 @@ private Geometry CreatePointerBorderGeometry( if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Top) { m *= 0.67; - double x0 = 0; - double x1 = width; - double y0 = m; - double y1 = m + height; + var x0 = 0; + var x1 = width; + var y0 = m; + var y1 = m + height; margin = new Thickness { Top = m, Right = m }; points = new[] { @@ -679,10 +590,10 @@ private Geometry CreatePointerBorderGeometry( if (ha == HorizontalAlignment.Left && va == VerticalAlignment.Bottom) { m *= 0.67; - double x0 = m; - double x1 = m + width; - double y0 = 0; - double y1 = height; + var x0 = m; + var x1 = m + width; + var y0 = 0; + var y1 = height; margin = new Thickness { Left = m, Bottom = m }; points = new[] { @@ -694,10 +605,10 @@ private Geometry CreatePointerBorderGeometry( if (ha == HorizontalAlignment.Right && va == VerticalAlignment.Bottom) { m *= 0.67; - double x0 = 0; - double x1 = width; - double y0 = 0; - double y1 = height; + var x0 = 0; + var x1 = width; + var y0 = 0; + var y1 = height; margin = new Thickness { Right = m, Bottom = m }; points = new[] { diff --git a/Source/OxyPlot.SharpDX.Wpf/Tracker/TrackerDefinition.cs b/Source/OxyPlot.SharpDX.Wpf/Tracker/TrackerDefinition.cs index 9947239..41953c3 100644 --- a/Source/OxyPlot.SharpDX.Wpf/Tracker/TrackerDefinition.cs +++ b/Source/OxyPlot.SharpDX.Wpf/Tracker/TrackerDefinition.cs @@ -21,13 +21,13 @@ public class TrackerDefinition : DependencyObject /// Identifies the dependency property. /// public static readonly DependencyProperty TrackerKeyProperty = DependencyProperty.Register( - "TrackerKey", typeof(string), typeof(TrackerDefinition), new PropertyMetadata(null)); + nameof(TrackerKey), typeof(string), typeof(TrackerDefinition), new PropertyMetadata(null)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty TrackerTemplateProperty = - DependencyProperty.Register("TrackerTemplate", typeof(ControlTemplate), typeof(TrackerDefinition), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(TrackerTemplate), typeof(ControlTemplate), typeof(TrackerDefinition), new PropertyMetadata(null)); /// /// Gets or sets the tracker key. @@ -35,15 +35,8 @@ public class TrackerDefinition : DependencyObject /// The Plot will use this property to find the TrackerDefinition that matches the TrackerKey of the current series. public string TrackerKey { - get - { - return (string)this.GetValue(TrackerKeyProperty); - } - - set - { - this.SetValue(TrackerKeyProperty, value); - } + get => (string)this.GetValue(TrackerKeyProperty); + set => this.SetValue(TrackerKeyProperty, value); } /// @@ -53,15 +46,8 @@ public string TrackerKey /// The DataContext of the tracker will be set to a TrackerHitResult with the current tracker data. public ControlTemplate TrackerTemplate { - get - { - return (ControlTemplate)this.GetValue(TrackerTemplateProperty); - } - - set - { - this.SetValue(TrackerTemplateProperty, value); - } + get => (ControlTemplate)this.GetValue(TrackerTemplateProperty); + set => this.SetValue(TrackerTemplateProperty, value); } } } diff --git a/Source/OxyPlot.SharpDX.Wpf/Utilities/ConverterExtensions.cs b/Source/OxyPlot.SharpDX.Wpf/Utilities/ConverterExtensions.cs index 46a8594..29f4256 100644 --- a/Source/OxyPlot.SharpDX.Wpf/Utilities/ConverterExtensions.cs +++ b/Source/OxyPlot.SharpDX.Wpf/Utilities/ConverterExtensions.cs @@ -9,38 +9,16 @@ namespace OxyPlot.SharpDX.Wpf { - using System; using System.Windows; using System.Windows.Input; using System.Windows.Media; - using Color4 = global::SharpDX.Color4; using DXColor = global::SharpDX.Color; - using HorizontalAlignment = OxyPlot.HorizontalAlignment; - using VerticalAlignment = OxyPlot.VerticalAlignment; /// /// Extension method used to convert to/from Windows/Windows.Media classes. /// internal static class ConverterExtensions { - /// - /// Byte to float converting coefficient. - /// - private static readonly float ByteToFloat = 1f / 255f; - - /// - /// Calculate the distance between two points. - /// - /// The first point. - /// The second point. - /// The distance. - public static double DistanceTo(this Point p1, Point p2) - { - double dx = p1.X - p2.X; - double dy = p1.Y - p2.Y; - return Math.Sqrt((dx * dx) + (dy * dy)); - } - /// /// Converts an to a . /// @@ -61,82 +39,16 @@ public static Color ToColor(this OxyColor c) return Color.FromArgb(c.A, c.R, c.G, c.B); } - /// - /// Converts an to a . - /// - /// The color. - /// A Color. - public static Color4 ToColor4(this OxyColor c) - { - return new Color4(c.R * ByteToFloat, c.G * ByteToFloat, c.B * ByteToFloat, c.A * ByteToFloat); - } - /// /// Converts an to a . /// /// The color. /// A Color. - public static DXColor ToDXColor(this OxyColor c) + public static DXColor ToDxColor(this OxyColor c) { return new DXColor(c.R, c.G, c.B, c.A); } - /// - /// Converts an OxyThickness to a Thickness. - /// - /// The thickness. - /// A instance. - public static Thickness ToThickness(this OxyThickness c) - { - return new Thickness(c.Left, c.Top, c.Right, c.Bottom); - } - - /// - /// Converts a ScreenVector to a Vector. - /// - /// The c. - /// A instance. - public static Vector ToVector(this ScreenVector c) - { - return new Vector(c.X, c.Y); - } - - /// - /// Converts a HorizontalAlignment to a HorizontalAlignment. - /// - /// The alignment. - /// A HorizontalAlignment. - public static HorizontalAlignment ToHorizontalAlignment(this System.Windows.HorizontalAlignment alignment) - { - switch (alignment) - { - case System.Windows.HorizontalAlignment.Center: - return HorizontalAlignment.Center; - case System.Windows.HorizontalAlignment.Right: - return HorizontalAlignment.Right; - default: - return HorizontalAlignment.Left; - } - } - - /// - /// Converts a HorizontalAlignment to a VerticalAlignment. - /// - /// The alignment. - /// A VerticalAlignment. - public static VerticalAlignment ToVerticalAlignment(this System.Windows.VerticalAlignment alignment) - { - switch (alignment) - { - case System.Windows.VerticalAlignment.Center: - return VerticalAlignment.Middle; - case System.Windows.VerticalAlignment.Top: - return VerticalAlignment.Top; - default: - return VerticalAlignment.Bottom; - } - } - /// /// Converts a Color to an OxyColor. /// @@ -147,27 +59,6 @@ public static OxyColor ToOxyColor(this Color color) return OxyColor.FromArgb(color.A, color.R, color.G, color.B); } - /// - /// Converts a to an . - /// - /// The brush. - /// An . - public static OxyColor ToOxyColor(this Brush brush) - { - var scb = brush as SolidColorBrush; - return scb != null ? scb.Color.ToOxyColor() : OxyColors.Undefined; - } - - /// - /// Converts a Thickness to an . - /// - /// The thickness. - /// An . - public static OxyThickness ToOxyThickness(this Thickness t) - { - return new OxyThickness(t.Left, t.Top, t.Right, t.Bottom); - } - /// /// Converts a to a . /// @@ -178,27 +69,6 @@ public static ScreenPoint ToScreenPoint(this Point pt) return new ScreenPoint(pt.X, pt.Y); } - /// - /// Converts a Point array to a ScreenPoint array. - /// - /// The points. - /// A ScreenPoint array. - public static ScreenPoint[] ToScreenPointArray(this Point[] points) - { - if (points == null) - { - return null; - } - - var pts = new ScreenPoint[points.Length]; - for (int i = 0; i < points.Length; i++) - { - pts[i] = points[i].ToScreenPoint(); - } - - return pts; - } - /// /// Converts the specified vector to a ScreenVector. /// @@ -216,167 +86,88 @@ public static ScreenVector ToScreenVector(this Vector vector) /// The converted key. public static OxyKey Convert(this Key k) { - switch (k) + return k switch { - case Key.A: - return OxyKey.A; - case Key.Add: - return OxyKey.Add; - case Key.B: - return OxyKey.B; - case Key.Back: - return OxyKey.Backspace; - case Key.C: - return OxyKey.C; - case Key.D: - return OxyKey.D; - case Key.D0: - return OxyKey.D0; - case Key.D1: - return OxyKey.D1; - case Key.D2: - return OxyKey.D2; - case Key.D3: - return OxyKey.D3; - case Key.D4: - return OxyKey.D4; - case Key.D5: - return OxyKey.D5; - case Key.D6: - return OxyKey.D6; - case Key.D7: - return OxyKey.D7; - case Key.D8: - return OxyKey.D8; - case Key.D9: - return OxyKey.D9; - case Key.Decimal: - return OxyKey.Decimal; - case Key.Delete: - return OxyKey.Delete; - case Key.Divide: - return OxyKey.Divide; - case Key.Down: - return OxyKey.Down; - case Key.E: - return OxyKey.E; - case Key.End: - return OxyKey.End; - case Key.Enter: - return OxyKey.Enter; - case Key.Escape: - return OxyKey.Escape; - case Key.F: - return OxyKey.F; - case Key.F1: - return OxyKey.F1; - case Key.F10: - return OxyKey.F10; - case Key.F11: - return OxyKey.F11; - case Key.F12: - return OxyKey.F12; - case Key.F2: - return OxyKey.F2; - case Key.F3: - return OxyKey.F3; - case Key.F4: - return OxyKey.F4; - case Key.F5: - return OxyKey.F5; - case Key.F6: - return OxyKey.F6; - case Key.F7: - return OxyKey.F7; - case Key.F8: - return OxyKey.F8; - case Key.F9: - return OxyKey.F9; - case Key.G: - return OxyKey.G; - case Key.H: - return OxyKey.H; - case Key.Home: - return OxyKey.Home; - case Key.I: - return OxyKey.I; - case Key.Insert: - return OxyKey.Insert; - case Key.J: - return OxyKey.J; - case Key.K: - return OxyKey.K; - case Key.L: - return OxyKey.L; - case Key.Left: - return OxyKey.Left; - case Key.M: - return OxyKey.M; - case Key.Multiply: - return OxyKey.Multiply; - case Key.N: - return OxyKey.N; - case Key.NumPad0: - return OxyKey.NumPad0; - case Key.NumPad1: - return OxyKey.NumPad1; - case Key.NumPad2: - return OxyKey.NumPad2; - case Key.NumPad3: - return OxyKey.NumPad3; - case Key.NumPad4: - return OxyKey.NumPad4; - case Key.NumPad5: - return OxyKey.NumPad5; - case Key.NumPad6: - return OxyKey.NumPad6; - case Key.NumPad7: - return OxyKey.NumPad7; - case Key.NumPad8: - return OxyKey.NumPad8; - case Key.NumPad9: - return OxyKey.NumPad9; - case Key.O: - return OxyKey.O; - case Key.P: - return OxyKey.P; - case Key.PageDown: - return OxyKey.PageDown; - case Key.PageUp: - return OxyKey.PageUp; - case Key.Q: - return OxyKey.Q; - case Key.R: - return OxyKey.R; - case Key.Right: - return OxyKey.Right; - case Key.S: - return OxyKey.S; - case Key.Space: - return OxyKey.Space; - case Key.Subtract: - return OxyKey.Subtract; - case Key.T: - return OxyKey.T; - case Key.Tab: - return OxyKey.Tab; - case Key.U: - return OxyKey.U; - case Key.Up: - return OxyKey.Up; - case Key.V: - return OxyKey.V; - case Key.W: - return OxyKey.W; - case Key.X: - return OxyKey.X; - case Key.Y: - return OxyKey.Y; - case Key.Z: - return OxyKey.Z; - default: - return OxyKey.Unknown; - } + Key.A => OxyKey.A, + Key.Add => OxyKey.Add, + Key.B => OxyKey.B, + Key.Back => OxyKey.Backspace, + Key.C => OxyKey.C, + Key.D => OxyKey.D, + Key.D0 => OxyKey.D0, + Key.D1 => OxyKey.D1, + Key.D2 => OxyKey.D2, + Key.D3 => OxyKey.D3, + Key.D4 => OxyKey.D4, + Key.D5 => OxyKey.D5, + Key.D6 => OxyKey.D6, + Key.D7 => OxyKey.D7, + Key.D8 => OxyKey.D8, + Key.D9 => OxyKey.D9, + Key.Decimal => OxyKey.Decimal, + Key.Delete => OxyKey.Delete, + Key.Divide => OxyKey.Divide, + Key.Down => OxyKey.Down, + Key.E => OxyKey.E, + Key.End => OxyKey.End, + Key.Enter => OxyKey.Enter, + Key.Escape => OxyKey.Escape, + Key.F => OxyKey.F, + Key.F1 => OxyKey.F1, + Key.F10 => OxyKey.F10, + Key.F11 => OxyKey.F11, + Key.F12 => OxyKey.F12, + Key.F2 => OxyKey.F2, + Key.F3 => OxyKey.F3, + Key.F4 => OxyKey.F4, + Key.F5 => OxyKey.F5, + Key.F6 => OxyKey.F6, + Key.F7 => OxyKey.F7, + Key.F8 => OxyKey.F8, + Key.F9 => OxyKey.F9, + Key.G => OxyKey.G, + Key.H => OxyKey.H, + Key.Home => OxyKey.Home, + Key.I => OxyKey.I, + Key.Insert => OxyKey.Insert, + Key.J => OxyKey.J, + Key.K => OxyKey.K, + Key.L => OxyKey.L, + Key.Left => OxyKey.Left, + Key.M => OxyKey.M, + Key.Multiply => OxyKey.Multiply, + Key.N => OxyKey.N, + Key.NumPad0 => OxyKey.NumPad0, + Key.NumPad1 => OxyKey.NumPad1, + Key.NumPad2 => OxyKey.NumPad2, + Key.NumPad3 => OxyKey.NumPad3, + Key.NumPad4 => OxyKey.NumPad4, + Key.NumPad5 => OxyKey.NumPad5, + Key.NumPad6 => OxyKey.NumPad6, + Key.NumPad7 => OxyKey.NumPad7, + Key.NumPad8 => OxyKey.NumPad8, + Key.NumPad9 => OxyKey.NumPad9, + Key.O => OxyKey.O, + Key.P => OxyKey.P, + Key.PageDown => OxyKey.PageDown, + Key.PageUp => OxyKey.PageUp, + Key.Q => OxyKey.Q, + Key.R => OxyKey.R, + Key.Right => OxyKey.Right, + Key.S => OxyKey.S, + Key.Space => OxyKey.Space, + Key.Subtract => OxyKey.Subtract, + Key.T => OxyKey.T, + Key.Tab => OxyKey.Tab, + Key.U => OxyKey.U, + Key.Up => OxyKey.Up, + Key.V => OxyKey.V, + Key.W => OxyKey.W, + Key.X => OxyKey.X, + Key.Y => OxyKey.Y, + Key.Z => OxyKey.Z, + _ => OxyKey.Unknown, + }; } /// @@ -386,21 +177,15 @@ public static OxyKey Convert(this Key k) /// The converted mouse button. public static OxyMouseButton Convert(this MouseButton button) { - switch (button) + return button switch { - case MouseButton.Left: - return OxyMouseButton.Left; - case MouseButton.Middle: - return OxyMouseButton.Middle; - case MouseButton.Right: - return OxyMouseButton.Right; - case MouseButton.XButton1: - return OxyMouseButton.XButton1; - case MouseButton.XButton2: - return OxyMouseButton.XButton2; - default: - return OxyMouseButton.None; - } + MouseButton.Left => OxyMouseButton.Left, + MouseButton.Middle => OxyMouseButton.Middle, + MouseButton.Right => OxyMouseButton.Right, + MouseButton.XButton1 => OxyMouseButton.XButton1, + MouseButton.XButton2 => OxyMouseButton.XButton2, + _ => OxyMouseButton.None, + }; } /// diff --git a/Source/OxyPlot.SharpDX.Wpf/packages.config b/Source/OxyPlot.SharpDX.Wpf/packages.config deleted file mode 100644 index 2561c49..0000000 --- a/Source/OxyPlot.SharpDX.Wpf/packages.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX.sln b/Source/OxyPlot.SharpDX.sln index 2cf4454..128fead 100644 --- a/Source/OxyPlot.SharpDX.sln +++ b/Source/OxyPlot.SharpDX.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2005 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29728.190 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Change log", "Change log", "{4334530D-EBDE-4F04-838A-DA5A8A598124}" ProjectSection(SolutionItems) = preProject @@ -16,17 +16,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentat ..\README.md = ..\README.md EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OxyPlot.SharpDX.Wpf", "OxyPlot.SharpDX.Wpf\OxyPlot.SharpDX.Wpf.csproj", "{92129D21-61E9-4952-AB75-6E5B27C8D3F7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OxyPlot.SharpDX.Wpf", "OxyPlot.SharpDX.Wpf\OxyPlot.SharpDX.Wpf.csproj", "{92129D21-61E9-4952-AB75-6E5B27C8D3F7}" EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "OxyPlot.SharpDX", "OxyPlot.SharpDX\OxyPlot.SharpDX.shproj", "{455376C6-4146-497C-BF77-61CBB67F5DF9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleDemo", "Examples\SharpDX.Wpf\SimpleDemo\SimpleDemo.csproj", "{48C8FBE0-C817-43BE-AC11-895A69100A86}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleDemo", "Examples\SharpDX.Wpf\SimpleDemo\SimpleDemo.csproj", "{48C8FBE0-C817-43BE-AC11-895A69100A86}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OxyPlot.SharpDX", "OxyPlot.SharpDX\OxyPlot.SharpDX.csproj", "{5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{52AFE7DD-A2EF-4AF5-901D-ABD477D99770}" EndProject Global - GlobalSection(SharedMSBuildProjectFiles) = preSolution - OxyPlot.SharpDX\OxyPlot.SharpDX.projitems*{455376c6-4146-497c-bf77-61cbb67f5df9}*SharedItemsImports = 13 - OxyPlot.SharpDX\OxyPlot.SharpDX.projitems*{92129d21-61e9-4952-ab75-6e5b27c8d3f7}*SharedItemsImports = 4 - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|ARM = Debug|ARM @@ -70,6 +68,22 @@ Global {48C8FBE0-C817-43BE-AC11-895A69100A86}.Release|x64.Build.0 = Release|Any CPU {48C8FBE0-C817-43BE-AC11-895A69100A86}.Release|x86.ActiveCfg = Release|Any CPU {48C8FBE0-C817-43BE-AC11-895A69100A86}.Release|x86.Build.0 = Release|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Debug|ARM.ActiveCfg = Debug|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Debug|ARM.Build.0 = Debug|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Debug|x64.ActiveCfg = Debug|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Debug|x64.Build.0 = Debug|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Debug|x86.ActiveCfg = Debug|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Debug|x86.Build.0 = Debug|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Release|Any CPU.Build.0 = Release|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Release|ARM.ActiveCfg = Release|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Release|ARM.Build.0 = Release|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Release|x64.ActiveCfg = Release|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Release|x64.Build.0 = Release|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Release|x86.ActiveCfg = Release|Any CPU + {5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Source/OxyPlot.SharpDX/CacherRenderContext.cs b/Source/OxyPlot.SharpDX/CacherRenderContext.cs index f6c79f9..eb9acef 100644 --- a/Source/OxyPlot.SharpDX/CacherRenderContext.cs +++ b/Source/OxyPlot.SharpDX/CacherRenderContext.cs @@ -17,6 +17,7 @@ namespace OxyPlot.SharpDX using global::SharpDX.Direct2D1; using global::SharpDX.DirectWrite; using global::SharpDX.WIC; + using OxyPlot; using Bitmap = global::SharpDX.Direct2D1.Bitmap; using BitmapInterpolationMode = global::SharpDX.Direct2D1.BitmapInterpolationMode; using D2DFactory = global::SharpDX.Direct2D1.Factory; @@ -27,7 +28,7 @@ namespace OxyPlot.SharpDX /// /// Represents class, that implements IRenderContext and caches render units to use them later render /// - internal class CacherRenderContext : IRenderContext, IDisposable + public class CacherRenderContext : IRenderContext, IDisposable { /// /// The brush cache. @@ -44,11 +45,6 @@ internal class CacherRenderContext : IRenderContext, IDisposable /// private readonly Dictionary imageCache = new Dictionary(); - /// - /// The Direct2D factory - /// - private D2DFactory d2dFactory; - /// /// The DirectWrite factory /// @@ -67,12 +63,7 @@ internal class CacherRenderContext : IRenderContext, IDisposable /// /// Units that will be rendered on Render call /// - private List renderUnits = new List(); - - /// - /// The current tool tip - /// - private string currentToolTip; + private readonly List renderUnits = new List(); /// /// The clip rectangle. @@ -84,24 +75,12 @@ internal class CacherRenderContext : IRenderContext, IDisposable /// public CacherRenderContext() { - this.d2dFactory = new D2DFactory(); + this.D2DFactory = new D2DFactory(); this.dwtFactory = new DWFactory(); this.wicFactory = new WICFactory(); this.RendersToScreen = true; } - /// - /// Gets a value indicating whether to paint the background. - /// - /// true if the background should be painted; otherwise, false. - public bool PaintBackground - { - get - { - return false; - } - } - /// /// Gets or sets a value indicating whether the context renders to screen. /// @@ -111,18 +90,7 @@ public bool PaintBackground /// /// Gets or sets the Direct2D factory /// - public D2DFactory D2DFactory - { - get - { - return this.d2dFactory; - } - - set - { - this.d2dFactory = value; - } - } + public D2DFactory D2DFactory { get; set; } /// /// Draws an ellipse. @@ -148,8 +116,8 @@ public void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thi /// The stroke thickness. public void DrawEllipses(IList rectangles, OxyColor fill, OxyColor stroke, double thickness) { - var ellipseGeometries = rectangles.Select(x => new EllipseGeometry(this.d2dFactory, x.ToEllipse())).ToArray(); - var group = new GeometryGroup(this.d2dFactory, FillMode.Winding, ellipseGeometries); + var ellipseGeometries = rectangles.Select(x => (Geometry)new EllipseGeometry(this.D2DFactory, x.ToEllipse())).ToArray(); + var group = new GeometryGroup(this.D2DFactory, FillMode.Winding, ellipseGeometries); this.renderUnits.Add(new GeometryRenderUnit(group, this.GetBrush(stroke), this.GetBrush(fill), (float)thickness, null)); @@ -179,7 +147,7 @@ public void DrawLine( if (points.Count <= 1) return; - var path = new PathGeometry(this.d2dFactory); + var path = new PathGeometry(this.D2DFactory); var sink = path.Open(); sink.BeginFigure(points[0].ToVector2(aliased), FigureBegin.Hollow); @@ -211,9 +179,9 @@ public void DrawLineSegments( OxyPlot.LineJoin lineJoin, bool aliased) { - var path = new PathGeometry(this.d2dFactory); + var path = new PathGeometry(this.D2DFactory); var sink = path.Open(); - for (int i = 0; i + 1 < points.Count; i += 2) + for (var i = 0; i + 1 < points.Count; i += 2) { sink.BeginFigure(points[i].ToVector2(aliased), FigureBegin.Hollow); @@ -248,9 +216,9 @@ public void DrawPolygon( OxyPlot.LineJoin lineJoin, bool aliased) { - var path = new PathGeometry(this.d2dFactory); + var path = new PathGeometry(this.D2DFactory); var sink = path.Open(); - sink.BeginFigure(points[0].ToVector2(aliased), FigureBegin.Hollow); + sink.BeginFigure(points[0].ToVector2(aliased), this.GetBrush(fill) == null ? FigureBegin.Hollow : FigureBegin.Filled); sink.AddLines(points.Skip(1).Select(pt => (dx.Mathematics.Interop.RawVector2)pt.ToVector2(aliased)).ToArray()); sink.EndFigure(FigureEnd.Closed); @@ -282,7 +250,7 @@ public void DrawPolygons( OxyPlot.LineJoin lineJoin, bool aliased) { - var path = new PathGeometry(this.d2dFactory); + var path = new PathGeometry(this.D2DFactory); var sink = path.Open(); foreach (var points in polygons) { @@ -321,8 +289,8 @@ public void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double t /// The stroke thickness. public void DrawRectangles(IList rectangles, OxyColor fill, OxyColor stroke, double thickness) { - var rectangleGeometries = rectangles.Select(x => new RectangleGeometry(this.d2dFactory, x.ToRectangleF())).ToArray(); - var group = new GeometryGroup(this.d2dFactory, FillMode.Winding, rectangleGeometries); + var rectangleGeometries = rectangles.Select(x => (Geometry)new RectangleGeometry(this.D2DFactory, x.ToRectangleF())).ToArray(); + var group = new GeometryGroup(this.D2DFactory, FillMode.Winding, rectangleGeometries); this.renderUnits.Add(new GeometryRenderUnit(group, this.GetBrush(stroke), this.GetBrush(fill), (float)thickness, null)); @@ -433,9 +401,9 @@ public OxySize MeasureText(string text, string fontFamily, double fontSize, doub fontFamily = "Arial"; } - if (text == null) + if (string.IsNullOrEmpty(text)) { - text = string.Empty; + return OxySize.Empty; } var format = new TextFormat(this.dwtFactory, fontFamily, GetFontWeight(fontWeight), FontStyle.Normal, FontStretch.Normal, (float)fontSize); @@ -455,7 +423,6 @@ public OxySize MeasureText(string text, string fontFamily, double fontSize, doub /// The text in the tooltip. public void SetToolTip(string text) { - this.currentToolTip = text; } /// @@ -509,7 +476,7 @@ public void DrawImage( public bool SetClip(OxyRect clippingRect) { this.clipRect = clippingRect.ToRectangleF(); - renderUnits.Add(new ClipRectRenderUnit(clipRect)); + this.renderUnits.Add(new ClipRectRenderUnit(this.clipRect)); return true; } @@ -518,7 +485,7 @@ public bool SetClip(OxyRect clippingRect) /// public void ResetClip() { - renderUnits.Add(new ClipRectRenderUnit(RectangleF.Empty)); + this.renderUnits.Add(new ClipRectRenderUnit(RectangleF.Empty)); } /// @@ -538,17 +505,17 @@ public void CleanUp() this.imagesInUse.Clear(); } - + /// /// On changing renderTarget (on resize for example), this method should be called. /// Clears invalid for new renderTarget resources (like brushes). /// - /// The render target. - public void ResetRenderTarget(RenderTarget renderTarget) + /// The render target. + public void ResetRenderTarget(RenderTarget newRenderTarget) { this.ResetRenderUnits(); - if (this.renderTarget == renderTarget) + if (this.renderTarget == newRenderTarget) { return; } @@ -569,7 +536,7 @@ public void ResetRenderTarget(RenderTarget renderTarget) this.imagesInUse.Clear(); - this.renderTarget = renderTarget; + this.renderTarget = newRenderTarget; } /// @@ -618,6 +585,15 @@ public void Render(RectangleF viewport) /// public void Dispose() { + this.Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!disposing) + return; + foreach (var item in this.brushCache.Values) { item.Dispose(); @@ -630,10 +606,7 @@ public void Dispose() this.imageCache.Clear(); this.brushCache.Clear(); - if (this.renderTarget != null) - { - this.renderTarget.Dispose(); - } + this.renderTarget?.Dispose(); foreach (var unit in this.renderUnits) { @@ -642,12 +615,11 @@ public void Dispose() this.renderUnits.Clear(); - // d2dFactory.Dispose(); this.dwtFactory.Dispose(); this.wicFactory.Dispose(); this.renderTarget = null; - this.d2dFactory = null; + this.D2DFactory = null; this.dwtFactory = null; this.wicFactory = null; } @@ -672,10 +644,11 @@ private StrokeStyle GetStroke(double[] dashArray, OxyPlot.LineJoin lineJoin) { if (dashArray == null) { - return new StrokeStyle(this.d2dFactory, new StrokeStyleProperties { LineJoin = lineJoin.ToDXLineJoin() }); + return new StrokeStyle(this.D2DFactory, new StrokeStyleProperties { LineJoin = lineJoin.ToDxLineJoin() }); } - return new StrokeStyle(this.d2dFactory, new StrokeStyleProperties { LineJoin = lineJoin.ToDXLineJoin(), DashStyle = DashStyle.Custom }, dashArray.Select(x => (float)x).ToArray()); + var strokeStyleProperties = new StrokeStyleProperties {LineJoin = lineJoin.ToDxLineJoin(), DashStyle = DashStyle.Custom}; + return new StrokeStyle(this.D2DFactory, strokeStyleProperties, dashArray.Select(x => (float)x).ToArray()); } /// @@ -690,10 +663,9 @@ private Brush GetBrush(OxyColor color) return null; } - Brush brush; - if (!this.brushCache.TryGetValue(color, out brush)) + if (!this.brushCache.TryGetValue(color, out var brush)) { - brush = new SolidColorBrush(this.renderTarget, color.ToDXColor()); + brush = new SolidColorBrush(this.renderTarget, color.ToDxColor()); this.brushCache.Add(color, brush); } @@ -717,16 +689,18 @@ private Bitmap GetBitmap(OxyImage image) this.imagesInUse.Add(image); } - Bitmap res; - using (var stream = new MemoryStream(image.GetData())) - { - var decoder = new BitmapDecoder(this.wicFactory, stream, DecodeOptions.CacheOnDemand); - var frame = decoder.GetFrame(0); - var converter = new FormatConverter(this.wicFactory); - converter.Initialize(frame, dx.WIC.PixelFormat.Format32bppPRGBA); + if (this.imageCache.ContainsKey(image)) + { + return this.imageCache[image]; + } - res = Bitmap.FromWicBitmap(this.renderTarget, converter); - } + using var stream = new MemoryStream(image.GetData()); + using var decoder = new BitmapDecoder(this.wicFactory, stream, DecodeOptions.CacheOnDemand); + var frame = decoder.GetFrame(0); + using var converter = new FormatConverter(this.wicFactory); + converter.Initialize(frame, dx.WIC.PixelFormat.Format32bppPRGBA); + + var res = Bitmap.FromWicBitmap(this.renderTarget, converter); this.imageCache.Add(image, res); return res; diff --git a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj b/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj new file mode 100644 index 0000000..5730f36 --- /dev/null +++ b/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj @@ -0,0 +1,17 @@ + + + + netstandard1.1 + true + 2.0.0 + 8 + + + + + + + + + + diff --git a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.projitems b/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.projitems deleted file mode 100644 index 6f18e8e..0000000 --- a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.projitems +++ /dev/null @@ -1,22 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - 455376c6-4146-497c-bf77-61cbb67f5df9 - - - OxyPlot.SharpDX - - - - - - - - - - - - - \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.shproj b/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.shproj deleted file mode 100644 index 5747af4..0000000 --- a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.shproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - 455376c6-4146-497c-bf77-61cbb67f5df9 - 14.0 - - - - - - - - diff --git a/Source/OxyPlot.SharpDX/RenderUnits/ClipRectRenderUnit.cs b/Source/OxyPlot.SharpDX/RenderUnits/ClipRectRenderUnit.cs index 56c1c94..56527a5 100644 --- a/Source/OxyPlot.SharpDX/RenderUnits/ClipRectRenderUnit.cs +++ b/Source/OxyPlot.SharpDX/RenderUnits/ClipRectRenderUnit.cs @@ -11,7 +11,7 @@ internal class ClipRectRenderUnit : IRenderUnit /// /// Clipping rect to set on a target. /// - private RectangleF clipRect; + private readonly RectangleF clipRect; /// /// Initializes a new instance of the class. @@ -28,9 +28,9 @@ public ClipRectRenderUnit(RectangleF clipRect) /// public void Render(RenderTarget renderTarget) { - if (clipRect != RectangleF.Empty) + if (this.clipRect != RectangleF.Empty) { - renderTarget.PushAxisAlignedClip(clipRect, AntialiasMode.PerPrimitive); + renderTarget.PushAxisAlignedClip(this.clipRect, AntialiasMode.PerPrimitive); } else { diff --git a/Source/OxyPlot.SharpDX/RenderUnits/GeometryRenderUnit.cs b/Source/OxyPlot.SharpDX/RenderUnits/GeometryRenderUnit.cs index b134ec6..0a2d048 100644 --- a/Source/OxyPlot.SharpDX/RenderUnits/GeometryRenderUnit.cs +++ b/Source/OxyPlot.SharpDX/RenderUnits/GeometryRenderUnit.cs @@ -95,12 +95,8 @@ public void Render(RenderTarget renderTarget) /// public void Dispose() { - if (this.strokeStyle != null) - { - this.strokeStyle.Dispose(); - } - - this.geometry.Dispose(); + this.strokeStyle?.Dispose(); + this.geometry?.Dispose(); this.fill = null; this.geometry = null; diff --git a/Source/OxyPlot.SharpDX/SharpDXOxyExtensions.cs b/Source/OxyPlot.SharpDX/SharpDXOxyExtensions.cs index 6846409..3943d40 100644 --- a/Source/OxyPlot.SharpDX/SharpDXOxyExtensions.cs +++ b/Source/OxyPlot.SharpDX/SharpDXOxyExtensions.cs @@ -16,7 +16,7 @@ namespace OxyPlot.SharpDX /// /// Represents class, that contains SharpDX and Oxy extensions. /// - internal static class SharpDXOxyExtensions + internal static class SharpDxOxyExtensions { /// /// Converts to . @@ -62,19 +62,15 @@ public static RectangleF ToRectangleF(this OxyRect rect) /// /// The to convert. /// Return - public static DXLineJoin ToDXLineJoin(this LineJoin lineJoin) + public static DXLineJoin ToDxLineJoin(this LineJoin lineJoin) { - switch (lineJoin) + return lineJoin switch { - case LineJoin.Miter: - return DXLineJoin.Miter; - case LineJoin.Round: - return DXLineJoin.Round; - case LineJoin.Bevel: - return DXLineJoin.Bevel; - default: - return DXLineJoin.MiterOrBevel; - } + LineJoin.Miter => DXLineJoin.Miter, + LineJoin.Round => DXLineJoin.Round, + LineJoin.Bevel => DXLineJoin.Bevel, + _ => DXLineJoin.MiterOrBevel, + }; } /// @@ -82,7 +78,7 @@ public static DXLineJoin ToDXLineJoin(this LineJoin lineJoin) /// /// The color to convert. /// Return - public static Color4 ToDXColor(this OxyColor color) + public static Color4 ToDxColor(this OxyColor color) { return new Color4(color.R * 1f / 255f, color.G * 1f / 255f, color.B * 1f / 255f, color.A * 1f / 255f); } diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 9cb3a98..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,33 +0,0 @@ -image: Visual Studio 2017 - -configuration: - - Release - -pull_requests: - do_not_increment_build_number: true - -install: - - cinst gitversion.portable -y - -before_build: - - appveyor DownloadFile https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - - NuGet restore Source/OxyPlot.SharpDX.sln - - gitversion /l console /output buildserver /updateAssemblyInfo - -build_script: - - msbuild Source/OxyPlot.SharpDX.sln "/property:Platform=Any CPU" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - -after_build: - - NuGet pack Source\OxyPlot.SharpDX.Wpf\OxyPlot.SharpDX.Wpf.nuspec -version "%GitVersion_NuGetVersion%" - -artifacts: - - path: '*.nupkg' - -deploy: - provider: NuGet - server: https://www.myget.org/F/oxyplot/api/v2/package - api_key: - secure: 2GnqgfpkOUH6Umfn1WWlun0b021+QeInBXkgQOQfa4/wDOYHLT757rrjTsb0lmon - skip_symbols: false - symbol_server: # remove to push symbols to SymbolSource.org - artifact: /.*\.nupkg/ diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..192181f --- /dev/null +++ b/nuget.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file