From d787656328f9316cb0b1c8791a45ab7790557b93 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Sun, 27 Apr 2014 21:09:51 +0200 Subject: [PATCH] [SDL] Fixed cursor support SDL.CreateColorCursor takes 3 arguments, not 5. --- Source/OpenTK/Platform/SDL2/Sdl2.cs | 6 ++++- .../OpenTK/Platform/SDL2/Sdl2NativeWindow.cs | 26 ++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Source/OpenTK/Platform/SDL2/Sdl2.cs b/Source/OpenTK/Platform/SDL2/Sdl2.cs index 021c9fad..11c8c468 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2.cs @@ -83,7 +83,7 @@ namespace OpenTK.Platform.SDL2 [SuppressUnmanagedCodeSecurity] [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_CreateColorCursor", ExactSpelling = true)] - public static extern Cursor CreateColorCursor(Surface surface, int w, int h, int hot_x, int hot_y); + public static extern Cursor CreateColorCursor(Surface surface, int hot_x, int hot_y); [SuppressUnmanagedCodeSecurity] [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_FreeCursor", ExactSpelling = true)] @@ -242,6 +242,10 @@ namespace OpenTK.Platform.SDL2 [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetModState", ExactSpelling = true)] public static extern Keymod GetModState(); + [SuppressUnmanagedCodeSecurity] + [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetMouseState", ExactSpelling = true)] + public static extern ButtonFlags GetMouseState(out int hx, out int hy); + [SuppressUnmanagedCodeSecurity] [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_GetNumDisplayModes", ExactSpelling = true)] public static extern int GetNumDisplayModes(int displayIndex); diff --git a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs index 25760b5f..b6013f65 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs @@ -498,21 +498,29 @@ namespace OpenTK.Platform.SDL2 IntPtr cursor_surface = SDL.CreateRGBSurfaceFrom( new IntPtr(pixels), - cursor.Width, - cursor.Height, + value.Width, + value.Height, 32, - cursor.Width * 4, + value.Width * 4, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); - sdl_cursor = SDL.CreateColorCursor( - cursor_surface, - cursor.Width, - cursor.Height, - cursor.X, - cursor.Y); + if (cursor_surface == IntPtr.Zero) + { + Debug.Print("[SDL2] Failed to create cursor surface. Error: {0}", + SDL.GetError()); + return; + } + + sdl_cursor = SDL.CreateColorCursor(cursor_surface, value.X, value.Y); + if (sdl_cursor == IntPtr.Zero) + { + Debug.Print("[SDL2] Failed to create cursor. Error: {0}", + SDL.GetError()); + return; + } if (sdl_cursor != IntPtr.Zero) {