From fa30d7bc331a53fe205a8a9157433dd0df65b26d Mon Sep 17 00:00:00 2001 From: Oystein Bjorke Date: Sun, 18 Feb 2018 10:18:47 +0100 Subject: [PATCH 01/14] update OxyPlot.Core dependency to latest pre-release --- Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj | 4 ++-- Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config | 2 +- Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj | 4 ++-- Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.nuspec | 2 +- Source/OxyPlot.SharpDX.Wpf/packages.config | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj b/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj index fee4912..5398a7d 100644 --- a/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj +++ b/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj @@ -36,8 +36,8 @@ 4 - - ..\..\..\packages\OxyPlot.Core.1.0.0\lib\net45\OxyPlot.dll + + ..\..\..\packages\OxyPlot.Core.2.0.0-unstable1035\lib\net45\OxyPlot.dll ..\..\..\packages\SharpDX.3.0.2\lib\net45\SharpDX.dll diff --git a/Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config b/Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config index d452220..516c852 100644 --- a/Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config +++ b/Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj index 458e674..213a1aa 100644 --- a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj +++ b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj @@ -41,8 +41,8 @@ OxyPlot.SharpDX.Wpf.snk - - ..\packages\OxyPlot.Core.1.0.0\lib\net45\OxyPlot.dll + + ..\packages\OxyPlot.Core.2.0.0-unstable1035\lib\net45\OxyPlot.dll diff --git a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.nuspec b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.nuspec index 9476ade..0ef588c 100644 --- a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.nuspec +++ b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.nuspec @@ -13,7 +13,7 @@ false wpf plotting plot charting chart sharpdx - + diff --git a/Source/OxyPlot.SharpDX.Wpf/packages.config b/Source/OxyPlot.SharpDX.Wpf/packages.config index 2561c49..0be21f2 100644 --- a/Source/OxyPlot.SharpDX.Wpf/packages.config +++ b/Source/OxyPlot.SharpDX.Wpf/packages.config @@ -1,6 +1,6 @@  - + From 0cf85af7f1da4db2b958432f0935ad6ffb9ef44f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Feb 2018 11:31:47 +0100 Subject: [PATCH 02/14] Added ContainsKey check for imageCache, fixes Issue #7 Updated Changelog --- CHANGELOG.md | 1 + Source/OxyPlot.SharpDX/CacherRenderContext.cs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4474349..fb9fb54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,3 +11,4 @@ All notable changes to this project will be documented in this file. ### Fixed - Clipping - Text rotation (#1075) +- Image Annotations (#7) diff --git a/Source/OxyPlot.SharpDX/CacherRenderContext.cs b/Source/OxyPlot.SharpDX/CacherRenderContext.cs index f6c79f9..2490f87 100644 --- a/Source/OxyPlot.SharpDX/CacherRenderContext.cs +++ b/Source/OxyPlot.SharpDX/CacherRenderContext.cs @@ -717,7 +717,12 @@ private Bitmap GetBitmap(OxyImage image) this.imagesInUse.Add(image); } - Bitmap res; + if (this.imageCache.ContainsKey(image)) + { + return this.imageCache[image]; + } + + Bitmap res; using (var stream = new MemoryStream(image.GetData())) { var decoder = new BitmapDecoder(this.wicFactory, stream, DecodeOptions.CacheOnDemand); From 11f63c649efcecee3d748a2be146b46003e4b4ff Mon Sep 17 00:00:00 2001 From: Dunkhan Date: Tue, 27 Feb 2018 11:47:10 +0100 Subject: [PATCH 03/14] Fix issue #6 Polygon geometries now render with fill Affects PolygonAnnotations and AreaSeries --- CHANGELOG.md | 1 + Source/OxyPlot.SharpDX/CacherRenderContext.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4474349..88a86ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,3 +11,4 @@ All notable changes to this project will be documented in this file. ### Fixed - Clipping - Text rotation (#1075) +- Polygon geometry fill rendering (#6) \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX/CacherRenderContext.cs b/Source/OxyPlot.SharpDX/CacherRenderContext.cs index f6c79f9..3248b33 100644 --- a/Source/OxyPlot.SharpDX/CacherRenderContext.cs +++ b/Source/OxyPlot.SharpDX/CacherRenderContext.cs @@ -250,7 +250,7 @@ public void DrawPolygon( { 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); From 2d9c5c1cc316f55b65c1d6f5d20d8a187ac9bcc2 Mon Sep 17 00:00:00 2001 From: Dunkhan Date: Thu, 8 Mar 2018 17:06:37 +0100 Subject: [PATCH 04/14] Fixed issue #8 CacherRenderContext.MeasureText now returns OxySize.Empty if the string is null or empty --- CHANGELOG.md | 1 + Source/OxyPlot.SharpDX/CacherRenderContext.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73cdf44..e4a4925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,3 +13,4 @@ All notable changes to this project will be documented in this file. - Text rotation (#1075) - Polygon geometry fill rendering (#6) - Image Annotations (#7) +- MeasureText fixed in cases where string is null or empty diff --git a/Source/OxyPlot.SharpDX/CacherRenderContext.cs b/Source/OxyPlot.SharpDX/CacherRenderContext.cs index c10aeb3..0ed6c96 100644 --- a/Source/OxyPlot.SharpDX/CacherRenderContext.cs +++ b/Source/OxyPlot.SharpDX/CacherRenderContext.cs @@ -433,9 +433,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); From f5be82e6ad8dd7937fc900eac1f032faedb9325a Mon Sep 17 00:00:00 2001 From: Dunkhan Date: Tue, 20 Mar 2018 14:59:05 +0100 Subject: [PATCH 05/14] Fixed #12 render extent not being set in ArrangeOverride step on WPF --- CHANGELOG.md | 1 + Source/OxyPlot.SharpDX.Wpf/PlotImage.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4a4925..bcc8085 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,3 +14,4 @@ All notable changes to this project will be documented in this file. - 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) diff --git a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs index 6f9c780..3dcc9a2 100644 --- a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs +++ b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs @@ -566,6 +566,7 @@ protected override Size ArrangeOverride(Size finalSize) bool sizeChanged = this.viewport != finalSize; this.viewport = finalSize; + this.extent = finalSize; if (this.ScrollOwner != null) { From 9d6e3d188f65b4e85d56d5319342b9ffaae51923 Mon Sep 17 00:00:00 2001 From: Dunkhan Date: Mon, 26 Mar 2018 10:13:35 +0200 Subject: [PATCH 06/14] Fixed #14, prevents crash when resized to zero dimensions --- CHANGELOG.md | 1 + Source/OxyPlot.SharpDX.Wpf/PlotImage.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcc8085..2dd4854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,3 +15,4 @@ All notable changes to this project will be documented in this file. - 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) diff --git a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs index 3dcc9a2..bb0434c 100644 --- a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs +++ b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs @@ -591,8 +591,8 @@ private void InitRendering() 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)); + int surfWidth = (int)(this.viewport.Width <= 0 ? 1 : Math.Ceiling(this.viewport.Width * dpiScale)); + int surfHeight = (int)(this.viewport.Height <= 0 ? 1 : Math.Ceiling(this.viewport.Height * dpiScale)); var windowHandle = (new WindowInteropHelper(Window.GetWindow(this))).Handle; From def2fa181b2d514ed363e6fc64244a2df64bde1b Mon Sep 17 00:00:00 2001 From: Dunkhan Date: Mon, 26 Mar 2018 18:05:42 +0200 Subject: [PATCH 07/14] Fixed an additional reproduction of #14 that occurred with certain custom panels --- Source/OxyPlot.SharpDX.Wpf/PlotImage.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs index bb0434c..e2bdcf0 100644 --- a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs +++ b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs @@ -563,10 +563,15 @@ protected override Size ArrangeOverride(Size finalSize) this.Overlay.Arrange(new Rect(overlaySize)); - bool sizeChanged = this.viewport != finalSize; + int width = (int)(finalSize.Width < 1 ? 1 : finalSize.Width); + int height = (int)(finalSize.Height < 1 ? 1 : finalSize.Height); - this.viewport = finalSize; - this.extent = finalSize; + Size renderSize = new Size(width, height); + + bool sizeChanged = this.viewport != renderSize; + + this.viewport = renderSize; + this.extent = renderSize; if (this.ScrollOwner != null) { From f38c43fd7590a3ecd05f1553865ae06fd84b0295 Mon Sep 17 00:00:00 2001 From: twsl <45483159+twsI@users.noreply.github.com> Date: Tue, 11 Dec 2018 17:40:27 +0100 Subject: [PATCH 08/14] Updated package.config to PackageReference Updated package.config to PackageReference Updated SharpDX nuget packages Updated OxyPlot nuget packages from MyGet Migrated to .NET Standard library Updated changelog Added contributors file --- CHANGELOG.md | 3 + CONTRIBUTORS | 25 ++++++++ .../SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj | 23 ++++--- .../SharpDX.Wpf/SimpleDemo/packages.config | 6 -- .../OxyPlot.SharpDX.Wpf.csproj | 60 +++++++++--------- Source/OxyPlot.SharpDX.Wpf/packages.config | 10 --- Source/OxyPlot.SharpDX.sln | 24 +++++-- Source/OxyPlot.SharpDX/CacherRenderContext.cs | 1 + Source/OxyPlot.SharpDX/InternalsVisibleTo.cs | 3 + Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj | 16 +++++ .../OxyPlot.SharpDX/OxyPlot.SharpDX.projitems | 22 ------- Source/OxyPlot.SharpDX/OxyPlot.SharpDX.shproj | 13 ---- Source/OxyPlot.SharpDX/OxyPlot.SharpDX.snk | Bin 0 -> 596 bytes nuget.config | 6 ++ 14 files changed, 112 insertions(+), 100 deletions(-) create mode 100644 CONTRIBUTORS delete mode 100644 Source/Examples/SharpDX.Wpf/SimpleDemo/packages.config delete mode 100644 Source/OxyPlot.SharpDX.Wpf/packages.config create mode 100644 Source/OxyPlot.SharpDX/InternalsVisibleTo.cs create mode 100644 Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj delete mode 100644 Source/OxyPlot.SharpDX/OxyPlot.SharpDX.projitems delete mode 100644 Source/OxyPlot.SharpDX/OxyPlot.SharpDX.shproj create mode 100644 Source/OxyPlot.SharpDX/OxyPlot.SharpDX.snk create mode 100644 nuget.config diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dd4854..8db3b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. ### Added ### Changed +Updated SharpDX nuget packages +Updated OxyPlot nuget packages from MyGet +Migrated to .NET Standard library ### Removed diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..37b7cae --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,25 @@ +# 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 +Just Slon +Oystein Bjorke +Thomas Ibel +twsl <45483159+twsI@users.noreply.github.com> +Soarc \ No newline at end of file diff --git a/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj b/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj index 5398a7d..599064c 100644 --- a/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj +++ b/Source/Examples/SharpDX.Wpf/SimpleDemo/SimpleDemo.csproj @@ -36,17 +36,6 @@ 4 - - ..\..\..\packages\OxyPlot.Core.2.0.0-unstable1035\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 - @@ -99,7 +88,6 @@ ResXFileCodeGenerator Resources.Designer.cs - SettingsSingleFileGenerator Settings.Designer.cs @@ -115,6 +103,17 @@ OxyPlot.SharpDX.Wpf + + + 2.0.0-unstable1059 + + + 4.2.0 + + + 4.2.0 + + + \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj index 90e8cc6..24c09ff 100644 --- a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj +++ b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj @@ -1,118 +1,31 @@ - - - + + - 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 - - 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 - - - - - - - - - - - - - - - - - - - - Properties\AssemblyInfo.cs - - - - - - - - - - - - - - - - MSBuild:Compile - Designer - - + - - 2.0.0-unstable1059 - - - 4.2.0 - - - 4.2.0 - - - 4.2.0 - - - 4.2.0 - - - 4.2.0 - - - 4.2.0 - + + + + + + - - {5d8ec148-9b3d-4a3d-a0b9-a2e9812e647d} - OxyPlot.SharpDX - + - - + \ 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 0ef588c..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 0133abf2af8753af18d3f9e43c832d13dc1a4bdf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098g5XbkMI`GujhC+mP9|T{kS#&du;1pvj zWpR2L2#zTJU{-Hq?!9bI%G91|qwqj^#dUILg=RE+9~0on>LyF+5yKFw9?Z=-Ukijp z(x20b_Vpu+(|S$Zu)7a`(pMZXrG+?QOt;)6j_=4<1my;;58;B>X9mDW#w3(dRPeu_ z(eeY_xsj%Z0_slVt%nMud)5vF9;Ywad4LH#PMa@JpL%95mU>=)5K!DX3AV{%gaz}) z(m%x2eSumo@<-84e5<=m{1X|Zm$?YvG|TD(q(fx-ZR(FBt&6j{RPw1L z%;_zoW3qllNmj(|_H1a3fUWwWP08x_v_?qZ3{6n^Pe~fxZZ6>U=f%PA&Is6jDkNYA zku%5u%o(}k%=!;rhMtr-CGv$w*a*9HoS_?IB<_(bd0_=fC)LKNy?EtQ1#?*ZC1``E z#=xm3;WNm1k0)YF /// 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. diff --git a/Source/OxyPlot.SharpDX/InternalsVisibleTo.cs b/Source/OxyPlot.SharpDX/InternalsVisibleTo.cs deleted file mode 100644 index 1526683..0000000 --- a/Source/OxyPlot.SharpDX/InternalsVisibleTo.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("OxyPlot.SharpDX.Wpf, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d310c7f79b3af0d4d7864284761f045fab5974338ce014632a65717a19088e28fe60566f63eebd6c4ecad49e69a3f04079c57572678566347b1f13e0c8ea264be911c310aa1ecccd395f0b8444d29fd389f6f5238bd37a4ddcb0bb0f7fd2571c30a58538614cb7dc258eefc85704e506ad0fe182d76706c047c624945254f0bf")] \ No newline at end of file diff --git a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj b/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj index 8ea1ac6..9815729 100644 --- a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj +++ b/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj @@ -1,13 +1,13 @@  - netstandard1.2 - true - OxyPlot.SharpDX.snk + netstandard1.1 + true + 2.0.0 - + diff --git a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.snk b/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.snk deleted file mode 100644 index 0133abf2af8753af18d3f9e43c832d13dc1a4bdf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098g5XbkMI`GujhC+mP9|T{kS#&du;1pvj zWpR2L2#zTJU{-Hq?!9bI%G91|qwqj^#dUILg=RE+9~0on>LyF+5yKFw9?Z=-Ukijp z(x20b_Vpu+(|S$Zu)7a`(pMZXrG+?QOt;)6j_=4<1my;;58;B>X9mDW#w3(dRPeu_ z(eeY_xsj%Z0_slVt%nMud)5vF9;Ywad4LH#PMa@JpL%95mU>=)5K!DX3AV{%gaz}) z(m%x2eSumo@<-84e5<=m{1X|Zm$?YvG|TD(q(fx-ZR(FBt&6j{RPw1L z%;_zoW3qllNmj(|_H1a3fUWwWP08x_v_?qZ3{6n^Pe~fxZZ6>U=f%PA&Is6jDkNYA zku%5u%o(}k%=!;rhMtr-CGv$w*a*9HoS_?IB<_(bd0_=fC)LKNy?EtQ1#?*ZC1``E z#=xm3;WNm1k0)YF Date: Wed, 26 Feb 2020 07:43:50 +0100 Subject: [PATCH 10/14] Update appveyor.yml --- appveyor.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b4ea821..bb99619 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,21 +1,17 @@ image: Visual Studio 2019 -configuration: - - Release - pull_requests: do_not_increment_build_number: true - -install: - - cinst gitversion.portable -y + +platform: Any CPU +configuration: Release +version: '2.0.0-unstable.{build}' 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 + - nuget restore Source/OxyPlot.SharpDX.sln build_script: - - msbuild Source/OxyPlot.SharpDX.sln "/property:Platform=Any CPU" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - msbuild Source/OxyPlot.SharpDX.sln "/p:Platform=Any CPU" "/p:Configuration=Release" "/p:Version=%APPVEYOR_BUILD_VERSION%" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" artifacts: - path: '**/bin/Release/*.nupkg' From 635709d2b57b884324b87b77999349dd4b09322f Mon Sep 17 00:00:00 2001 From: "jonathan.arweck" Date: Thu, 27 Feb 2020 08:14:14 +0100 Subject: [PATCH 11/14] fix #23 Clean up Code --- .../SharpDX.Wpf/SimpleDemo/MainViewModel.cs | 2 +- .../Converters/OxyColorConverter.cs | 8 +- .../Converters/ThicknessConverter.cs | 8 +- .../OxyPlot.SharpDX.Wpf.csproj | 1 + Source/OxyPlot.SharpDX.Wpf/PlotImage.cs | 76 ++-- Source/OxyPlot.SharpDX.Wpf/PlotView.cs | 225 +++------- .../Tracker/TrackerControl.cs | 273 ++++-------- .../Tracker/TrackerDefinition.cs | 26 +- .../Utilities/ConverterExtensions.cs | 395 ++++-------------- Source/OxyPlot.SharpDX.sln | 12 +- Source/OxyPlot.SharpDX/CacherRenderContext.cs | 114 ++--- Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj | 1 + .../RenderUnits/ClipRectRenderUnit.cs | 6 +- .../RenderUnits/GeometryRenderUnit.cs | 8 +- .../OxyPlot.SharpDX/SharpDXOxyExtensions.cs | 22 +- 15 files changed, 343 insertions(+), 834 deletions(-) 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/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 24c09ff..61a34e5 100644 --- a/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj +++ b/Source/OxyPlot.SharpDX.Wpf/OxyPlot.SharpDX.Wpf.csproj @@ -14,6 +14,7 @@ https://oxyplot.github.io/ https://github.com/oxyplot/oxyplot-sharpdx true + 8 diff --git a/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs b/Source/OxyPlot.SharpDX.Wpf/PlotImage.cs index e2bdcf0..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,12 +558,12 @@ protected override Size ArrangeOverride(Size finalSize) this.Overlay.Arrange(new Rect(overlaySize)); - int width = (int)(finalSize.Width < 1 ? 1 : finalSize.Width); - int height = (int)(finalSize.Height < 1 ? 1 : finalSize.Height); + var width = (int)(finalSize.Width < 1 ? 1 : finalSize.Width); + var height = (int)(finalSize.Height < 1 ? 1 : finalSize.Height); - Size renderSize = new Size(width, height); + var renderSize = new Size(width, height); - bool sizeChanged = this.viewport != renderSize; + var sizeChanged = this.viewport != renderSize; this.viewport = renderSize; this.extent = renderSize; @@ -588,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 ? 1 : Math.Ceiling(this.viewport.Width * dpiScale)); - int surfHeight = (int)(this.viewport.Height <= 0 ? 1 : 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, @@ -611,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 { @@ -627,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, @@ -647,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); } @@ -666,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/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.sln b/Source/OxyPlot.SharpDX.sln index 86e607e..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,11 +16,13 @@ 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleDemo", "Examples\SharpDX.Wpf\SimpleDemo\SimpleDemo.csproj", "{48C8FBE0-C817-43BE-AC11-895A69100A86}" +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}") = "OxyPlot.SharpDX", "OxyPlot.SharpDX\OxyPlot.SharpDX.csproj", "{5D8EC148-9B3D-4A3D-A0B9-A2E9812E647D}" +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(SolutionConfigurationPlatforms) = preSolution diff --git a/Source/OxyPlot.SharpDX/CacherRenderContext.cs b/Source/OxyPlot.SharpDX/CacherRenderContext.cs index 52c91f9..eb9acef 100644 --- a/Source/OxyPlot.SharpDX/CacherRenderContext.cs +++ b/Source/OxyPlot.SharpDX/CacherRenderContext.cs @@ -45,11 +45,6 @@ public class CacherRenderContext : IRenderContext, IDisposable /// private readonly Dictionary imageCache = new Dictionary(); - /// - /// The Direct2D factory - /// - private D2DFactory d2dFactory; - /// /// The DirectWrite factory /// @@ -68,12 +63,7 @@ public 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. @@ -85,24 +75,12 @@ public 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. /// @@ -112,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. @@ -149,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)); @@ -180,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); @@ -212,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); @@ -249,7 +216,7 @@ 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), this.GetBrush(fill) == null ? FigureBegin.Hollow : FigureBegin.Filled); @@ -283,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) { @@ -322,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)); @@ -456,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; } /// @@ -510,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; } @@ -519,7 +485,7 @@ public bool SetClip(OxyRect clippingRect) /// public void ResetClip() { - renderUnits.Add(new ClipRectRenderUnit(RectangleF.Empty)); + this.renderUnits.Add(new ClipRectRenderUnit(RectangleF.Empty)); } /// @@ -539,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; } @@ -570,7 +536,7 @@ public void ResetRenderTarget(RenderTarget renderTarget) this.imagesInUse.Clear(); - this.renderTarget = renderTarget; + this.renderTarget = newRenderTarget; } /// @@ -619,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(); @@ -631,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) { @@ -643,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; } @@ -673,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()); } /// @@ -691,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); } @@ -723,16 +694,13 @@ private Bitmap GetBitmap(OxyImage image) return this.imageCache[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); + 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); - res = Bitmap.FromWicBitmap(this.renderTarget, converter); - } + 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 index 9815729..5730f36 100644 --- a/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj +++ b/Source/OxyPlot.SharpDX/OxyPlot.SharpDX.csproj @@ -4,6 +4,7 @@ netstandard1.1 true 2.0.0 + 8 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); } From ec4aac4b80af86c20e0d072809bd9e9e596d7c1f Mon Sep 17 00:00:00 2001 From: "jonathan.arweck" Date: Fri, 28 Feb 2020 08:02:51 +0100 Subject: [PATCH 12/14] Fix #24 Zooming via MouseWheel not working --- CHANGELOG.md | 1 + Source/OxyPlot.SharpDX.Wpf/Themes/Generic.xaml | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32f830d..a7be706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,3 +22,4 @@ SimpleDemo: Target .NET Core 3.1 - 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/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 @@ - - - + From aac5904760b9a41e6941c0c134fdbd524577cb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Bj=C3=B8rke?= Date: Mon, 29 Jul 2024 10:41:25 +0200 Subject: [PATCH 13/14] Remove references to AppVeyor --- .github/CONTRIBUTING.md | 2 +- README.md | 16 +--------------- Source/AssemblyInfo.cs | 1 - appveyor.yml | 27 --------------------------- 4 files changed, 2 insertions(+), 44 deletions(-) delete mode 100644 appveyor.yml 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/README.md b/README.md index 8a935cb..468e06f 100644 --- a/README.md +++ b/README.md @@ -2,20 +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 @@ -31,7 +17,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/appveyor.yml b/appveyor.yml deleted file mode 100644 index bb99619..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,27 +0,0 @@ -image: Visual Studio 2019 - -pull_requests: - do_not_increment_build_number: true - -platform: Any CPU -configuration: Release -version: '2.0.0-unstable.{build}' - -before_build: - - nuget restore Source/OxyPlot.SharpDX.sln - -build_script: - - msbuild Source/OxyPlot.SharpDX.sln "/p:Platform=Any CPU" "/p:Configuration=Release" "/p:Version=%APPVEYOR_BUILD_VERSION%" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - -artifacts: - - path: '**/bin/Release/*.nupkg' - name: packages - -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: packages From 97a40325c795ba0199f666b652ee16880adccb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Bj=C3=B8rke?= Date: Mon, 29 Jul 2024 10:45:52 +0200 Subject: [PATCH 14/14] Remove image from README --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 468e06f..dc5b79e 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ OxyPlot is a cross-platform plotting library for .NET. This repository contains the SharpDX/WPF implementation. -![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)