2013-09-27 21:07:23 +00:00
|
|
|
#region License
|
|
|
|
//
|
|
|
|
// The Open Toolkit Library License
|
|
|
|
//
|
|
|
|
// Copyright (c) 2006 - 2013 Stefanos Apostolopoulos for the Open Toolkit library.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2013-09-27 12:41:37 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Drawing;
|
2013-10-12 03:06:54 +00:00
|
|
|
#if ANDROID || IPHONE || MINIMAL
|
|
|
|
using OpenTK.Minimal;
|
|
|
|
#else
|
2013-09-27 12:41:37 +00:00
|
|
|
using System.Drawing.Imaging;
|
2013-10-12 03:06:54 +00:00
|
|
|
#endif
|
2013-09-27 21:01:46 +00:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using OpenTK;
|
2013-09-27 12:41:37 +00:00
|
|
|
using OpenTK.Input;
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.SDL2
|
|
|
|
{
|
|
|
|
class Sdl2NativeWindow : INativeWindow, IInputDriver
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
readonly object sync = new object();
|
|
|
|
|
2013-09-27 12:41:37 +00:00
|
|
|
Sdl2WindowInfo window;
|
2013-09-27 21:01:46 +00:00
|
|
|
uint window_id;
|
2013-09-27 12:41:37 +00:00
|
|
|
bool is_visible;
|
|
|
|
bool is_focused;
|
|
|
|
bool is_cursor_visible = true;
|
|
|
|
bool exists;
|
|
|
|
bool disposed;
|
2013-09-27 21:01:46 +00:00
|
|
|
WindowState window_state = WindowState.Normal;
|
|
|
|
WindowState previous_window_state = WindowState.Normal;
|
|
|
|
WindowBorder window_border = WindowBorder.Resizable;
|
2013-09-27 12:41:37 +00:00
|
|
|
Icon icon;
|
2013-10-01 20:01:27 +00:00
|
|
|
string window_title;
|
2013-09-27 12:41:37 +00:00
|
|
|
|
2013-10-04 08:02:19 +00:00
|
|
|
readonly IInputDriver input_driver = new Sdl2InputDriver();
|
2013-10-04 00:37:41 +00:00
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
readonly EventFilter EventFilterDelegate = FilterEvents;
|
2013-09-27 21:01:46 +00:00
|
|
|
|
|
|
|
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
|
|
|
|
new Dictionary<uint, Sdl2NativeWindow>();
|
|
|
|
|
|
|
|
static readonly Sdl2KeyMap map = new Sdl2KeyMap();
|
|
|
|
|
2013-09-27 16:57:05 +00:00
|
|
|
public Sdl2NativeWindow(int x, int y, int width, int height,
|
|
|
|
string title, GameWindowFlags options, DisplayDevice device)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
var bounds = device.Bounds;
|
|
|
|
var flags = TranslateFlags(options);
|
2013-10-23 23:45:13 +00:00
|
|
|
flags |= WindowFlags.OPENGL;
|
|
|
|
flags |= WindowFlags.RESIZABLE;
|
|
|
|
flags |= WindowFlags.HIDDEN;
|
|
|
|
flags |= WindowFlags.ALLOW_HIGHDPI;
|
2013-09-27 21:01:46 +00:00
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
if ((flags & WindowFlags.FULLSCREEN_DESKTOP) != 0 ||
|
|
|
|
(flags & WindowFlags.FULLSCREEN) != 0)
|
2013-10-03 12:59:30 +00:00
|
|
|
window_state = WindowState.Fullscreen;
|
2013-09-27 21:01:46 +00:00
|
|
|
|
2013-10-03 12:59:30 +00:00
|
|
|
IntPtr handle;
|
|
|
|
lock (SDL.Sync)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
|
|
|
|
SDL.AddEventWatch(EventFilterDelegate, handle);
|
|
|
|
SDL.PumpEvents();
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
|
|
|
window = new Sdl2WindowInfo(handle, null);
|
2013-10-23 23:45:13 +00:00
|
|
|
window_id = SDL.GetWindowID(handle);
|
2013-10-03 12:59:30 +00:00
|
|
|
windows.Add(window_id, this);
|
|
|
|
window_title = title;
|
2013-09-27 12:41:37 +00:00
|
|
|
|
2013-10-03 12:59:30 +00:00
|
|
|
exists = true;
|
2013-10-01 23:14:26 +00:00
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#region Private Members
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
static WindowFlags TranslateFlags(GameWindowFlags flags)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
|
|
|
switch (flags)
|
|
|
|
{
|
|
|
|
case GameWindowFlags.Fullscreen:
|
2013-10-23 23:45:13 +00:00
|
|
|
return WindowFlags.FULLSCREEN_DESKTOP;
|
2013-09-27 12:41:37 +00:00
|
|
|
|
|
|
|
default:
|
2013-10-23 23:45:13 +00:00
|
|
|
return WindowFlags.Default;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
static Key TranslateKey(Scancode scan)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
|
|
|
Key result = Key.Unknown;
|
2013-09-30 11:51:31 +00:00
|
|
|
if (map.ContainsKey(scan))
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-09-30 11:51:31 +00:00
|
|
|
result = map[scan];
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
static Key TranslateKey(Keycode key)
|
2013-09-30 11:51:31 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
Scancode scan = SDL.GetScancodeFromKey(key);
|
2013-09-30 11:51:31 +00:00
|
|
|
return TranslateKey(scan);
|
|
|
|
}
|
|
|
|
|
2013-10-01 23:14:26 +00:00
|
|
|
unsafe static int FilterEvents(IntPtr user_data, IntPtr e)
|
2013-09-27 21:01:46 +00:00
|
|
|
{
|
2013-10-01 23:14:26 +00:00
|
|
|
bool processed = false;
|
|
|
|
|
|
|
|
try
|
2013-09-27 21:01:46 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
Sdl2NativeWindow window = null;
|
2013-10-23 23:45:13 +00:00
|
|
|
Event ev = *(Event*)e;
|
2013-09-27 21:01:46 +00:00
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
switch (ev.Type)
|
2013-10-03 12:59:30 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
case EventType.WINDOWEVENT:
|
|
|
|
if (windows.TryGetValue(ev.Window.WindowID, out window))
|
2013-10-03 12:59:30 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
ProcessWindowEvent(window, ev.Window);
|
2013-10-03 12:59:30 +00:00
|
|
|
processed = true;
|
|
|
|
}
|
|
|
|
break;
|
2013-10-01 23:14:26 +00:00
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case EventType.KEYDOWN:
|
|
|
|
case EventType.KEYUP:
|
|
|
|
if (windows.TryGetValue(ev.Key.WindowID, out window))
|
2013-10-03 12:59:30 +00:00
|
|
|
{
|
|
|
|
ProcessKeyEvent(window, ev);
|
|
|
|
processed = true;
|
|
|
|
}
|
|
|
|
break;
|
2013-10-01 23:14:26 +00:00
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case EventType.MOUSEBUTTONDOWN:
|
|
|
|
case EventType.MOUSEBUTTONUP:
|
|
|
|
if (windows.TryGetValue(ev.Button.WindowID, out window))
|
2013-10-03 12:59:30 +00:00
|
|
|
{
|
|
|
|
ProcessButtonEvent(window, ev);
|
|
|
|
processed = true;
|
|
|
|
}
|
|
|
|
break;
|
2013-10-01 23:14:26 +00:00
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case EventType.MOUSEMOTION:
|
|
|
|
if (windows.TryGetValue(ev.Motion.WindowID, out window))
|
2013-10-03 12:59:30 +00:00
|
|
|
{
|
|
|
|
ProcessMotionEvent(window, ev);
|
|
|
|
processed = true;
|
|
|
|
}
|
|
|
|
break;
|
2013-10-01 23:14:26 +00:00
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case EventType.MOUSEWHEEL:
|
|
|
|
if (windows.TryGetValue(ev.Wheel.WindowID, out window))
|
2013-10-03 12:59:30 +00:00
|
|
|
{
|
|
|
|
ProcessWheelEvent(window, ev);
|
|
|
|
processed = true;
|
|
|
|
}
|
|
|
|
break;
|
2013-10-01 23:14:26 +00:00
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case EventType.QUIT:
|
2013-10-03 12:59:30 +00:00
|
|
|
Debug.WriteLine("Sdl2 application quit");
|
|
|
|
break;
|
|
|
|
}
|
2013-09-27 21:01:46 +00:00
|
|
|
}
|
2013-10-01 23:14:26 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
Debug.Print(ex.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return processed ? 0 : 1;
|
2013-09-27 21:01:46 +00:00
|
|
|
}
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
static void ProcessButtonEvent(Sdl2NativeWindow window, Event ev)
|
2013-10-01 23:14:26 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
bool button_pressed = ev.Button.State == State.Pressed;
|
2013-10-02 15:55:30 +00:00
|
|
|
|
|
|
|
// We need MouseUp events to be reported even if they occur
|
|
|
|
// outside the window. SetWindowGrab ensures we get them.
|
|
|
|
if (window.CursorVisible)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowGrab(window.window.Handle,
|
|
|
|
button_pressed ? true : false);
|
2013-10-01 23:14:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
|
2013-10-01 23:14:26 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
bool key_pressed = ev.Key.State == State.Pressed;
|
|
|
|
var key = ev.Key.Keysym;
|
2013-10-04 08:02:19 +00:00
|
|
|
//window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
|
2013-10-01 23:14:26 +00:00
|
|
|
}
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev)
|
2013-10-01 23:14:26 +00:00
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
float scale = window.ClientSize.Width / (float)window.Size.Width;
|
2013-10-04 08:02:19 +00:00
|
|
|
//window.mouse.Position = new Point(
|
|
|
|
// (int)(ev.motion.x * scale), (int)(ev.motion.y * scale));
|
2013-10-01 23:14:26 +00:00
|
|
|
}
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
static void ProcessWheelEvent(Sdl2NativeWindow window, Event ev)
|
2013-10-01 23:14:26 +00:00
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
//window.mouse.Wheel += ev.wheel.y;
|
2013-10-01 23:14:26 +00:00
|
|
|
}
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
static void ProcessWindowEvent(Sdl2NativeWindow window, WindowEvent e)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
switch (e.Event)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.CLOSE:
|
2013-10-01 23:14:26 +00:00
|
|
|
var close_args = new System.ComponentModel.CancelEventArgs();
|
|
|
|
window.Closing(window, close_args);
|
|
|
|
if (!close_args.Cancel)
|
|
|
|
{
|
|
|
|
window.Closed(window, EventArgs.Empty);
|
2013-10-03 12:59:30 +00:00
|
|
|
//window.DestroyWindow();
|
2013-10-01 23:14:26 +00:00
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.ENTER:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.MouseEnter(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.LEAVE:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.MouseLeave(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.EXPOSED:
|
2013-09-27 12:41:37 +00:00
|
|
|
// do nothing
|
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.FOCUS_GAINED:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.is_focused = true;
|
|
|
|
window.FocusedChanged(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.FOCUS_LOST:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.is_focused = false;
|
|
|
|
window.FocusedChanged(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.HIDDEN:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.is_visible = false;
|
|
|
|
window.VisibleChanged(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.SHOWN:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.is_visible = true;
|
|
|
|
window.VisibleChanged(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.MAXIMIZED:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.previous_window_state = window.window_state;
|
|
|
|
window.window_state = OpenTK.WindowState.Maximized;
|
|
|
|
window.WindowStateChanged(window, EventArgs.Empty);
|
2013-09-27 21:01:46 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.MINIMIZED:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.previous_window_state = window.window_state;
|
|
|
|
window.window_state = OpenTK.WindowState.Minimized;
|
|
|
|
window.WindowStateChanged(window, EventArgs.Empty);
|
2013-09-27 21:01:46 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.RESTORED:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.window_state = window.previous_window_state;
|
|
|
|
window.WindowStateChanged(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.MOVED:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.Move(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
case WindowEventID.RESIZED:
|
|
|
|
case WindowEventID.SIZE_CHANGED:
|
2013-10-01 23:14:26 +00:00
|
|
|
window.Resize(window, EventArgs.Empty);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-10-23 23:45:13 +00:00
|
|
|
Debug.Print("SDL2 unhandled event: {0}", e.Type);
|
2013-09-27 12:41:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 16:57:05 +00:00
|
|
|
void DestroyWindow()
|
|
|
|
{
|
|
|
|
exists = false;
|
2013-09-27 21:01:46 +00:00
|
|
|
|
2013-10-01 23:14:26 +00:00
|
|
|
if (window.Handle != IntPtr.Zero)
|
2013-09-27 21:01:46 +00:00
|
|
|
{
|
2013-10-01 23:14:26 +00:00
|
|
|
lock (SDL.Sync)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.DelEventWatch(EventFilterDelegate, window.Handle);
|
2013-10-01 23:14:26 +00:00
|
|
|
if (windows.ContainsKey(window_id))
|
|
|
|
{
|
|
|
|
windows.Remove(window_id);
|
|
|
|
}
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.DestroyWindow(window.Handle);
|
2013-10-01 23:14:26 +00:00
|
|
|
}
|
2013-09-27 21:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
window_id = 0;
|
2013-09-27 16:57:05 +00:00
|
|
|
window.Handle = IntPtr.Zero;
|
|
|
|
}
|
|
|
|
|
2013-09-27 21:01:46 +00:00
|
|
|
void GrabCursor(bool grab)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.ShowCursor(!grab);
|
|
|
|
SDL.SetWindowGrab(window.Handle, grab);
|
|
|
|
SDL.SetRelativeMouseMode(grab);
|
2013-09-27 21:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hack to force WindowState events to be pumped
|
|
|
|
void HideShowWindowHack()
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.HideWindow(window.Handle);
|
2013-10-01 23:14:26 +00:00
|
|
|
ProcessEvents();
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.ShowWindow(window.Handle);
|
2013-10-01 23:14:26 +00:00
|
|
|
ProcessEvents();
|
2013-09-27 21:01:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Revert to WindowState.Normal if necessary
|
|
|
|
void RestoreWindow()
|
|
|
|
{
|
|
|
|
WindowState state = WindowState;
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case WindowState.Fullscreen:
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowFullscreen(window.Handle, 0);
|
2013-09-27 21:01:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowState.Maximized:
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.RestoreWindow(window.Handle);
|
2013-09-27 21:01:46 +00:00
|
|
|
HideShowWindowHack();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowState.Minimized:
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.RestoreWindow(window.Handle);
|
2013-09-27 21:01:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-01 23:14:26 +00:00
|
|
|
ProcessEvents();
|
2013-09-27 21:01:46 +00:00
|
|
|
|
|
|
|
window_state = WindowState.Normal;
|
|
|
|
}
|
|
|
|
|
2013-09-27 12:41:37 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region INativeWindow Members
|
|
|
|
|
|
|
|
public event EventHandler<EventArgs> Move = delegate { };
|
|
|
|
public event EventHandler<EventArgs> Resize = delegate { };
|
|
|
|
public event EventHandler<System.ComponentModel.CancelEventArgs> Closing = delegate { };
|
|
|
|
public event EventHandler<EventArgs> Closed = delegate { };
|
|
|
|
public event EventHandler<EventArgs> Disposed = delegate { };
|
|
|
|
public event EventHandler<EventArgs> IconChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> TitleChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> VisibleChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> FocusedChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> WindowBorderChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> WindowStateChanged = delegate { };
|
|
|
|
public event EventHandler<KeyboardKeyEventArgs> KeyDown = delegate { };
|
|
|
|
public event EventHandler<KeyPressEventArgs> KeyPress = delegate { };
|
|
|
|
public event EventHandler<KeyboardKeyEventArgs> KeyUp = delegate { };
|
|
|
|
public event EventHandler<EventArgs> MouseEnter = delegate { };
|
|
|
|
public event EventHandler<EventArgs> MouseLeave = delegate { };
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
if (Exists)
|
2013-10-01 23:14:26 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
Debug.Print("SDL2 destroying window {0}", window.Handle);
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
Event e = new Event();
|
|
|
|
e.Type = EventType.WINDOWEVENT;
|
|
|
|
e.Window.Event = WindowEventID.CLOSE;
|
|
|
|
e.Window.WindowID = window_id;
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (SDL.Sync)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.PushEvent(ref e);
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
2013-10-01 23:14:26 +00:00
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ProcessEvents()
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
if (Exists)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.PumpEvents();
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Point PointToClient(Point point)
|
|
|
|
{
|
|
|
|
var origin = DisplayDevice.Default.Bounds.Location;
|
|
|
|
var client = Location;
|
|
|
|
return new Point(point.X + client.X - origin.X, point.Y + client.Y - origin.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Point PointToScreen(Point point)
|
|
|
|
{
|
|
|
|
var origin = DisplayDevice.Default.Bounds.Location;
|
|
|
|
var client = Location;
|
|
|
|
return new Point(point.X + origin.X - client.X, point.Y + origin.Y - client.Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Icon Icon
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
if (Exists)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
// Set the new icon, if any, or clear the current
|
|
|
|
// icon if null
|
|
|
|
if (value != null)
|
|
|
|
{
|
|
|
|
using (Bitmap bmp = value.ToBitmap())
|
|
|
|
{
|
|
|
|
// Decode the icon into a SDL surface
|
|
|
|
var data = bmp.LockBits(
|
|
|
|
new Rectangle(0, 0, value.Width, value.Height),
|
|
|
|
ImageLockMode.ReadWrite,
|
|
|
|
PixelFormat.Format32bppArgb);
|
|
|
|
|
2013-10-23 23:45:13 +00:00
|
|
|
IntPtr surface = SDL.CreateRGBSurfaceFrom(
|
2013-10-03 12:59:30 +00:00
|
|
|
data.Scan0, data.Width, data.Height, 32, data.Stride,
|
|
|
|
0x00ff0000u, 0x0000ff00u, 0x000000ffu, 0xff000000u);
|
|
|
|
|
|
|
|
// Update the window icon
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowIcon(window.Handle, surface);
|
2013-10-03 12:59:30 +00:00
|
|
|
|
|
|
|
// Free the SDL surface as it is no longer needed
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.FreeSurface(surface);
|
2013-10-03 12:59:30 +00:00
|
|
|
bmp.UnlockBits(data);
|
|
|
|
}
|
2013-09-29 21:36:28 +00:00
|
|
|
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Clear the window icon
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowIcon(window.Handle, IntPtr.Zero);
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
2013-09-29 21:36:28 +00:00
|
|
|
|
2013-10-03 12:59:30 +00:00
|
|
|
icon = value;
|
|
|
|
IconChanged(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Title
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
if (Exists)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
return SDL.GetWindowTitle(window.Handle);
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
|
|
|
return String.Empty;
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
if (Exists)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowTitle(window.Handle, value);
|
2013-10-03 12:59:30 +00:00
|
|
|
window_title = value;
|
|
|
|
}
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Focused
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return is_focused;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Visible
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return is_visible;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
if (value)
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.ShowWindow(window.Handle);
|
2013-10-03 12:59:30 +00:00
|
|
|
else
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.HideWindow(window.Handle);
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Exists
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return exists;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public IWindowInfo WindowInfo
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public WindowState WindowState
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-09-27 21:01:46 +00:00
|
|
|
return window_state;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
2013-09-27 21:01:46 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
if (WindowState != value)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
// Set the new WindowState
|
|
|
|
switch (value)
|
2013-09-27 16:57:05 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
case WindowState.Fullscreen:
|
|
|
|
RestoreWindow();
|
2013-10-23 23:45:13 +00:00
|
|
|
if (SDL.SetWindowFullscreen(window.Handle, (uint)WindowFlags.FULLSCREEN_DESKTOP) < 0)
|
2013-10-03 12:59:30 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
if (SDL.SetWindowFullscreen(window.Handle, (uint)WindowFlags.FULLSCREEN) < 0)
|
2013-10-03 12:59:30 +00:00
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
Debug.Print("SDL2 failed to enter fullscreen mode: {0}", SDL.GetError());
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.RaiseWindow(window.Handle);
|
2013-10-03 12:59:30 +00:00
|
|
|
// There is no "fullscreen" message in the event loop
|
|
|
|
// so we have to mark that ourselves
|
|
|
|
window_state = WindowState.Fullscreen;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowState.Maximized:
|
|
|
|
RestoreWindow();
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.MaximizeWindow(window.Handle);
|
2013-10-03 12:59:30 +00:00
|
|
|
HideShowWindowHack();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowState.Minimized:
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.MinimizeWindow(window.Handle);
|
2013-10-03 12:59:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowState.Normal:
|
|
|
|
RestoreWindow();
|
|
|
|
break;
|
2013-09-27 16:57:05 +00:00
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
|
2013-10-03 12:59:30 +00:00
|
|
|
if (!CursorVisible)
|
|
|
|
GrabCursor(true);
|
|
|
|
}
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public WindowBorder WindowBorder
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-09-27 21:01:46 +00:00
|
|
|
return window_border;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
if (WindowBorder != value)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
2013-09-27 21:01:46 +00:00
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case WindowBorder.Resizable:
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowBordered(window.Handle, true);
|
2013-10-03 12:59:30 +00:00
|
|
|
window_border = WindowBorder.Resizable;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowBorder.Hidden:
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowBordered(window.Handle, false);
|
2013-10-03 12:59:30 +00:00
|
|
|
window_border = WindowBorder.Hidden;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowBorder.Fixed:
|
|
|
|
Debug.WriteLine("SDL2 cannot change to fixed-size windows at runtime.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-27 21:01:46 +00:00
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
|
2013-10-03 12:59:30 +00:00
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
WindowBorderChanged(this, EventArgs.Empty);
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Rectangle Bounds
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return new Rectangle(Location, Size);
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Size = value.Size;
|
|
|
|
Location = value.Location;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Point Location
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
int x, y;
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.GetWindowPosition(window.Handle, out x, out y);
|
2013-10-03 12:59:30 +00:00
|
|
|
return new Point(x, y);
|
|
|
|
}
|
|
|
|
return new Point();
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
if (Exists)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowPosition(window.Handle, value.X, value.Y);
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Size Size
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
int w, h;
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.GetWindowSize(window.Handle, out w, out h);
|
2013-10-03 12:59:30 +00:00
|
|
|
return new Size(w, h);
|
|
|
|
}
|
|
|
|
return new Size();
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
if (Exists)
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.SetWindowSize(window.Handle, value.Width, value.Height);
|
2013-10-03 12:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int X
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return Location.X;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Location = new Point(value, Y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Y
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return Location.Y;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Location = new Point(X, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
return ClientSize.Width;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
ClientSize = new Size(value, Height);
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
return ClientSize.Height;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
ClientSize = new Size(Width, value);
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Rectangle ClientRectangle
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
return new Rectangle(new Point(), ClientSize);
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
ClientSize = value.Size;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Size ClientSize
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
int w, h;
|
2013-10-07 11:17:42 +00:00
|
|
|
if (SDL.Version.Number > 2000)
|
|
|
|
{
|
|
|
|
// SDL > 2.0.0 supports SDL_GL_GetDrawableSize for
|
|
|
|
// hidpi windows.
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.GL.GetDrawableSize(window.Handle, out w, out h);
|
2013-10-07 11:17:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-23 23:45:13 +00:00
|
|
|
SDL.GetWindowSize(window.Handle, out w, out h);
|
2013-10-07 11:17:42 +00:00
|
|
|
}
|
2013-10-03 23:38:19 +00:00
|
|
|
return new Size(w, h);
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 23:38:19 +00:00
|
|
|
float scale = Size.Width / (float)ClientSize.Width;
|
|
|
|
Size = new Size((int)(value.Width * scale), (int)(value.Height * scale));
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public IInputDriver InputDriver
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
return input_driver;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CursorVisible
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return is_cursor_visible;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2013-10-03 12:59:30 +00:00
|
|
|
lock (sync)
|
|
|
|
{
|
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
GrabCursor(!value);
|
|
|
|
is_cursor_visible = value;
|
|
|
|
}
|
|
|
|
}
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IInputDriver Members
|
|
|
|
|
|
|
|
public void Poll()
|
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
InputDriver.Poll();
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IJoystickDriver Members
|
|
|
|
|
|
|
|
public IList<JoystickDevice> Joysticks
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
return InputDriver.Joysticks;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IMouseDriver Members
|
|
|
|
|
|
|
|
public IList<MouseDevice> Mouse
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
return InputDriver.Mouse;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IKeyboardDriver Members
|
|
|
|
|
|
|
|
public IList<KeyboardDevice> Keyboard
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
return InputDriver.Keyboard;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IDisposable implementation
|
|
|
|
|
|
|
|
void Dispose(bool manual)
|
|
|
|
{
|
2013-10-01 23:14:26 +00:00
|
|
|
if (!disposed)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
lock (sync)
|
2013-09-27 12:41:37 +00:00
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
if (manual)
|
2013-09-27 16:57:05 +00:00
|
|
|
{
|
2013-10-04 08:02:19 +00:00
|
|
|
Debug.Print("Disposing {0}", GetType());
|
|
|
|
InputDriver.Dispose();
|
2013-10-03 12:59:30 +00:00
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
DestroyWindow();
|
|
|
|
}
|
2013-09-27 16:57:05 +00:00
|
|
|
}
|
2013-10-04 08:02:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.WriteLine("Sdl2NativeWindow leaked, did you forget to call Dispose()?");
|
|
|
|
}
|
|
|
|
disposed = true;
|
2013-09-27 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~Sdl2NativeWindow()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|