mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-11 01:35:40 +00:00
Merge branch 'legacy_joystick' into linux_joystick
This commit is contained in:
commit
cb4e4d5e72
|
@ -798,6 +798,8 @@
|
||||||
<Compile Include="Input\ConfigurationType.cs" />
|
<Compile Include="Input\ConfigurationType.cs" />
|
||||||
<Compile Include="Input\GamePadConfigurationSource.cs" />
|
<Compile Include="Input\GamePadConfigurationSource.cs" />
|
||||||
<Compile Include="Input\GamePadConfigurationItem.cs" />
|
<Compile Include="Input\GamePadConfigurationItem.cs" />
|
||||||
|
<Compile Include="Platform\LegacyJoystickDriver.cs" />
|
||||||
|
<Compile Include="Platform\PlatformFactoryBase.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|
|
@ -33,6 +33,7 @@ using System.Text;
|
||||||
namespace OpenTK.Platform
|
namespace OpenTK.Platform
|
||||||
{
|
{
|
||||||
using Graphics;
|
using Graphics;
|
||||||
|
using Input;
|
||||||
|
|
||||||
sealed class Factory : IPlatformFactory
|
sealed class Factory : IPlatformFactory
|
||||||
{
|
{
|
||||||
|
@ -134,27 +135,32 @@ namespace OpenTK.Platform
|
||||||
return default_implementation.CreateGraphicsMode();
|
return default_implementation.CreateGraphicsMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
public IKeyboardDriver2 CreateKeyboardDriver()
|
||||||
{
|
{
|
||||||
return default_implementation.CreateKeyboardDriver();
|
return default_implementation.CreateKeyboardDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenTK.Input.IMouseDriver2 CreateMouseDriver()
|
public IMouseDriver2 CreateMouseDriver()
|
||||||
{
|
{
|
||||||
return default_implementation.CreateMouseDriver();
|
return default_implementation.CreateMouseDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
public IGamePadDriver CreateGamePadDriver()
|
||||||
{
|
{
|
||||||
return default_implementation.CreateGamePadDriver();
|
return default_implementation.CreateGamePadDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Input.IJoystickDriver2 CreateJoystickDriver()
|
public IJoystickDriver2 CreateJoystickDriver()
|
||||||
{
|
{
|
||||||
return default_implementation.CreateJoystickDriver();
|
return default_implementation.CreateJoystickDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnsupportedPlatform : IPlatformFactory
|
public IJoystickDriver CreateLegacyJoystickDriver()
|
||||||
|
{
|
||||||
|
return default_implementation.CreateLegacyJoystickDriver();
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnsupportedPlatform : PlatformFactoryBase
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
|
@ -165,92 +171,51 @@ namespace OpenTK.Platform
|
||||||
|
|
||||||
#region IPlatformFactory Members
|
#region IPlatformFactory Members
|
||||||
|
|
||||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
public override IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGraphicsContext CreateESContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags)
|
public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
public override IGraphicsMode CreateGraphicsMode()
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGraphicsMode CreateGraphicsMode()
|
public override IKeyboardDriver2 CreateKeyboardDriver()
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
public override IMouseDriver2 CreateMouseDriver()
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenTK.Input.IMouseDriver2 CreateMouseDriver()
|
public override IJoystickDriver2 CreateJoystickDriver()
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException(error_string);
|
throw new PlatformNotSupportedException(error_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
|
||||||
{
|
|
||||||
throw new PlatformNotSupportedException(error_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Input.IJoystickDriver2 CreateJoystickDriver()
|
|
||||||
{
|
|
||||||
throw new PlatformNotSupportedException(error_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
void Dispose(bool manual)
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
if (manual)
|
|
||||||
{
|
|
||||||
// nothing to do
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Print("{0} leaked, did you forget to call Dispose()?", GetType());
|
|
||||||
}
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~UnsupportedPlatform()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,5 +54,7 @@ namespace OpenTK.Platform
|
||||||
OpenTK.Input.IGamePadDriver CreateGamePadDriver();
|
OpenTK.Input.IGamePadDriver CreateGamePadDriver();
|
||||||
|
|
||||||
Input.IJoystickDriver2 CreateJoystickDriver();
|
Input.IJoystickDriver2 CreateJoystickDriver();
|
||||||
|
|
||||||
|
Input.IJoystickDriver CreateLegacyJoystickDriver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
106
Source/OpenTK/Platform/LegacyJoystickDriver.cs
Normal file
106
Source/OpenTK/Platform/LegacyJoystickDriver.cs
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
#region License
|
||||||
|
//
|
||||||
|
// LegacyJoystickDriver.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Stefanos A. <stapostol@gmail.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
|
namespace OpenTK.Platform
|
||||||
|
{
|
||||||
|
internal class LegacyJoystickDriver : IJoystickDriver
|
||||||
|
{
|
||||||
|
static readonly string ConnectedName = "Connected Joystick";
|
||||||
|
static readonly string DisconnectedName = "Disconnected Joystick";
|
||||||
|
readonly List<JoystickDevice> joysticks = new List<JoystickDevice>();
|
||||||
|
readonly IList<JoystickDevice> joysticks_readonly;
|
||||||
|
|
||||||
|
class LegacyJoystickDevice : JoystickDevice
|
||||||
|
{
|
||||||
|
public LegacyJoystickDevice(int id, int axes, int buttons)
|
||||||
|
: base(id, axes, buttons)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal LegacyJoystickDriver()
|
||||||
|
{
|
||||||
|
joysticks_readonly = joysticks.AsReadOnly();
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
joysticks.Add(new LegacyJoystickDevice(i, 0, 0));
|
||||||
|
joysticks[i].Description = DisconnectedName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Poll()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
JoystickCapabilities caps = Joystick.GetCapabilities(i);
|
||||||
|
if (caps.IsConnected && joysticks[i].Description == DisconnectedName)
|
||||||
|
{
|
||||||
|
// New joystick connected
|
||||||
|
JoystickDevice device = new LegacyJoystickDevice(i, caps.AxisCount, caps.ButtonCount);
|
||||||
|
//device.Description = Joystick.GetName(i);
|
||||||
|
device.Description = ConnectedName;
|
||||||
|
}
|
||||||
|
else if (!caps.IsConnected && joysticks[i].Description != DisconnectedName)
|
||||||
|
{
|
||||||
|
// Joystick disconnected
|
||||||
|
joysticks[i] = new LegacyJoystickDevice(i, 0, 0);
|
||||||
|
joysticks[i].Description = DisconnectedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
JoystickState state = Joystick.GetState(i);
|
||||||
|
for (int axis_index = 0; axis_index < (int)JoystickAxis.Last; axis_index++)
|
||||||
|
{
|
||||||
|
JoystickAxis axis = JoystickAxis.Axis0 + axis_index;
|
||||||
|
joysticks[i].SetAxis(axis, state.GetAxis(axis));
|
||||||
|
}
|
||||||
|
for (int button_index = 0; button_index < (int)JoystickButton.Last; button_index++)
|
||||||
|
{
|
||||||
|
JoystickButton button = JoystickButton.Button0 + button_index;
|
||||||
|
joysticks[i].SetButton(button, state.GetButton(button) == ButtonState.Pressed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IJoystickDriver Members
|
||||||
|
|
||||||
|
public IList<JoystickDevice> Joysticks
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return joysticks_readonly;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -35,38 +35,33 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
using Graphics;
|
using Graphics;
|
||||||
|
|
||||||
class MacOSFactory : IPlatformFactory
|
class MacOSFactory : PlatformFactoryBase
|
||||||
{
|
{
|
||||||
#region Fields
|
|
||||||
|
|
||||||
bool disposed;
|
|
||||||
readonly IInputDriver2 InputDriver = new HIDInput();
|
readonly IInputDriver2 InputDriver = new HIDInput();
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IPlatformFactory Members
|
#region IPlatformFactory Members
|
||||||
|
|
||||||
public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
||||||
{
|
{
|
||||||
return new CarbonGLNative(x, y, width, height, title, mode, options, device);
|
return new CarbonGLNative(x, y, width, height, title, mode, options, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
public override IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||||
{
|
{
|
||||||
return new QuartzDisplayDeviceDriver();
|
return new QuartzDisplayDeviceDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
return new AglContext(mode, window, shareContext);
|
return new AglContext(mode, window, shareContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
return new AglContext(handle, window, shareContext);
|
return new AglContext(handle, window, shareContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
||||||
{
|
{
|
||||||
return (GraphicsContext.GetCurrentContextDelegate)delegate
|
return (GraphicsContext.GetCurrentContextDelegate)delegate
|
||||||
{
|
{
|
||||||
|
@ -74,27 +69,17 @@ namespace OpenTK.Platform.MacOS
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsMode CreateGraphicsMode()
|
public override IKeyboardDriver2 CreateKeyboardDriver()
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
|
||||||
{
|
{
|
||||||
return InputDriver.KeyboardDriver;
|
return InputDriver.KeyboardDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IMouseDriver2 CreateMouseDriver()
|
public override IMouseDriver2 CreateMouseDriver()
|
||||||
{
|
{
|
||||||
return InputDriver.MouseDriver;
|
return InputDriver.MouseDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
public override IJoystickDriver2 CreateJoystickDriver()
|
||||||
{
|
|
||||||
return InputDriver.GamePadDriver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IJoystickDriver2 CreateJoystickDriver()
|
|
||||||
{
|
{
|
||||||
return InputDriver.JoystickDriver;
|
return InputDriver.JoystickDriver;
|
||||||
}
|
}
|
||||||
|
@ -103,33 +88,19 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
#region IDisposable Members
|
#region IDisposable Members
|
||||||
|
|
||||||
void Dispose(bool manual)
|
protected override void Dispose(bool manual)
|
||||||
{
|
{
|
||||||
if (!disposed)
|
if (!IsDisposed)
|
||||||
{
|
{
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
InputDriver.Dispose();
|
InputDriver.Dispose();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
base.Dispose(manual);
|
||||||
Debug.Print("{0} leaked, did you forget to call Dispose()?", GetType());
|
|
||||||
}
|
|
||||||
disposed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~MacOSFactory()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
120
Source/OpenTK/Platform/PlatformFactoryBase.cs
Normal file
120
Source/OpenTK/Platform/PlatformFactoryBase.cs
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
#region License
|
||||||
|
//
|
||||||
|
// PlatformFactoryBase.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Stefanos A. <stapostol@gmail.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using OpenTK.Graphics;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
|
namespace OpenTK.Platform
|
||||||
|
{
|
||||||
|
/// \internal
|
||||||
|
/// <summary>
|
||||||
|
/// Implements IPlatformFactory functionality that is common
|
||||||
|
/// for all platform backends. IPlatformFactory implementations
|
||||||
|
/// should inherit from this class.
|
||||||
|
/// </summary>
|
||||||
|
abstract class PlatformFactoryBase : IPlatformFactory
|
||||||
|
{
|
||||||
|
protected bool IsDisposed;
|
||||||
|
|
||||||
|
public PlatformFactoryBase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IPlatformFactory Members
|
||||||
|
|
||||||
|
public abstract INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device);
|
||||||
|
|
||||||
|
public abstract IDisplayDeviceDriver CreateDisplayDeviceDriver();
|
||||||
|
|
||||||
|
public abstract IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags);
|
||||||
|
|
||||||
|
public virtual IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext();
|
||||||
|
|
||||||
|
public virtual IGraphicsMode CreateGraphicsMode()
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract IKeyboardDriver2 CreateKeyboardDriver();
|
||||||
|
|
||||||
|
public abstract IMouseDriver2 CreateMouseDriver();
|
||||||
|
|
||||||
|
public virtual IGamePadDriver CreateGamePadDriver()
|
||||||
|
{
|
||||||
|
return new MappedGamePadDriver();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract IJoystickDriver2 CreateJoystickDriver();
|
||||||
|
|
||||||
|
public virtual IJoystickDriver CreateLegacyJoystickDriver()
|
||||||
|
{
|
||||||
|
return new LegacyJoystickDriver();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDisposable implementation
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool manual)
|
||||||
|
{
|
||||||
|
if (!IsDisposed)
|
||||||
|
{
|
||||||
|
if (manual)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Print("[OpenTK] {0} leaked, did you forget to call Dispose()?", GetType());
|
||||||
|
}
|
||||||
|
IsDisposed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~PlatformFactoryBase()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -32,10 +32,9 @@ using OpenTK.Input;
|
||||||
|
|
||||||
namespace OpenTK.Platform.SDL2
|
namespace OpenTK.Platform.SDL2
|
||||||
{
|
{
|
||||||
class Sdl2Factory : IPlatformFactory
|
class Sdl2Factory : PlatformFactoryBase
|
||||||
{
|
{
|
||||||
readonly Sdl2InputDriver InputDriver = new Sdl2InputDriver();
|
readonly Sdl2InputDriver InputDriver = new Sdl2InputDriver();
|
||||||
bool disposed;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether to use SDL2 fullscreen-desktop mode
|
/// Gets or sets a value indicating whether to use SDL2 fullscreen-desktop mode
|
||||||
|
@ -56,27 +55,27 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
#region IPlatformFactory implementation
|
#region IPlatformFactory implementation
|
||||||
|
|
||||||
public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
||||||
{
|
{
|
||||||
return new Sdl2NativeWindow(x, y, width, height, title, options, device, InputDriver);
|
return new Sdl2NativeWindow(x, y, width, height, title, options, device, InputDriver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
public override IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||||
{
|
{
|
||||||
return new Sdl2DisplayDeviceDriver();
|
return new Sdl2DisplayDeviceDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
return new Sdl2GraphicsContext(mode, window, shareContext, major, minor, flags);
|
return new Sdl2GraphicsContext(mode, window, shareContext, major, minor, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
||||||
{
|
{
|
||||||
return (GraphicsContext.GetCurrentContextDelegate)delegate
|
return (GraphicsContext.GetCurrentContextDelegate)delegate
|
||||||
{
|
{
|
||||||
|
@ -84,27 +83,17 @@ namespace OpenTK.Platform.SDL2
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGraphicsMode CreateGraphicsMode()
|
public override IKeyboardDriver2 CreateKeyboardDriver()
|
||||||
{
|
|
||||||
return new Sdl2GraphicsMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IKeyboardDriver2 CreateKeyboardDriver()
|
|
||||||
{
|
{
|
||||||
return InputDriver.KeyboardDriver;
|
return InputDriver.KeyboardDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMouseDriver2 CreateMouseDriver()
|
public override IMouseDriver2 CreateMouseDriver()
|
||||||
{
|
{
|
||||||
return InputDriver.MouseDriver;
|
return InputDriver.MouseDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IGamePadDriver CreateGamePadDriver()
|
public override IJoystickDriver2 CreateJoystickDriver()
|
||||||
{
|
|
||||||
return InputDriver.GamePadDriver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IJoystickDriver2 CreateJoystickDriver()
|
|
||||||
{
|
{
|
||||||
return InputDriver.JoystickDriver;
|
return InputDriver.JoystickDriver;
|
||||||
}
|
}
|
||||||
|
@ -113,34 +102,19 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
#region IDisposable Members
|
#region IDisposable Members
|
||||||
|
|
||||||
void Dispose(bool manual)
|
protected override void Dispose(bool manual)
|
||||||
{
|
{
|
||||||
if (!disposed)
|
if (!IsDisposed)
|
||||||
{
|
{
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
Debug.Print("Disposing {0}", GetType());
|
|
||||||
InputDriver.Dispose();
|
InputDriver.Dispose();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
base.Dispose(manual);
|
||||||
Debug.WriteLine("Sdl2Factory leaked, did you forget to call Dispose()?");
|
|
||||||
}
|
|
||||||
disposed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~Sdl2Factory()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,8 @@ using OpenTK.Input;
|
||||||
namespace OpenTK.Platform.Windows
|
namespace OpenTK.Platform.Windows
|
||||||
{
|
{
|
||||||
|
|
||||||
class WinFactory : IPlatformFactory
|
class WinFactory : PlatformFactoryBase
|
||||||
{
|
{
|
||||||
bool disposed;
|
|
||||||
readonly object SyncRoot = new object();
|
readonly object SyncRoot = new object();
|
||||||
IInputDriver2 inputDriver;
|
IInputDriver2 inputDriver;
|
||||||
|
|
||||||
|
@ -83,27 +82,27 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
#region IPlatformFactory Members
|
#region IPlatformFactory Members
|
||||||
|
|
||||||
public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
||||||
{
|
{
|
||||||
return new WinGLNative(x, y, width, height, title, options, device);
|
return new WinGLNative(x, y, width, height, title, options, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
public override IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||||
{
|
{
|
||||||
return new WinDisplayDeviceDriver();
|
return new WinDisplayDeviceDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
return new WinGLContext(mode, (WinWindowInfo)window, shareContext, major, minor, flags);
|
return new WinGLContext(mode, (WinWindowInfo)window, shareContext, major, minor, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
return new WinGLContext(handle, (WinWindowInfo)window, shareContext, major, minor, flags);
|
return new WinGLContext(handle, (WinWindowInfo)window, shareContext, major, minor, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
||||||
{
|
{
|
||||||
return (GraphicsContext.GetCurrentContextDelegate)delegate
|
return (GraphicsContext.GetCurrentContextDelegate)delegate
|
||||||
{
|
{
|
||||||
|
@ -111,27 +110,22 @@ namespace OpenTK.Platform.Windows
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsMode CreateGraphicsMode()
|
public override OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
|
||||||
{
|
{
|
||||||
return InputDriver.KeyboardDriver;
|
return InputDriver.KeyboardDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IMouseDriver2 CreateMouseDriver()
|
public override OpenTK.Input.IMouseDriver2 CreateMouseDriver()
|
||||||
{
|
{
|
||||||
return InputDriver.MouseDriver;
|
return InputDriver.MouseDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
public override OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
||||||
{
|
{
|
||||||
return InputDriver.GamePadDriver;
|
return InputDriver.GamePadDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IJoystickDriver2 CreateJoystickDriver()
|
public override IJoystickDriver2 CreateJoystickDriver()
|
||||||
{
|
{
|
||||||
return InputDriver.JoystickDriver;
|
return InputDriver.JoystickDriver;
|
||||||
}
|
}
|
||||||
|
@ -155,33 +149,19 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
#region IDisposable Members
|
#region IDisposable Members
|
||||||
|
|
||||||
void Dispose(bool manual)
|
protected override void Dispose(bool manual)
|
||||||
{
|
{
|
||||||
if (!disposed)
|
if (!IsDisposed)
|
||||||
{
|
{
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
InputDriver.Dispose();
|
InputDriver.Dispose();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
base.Dispose(manual);
|
||||||
Debug.Print("{0} leaked, did you forget to call Dispose()?", GetType());
|
|
||||||
}
|
|
||||||
disposed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~WinFactory()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,11 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace OpenTK.Platform.X11
|
namespace OpenTK.Platform.X11
|
||||||
{
|
{
|
||||||
class X11Factory : IPlatformFactory
|
class X11Factory : PlatformFactoryBase
|
||||||
{
|
{
|
||||||
bool disposed;
|
bool disposed;
|
||||||
|
|
||||||
|
@ -47,27 +48,27 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
#region IPlatformFactory Members
|
#region IPlatformFactory Members
|
||||||
|
|
||||||
public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
||||||
{
|
{
|
||||||
return new X11GLNative(x, y, width, height, title, mode, options, device);
|
return new X11GLNative(x, y, width, height, title, mode, options, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
public override IDisplayDeviceDriver CreateDisplayDeviceDriver()
|
||||||
{
|
{
|
||||||
return new X11DisplayDevice();
|
return new X11DisplayDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
return new X11GLContext(mode, window, shareContext, directRendering, major, minor, flags);
|
return new X11GLContext(mode, window, shareContext, directRendering, major, minor, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
|
||||||
{
|
{
|
||||||
return new X11GLContext(handle, window, shareContext, directRendering, major, minor, flags);
|
return new X11GLContext(handle, window, shareContext, directRendering, major, minor, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
|
||||||
{
|
{
|
||||||
return (GraphicsContext.GetCurrentContextDelegate)delegate
|
return (GraphicsContext.GetCurrentContextDelegate)delegate
|
||||||
{
|
{
|
||||||
|
@ -75,17 +76,17 @@ namespace OpenTK.Platform.X11
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IGraphicsMode CreateGraphicsMode()
|
public override IGraphicsMode CreateGraphicsMode()
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IKeyboardDriver2 CreateKeyboardDriver()
|
public override IKeyboardDriver2 CreateKeyboardDriver()
|
||||||
{
|
{
|
||||||
return new X11Keyboard();
|
return new X11Keyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IMouseDriver2 CreateMouseDriver()
|
public override IMouseDriver2 CreateMouseDriver()
|
||||||
{
|
{
|
||||||
if (XI2Mouse.IsSupported(IntPtr.Zero))
|
if (XI2Mouse.IsSupported(IntPtr.Zero))
|
||||||
return new XI2Mouse(); // Requires xorg 1.7 or higher.
|
return new XI2Mouse(); // Requires xorg 1.7 or higher.
|
||||||
|
@ -93,48 +94,11 @@ namespace OpenTK.Platform.X11
|
||||||
return new X11Mouse(); // Always supported.
|
return new X11Mouse(); // Always supported.
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IGamePadDriver CreateGamePadDriver()
|
public override IJoystickDriver2 CreateJoystickDriver()
|
||||||
{
|
{
|
||||||
return new X11Joystick();
|
return new X11Joystick();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual OpenTK.Input.IJoystickDriver2 CreateJoystickDriver()
|
|
||||||
{
|
|
||||||
return new X11Joystick();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
void Dispose(bool manual)
|
|
||||||
{
|
|
||||||
if (!disposed)
|
|
||||||
{
|
|
||||||
if (manual)
|
|
||||||
{
|
|
||||||
// nothing to do
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Print("{0} leaked, did you forget to call Dispose()?", GetType());
|
|
||||||
}
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~X11Factory()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue