Conflicts:
	Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs
This commit is contained in:
Stefanos A 2013-10-03 15:11:59 +02:00
commit be7200d37e
2 changed files with 274 additions and 195 deletions

View file

@ -38,6 +38,8 @@ namespace OpenTK.Platform.SDL2
{
class Sdl2NativeWindow : INativeWindow, IInputDriver
{
readonly object sync = new object();
Sdl2WindowInfo window;
uint window_id;
bool is_visible;
@ -65,6 +67,8 @@ namespace OpenTK.Platform.SDL2
public Sdl2NativeWindow(int x, int y, int width, int height,
string title, GameWindowFlags options, DisplayDevice device)
{
lock (sync)
{
var bounds = device.Bounds;
var flags = TranslateFlags(options);
@ -80,31 +84,29 @@ namespace OpenTK.Platform.SDL2
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();
}
window = new Sdl2WindowInfo(handle, null);
window_id = SDL.SDL_GetWindowID(handle);
windows.Add(window_id, this);
window_title = title;
keyboard.Description = "Standard Windows keyboard";
keyboard.Description = "Standard keyboard";
keyboard.NumberOfFunctionKeys = 12;
keyboard.NumberOfKeys = 101;
keyboard.NumberOfLeds = 3;
mouse.Description = "Standard Windows mouse";
mouse.Description = "Standard mouse";
mouse.NumberOfButtons = 3;
mouse.NumberOfWheels = 1;
keyboards.Add(keyboard);
mice.Add(mouse);
lock (SDL.Sync)
{
SDL.SDL_AddEventWatch(EventFilterDelegate, handle);
}
exists = true;
}
}
#region Private Members
@ -142,7 +144,6 @@ namespace OpenTK.Platform.SDL2
try
{
Sdl2NativeWindow window = null;
SDL.SDL_Event ev = *(SDL.SDL_Event*)e;
@ -191,12 +192,7 @@ namespace OpenTK.Platform.SDL2
break;
case SDL.SDL_EventType.SDL_QUIT:
/*
if (windows.TryGetValue(ev.quit.windowID, out window))
{
}
*/
Debug.WriteLine("Sdl2 application quit");
break;
}
}
@ -271,7 +267,7 @@ namespace OpenTK.Platform.SDL2
if (!close_args.Cancel)
{
window.Closed(window, EventArgs.Empty);
window.DestroyWindow();
//window.DestroyWindow();
}
break;
@ -347,12 +343,12 @@ namespace OpenTK.Platform.SDL2
{
lock (SDL.Sync)
{
SDL.SDL_DestroyWindow(window.Handle);
SDL.SDL_DelEventWatch(EventFilterDelegate, window.Handle);
if (windows.ContainsKey(window_id))
{
windows.Remove(window_id);
}
SDL.SDL_DestroyWindow(window.Handle);
}
}
@ -426,12 +422,14 @@ namespace OpenTK.Platform.SDL2
public event EventHandler<EventArgs> MouseLeave = delegate { };
public void Close()
{
lock (sync)
{
if (Exists)
{
Debug.Print("SDL2 destroying window {0}", window.Handle);
SDL.SDL_Event e = new SDL.SDL_Event();
//e.type = SDL.SDL_EventType.SDL_QUIT;
e.type = SDL.SDL_EventType.SDL_WINDOWEVENT;
e.window.windowEvent = SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE;
e.window.windowID = window_id;
@ -441,12 +439,13 @@ namespace OpenTK.Platform.SDL2
}
}
}
}
public void ProcessEvents()
{
if (Exists)
lock (sync)
{
lock (SDL.Sync)
if (Exists)
{
SDL.SDL_PumpEvents();
}
@ -474,6 +473,10 @@ namespace OpenTK.Platform.SDL2
return icon;
}
set
{
lock (sync)
{
if (Exists)
{
// Set the new icon, if any, or clear the current
// icon if null
@ -510,19 +513,34 @@ namespace OpenTK.Platform.SDL2
IconChanged(this, EventArgs.Empty);
}
}
}
}
public string Title
{
get
{
lock (sync)
{
if (Exists)
{
return SDL.SDL_GetWindowTitle(window.Handle);
}
return String.Empty;
}
}
set
{
lock (sync)
{
if (Exists)
{
SDL.SDL_SetWindowTitle(window.Handle, value);
window_title = value;
}
}
}
}
public bool Focused
{
@ -539,6 +557,10 @@ namespace OpenTK.Platform.SDL2
return is_visible;
}
set
{
lock (sync)
{
if (Exists)
{
if (value)
SDL.SDL_ShowWindow(window.Handle);
@ -546,6 +568,8 @@ namespace OpenTK.Platform.SDL2
SDL.SDL_HideWindow(window.Handle);
}
}
}
}
public bool Exists
{
@ -571,11 +595,12 @@ namespace OpenTK.Platform.SDL2
}
set
{
if (WindowState == value)
lock (sync)
{
if (Exists)
{
if (WindowState != value)
{
return;
}
// Set the new WindowState
switch (value)
{
@ -613,6 +638,9 @@ namespace OpenTK.Platform.SDL2
GrabCursor(true);
}
}
}
}
}
public WindowBorder WindowBorder
{
@ -622,8 +650,13 @@ namespace OpenTK.Platform.SDL2
}
set
{
if (value != WindowBorder)
if (WindowBorder != value)
{
lock (sync)
{
if (Exists)
{
switch (value)
{
case WindowBorder.Resizable:
@ -640,11 +673,16 @@ namespace OpenTK.Platform.SDL2
Debug.WriteLine("SDL2 cannot change to fixed-size windows at runtime.");
break;
}
}
}
if (Exists)
{
WindowBorderChanged(this, EventArgs.Empty);
}
}
}
}
public Rectangle Bounds
{
@ -662,30 +700,56 @@ namespace OpenTK.Platform.SDL2
public Point Location
{
get
{
lock (sync)
{
if (Exists)
{
int x, y;
SDL.SDL_GetWindowPosition(window.Handle, out x, out y);
return new Point(x, y);
}
return new Point();
}
}
set
{
lock (sync)
{
if (Exists)
{
SDL.SDL_SetWindowPosition(window.Handle, value.X, value.Y);
}
}
}
}
public Size Size
{
get
{
lock (sync)
{
if (Exists)
{
int w, h;
SDL.SDL_GetWindowSize(window.Handle, out w, out h);
return new Size(w, h);
}
return new Size();
}
}
set
{
lock (sync)
{
if (Exists)
{
SDL.SDL_SetWindowSize(window.Handle, value.Width, value.Height);
}
}
}
}
public int X
{
@ -778,11 +842,17 @@ namespace OpenTK.Platform.SDL2
return is_cursor_visible;
}
set
{
lock (sync)
{
if (Exists)
{
GrabCursor(!value);
is_cursor_visible = value;
}
}
}
}
#endregion
@ -790,7 +860,6 @@ namespace OpenTK.Platform.SDL2
public void Poll()
{
throw new NotImplementedException();
}
#endregion
@ -840,11 +909,14 @@ namespace OpenTK.Platform.SDL2
if (manual)
{
Debug.Print("Disposing {0}", GetType());
lock (sync)
{
if (Exists)
{
DestroyWindow();
}
}
}
else
{
Debug.WriteLine("Sdl2NativeWindow leaked, did you forget to call Dispose()?");

View file

@ -64,7 +64,14 @@ namespace OpenTK.Platform.Windows
lock (LoadLock)
{
if (!wgl_loaded)
// On intel drivers, wgl entry points appear to change
// when creating multiple contexts. As a workaround,
// we reload Wgl entry points every time we create a
// new context - this solves the issue without any apparent
// side-effects (i.e. the old contexts can still be handled
// using the new entry points.)
// Sigh...
// if (!wgl_loaded)
{
// We need to create a temp context in order to load wgl extensions (e.g. for multisampling or GL3).
// We cannot rely on OpenTK.Platform.Wgl until we create the context and call Wgl.LoadAll().