Implemented new, leaner SDL2 binding.
The new binding is based on the SDL2.0.1 RC1 headers.
This commit is contained in:
parent
907a1de89f
commit
80f0569f9a
11 changed files with 1474 additions and 320 deletions
|
@ -174,17 +174,17 @@ namespace OpenTK
|
|||
// Detect whether SDL2 is supported
|
||||
try
|
||||
{
|
||||
if (OpenTK.Platform.SDL2.SDL.SDL_WasInit(0) == 0)
|
||||
if (!OpenTK.Platform.SDL2.SDL.WasInit(0))
|
||||
{
|
||||
var flags = OpenTK.Platform.SDL2.SDL.SDL_INIT_EVERYTHING;
|
||||
flags &= ~OpenTK.Platform.SDL2.SDL.SDL_INIT_AUDIO;
|
||||
if (OpenTK.Platform.SDL2.SDL.SDL_Init((uint)flags) == 0)
|
||||
var flags = OpenTK.Platform.SDL2.SystemFlags.EVERYTHING;
|
||||
flags &= ~OpenTK.Platform.SDL2.SystemFlags.AUDIO;
|
||||
if (OpenTK.Platform.SDL2.SDL.Init(flags) == 0)
|
||||
{
|
||||
supported = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Print("SDL2 init failed with error: {0}", OpenTK.Platform.SDL2.SDL.SDL_GetError());
|
||||
Debug.Print("SDL2 init failed with error: {0}", OpenTK.Platform.SDL2.SDL.GetError());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -36,33 +36,33 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
public Sdl2DisplayDeviceDriver()
|
||||
{
|
||||
int displays = SDL.SDL_GetNumVideoDisplays();
|
||||
int displays = SDL.GetNumVideoDisplays();
|
||||
for (int d = 0; d < displays; d++)
|
||||
{
|
||||
SDL.SDL_Rect bounds;
|
||||
SDL.SDL_GetDisplayBounds(d, out bounds);
|
||||
Rect bounds;
|
||||
SDL.GetDisplayBounds(d, out bounds);
|
||||
|
||||
SDL.SDL_DisplayMode current_mode;
|
||||
SDL.SDL_GetCurrentDisplayMode(d, out current_mode);
|
||||
DisplayMode current_mode;
|
||||
SDL.GetCurrentDisplayMode(d, out current_mode);
|
||||
|
||||
var mode_list = new List<DisplayResolution>();
|
||||
int num_modes = SDL.SDL_GetNumDisplayModes(d);
|
||||
int num_modes = SDL.GetNumDisplayModes(d);
|
||||
for (int m = 0; m < num_modes; m++)
|
||||
{
|
||||
SDL.SDL_DisplayMode sdl_mode;
|
||||
SDL.SDL_GetDisplayMode(d, m, out sdl_mode);
|
||||
DisplayMode sdl_mode;
|
||||
SDL.GetDisplayMode(d, m, out sdl_mode);
|
||||
mode_list.Add(new DisplayResolution(
|
||||
bounds.x, bounds.y,
|
||||
sdl_mode.w, sdl_mode.h,
|
||||
TranslateFormat(sdl_mode.format),
|
||||
sdl_mode.refresh_rate));
|
||||
bounds.X, bounds.Y,
|
||||
sdl_mode.Width, sdl_mode.Height,
|
||||
TranslateFormat(sdl_mode.Format),
|
||||
sdl_mode.RefreshRate));
|
||||
}
|
||||
|
||||
var current_resolution = new DisplayResolution(
|
||||
bounds.x, bounds.y,
|
||||
current_mode.w, current_mode.h,
|
||||
TranslateFormat(current_mode.format),
|
||||
current_mode.refresh_rate);
|
||||
bounds.X, bounds.Y,
|
||||
current_mode.Width, current_mode.Height,
|
||||
TranslateFormat(current_mode.Format),
|
||||
current_mode.RefreshRate);
|
||||
|
||||
var device = new DisplayDevice(
|
||||
current_resolution, d == 0, mode_list, TranslateBounds(bounds), d);
|
||||
|
@ -79,13 +79,13 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
int bpp;
|
||||
uint a, r, g, b;
|
||||
SDL.SDL_PixelFormatEnumToMasks(format, out bpp, out r, out g, out b, out a);
|
||||
SDL.PixelFormatEnumToMasks(format, out bpp, out r, out g, out b, out a);
|
||||
return bpp;
|
||||
}
|
||||
|
||||
Rectangle TranslateBounds(SDL.SDL_Rect rect)
|
||||
Rectangle TranslateBounds(Rect rect)
|
||||
{
|
||||
return new Rectangle(rect.x, rect.y, rect.w, rect.h);
|
||||
return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace OpenTK.Platform.SDL2
|
|||
else
|
||||
{
|
||||
Window = new Sdl2WindowInfo(
|
||||
SDL.SDL_CreateWindowFrom(window.Handle),
|
||||
SDL.CreateWindowFrom(window.Handle),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
@ -64,11 +64,11 @@ namespace OpenTK.Platform.SDL2
|
|||
lock (SDL.Sync)
|
||||
{
|
||||
SetGLAttributes(mode, shareContext, major, minor, flags);
|
||||
SdlContext = new ContextHandle(SDL.SDL_GL_CreateContext(Window.Handle));
|
||||
SdlContext = new ContextHandle(SDL.GL.CreateContext(Window.Handle));
|
||||
}
|
||||
if (SdlContext == ContextHandle.Zero)
|
||||
{
|
||||
var error = SDL.SDL_GetError();
|
||||
var error = SDL.GetError();
|
||||
Debug.Print("SDL2 failed to create OpenGL context: {0}", error);
|
||||
throw new GraphicsContextException(error);
|
||||
}
|
||||
|
@ -84,85 +84,93 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
if (mode.AccumulatorFormat.BitsPerPixel > 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
|
||||
SDL.GL.SetAttribute(ContextAttribute.ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
|
||||
SDL.GL.SetAttribute(ContextAttribute.ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
|
||||
SDL.GL.SetAttribute(ContextAttribute.ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
|
||||
SDL.GL.SetAttribute(ContextAttribute.ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
|
||||
}
|
||||
|
||||
if (mode.Buffers > 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, mode.Buffers > 1 ? 1 : 0);
|
||||
SDL.GL.SetAttribute(ContextAttribute.DOUBLEBUFFER, mode.Buffers > 1 ? 1 : 0);
|
||||
}
|
||||
|
||||
if (mode.ColorFormat > 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, mode.ColorFormat.Alpha);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, mode.ColorFormat.Red);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, mode.ColorFormat.Green);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, mode.ColorFormat.Blue);
|
||||
SDL.GL.SetAttribute(ContextAttribute.ALPHA_SIZE, mode.ColorFormat.Alpha);
|
||||
SDL.GL.SetAttribute(ContextAttribute.RED_SIZE, mode.ColorFormat.Red);
|
||||
SDL.GL.SetAttribute(ContextAttribute.GREEN_SIZE, mode.ColorFormat.Green);
|
||||
SDL.GL.SetAttribute(ContextAttribute.BLUE_SIZE, mode.ColorFormat.Blue);
|
||||
}
|
||||
|
||||
if (mode.Depth > 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, mode.Depth);
|
||||
SDL.GL.SetAttribute(ContextAttribute.DEPTH_SIZE, mode.Depth);
|
||||
}
|
||||
|
||||
if (mode.Samples > 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_MULTISAMPLESAMPLES, mode.Samples);
|
||||
SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLEBUFFERS, 1);
|
||||
SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLESAMPLES, mode.Samples);
|
||||
}
|
||||
|
||||
if (mode.Stencil > 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_STENCIL_SIZE, mode.Stereo ? 1 : 0);
|
||||
SDL.GL.SetAttribute(ContextAttribute.STENCIL_SIZE, mode.Stereo ? 1 : 0);
|
||||
}
|
||||
|
||||
if (mode.Stereo)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_STEREO, 1);
|
||||
SDL.GL.SetAttribute(ContextAttribute.STEREO, 1);
|
||||
}
|
||||
|
||||
if (major > 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, major);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, minor);
|
||||
SDL.GL.SetAttribute(ContextAttribute.CONTEXT_MAJOR_VERSION, major);
|
||||
SDL.GL.SetAttribute(ContextAttribute.CONTEXT_MINOR_VERSION, minor);
|
||||
}
|
||||
|
||||
if ((flags & GraphicsContextFlags.Debug) != 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_FLAGS, (int)SDL.SDL_GLcontext.SDL_GL_CONTEXT_DEBUG_FLAG);
|
||||
}
|
||||
|
||||
if ((flags & GraphicsContextFlags.Embedded) != 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_EGL, 1);
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, (int)SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_ES);
|
||||
}
|
||||
|
||||
if ((flags & GraphicsContextFlags.ForwardCompatible) != 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, (int)SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.DEBUG);
|
||||
}
|
||||
|
||||
/*
|
||||
if ((flags & GraphicsContextFlags.Robust) != 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_FLAGS, (int)SDL.SDL_GLcontext.SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG);
|
||||
SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.ROBUST_ACCESS_FLAG);
|
||||
}
|
||||
|
||||
if ((flags & GraphicsContextFlags.ResetIsolation) != 0)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_FLAGS, (int)SDL.SDL_GLcontext.SDL_GL_CONTEXT_RESET_ISOLATION_FLAG);
|
||||
SDL.GL.SetAttribute(ContextAttribute.CONTEXT_FLAGS, ContextFlags.RESET_ISOLATION_FLAG);
|
||||
}
|
||||
*/
|
||||
|
||||
{
|
||||
ContextProfileFlags cpflags = 0;
|
||||
if ((flags & GraphicsContextFlags.Embedded) != 0)
|
||||
{
|
||||
cpflags |= ContextProfileFlags.ES;
|
||||
SDL.GL.SetAttribute(ContextAttribute.CONTEXT_EGL, 1);
|
||||
}
|
||||
|
||||
if ((flags & GraphicsContextFlags.ForwardCompatible) != 0)
|
||||
{
|
||||
cpflags |= ContextProfileFlags.CORE;
|
||||
}
|
||||
|
||||
if (cpflags != 0)
|
||||
{
|
||||
SDL.GL.SetAttribute(ContextAttribute.CONTEXT_PROFILE_MASK, cpflags);
|
||||
}
|
||||
}
|
||||
|
||||
if (shareContext != null)
|
||||
{
|
||||
if (shareContext.IsCurrent)
|
||||
{
|
||||
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
|
||||
SDL.GL.SetAttribute(ContextAttribute.SHARE_WITH_CURRENT_CONTEXT, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -177,7 +185,7 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
public override void SwapBuffers()
|
||||
{
|
||||
SDL.SDL_GL_SwapWindow(Window.Handle);
|
||||
SDL.GL.SwapWindow(Window.Handle);
|
||||
}
|
||||
|
||||
public override void MakeCurrent(IWindowInfo window)
|
||||
|
@ -185,22 +193,22 @@ namespace OpenTK.Platform.SDL2
|
|||
int result = 0;
|
||||
if (window != null)
|
||||
{
|
||||
result = SDL.SDL_GL_MakeCurrent(window.Handle, SdlContext.Handle);
|
||||
result = SDL.GL.MakeCurrent(window.Handle, SdlContext.Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = SDL.SDL_GL_MakeCurrent(IntPtr.Zero, IntPtr.Zero);
|
||||
result = SDL.GL.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
Debug.Print("SDL2 MakeCurrent failed with: {0}", SDL.SDL_GetError());
|
||||
Debug.Print("SDL2 MakeCurrent failed with: {0}", SDL.GetError());
|
||||
}
|
||||
}
|
||||
|
||||
public override IntPtr GetAddress(string function)
|
||||
{
|
||||
return SDL.SDL_GL_GetProcAddress(function);
|
||||
return SDL.GL.GetProcAddress(function);
|
||||
}
|
||||
|
||||
public override bool IsCurrent
|
||||
|
@ -215,13 +223,13 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
get
|
||||
{
|
||||
return SDL.SDL_GL_GetSwapInterval();
|
||||
return SDL.GL.GetSwapInterval();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SDL.SDL_GL_SetSwapInterval(value) < 0)
|
||||
if (SDL.GL.SetSwapInterval(value) < 0)
|
||||
{
|
||||
Debug.Print("SDL2 failed to set swap interval: {0}", SDL.SDL_GetError());
|
||||
Debug.Print("SDL2 failed to set swap interval: {0}", SDL.GetError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +247,7 @@ namespace OpenTK.Platform.SDL2
|
|||
Debug.Print("Disposing {0}", GetType());
|
||||
lock (SDL.Sync)
|
||||
{
|
||||
SDL.SDL_GL_DeleteContext(SdlContext.Handle);
|
||||
SDL.GL.DeleteContext(SdlContext.Handle);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -45,22 +45,18 @@ namespace OpenTK.Platform.SDL2
|
|||
readonly Sdl2Mouse mouse_driver = new Sdl2Mouse();
|
||||
readonly Sdl2JoystickDriver joystick_driver = new Sdl2JoystickDriver();
|
||||
|
||||
readonly SDL.SDL_EventFilter EventFilterDelegate = FilterInputEvents;
|
||||
readonly IntPtr EventFilterPointer;
|
||||
readonly EventFilter EventFilterDelegate = FilterInputEvents;
|
||||
|
||||
static int count;
|
||||
bool disposed;
|
||||
|
||||
public Sdl2InputDriver()
|
||||
{
|
||||
EventFilterPointer = Marshal.GetFunctionPointerForDelegate(
|
||||
EventFilterDelegate);
|
||||
|
||||
lock (SDL.Sync)
|
||||
{
|
||||
driver_handle = new IntPtr(count++);
|
||||
DriverHandles.Add(driver_handle, this);
|
||||
SDL.SDL_AddEventWatch(EventFilterPointer, driver_handle);
|
||||
SDL.AddEventWatch(EventFilterDelegate, driver_handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,29 +66,29 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
try
|
||||
{
|
||||
SDL.SDL_Event ev = *(SDL.SDL_Event*)e;
|
||||
Event ev = *(Event*)e;
|
||||
|
||||
Sdl2InputDriver driver;
|
||||
if (DriverHandles.TryGetValue(driver_handle, out driver))
|
||||
{
|
||||
switch (ev.type)
|
||||
switch (ev.Type)
|
||||
{
|
||||
case SDL.SDL_EventType.SDL_KEYDOWN:
|
||||
case SDL.SDL_EventType.SDL_KEYUP:
|
||||
driver.keyboard_driver.ProcessKeyboardEvent(ev.key);
|
||||
case EventType.KEYDOWN:
|
||||
case EventType.KEYUP:
|
||||
driver.keyboard_driver.ProcessKeyboardEvent(ev.Key);
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
|
||||
case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
|
||||
driver.mouse_driver.ProcessMouseEvent(ev.button);
|
||||
case EventType.MOUSEBUTTONDOWN:
|
||||
case EventType.MOUSEBUTTONUP:
|
||||
driver.mouse_driver.ProcessMouseEvent(ev.Button);
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_MOUSEMOTION:
|
||||
driver.mouse_driver.ProcessMouseEvent(ev.motion);
|
||||
case EventType.MOUSEMOTION:
|
||||
driver.mouse_driver.ProcessMouseEvent(ev.Motion);
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
|
||||
driver.mouse_driver.ProcessWheelEvent(ev.wheel);
|
||||
case EventType.MOUSEWHEEL:
|
||||
driver.mouse_driver.ProcessWheelEvent(ev.Wheel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +188,7 @@ namespace OpenTK.Platform.SDL2
|
|||
joystick_driver.Dispose();
|
||||
lock (SDL.Sync)
|
||||
{
|
||||
SDL.SDL_DelEventWatch(EventFilterPointer, IntPtr.Zero);
|
||||
SDL.DelEventWatch(EventFilterDelegate, IntPtr.Zero);
|
||||
}
|
||||
DriverHandles.Remove(driver_handle);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
joysticks.Clear();
|
||||
|
||||
int count = SDL.SDL_NumJoysticks();
|
||||
int count = SDL.NumJoysticks();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
JoystickDevice<Sdl2JoystickDetails> joystick = null;
|
||||
|
@ -69,16 +69,16 @@ namespace OpenTK.Platform.SDL2
|
|||
int num_hats = 0;
|
||||
int num_balls = 0;
|
||||
|
||||
IntPtr handle = SDL.SDL_JoystickOpen(i);
|
||||
IntPtr handle = SDL.JoystickOpen(i);
|
||||
if (handle != IntPtr.Zero)
|
||||
{
|
||||
num_axes = SDL.SDL_JoystickNumAxes(handle);
|
||||
num_buttons = SDL.SDL_JoystickNumButtons(handle);
|
||||
num_hats = SDL.SDL_JoystickNumHats(handle);
|
||||
num_balls = SDL.SDL_JoystickNumBalls(handle);
|
||||
num_axes = SDL.JoystickNumAxes(handle);
|
||||
num_buttons = SDL.JoystickNumButtons(handle);
|
||||
num_hats = SDL.JoystickNumHats(handle);
|
||||
num_balls = SDL.JoystickNumBalls(handle);
|
||||
|
||||
joystick = new JoystickDevice<Sdl2JoystickDetails>(i, num_axes, num_buttons);
|
||||
joystick.Description = SDL.SDL_JoystickName(handle);
|
||||
joystick.Description = SDL.JoystickName(handle);
|
||||
joystick.Details.Handle = handle;
|
||||
joystick.Details.HatCount = num_hats;
|
||||
joystick.Details.BallCount = num_balls;
|
||||
|
@ -101,7 +101,7 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
public void Poll()
|
||||
{
|
||||
SDL.SDL_JoystickUpdate();
|
||||
SDL.JoystickUpdate();
|
||||
foreach (var j in joysticks)
|
||||
{
|
||||
var joystick = (JoystickDevice<Sdl2JoystickDetails>)j;
|
||||
|
@ -110,13 +110,13 @@ namespace OpenTK.Platform.SDL2
|
|||
for (int i = 0; i < joystick.Axis.Count; i++)
|
||||
{
|
||||
var axis = JoystickAxis.Axis0 + i;
|
||||
joystick.SetAxis(axis, SDL.SDL_JoystickGetAxis(handle, i) * joystick.Details.RangeMultiplier);
|
||||
joystick.SetAxis(axis, SDL.JoystickGetAxis(handle, i) * joystick.Details.RangeMultiplier);
|
||||
}
|
||||
|
||||
for (int i = 0; i < joystick.Button.Count; i++)
|
||||
{
|
||||
var button = JoystickButton.Button0 + i;
|
||||
joystick.SetButton(button, SDL.SDL_JoystickGetButton(handle, i) != 0);
|
||||
joystick.SetButton(button, SDL.JoystickGetButton(handle, i) != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
var joystick = (JoystickDevice<Sdl2JoystickDetails>)j;
|
||||
IntPtr handle = joystick.Details.Handle;
|
||||
SDL.SDL_JoystickClose(handle);
|
||||
SDL.JoystickClose(handle);
|
||||
}
|
||||
|
||||
joysticks.Clear();
|
||||
|
|
|
@ -31,93 +31,93 @@ using OpenTK.Input;
|
|||
|
||||
namespace OpenTK.Platform.SDL2
|
||||
{
|
||||
using Code = SDL.SDL_Scancode;
|
||||
using Code = Scancode;
|
||||
|
||||
class Sdl2KeyMap : Dictionary<SDL.SDL_Scancode, Key>
|
||||
class Sdl2KeyMap : Dictionary<Scancode, Key>
|
||||
{
|
||||
public Sdl2KeyMap()
|
||||
{
|
||||
Add(Code.SDL_SCANCODE_ESCAPE, Key.Escape);
|
||||
Add(Code.ESCAPE, Key.Escape);
|
||||
|
||||
// Function keys
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
Add(Code.SDL_SCANCODE_F1 + i, Key.F1 + i);
|
||||
Add(Code.F1 + i, Key.F1 + i);
|
||||
}
|
||||
|
||||
// Number keys (0-9)
|
||||
Add(Code.SDL_SCANCODE_0, Key.Number0);
|
||||
Add(Code.Num0, Key.Number0);
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
Add(Code.SDL_SCANCODE_1 + i, Key.Number1 + i);
|
||||
Add(Code.Num1 + i, Key.Number1 + i);
|
||||
}
|
||||
|
||||
// Letters (A-Z)
|
||||
for (int i = 0; i < 26; i++)
|
||||
{
|
||||
Add(Code.SDL_SCANCODE_A + i, Key.A + i);
|
||||
Add(Code.A + i, Key.A + i);
|
||||
}
|
||||
|
||||
Add(Code.SDL_SCANCODE_TAB, Key.Tab);
|
||||
Add(Code.SDL_SCANCODE_CAPSLOCK, Key.CapsLock);
|
||||
Add(Code.SDL_SCANCODE_LCTRL, Key.ControlLeft);
|
||||
Add(Code.SDL_SCANCODE_LSHIFT, Key.ShiftLeft);
|
||||
Add(Code.SDL_SCANCODE_LALT, Key.WinLeft);
|
||||
Add(Code.SDL_SCANCODE_MENU, Key.AltLeft);
|
||||
Add(Code.SDL_SCANCODE_SPACE, Key.Space);
|
||||
Add(Code.SDL_SCANCODE_RALT, Key.AltRight);
|
||||
Add(Code.TAB, Key.Tab);
|
||||
Add(Code.CAPSLOCK, Key.CapsLock);
|
||||
Add(Code.LCTRL, Key.ControlLeft);
|
||||
Add(Code.LSHIFT, Key.ShiftLeft);
|
||||
Add(Code.LALT, Key.WinLeft);
|
||||
Add(Code.MENU, Key.AltLeft);
|
||||
Add(Code.SPACE, Key.Space);
|
||||
Add(Code.RALT, Key.AltRight);
|
||||
//Add(Code., Key.WinRight);
|
||||
Add(Code.SDL_SCANCODE_APPLICATION, Key.Menu);
|
||||
Add(Code.SDL_SCANCODE_RCTRL, Key.ControlRight);
|
||||
Add(Code.SDL_SCANCODE_RSHIFT, Key.ShiftRight);
|
||||
Add(Code.SDL_SCANCODE_RETURN, Key.Enter);
|
||||
Add(Code.SDL_SCANCODE_BACKSPACE, Key.BackSpace);
|
||||
Add(Code.APPLICATION, Key.Menu);
|
||||
Add(Code.RCTRL, Key.ControlRight);
|
||||
Add(Code.RSHIFT, Key.ShiftRight);
|
||||
Add(Code.RETURN, Key.Enter);
|
||||
Add(Code.BACKSPACE, Key.BackSpace);
|
||||
|
||||
Add(Code.SDL_SCANCODE_SEMICOLON, Key.Semicolon); // Varies by keyboard, ;: on Win2K/US
|
||||
Add(Code.SDL_SCANCODE_SLASH, Key.Slash); // Varies by keyboard, /? on Win2K/US
|
||||
Add(Code.SDL_SCANCODE_GRAVE, Key.Tilde); // Varies by keyboard, `~ on Win2K/US
|
||||
Add(Code.SDL_SCANCODE_LEFTBRACKET, Key.BracketLeft); // Varies by keyboard, [{ on Win2K/US
|
||||
Add(Code.SDL_SCANCODE_BACKSLASH, Key.BackSlash); // Varies by keyboard, \| on Win2K/US
|
||||
Add(Code.SDL_SCANCODE_RIGHTBRACKET, Key.BracketRight); // Varies by keyboard, ]} on Win2K/US
|
||||
Add(Code.SDL_SCANCODE_APOSTROPHE, Key.Quote); // Varies by keyboard, '" on Win2K/US
|
||||
Add(Code.SDL_SCANCODE_EQUALS, Key.Plus);
|
||||
Add(Code.SDL_SCANCODE_COMMA, Key.Comma); // Invariant: ,
|
||||
Add(Code.SDL_SCANCODE_MINUS, Key.Minus); // Invariant: -
|
||||
Add(Code.SDL_SCANCODE_PERIOD, Key.Period); // Invariant: .
|
||||
Add(Code.SEMICOLON, Key.Semicolon); // Varies by keyboard, ;: on Win2K/US
|
||||
Add(Code.SLASH, Key.Slash); // Varies by keyboard, /? on Win2K/US
|
||||
Add(Code.GRAVE, Key.Tilde); // Varies by keyboard, `~ on Win2K/US
|
||||
Add(Code.LEFTBRACKET, Key.BracketLeft); // Varies by keyboard, [{ on Win2K/US
|
||||
Add(Code.BACKSLASH, Key.BackSlash); // Varies by keyboard, \| on Win2K/US
|
||||
Add(Code.RIGHTBRACKET, Key.BracketRight); // Varies by keyboard, ]} on Win2K/US
|
||||
Add(Code.APOSTROPHE, Key.Quote); // Varies by keyboard, '" on Win2K/US
|
||||
Add(Code.EQUALS, Key.Plus);
|
||||
Add(Code.COMMA, Key.Comma); // Invariant: ,
|
||||
Add(Code.MINUS, Key.Minus); // Invariant: -
|
||||
Add(Code.PERIOD, Key.Period); // Invariant: .
|
||||
|
||||
Add(Code.SDL_SCANCODE_HOME, Key.Home);
|
||||
Add(Code.SDL_SCANCODE_END, Key.End);
|
||||
Add(Code.SDL_SCANCODE_DELETE, Key.Delete);
|
||||
Add(Code.SDL_SCANCODE_PAGEUP, Key.PageUp);
|
||||
Add(Code.SDL_SCANCODE_PAGEDOWN, Key.PageDown);
|
||||
Add(Code.SDL_SCANCODE_PAUSE, Key.Pause);
|
||||
Add(Code.SDL_SCANCODE_NUMLOCKCLEAR, Key.NumLock);
|
||||
Add(Code.HOME, Key.Home);
|
||||
Add(Code.END, Key.End);
|
||||
Add(Code.DELETE, Key.Delete);
|
||||
Add(Code.PAGEUP, Key.PageUp);
|
||||
Add(Code.PAGEDOWN, Key.PageDown);
|
||||
Add(Code.PAUSE, Key.Pause);
|
||||
Add(Code.NUMLOCKCLEAR, Key.NumLock);
|
||||
|
||||
Add(Code.SDL_SCANCODE_SCROLLLOCK, Key.ScrollLock);
|
||||
Add(Code.SDL_SCANCODE_PRINTSCREEN, Key.PrintScreen);
|
||||
Add(Code.SDL_SCANCODE_CLEAR, Key.Clear);
|
||||
Add(Code.SDL_SCANCODE_INSERT, Key.Insert);
|
||||
Add(Code.SCROLLLOCK, Key.ScrollLock);
|
||||
Add(Code.PRINTSCREEN, Key.PrintScreen);
|
||||
Add(Code.CLEAR, Key.Clear);
|
||||
Add(Code.INSERT, Key.Insert);
|
||||
|
||||
Add(Code.SDL_SCANCODE_SLEEP, Key.Sleep);
|
||||
Add(Code.SLEEP, Key.Sleep);
|
||||
|
||||
// Keypad
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
Add(Code.SDL_SCANCODE_KP_1 + i, Key.Keypad1 + i);
|
||||
Add(Code.KP_1 + i, Key.Keypad1 + i);
|
||||
}
|
||||
Add(Code.SDL_SCANCODE_KP_0, Key.Keypad0); // Note: SDL2 goes KP_1..KP_9, then KP_0
|
||||
Add(Code.KP_0, Key.Keypad0); // Note: SDL2 goes KP_1..KP_9, then KP_0
|
||||
|
||||
Add(Code.SDL_SCANCODE_KP_DECIMAL, Key.KeypadDecimal);
|
||||
Add(Code.SDL_SCANCODE_KP_PLUS, Key.KeypadAdd);
|
||||
Add(Code.SDL_SCANCODE_KP_MINUS, Key.KeypadSubtract);
|
||||
Add(Code.SDL_SCANCODE_KP_DIVIDE, Key.KeypadDivide);
|
||||
Add(Code.SDL_SCANCODE_KP_MULTIPLY, Key.KeypadMultiply);
|
||||
Add(Code.KP_DECIMAL, Key.KeypadDecimal);
|
||||
Add(Code.KP_PLUS, Key.KeypadAdd);
|
||||
Add(Code.KP_MINUS, Key.KeypadSubtract);
|
||||
Add(Code.KP_DIVIDE, Key.KeypadDivide);
|
||||
Add(Code.KP_MULTIPLY, Key.KeypadMultiply);
|
||||
|
||||
// Navigation
|
||||
Add(Code.SDL_SCANCODE_UP, Key.Up);
|
||||
Add(Code.SDL_SCANCODE_DOWN, Key.Down);
|
||||
Add(Code.SDL_SCANCODE_LEFT, Key.Left);
|
||||
Add(Code.SDL_SCANCODE_RIGHT, Key.Right);
|
||||
Add(Code.UP, Key.Up);
|
||||
Add(Code.DOWN, Key.Down);
|
||||
Add(Code.LEFT, Key.Left);
|
||||
Add(Code.RIGHT, Key.Right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,29 +64,29 @@ namespace OpenTK.Platform.SDL2
|
|||
// Fixme: this does not appear to work as expected.
|
||||
void UpdateModifiers()
|
||||
{
|
||||
SDL.SDL_Keymod mod = SDL.SDL_GetModState();
|
||||
Keymod mod = SDL.GetModState();
|
||||
|
||||
state.SetKeyState(Key.LAlt, (byte)SDL.SDL_Scancode.SDL_SCANCODE_LALT, (mod & SDL.SDL_Keymod.KMOD_LALT) != 0);
|
||||
state.SetKeyState(Key.RAlt, (byte)SDL.SDL_Scancode.SDL_SCANCODE_RALT, (mod & SDL.SDL_Keymod.KMOD_RALT) != 0);
|
||||
state.SetKeyState(Key.LControl, (byte)SDL.SDL_Scancode.SDL_SCANCODE_LCTRL, (mod & SDL.SDL_Keymod.KMOD_LCTRL) != 0);
|
||||
state.SetKeyState(Key.RControl, (byte)SDL.SDL_Scancode.SDL_SCANCODE_RCTRL, (mod & SDL.SDL_Keymod.KMOD_RCTRL) != 0);
|
||||
state.SetKeyState(Key.LShift, (byte)SDL.SDL_Scancode.SDL_SCANCODE_LSHIFT, (mod & SDL.SDL_Keymod.KMOD_LSHIFT) != 0);
|
||||
state.SetKeyState(Key.RShift, (byte)SDL.SDL_Scancode.SDL_SCANCODE_RSHIFT, (mod & SDL.SDL_Keymod.KMOD_RSHIFT) != 0);
|
||||
state.SetKeyState(Key.Menu, (byte)SDL.SDL_Scancode.SDL_SCANCODE_APPLICATION, (mod & SDL.SDL_Keymod.KMOD_GUI) != 0);
|
||||
state.SetKeyState(Key.CapsLock, (byte)SDL.SDL_Scancode.SDL_SCANCODE_CAPSLOCK, (mod & SDL.SDL_Keymod.KMOD_CAPS) != 0);
|
||||
state.SetKeyState(Key.NumLock, (byte)SDL.SDL_Scancode.SDL_SCANCODE_NUMLOCKCLEAR, (mod & SDL.SDL_Keymod.KMOD_NUM) != 0);
|
||||
//state.SetKeyState(Key., (byte)SDL.SDL_Scancode.SDL_SCANCODE_MODE, (mod & SDL.SDL_Keymod.KMOD_MODE) != 0);
|
||||
state.SetKeyState(Key.LAlt, (byte)Scancode.LALT, (mod & Keymod.LALT) != 0);
|
||||
state.SetKeyState(Key.RAlt, (byte)Scancode.RALT, (mod & Keymod.RALT) != 0);
|
||||
state.SetKeyState(Key.LControl, (byte)Scancode.LCTRL, (mod & Keymod.LCTRL) != 0);
|
||||
state.SetKeyState(Key.RControl, (byte)Scancode.RCTRL, (mod & Keymod.CTRL) != 0);
|
||||
state.SetKeyState(Key.LShift, (byte)Scancode.LSHIFT, (mod & Keymod.LSHIFT) != 0);
|
||||
state.SetKeyState(Key.RShift, (byte)Scancode.RSHIFT, (mod & Keymod.RSHIFT) != 0);
|
||||
state.SetKeyState(Key.Menu, (byte)Scancode.APPLICATION, (mod & Keymod.GUI) != 0);
|
||||
state.SetKeyState(Key.CapsLock, (byte)Scancode.CAPSLOCK, (mod & Keymod.CAPS) != 0);
|
||||
state.SetKeyState(Key.NumLock, (byte)Scancode.NUMLOCKCLEAR, (mod & Keymod.NUM) != 0);
|
||||
//state.SetKeyState(Key., (byte)Scancode.MODE, (mod & Keymod.MODE) != 0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Members
|
||||
|
||||
internal void ProcessKeyboardEvent(SDL.SDL_KeyboardEvent e)
|
||||
internal void ProcessKeyboardEvent(KeyboardEvent e)
|
||||
{
|
||||
Key key;
|
||||
bool pressed = e.state != 0;
|
||||
var scancode = e.keysym.scancode;
|
||||
bool pressed = e.State != 0;
|
||||
var scancode = e.Keysym.Scancode;
|
||||
if (KeyMap.TryGetValue(scancode, out key))
|
||||
{
|
||||
state.SetKeyState(key, (byte)scancode, pressed);
|
||||
|
|
|
@ -54,23 +54,23 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
#region Private Members
|
||||
|
||||
MouseButton TranslateButton(uint button)
|
||||
MouseButton TranslateButton(Button button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case SDL.SDL_BUTTON_LEFT:
|
||||
case Button.Left:
|
||||
return MouseButton.Left;
|
||||
|
||||
case SDL.SDL_BUTTON_RIGHT:
|
||||
case Button.Right:
|
||||
return MouseButton.Right;
|
||||
|
||||
case SDL.SDL_BUTTON_MIDDLE:
|
||||
case Button.Middle:
|
||||
return MouseButton.Middle;
|
||||
|
||||
case SDL.SDL_BUTTON_X1:
|
||||
case Button.X1:
|
||||
return MouseButton.Button1;
|
||||
|
||||
case SDL.SDL_BUTTON_X2:
|
||||
case Button.X2:
|
||||
return MouseButton.Button2;
|
||||
|
||||
default:
|
||||
|
@ -95,24 +95,24 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
#region Public Members
|
||||
|
||||
public void ProcessWheelEvent(SDL.SDL_MouseWheelEvent wheel)
|
||||
public void ProcessWheelEvent(MouseWheelEvent wheel)
|
||||
{
|
||||
state.WheelPrecise += wheel.y;
|
||||
mice[0].WheelPrecise += wheel.y;
|
||||
state.WheelPrecise += wheel.Y;
|
||||
mice[0].WheelPrecise += wheel.Y;
|
||||
}
|
||||
|
||||
public void ProcessMouseEvent(SDL.SDL_MouseMotionEvent motion)
|
||||
public void ProcessMouseEvent(MouseMotionEvent motion)
|
||||
{
|
||||
state.X += motion.xrel;
|
||||
state.Y += motion.yrel;
|
||||
mice[0].Position = new Point(motion.x, motion.y);
|
||||
state.X += motion.Xrel;
|
||||
state.Y += motion.Yrel;
|
||||
mice[0].Position = new Point(motion.X, motion.Y);
|
||||
}
|
||||
|
||||
public void ProcessMouseEvent(SDL.SDL_MouseButtonEvent button)
|
||||
public void ProcessMouseEvent(MouseButtonEvent button)
|
||||
{
|
||||
bool pressed = button.state == SDL.SDL_PRESSED;
|
||||
SetButtonState(TranslateButton(button.button), pressed);
|
||||
mice[0][TranslateButton(button.button)] = pressed;
|
||||
bool pressed = button.State == State.Pressed;
|
||||
SetButtonState(TranslateButton(button.Button), pressed);
|
||||
mice[0][TranslateButton(button.Button)] = pressed;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -146,7 +146,7 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
public void SetPosition(double x, double y)
|
||||
{
|
||||
SDL.SDL_WarpMouseInWindow(IntPtr.Zero, (int)x, (int)y);
|
||||
SDL.WarpMouseInWindow(IntPtr.Zero, (int)x, (int)y);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
readonly IInputDriver input_driver = new Sdl2InputDriver();
|
||||
|
||||
readonly SDL.SDL_EventFilter EventFilterDelegate = FilterEvents;
|
||||
readonly EventFilter EventFilterDelegate = FilterEvents;
|
||||
|
||||
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
|
||||
new Dictionary<uint, Sdl2NativeWindow>();
|
||||
|
@ -73,24 +73,24 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
var bounds = device.Bounds;
|
||||
var flags = TranslateFlags(options);
|
||||
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL;
|
||||
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;
|
||||
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN;
|
||||
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI;
|
||||
flags |= WindowFlags.OPENGL;
|
||||
flags |= WindowFlags.RESIZABLE;
|
||||
flags |= WindowFlags.HIDDEN;
|
||||
flags |= WindowFlags.ALLOW_HIGHDPI;
|
||||
|
||||
if ((flags & SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) != 0 ||
|
||||
(flags & SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN) != 0)
|
||||
if ((flags & WindowFlags.FULLSCREEN_DESKTOP) != 0 ||
|
||||
(flags & WindowFlags.FULLSCREEN) != 0)
|
||||
window_state = WindowState.Fullscreen;
|
||||
|
||||
IntPtr handle;
|
||||
lock (SDL.Sync)
|
||||
{
|
||||
handle = SDL.SDL_CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
||||
SDL.SDL_AddEventWatch(EventFilterDelegate, handle);
|
||||
SDL.SDL_PumpEvents();
|
||||
handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
||||
SDL.AddEventWatch(EventFilterDelegate, handle);
|
||||
SDL.PumpEvents();
|
||||
}
|
||||
window = new Sdl2WindowInfo(handle, null);
|
||||
window_id = SDL.SDL_GetWindowID(handle);
|
||||
window_id = SDL.GetWindowID(handle);
|
||||
windows.Add(window_id, this);
|
||||
window_title = title;
|
||||
|
||||
|
@ -100,19 +100,19 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
#region Private Members
|
||||
|
||||
static SDL.SDL_WindowFlags TranslateFlags(GameWindowFlags flags)
|
||||
static WindowFlags TranslateFlags(GameWindowFlags flags)
|
||||
{
|
||||
switch (flags)
|
||||
{
|
||||
case GameWindowFlags.Fullscreen:
|
||||
return SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
return WindowFlags.FULLSCREEN_DESKTOP;
|
||||
|
||||
default:
|
||||
return (SDL.SDL_WindowFlags)0;
|
||||
return WindowFlags.Default;
|
||||
}
|
||||
}
|
||||
|
||||
static Key TranslateKey(SDL.SDL_Scancode scan)
|
||||
static Key TranslateKey(Scancode scan)
|
||||
{
|
||||
Key result = Key.Unknown;
|
||||
if (map.ContainsKey(scan))
|
||||
|
@ -122,9 +122,9 @@ namespace OpenTK.Platform.SDL2
|
|||
return result;
|
||||
}
|
||||
|
||||
static Key TranslateKey(SDL.SDL_Keycode key)
|
||||
static Key TranslateKey(Keycode key)
|
||||
{
|
||||
SDL.SDL_Scancode scan = SDL.SDL_GetScancodeFromKey(key);
|
||||
Scancode scan = SDL.GetScancodeFromKey(key);
|
||||
return TranslateKey(scan);
|
||||
}
|
||||
|
||||
|
@ -135,53 +135,53 @@ namespace OpenTK.Platform.SDL2
|
|||
try
|
||||
{
|
||||
Sdl2NativeWindow window = null;
|
||||
SDL.SDL_Event ev = *(SDL.SDL_Event*)e;
|
||||
Event ev = *(Event*)e;
|
||||
|
||||
switch (ev.type)
|
||||
switch (ev.Type)
|
||||
{
|
||||
case SDL.SDL_EventType.SDL_WINDOWEVENT:
|
||||
if (windows.TryGetValue(ev.window.windowID, out window))
|
||||
case EventType.WINDOWEVENT:
|
||||
if (windows.TryGetValue(ev.Window.WindowID, out window))
|
||||
{
|
||||
ProcessWindowEvent(window, ev.window);
|
||||
ProcessWindowEvent(window, ev.Window);
|
||||
processed = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_KEYDOWN:
|
||||
case SDL.SDL_EventType.SDL_KEYUP:
|
||||
if (windows.TryGetValue(ev.key.windowID, out window))
|
||||
case EventType.KEYDOWN:
|
||||
case EventType.KEYUP:
|
||||
if (windows.TryGetValue(ev.Key.WindowID, out window))
|
||||
{
|
||||
ProcessKeyEvent(window, ev);
|
||||
processed = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
|
||||
case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
|
||||
if (windows.TryGetValue(ev.button.windowID, out window))
|
||||
case EventType.MOUSEBUTTONDOWN:
|
||||
case EventType.MOUSEBUTTONUP:
|
||||
if (windows.TryGetValue(ev.Button.WindowID, out window))
|
||||
{
|
||||
ProcessButtonEvent(window, ev);
|
||||
processed = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_MOUSEMOTION:
|
||||
if (windows.TryGetValue(ev.motion.windowID, out window))
|
||||
case EventType.MOUSEMOTION:
|
||||
if (windows.TryGetValue(ev.Motion.WindowID, out window))
|
||||
{
|
||||
ProcessMotionEvent(window, ev);
|
||||
processed = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
|
||||
if (windows.TryGetValue(ev.wheel.windowID, out window))
|
||||
case EventType.MOUSEWHEEL:
|
||||
if (windows.TryGetValue(ev.Wheel.WindowID, out window))
|
||||
{
|
||||
ProcessWheelEvent(window, ev);
|
||||
processed = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_QUIT:
|
||||
case EventType.QUIT:
|
||||
Debug.WriteLine("Sdl2 application quit");
|
||||
break;
|
||||
}
|
||||
|
@ -194,68 +194,43 @@ namespace OpenTK.Platform.SDL2
|
|||
return processed ? 0 : 1;
|
||||
}
|
||||
|
||||
static void ProcessButtonEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
|
||||
static void ProcessButtonEvent(Sdl2NativeWindow window, Event ev)
|
||||
{
|
||||
bool button_pressed = ev.button.state == SDL.SDL_PRESSED;
|
||||
bool button_pressed = ev.Button.State == State.Pressed;
|
||||
|
||||
// We need MouseUp events to be reported even if they occur
|
||||
// outside the window. SetWindowGrab ensures we get them.
|
||||
if (window.CursorVisible)
|
||||
{
|
||||
SDL.SDL_SetWindowGrab(window.window.Handle,
|
||||
button_pressed ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);
|
||||
}
|
||||
|
||||
switch (ev.button.button)
|
||||
{/*
|
||||
|
||||
case (byte)SDL.SDL_BUTTON_LEFT:
|
||||
window.mouse[MouseButton.Left] = button_pressed;
|
||||
break;
|
||||
|
||||
case (byte)SDL.SDL_BUTTON_MIDDLE:
|
||||
window.mouse[MouseButton.Middle] = button_pressed;
|
||||
break;
|
||||
|
||||
case (byte)SDL.SDL_BUTTON_RIGHT:
|
||||
window.mouse[MouseButton.Right] = button_pressed;
|
||||
break;
|
||||
|
||||
case (byte)SDL.SDL_BUTTON_X1:
|
||||
window.mouse[MouseButton.Button1] = button_pressed;
|
||||
break;
|
||||
|
||||
case (byte)SDL.SDL_BUTTON_X2:
|
||||
window.mouse[MouseButton.Button2] = button_pressed;
|
||||
break;
|
||||
*/
|
||||
SDL.SetWindowGrab(window.window.Handle,
|
||||
button_pressed ? true : false);
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessKeyEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
|
||||
static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
|
||||
{
|
||||
bool key_pressed = ev.key.state == SDL.SDL_PRESSED;
|
||||
var key = ev.key.keysym;
|
||||
bool key_pressed = ev.Key.State == State.Pressed;
|
||||
var key = ev.Key.Keysym;
|
||||
//window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
|
||||
}
|
||||
|
||||
static void ProcessMotionEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
|
||||
static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev)
|
||||
{
|
||||
float scale = window.ClientSize.Width / (float)window.Size.Width;
|
||||
//window.mouse.Position = new Point(
|
||||
// (int)(ev.motion.x * scale), (int)(ev.motion.y * scale));
|
||||
}
|
||||
|
||||
static void ProcessWheelEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
|
||||
static void ProcessWheelEvent(Sdl2NativeWindow window, Event ev)
|
||||
{
|
||||
//window.mouse.Wheel += ev.wheel.y;
|
||||
}
|
||||
|
||||
static void ProcessWindowEvent(Sdl2NativeWindow window, SDL.SDL_WindowEvent e)
|
||||
static void ProcessWindowEvent(Sdl2NativeWindow window, WindowEvent e)
|
||||
{
|
||||
switch (e.windowEvent)
|
||||
switch (e.Event)
|
||||
{
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE:
|
||||
case WindowEventID.CLOSE:
|
||||
var close_args = new System.ComponentModel.CancelEventArgs();
|
||||
window.Closing(window, close_args);
|
||||
if (!close_args.Cancel)
|
||||
|
@ -265,66 +240,66 @@ namespace OpenTK.Platform.SDL2
|
|||
}
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER:
|
||||
case WindowEventID.ENTER:
|
||||
window.MouseEnter(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE:
|
||||
case WindowEventID.LEAVE:
|
||||
window.MouseLeave(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED:
|
||||
case WindowEventID.EXPOSED:
|
||||
// do nothing
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
case WindowEventID.FOCUS_GAINED:
|
||||
window.is_focused = true;
|
||||
window.FocusedChanged(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
case WindowEventID.FOCUS_LOST:
|
||||
window.is_focused = false;
|
||||
window.FocusedChanged(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN:
|
||||
case WindowEventID.HIDDEN:
|
||||
window.is_visible = false;
|
||||
window.VisibleChanged(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN:
|
||||
case WindowEventID.SHOWN:
|
||||
window.is_visible = true;
|
||||
window.VisibleChanged(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MAXIMIZED:
|
||||
case WindowEventID.MAXIMIZED:
|
||||
window.previous_window_state = window.window_state;
|
||||
window.window_state = OpenTK.WindowState.Maximized;
|
||||
window.WindowStateChanged(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED:
|
||||
case WindowEventID.MINIMIZED:
|
||||
window.previous_window_state = window.window_state;
|
||||
window.window_state = OpenTK.WindowState.Minimized;
|
||||
window.WindowStateChanged(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED:
|
||||
case WindowEventID.RESTORED:
|
||||
window.window_state = window.previous_window_state;
|
||||
window.WindowStateChanged(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED:
|
||||
case WindowEventID.MOVED:
|
||||
window.Move(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED:
|
||||
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
case WindowEventID.RESIZED:
|
||||
case WindowEventID.SIZE_CHANGED:
|
||||
window.Resize(window, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.Print("SDL2 unhandled event: {0}", e.type);
|
||||
Debug.Print("SDL2 unhandled event: {0}", e.Type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -337,12 +312,12 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
lock (SDL.Sync)
|
||||
{
|
||||
SDL.SDL_DelEventWatch(EventFilterDelegate, window.Handle);
|
||||
SDL.DelEventWatch(EventFilterDelegate, window.Handle);
|
||||
if (windows.ContainsKey(window_id))
|
||||
{
|
||||
windows.Remove(window_id);
|
||||
}
|
||||
SDL.SDL_DestroyWindow(window.Handle);
|
||||
SDL.DestroyWindow(window.Handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,19 +327,17 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
void GrabCursor(bool grab)
|
||||
{
|
||||
SDL.SDL_ShowCursor(grab ? 0 : 1);
|
||||
SDL.SDL_SetWindowGrab(window.Handle,
|
||||
grab ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);
|
||||
SDL.SDL_SetRelativeMouseMode(
|
||||
grab ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);
|
||||
SDL.ShowCursor(!grab);
|
||||
SDL.SetWindowGrab(window.Handle, grab);
|
||||
SDL.SetRelativeMouseMode(grab);
|
||||
}
|
||||
|
||||
// Hack to force WindowState events to be pumped
|
||||
void HideShowWindowHack()
|
||||
{
|
||||
SDL.SDL_HideWindow(window.Handle);
|
||||
SDL.HideWindow(window.Handle);
|
||||
ProcessEvents();
|
||||
SDL.SDL_ShowWindow(window.Handle);
|
||||
SDL.ShowWindow(window.Handle);
|
||||
ProcessEvents();
|
||||
}
|
||||
|
||||
|
@ -376,16 +349,16 @@ namespace OpenTK.Platform.SDL2
|
|||
switch (state)
|
||||
{
|
||||
case WindowState.Fullscreen:
|
||||
SDL.SDL_SetWindowFullscreen(window.Handle, 0);
|
||||
SDL.SetWindowFullscreen(window.Handle, 0);
|
||||
break;
|
||||
|
||||
case WindowState.Maximized:
|
||||
SDL.SDL_RestoreWindow(window.Handle);
|
||||
SDL.RestoreWindow(window.Handle);
|
||||
HideShowWindowHack();
|
||||
break;
|
||||
|
||||
case WindowState.Minimized:
|
||||
SDL.SDL_RestoreWindow(window.Handle);
|
||||
SDL.RestoreWindow(window.Handle);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -423,13 +396,13 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
Debug.Print("SDL2 destroying window {0}", window.Handle);
|
||||
|
||||
SDL.SDL_Event e = new SDL.SDL_Event();
|
||||
e.type = SDL.SDL_EventType.SDL_WINDOWEVENT;
|
||||
e.window.windowEvent = SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE;
|
||||
e.window.windowID = window_id;
|
||||
Event e = new Event();
|
||||
e.Type = EventType.WINDOWEVENT;
|
||||
e.Window.Event = WindowEventID.CLOSE;
|
||||
e.Window.WindowID = window_id;
|
||||
lock (SDL.Sync)
|
||||
{
|
||||
SDL.SDL_PushEvent(ref e);
|
||||
SDL.PushEvent(ref e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -441,7 +414,7 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
if (Exists)
|
||||
{
|
||||
SDL.SDL_PumpEvents();
|
||||
SDL.PumpEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -484,15 +457,15 @@ namespace OpenTK.Platform.SDL2
|
|||
ImageLockMode.ReadWrite,
|
||||
PixelFormat.Format32bppArgb);
|
||||
|
||||
IntPtr surface = SDL.SDL_CreateRGBSurfaceFrom(
|
||||
IntPtr surface = SDL.CreateRGBSurfaceFrom(
|
||||
data.Scan0, data.Width, data.Height, 32, data.Stride,
|
||||
0x00ff0000u, 0x0000ff00u, 0x000000ffu, 0xff000000u);
|
||||
|
||||
// Update the window icon
|
||||
SDL.SDL_SetWindowIcon(window.Handle, surface);
|
||||
SDL.SetWindowIcon(window.Handle, surface);
|
||||
|
||||
// Free the SDL surface as it is no longer needed
|
||||
SDL.SDL_FreeSurface(surface);
|
||||
SDL.FreeSurface(surface);
|
||||
bmp.UnlockBits(data);
|
||||
}
|
||||
|
||||
|
@ -500,7 +473,7 @@ namespace OpenTK.Platform.SDL2
|
|||
else
|
||||
{
|
||||
// Clear the window icon
|
||||
SDL.SDL_SetWindowIcon(window.Handle, IntPtr.Zero);
|
||||
SDL.SetWindowIcon(window.Handle, IntPtr.Zero);
|
||||
}
|
||||
|
||||
icon = value;
|
||||
|
@ -518,7 +491,7 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
if (Exists)
|
||||
{
|
||||
return SDL.SDL_GetWindowTitle(window.Handle);
|
||||
return SDL.GetWindowTitle(window.Handle);
|
||||
}
|
||||
return String.Empty;
|
||||
}
|
||||
|
@ -529,7 +502,7 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
if (Exists)
|
||||
{
|
||||
SDL.SDL_SetWindowTitle(window.Handle, value);
|
||||
SDL.SetWindowTitle(window.Handle, value);
|
||||
window_title = value;
|
||||
}
|
||||
}
|
||||
|
@ -557,9 +530,9 @@ namespace OpenTK.Platform.SDL2
|
|||
if (Exists)
|
||||
{
|
||||
if (value)
|
||||
SDL.SDL_ShowWindow(window.Handle);
|
||||
SDL.ShowWindow(window.Handle);
|
||||
else
|
||||
SDL.SDL_HideWindow(window.Handle);
|
||||
SDL.HideWindow(window.Handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -600,14 +573,14 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
case WindowState.Fullscreen:
|
||||
RestoreWindow();
|
||||
if (SDL.SDL_SetWindowFullscreen(window.Handle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) < 0)
|
||||
if (SDL.SetWindowFullscreen(window.Handle, (uint)WindowFlags.FULLSCREEN_DESKTOP) < 0)
|
||||
{
|
||||
if (SDL.SDL_SetWindowFullscreen(window.Handle, (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN) < 0)
|
||||
if (SDL.SetWindowFullscreen(window.Handle, (uint)WindowFlags.FULLSCREEN) < 0)
|
||||
{
|
||||
Debug.Print("SDL2 failed to enter fullscreen mode: {0}", SDL.SDL_GetError());
|
||||
Debug.Print("SDL2 failed to enter fullscreen mode: {0}", SDL.GetError());
|
||||
}
|
||||
}
|
||||
SDL.SDL_RaiseWindow(window.Handle);
|
||||
SDL.RaiseWindow(window.Handle);
|
||||
// There is no "fullscreen" message in the event loop
|
||||
// so we have to mark that ourselves
|
||||
window_state = WindowState.Fullscreen;
|
||||
|
@ -615,12 +588,12 @@ namespace OpenTK.Platform.SDL2
|
|||
|
||||
case WindowState.Maximized:
|
||||
RestoreWindow();
|
||||
SDL.SDL_MaximizeWindow(window.Handle);
|
||||
SDL.MaximizeWindow(window.Handle);
|
||||
HideShowWindowHack();
|
||||
break;
|
||||
|
||||
case WindowState.Minimized:
|
||||
SDL.SDL_MinimizeWindow(window.Handle);
|
||||
SDL.MinimizeWindow(window.Handle);
|
||||
break;
|
||||
|
||||
case WindowState.Normal:
|
||||
|
@ -654,12 +627,12 @@ namespace OpenTK.Platform.SDL2
|
|||
switch (value)
|
||||
{
|
||||
case WindowBorder.Resizable:
|
||||
SDL.SDL_SetWindowBordered(window.Handle, SDL.SDL_bool.SDL_TRUE);
|
||||
SDL.SetWindowBordered(window.Handle, true);
|
||||
window_border = WindowBorder.Resizable;
|
||||
break;
|
||||
|
||||
case WindowBorder.Hidden:
|
||||
SDL.SDL_SetWindowBordered(window.Handle, SDL.SDL_bool.SDL_FALSE);
|
||||
SDL.SetWindowBordered(window.Handle, false);
|
||||
window_border = WindowBorder.Hidden;
|
||||
break;
|
||||
|
||||
|
@ -700,7 +673,7 @@ namespace OpenTK.Platform.SDL2
|
|||
if (Exists)
|
||||
{
|
||||
int x, y;
|
||||
SDL.SDL_GetWindowPosition(window.Handle, out x, out y);
|
||||
SDL.GetWindowPosition(window.Handle, out x, out y);
|
||||
return new Point(x, y);
|
||||
}
|
||||
return new Point();
|
||||
|
@ -712,7 +685,7 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
if (Exists)
|
||||
{
|
||||
SDL.SDL_SetWindowPosition(window.Handle, value.X, value.Y);
|
||||
SDL.SetWindowPosition(window.Handle, value.X, value.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -727,7 +700,7 @@ namespace OpenTK.Platform.SDL2
|
|||
if (Exists)
|
||||
{
|
||||
int w, h;
|
||||
SDL.SDL_GetWindowSize(window.Handle, out w, out h);
|
||||
SDL.GetWindowSize(window.Handle, out w, out h);
|
||||
return new Size(w, h);
|
||||
}
|
||||
return new Size();
|
||||
|
@ -739,7 +712,7 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
if (Exists)
|
||||
{
|
||||
SDL.SDL_SetWindowSize(window.Handle, value.Width, value.Height);
|
||||
SDL.SetWindowSize(window.Handle, value.Width, value.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -814,11 +787,11 @@ namespace OpenTK.Platform.SDL2
|
|||
{
|
||||
// SDL > 2.0.0 supports SDL_GL_GetDrawableSize for
|
||||
// hidpi windows.
|
||||
SDL.SDL_GL_GetDrawableSize(window.Handle, out w, out h);
|
||||
SDL.GL.GetDrawableSize(window.Handle, out w, out h);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL.SDL_GetWindowSize(window.Handle, out w, out h);
|
||||
SDL.GetWindowSize(window.Handle, out w, out h);
|
||||
}
|
||||
return new Size(w, h);
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ namespace OpenTK.Platform
|
|||
public static IWindowInfo CreateSdl2WindowInfo(IntPtr windowHandle)
|
||||
{
|
||||
return new OpenTK.Platform.SDL2.Sdl2WindowInfo(
|
||||
SDL2.SDL.SDL_CreateWindowFrom(windowHandle), null);
|
||||
SDL2.SDL.CreateWindowFrom(windowHandle), null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Loading…
Reference in a new issue