Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add netcore support to OxyPlot.GtkSharp3 #10

Merged
merged 9 commits into from
Oct 13, 2021
2 changes: 1 addition & 1 deletion Source/Examples/GtkSharp.Shared/GtkSharpDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static void Main()
{
window.SetSizeRequest(800, 600);
window.Add(plotView);
window.Focus = plotView;
plotView.GrabFocus();
window.Show();
window.DeleteEvent += (s, a) =>
{
Expand Down
17 changes: 13 additions & 4 deletions Source/Examples/GtkSharp3/ExampleBrowser/ExampleBrowserGtk3.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>net451;net452;net461;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<RootNamespace>ExampleBrowser</RootNamespace>
<OutputType>WinExe</OutputType>
</PropertyGroup>
Expand All @@ -9,11 +9,20 @@
<ProjectReference Include="..\..\..\OxyPlot.GtkSharp3\OxyPlot.GtkSharp3.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="OxyPlot.ExampleLibrary" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
VisualMelon marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="GtkSharp" Version="3.22.25.*" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net451'">
<PackageReference Include="gtk-sharp-3" Version="3.22.6.4" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net452'">
<PackageReference Include="gtk-sharp-3" Version="3.22.6.4" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
<PackageReference Include="gtk-sharp-3" Version="3.22.6.4" />
<PackageReference Include="OxyPlot.Core" Version="2.0.0-unstable1013" />
<PackageReference Include="OxyPlot.ExampleLibrary" Version="2.0.0-unstable0956" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
Expand Down
14 changes: 11 additions & 3 deletions Source/Examples/GtkSharp3/GtkSharpDemo/GtkSharp3Demo.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>net451;net452;net461;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<RootNamespace>GtkSharpDemo</RootNamespace>
<OutputType>WinExe</OutputType>
</PropertyGroup>
<Import Project="..\..\GtkSharp.Shared\GtkSharpDemo\GtkSharpDemo.Shared.projitems" Label="Shared" />
<ItemGroup>
<ProjectReference Include="..\..\..\OxyPlot.GtkSharp3\OxyPlot.GtkSharp3.csproj" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
VisualMelon marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="GtkSharp" Version="3.22.25.*" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net451'">
<PackageReference Include="gtk-sharp-3" Version="3.22.6.4" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net452'">
<PackageReference Include="gtk-sharp-3" Version="3.22.6.4" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
VisualMelon marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="gtk-sharp-3" Version="3.22.6.4" />
<PackageReference Include="OxyPlot.Core" Version="2.0.0-unstable1013" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
7 changes: 6 additions & 1 deletion Source/OxyPlot.GtkSharp.Shared/PlotView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,14 @@ protected override bool OnButtonReleaseEvent(EventButton e)
/// </summary>
/// <param name="e">An instance that contains the event data.</param>
/// <returns><c>true</c> if the event was handled.</returns>
/// <remarks>
/// The way that scroll direction is determined is different between
/// gtk2 and gtk3, hence the need for version-specific imlementations of
/// GetMouseWheelEventArgs(Gdk.EventScroll) function.
/// </remarks>
protected override bool OnScrollEvent(EventScroll e)
{
return this.ActualController.HandleMouseWheel(this, e.ToMouseWheelEventArgs());
return this.ActualController.HandleMouseWheel(this, GetMouseWheelEventArgs(e));
}

/// <summary>
Expand Down
17 changes: 1 addition & 16 deletions Source/OxyPlot.GtkSharp.Shared/Utilities/ConverterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,6 @@ public static OxyMouseEventArgs ToMouseEventArgs(this EventCrossing e)
};
}

/// <summary>
/// Creates the mouse wheel event arguments.
/// </summary>
/// <param name="e">The scroll event args.</param>
/// <returns>Mouse event arguments.</returns>
public static OxyMouseWheelEventArgs ToMouseWheelEventArgs(this EventScroll e)
{
return new OxyMouseWheelEventArgs
{
Delta = e.Direction == ScrollDirection.Down ? -120 : 120,
Position = new ScreenPoint(e.X, e.Y),
ModifierKeys = GetModifiers(e.State)
};
}

/// <summary>
/// Creates the key event arguments.
/// </summary>
Expand Down Expand Up @@ -434,7 +419,7 @@ private static OxyMouseButton ConvertButton(EventButton e)
/// </summary>
/// <param name="state">The state.</param>
/// <returns>The modifier keys.</returns>
private static OxyModifierKeys GetModifiers(ModifierType state)
public static OxyModifierKeys GetModifiers(ModifierType state)
{
var result = OxyModifierKeys.None;

Expand Down
10 changes: 8 additions & 2 deletions Source/OxyPlot.GtkSharp.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
# Visual Studio Version 16
VisualStudioVersion = 16.0.30204.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OxyPlot.GtkSharp", "OxyPlot.GtkSharp\OxyPlot.GtkSharp.csproj", "{89D008D7-AD33-4AB6-B61A-064C48DA6699}"
EndProject
Expand Down Expand Up @@ -37,9 +37,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Examples\GtkSharp.Shared\GtkSharpDemo\GtkSharpDemo.Shared.projitems*{04c4f5cf-4b8a-4d27-9562-462581c1d323}*SharedItemsImports = 5
Examples\GtkSharp.Shared\ExampleBrowser\ExampleBrowser.Shared.projitems*{064ee52b-483c-4e96-a9de-2a2d293ea741}*SharedItemsImports = 13
Examples\GtkSharp.Shared\GtkSharpDemo\GtkSharpDemo.Shared.projitems*{08c8bdff-cf2a-484d-8051-289538774d35}*SharedItemsImports = 13
Examples\GtkSharp.Shared\GtkSharpDemo\GtkSharpDemo.Shared.projitems*{480a7e68-5f4d-48c8-a8bd-e2dc1ba362e6}*SharedItemsImports = 5
Examples\GtkSharp.Shared\ExampleBrowser\ExampleBrowser.Shared.projitems*{7cecf810-9b40-46a9-9b56-5a719cfdcad0}*SharedItemsImports = 5
OxyPlot.GtkSharp.Shared\OxyPlot.GtkSharp.Shared.projitems*{89d008d7-ad33-4ab6-b61a-064c48da6699}*SharedItemsImports = 5
OxyPlot.GtkSharp.Shared\OxyPlot.GtkSharp.Shared.projitems*{8b2dc377-4689-4252-aa08-3acd06a045f3}*SharedItemsImports = 5
OxyPlot.GtkSharp.Shared\OxyPlot.GtkSharp.Shared.projitems*{ae281d72-34a8-4b84-aa7c-e1bace70f0c0}*SharedItemsImports = 13
Examples\GtkSharp.Shared\ExampleBrowser\ExampleBrowser.Shared.projitems*{ba5651be-8b77-4107-8df7-ffb73c850e18}*SharedItemsImports = 5
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
15 changes: 15 additions & 0 deletions Source/OxyPlot.GtkSharp/PlotViewGtk2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ protected override bool OnExposeEvent(Gdk.EventExpose evnt)

return base.OnExposeEvent(evnt);
}

/// <summary>
/// Creates the mouse wheel event arguments.
/// </summary>
/// <param name="e">The scroll event args.</param>
/// <returns>Mouse event arguments.</returns>
private static OxyMouseWheelEventArgs GetMouseWheelEventArgs(Gdk.EventScroll e)
{
return new OxyMouseWheelEventArgs
{
Delta = e.Direction == Gdk.ScrollDirection.Down ? -120 : 120,
Position = new ScreenPoint(e.X, e.Y),
ModifierKeys = ConverterExtensions.GetModifiers(e.State)
};
}
}
}

9 changes: 7 additions & 2 deletions Source/OxyPlot.GtkSharp3/OxyPlot.GtkSharp3.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>netstandard2.0;net451</TargetFrameworks>
<RootNamespace>OxyPlot.GtkSharp</RootNamespace>
<PackageId>OxyPlot.GtkSharp3</PackageId>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
Expand All @@ -17,7 +17,12 @@
</PropertyGroup>
<Import Project="..\OxyPlot.GtkSharp.Shared\OxyPlot.GtkSharp.Shared.projitems" Label="Shared" />
<ItemGroup>
<PackageReference Include="gtk-sharp-3" Version="3.22.6.4" />
<PackageReference Include="OxyPlot.Core" Version="2.0.0-unstable1013" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<PackageReference Include="GtkSharp" Version="3.22.25.*" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net451'">
<PackageReference Include="gtk-sharp-3" Version="3.22.6.4" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions Source/OxyPlot.GtkSharp3/PlotViewGtk3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ protected override bool OnDrawn (Cairo.Context cr)
this.DrawPlot (cr);
return base.OnDrawn (cr);
}

/// <summary>
/// Creates the mouse wheel event arguments.
/// </summary>
/// <param name="e">The scroll event args.</param>
/// <returns>Mouse event arguments.</returns>
private static OxyMouseWheelEventArgs GetMouseWheelEventArgs(Gdk.EventScroll e)
{
int delta;
#if NETSTANDARD2_0
if (e.Direction == Gdk.ScrollDirection.Smooth)
delta = e.DeltaY < 0 ? 120 : -120;
else
#endif
delta = e.Direction == Gdk.ScrollDirection.Down ? -120 : 120;
return new OxyMouseWheelEventArgs
{
Delta = delta,
Position = new ScreenPoint(e.X, e.Y),
ModifierKeys = ConverterExtensions.GetModifiers(e.State)
};
}
}
}