2009-11-02 09:33:53 +00:00
|
|
|
#region License
|
2009-06-02 15:49:39 +00:00
|
|
|
//
|
|
|
|
// The Open Toolkit Library License
|
|
|
|
//
|
|
|
|
// Copyright (c) 2006 - 2009 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.
|
|
|
|
//
|
2009-02-22 10:43:35 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
2009-06-02 15:49:39 +00:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Text;
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
using OpenTK.Input;
|
|
|
|
using System.Collections.Generic;
|
2009-10-14 21:50:40 +00:00
|
|
|
using System.IO;
|
2009-11-01 12:44:38 +00:00
|
|
|
using System.Drawing;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
namespace OpenTK.Platform.Windows
|
|
|
|
{
|
2010-03-11 22:53:11 +00:00
|
|
|
/// \internal
|
2009-02-22 10:43:35 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Drives GameWindow on Windows.
|
|
|
|
/// This class supports OpenTK, and is not intended for use by OpenTK programs.
|
|
|
|
/// </summary>
|
2009-06-02 15:49:39 +00:00
|
|
|
internal sealed class WinGLNative : INativeWindow, IInputDriver
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Fields
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-11-04 09:21:41 +00:00
|
|
|
const ExtendedWindowStyle ParentStyleEx = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow;
|
|
|
|
const ExtendedWindowStyle ChildStyleEx = 0;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
readonly IntPtr Instance = Marshal.GetHINSTANCE(typeof(WinGLNative).Module);
|
2010-03-11 22:53:11 +00:00
|
|
|
readonly IntPtr ClassName = Marshal.StringToHGlobalAuto(Guid.NewGuid().ToString());
|
2009-06-02 15:49:39 +00:00
|
|
|
readonly WindowProcedure WindowProcedureDelegate;
|
2009-10-07 13:07:36 +00:00
|
|
|
readonly uint ModalLoopTimerPeriod = 1;
|
|
|
|
UIntPtr timer_handle;
|
2009-10-07 15:18:53 +00:00
|
|
|
readonly Functions.TimerProc ModalLoopCallback;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
bool class_registered;
|
|
|
|
bool disposed;
|
|
|
|
bool exists;
|
|
|
|
WinWindowInfo window, child_window;
|
2009-10-19 21:32:33 +00:00
|
|
|
WindowBorder windowBorder = WindowBorder.Resizable;
|
|
|
|
Nullable<WindowBorder> previous_window_border; // Set when changing to fullscreen state.
|
|
|
|
Nullable<WindowBorder> deferred_window_border; // Set to avoid changing borders during fullscreen state.
|
2009-06-02 15:49:39 +00:00
|
|
|
WindowState windowState = WindowState.Normal;
|
2009-10-18 14:56:53 +00:00
|
|
|
bool borderless_maximized_window_state = false; // Hack to get maximized mode with hidden border (not normally possible).
|
2009-10-18 15:11:41 +00:00
|
|
|
bool focused;
|
2010-02-03 19:04:42 +00:00
|
|
|
bool mouse_outside_window = true;
|
2010-03-11 22:53:11 +00:00
|
|
|
bool invisible_since_creation; // Set by WindowsMessage.CREATE and consumed by Visible = true (calls BringWindowToFront).
|
|
|
|
int suppress_resize; // Used in WindowBorder and WindowState in order to avoid rapid, consecutive resize events.
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
Rectangle
|
|
|
|
bounds = new Rectangle(),
|
|
|
|
client_rectangle = new Rectangle(),
|
|
|
|
previous_bounds = new Rectangle(); // Used to restore previous size when leaving fullscreen mode.
|
2009-11-02 09:33:53 +00:00
|
|
|
Icon icon;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
const ClassStyle DefaultClassStyle = ClassStyle.OwnDC;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-11-03 23:42:06 +00:00
|
|
|
readonly IntPtr DefaultWindowProcedure =
|
2009-06-02 15:49:39 +00:00
|
|
|
Marshal.GetFunctionPointerForDelegate(new WindowProcedure(Functions.DefWindowProc));
|
|
|
|
|
|
|
|
// Used for IInputDriver implementation
|
|
|
|
WinMMJoystick joystick_driver = new WinMMJoystick();
|
|
|
|
KeyboardDevice keyboard = new KeyboardDevice();
|
|
|
|
MouseDevice mouse = new MouseDevice();
|
|
|
|
IList<KeyboardDevice> keyboards = new List<KeyboardDevice>(1);
|
|
|
|
IList<MouseDevice> mice = new List<MouseDevice>(1);
|
|
|
|
internal static readonly WinKeyMap KeyMap = new WinKeyMap();
|
|
|
|
const long ExtendedBit = 1 << 24; // Used to distinguish left and right control, alt and enter keys.
|
|
|
|
static readonly uint ShiftRightScanCode = Functions.MapVirtualKey(VirtualKeys.RSHIFT, 0); // Used to distinguish left and right shift keys.
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-09-26 21:56:42 +00:00
|
|
|
KeyPressEventArgs key_press = new KeyPressEventArgs((char)0);
|
|
|
|
|
2010-10-19 09:20:59 +00:00
|
|
|
int cursor_visible_count = 0;
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Contructors
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
// This is the main window procedure callback. We need the callback in order to create the window, so
|
|
|
|
// don't move it below the CreateWindow calls.
|
|
|
|
WindowProcedureDelegate = WindowProcedure;
|
|
|
|
|
2010-10-02 18:52:34 +00:00
|
|
|
//// This timer callback is called periodically when the window enters a sizing / moving modal loop.
|
|
|
|
//ModalLoopCallback = delegate(IntPtr handle, WindowMessage msg, UIntPtr eventId, int time)
|
|
|
|
//{
|
|
|
|
// // Todo: find a way to notify the frontend that it should process queued up UpdateFrame/RenderFrame events.
|
|
|
|
// if (Move != null)
|
|
|
|
// Move(this, EventArgs.Empty);
|
|
|
|
//};
|
2009-10-07 15:18:53 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
// To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be
|
|
|
|
// bound to the top-level window, but rather to a child window docked in the parent.
|
|
|
|
window = new WinWindowInfo(
|
|
|
|
CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), null);
|
|
|
|
child_window = new WinWindowInfo(
|
|
|
|
CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window);
|
|
|
|
|
|
|
|
exists = true;
|
|
|
|
|
|
|
|
keyboard.Description = "Standard Windows keyboard";
|
|
|
|
keyboard.NumberOfFunctionKeys = 12;
|
|
|
|
keyboard.NumberOfKeys = 101;
|
|
|
|
keyboard.NumberOfLeds = 3;
|
|
|
|
|
|
|
|
mouse.Description = "Standard Windows mouse";
|
|
|
|
mouse.NumberOfButtons = 3;
|
|
|
|
mouse.NumberOfWheels = 1;
|
|
|
|
|
|
|
|
keyboards.Add(keyboard);
|
|
|
|
mice.Add(mouse);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Private Members
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region WindowProcedure
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
switch (message)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-10-17 22:02:08 +00:00
|
|
|
#region Size / Move / Style events
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
case WindowMessage.ACTIVATE:
|
2009-10-18 15:11:41 +00:00
|
|
|
// See http://msdn.microsoft.com/en-us/library/ms646274(VS.85).aspx (WM_ACTIVATE notification):
|
|
|
|
// wParam: The low-order word specifies whether the window is being activated or deactivated.
|
|
|
|
bool new_focused_state = Focused;
|
|
|
|
if (IntPtr.Size == 4)
|
|
|
|
focused = (wParam.ToInt32() & 0xFFFF) != 0;
|
|
|
|
else
|
|
|
|
focused = (wParam.ToInt64() & 0xFFFF) != 0;
|
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
if (new_focused_state != Focused)
|
2009-10-18 15:11:41 +00:00
|
|
|
FocusedChanged(this, EventArgs.Empty);
|
2010-03-11 22:53:11 +00:00
|
|
|
break;
|
2009-11-04 18:35:32 +00:00
|
|
|
|
2009-10-12 13:15:12 +00:00
|
|
|
case WindowMessage.ENTERMENULOOP:
|
2009-10-07 13:07:36 +00:00
|
|
|
case WindowMessage.ENTERSIZEMOVE:
|
|
|
|
// Entering the modal size/move loop: we don't want rendering to
|
|
|
|
// stop during this time, so we register a timer callback to continue
|
|
|
|
// processing from time to time.
|
2009-11-04 18:35:32 +00:00
|
|
|
StartTimer(handle);
|
2009-10-07 13:07:36 +00:00
|
|
|
break;
|
|
|
|
|
2009-10-12 13:15:12 +00:00
|
|
|
case WindowMessage.EXITMENULOOP:
|
2009-10-07 13:07:36 +00:00
|
|
|
case WindowMessage.EXITSIZEMOVE:
|
|
|
|
// ExitingmModal size/move loop: the timer callback is no longer
|
|
|
|
// necessary.
|
2009-11-04 18:35:32 +00:00
|
|
|
StopTimer(handle);
|
2009-10-07 13:07:36 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
case WindowMessage.ERASEBKGND:
|
|
|
|
return new IntPtr(1);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
case WindowMessage.WINDOWPOSCHANGED:
|
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
WindowPosition* pos = (WindowPosition*)lParam;
|
|
|
|
if (window != null && pos->hwnd == window.WindowHandle)
|
|
|
|
{
|
|
|
|
Point new_location = new Point(pos->x, pos->y);
|
|
|
|
if (Location != new_location)
|
|
|
|
{
|
|
|
|
bounds.Location = new_location;
|
2010-10-28 09:31:00 +00:00
|
|
|
Move(this, EventArgs.Empty);
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Size new_size = new Size(pos->cx, pos->cy);
|
|
|
|
if (Size != new_size)
|
|
|
|
{
|
|
|
|
bounds.Width = pos->cx;
|
|
|
|
bounds.Height = pos->cy;
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
Win32Rectangle rect;
|
2009-06-02 15:49:39 +00:00
|
|
|
Functions.GetClientRect(handle, out rect);
|
|
|
|
client_rectangle = rect.ToRectangle();
|
|
|
|
|
|
|
|
Functions.SetWindowPos(child_window.WindowHandle, IntPtr.Zero, 0, 0, ClientRectangle.Width, ClientRectangle.Height,
|
|
|
|
SetWindowPosFlags.NOZORDER | SetWindowPosFlags.NOOWNERZORDER |
|
|
|
|
SetWindowPosFlags.NOACTIVATE | SetWindowPosFlags.NOSENDCHANGING);
|
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
if (suppress_resize <= 0)
|
2009-06-02 15:49:39 +00:00
|
|
|
Resize(this, EventArgs.Empty);
|
|
|
|
}
|
2010-10-22 13:36:05 +00:00
|
|
|
|
|
|
|
// Ensure cursor remains grabbed
|
|
|
|
if (!CursorVisible)
|
|
|
|
GrabCursor();
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.STYLECHANGED:
|
2009-06-02 15:49:39 +00:00
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
if (wParam.ToInt64() == (long)GWL.STYLE)
|
|
|
|
{
|
|
|
|
WindowStyle style = ((StyleStruct*)lParam)->New;
|
|
|
|
if ((style & WindowStyle.Popup) != 0)
|
|
|
|
windowBorder = WindowBorder.Hidden;
|
|
|
|
else if ((style & WindowStyle.ThickFrame) != 0)
|
|
|
|
windowBorder = WindowBorder.Resizable;
|
|
|
|
else if ((style & ~(WindowStyle.ThickFrame | WindowStyle.MaximizeBox)) != 0)
|
|
|
|
windowBorder = WindowBorder.Fixed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 13:36:05 +00:00
|
|
|
// Ensure cursor remains grabbed
|
|
|
|
if (!CursorVisible)
|
|
|
|
GrabCursor();
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.SIZE:
|
2009-06-02 15:49:39 +00:00
|
|
|
SizeMessage state = (SizeMessage)wParam.ToInt64();
|
2009-10-18 09:42:41 +00:00
|
|
|
WindowState new_state = windowState;
|
2009-02-22 10:43:35 +00:00
|
|
|
switch (state)
|
|
|
|
{
|
2009-10-18 09:42:41 +00:00
|
|
|
case SizeMessage.RESTORED: new_state = borderless_maximized_window_state ?
|
|
|
|
WindowState.Maximized : WindowState.Normal; break;
|
|
|
|
case SizeMessage.MINIMIZED: new_state = WindowState.Minimized; break;
|
|
|
|
case SizeMessage.MAXIMIZED: new_state = WindowBorder == WindowBorder.Hidden ?
|
|
|
|
WindowState.Fullscreen : WindowState.Maximized;
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-10-18 09:42:41 +00:00
|
|
|
if (new_state != windowState)
|
|
|
|
{
|
|
|
|
windowState = new_state;
|
2010-10-28 09:31:00 +00:00
|
|
|
WindowStateChanged(this, EventArgs.Empty);
|
2009-10-18 09:42:41 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 13:36:05 +00:00
|
|
|
// Ensure cursor remains grabbed
|
|
|
|
if (!CursorVisible)
|
|
|
|
GrabCursor();
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Input events
|
|
|
|
|
2009-09-26 21:56:42 +00:00
|
|
|
case WindowMessage.CHAR:
|
|
|
|
if (IntPtr.Size == 4)
|
|
|
|
key_press.KeyChar = (char)wParam.ToInt32();
|
|
|
|
else
|
|
|
|
key_press.KeyChar = (char)wParam.ToInt64();
|
2010-03-11 22:53:11 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
KeyPress(this, key_press);
|
2009-09-26 21:56:42 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
case WindowMessage.MOUSEMOVE:
|
2009-11-01 12:44:38 +00:00
|
|
|
Point point = new Point(
|
2009-11-16 10:38:49 +00:00
|
|
|
(short)((uint)lParam.ToInt32() & 0x0000FFFF),
|
|
|
|
(short)(((uint)lParam.ToInt32() & 0xFFFF0000) >> 16));
|
2009-10-27 23:57:44 +00:00
|
|
|
mouse.Position = point;
|
2010-02-03 19:04:42 +00:00
|
|
|
|
|
|
|
if (mouse_outside_window)
|
2009-06-02 15:49:39 +00:00
|
|
|
{
|
2010-02-03 19:04:42 +00:00
|
|
|
// Once we receive a mouse move event, it means that the mouse has
|
|
|
|
// re-entered the window.
|
|
|
|
mouse_outside_window = false;
|
|
|
|
EnableMouseTracking();
|
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
MouseEnter(this, EventArgs.Empty);
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
case WindowMessage.MOUSELEAVE:
|
|
|
|
mouse_outside_window = true;
|
|
|
|
// Mouse tracking is disabled automatically by the OS
|
2010-03-11 22:53:11 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
MouseLeave(this, EventArgs.Empty);
|
2010-02-03 19:04:42 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
case WindowMessage.MOUSEWHEEL:
|
|
|
|
// This is due to inconsistent behavior of the WParam value on 64bit arch, whese
|
|
|
|
// wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000
|
2009-11-16 12:15:35 +00:00
|
|
|
mouse.WheelPrecise += ((long)wParam << 32 >> 48) / 120.0f;
|
2009-06-02 15:49:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.LBUTTONDOWN:
|
|
|
|
mouse[MouseButton.Left] = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.MBUTTONDOWN:
|
|
|
|
mouse[MouseButton.Middle] = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.RBUTTONDOWN:
|
|
|
|
mouse[MouseButton.Right] = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.XBUTTONDOWN:
|
|
|
|
mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.LBUTTONUP:
|
|
|
|
mouse[MouseButton.Left] = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.MBUTTONUP:
|
|
|
|
mouse[MouseButton.Middle] = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.RBUTTONUP:
|
|
|
|
mouse[MouseButton.Right] = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowMessage.XBUTTONUP:
|
|
|
|
// TODO: Is this correct?
|
|
|
|
mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) != (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Keyboard events:
|
|
|
|
case WindowMessage.KEYDOWN:
|
|
|
|
case WindowMessage.KEYUP:
|
|
|
|
case WindowMessage.SYSKEYDOWN:
|
|
|
|
case WindowMessage.SYSKEYUP:
|
|
|
|
bool pressed =
|
|
|
|
message == WindowMessage.KEYDOWN ||
|
|
|
|
message == WindowMessage.SYSKEYDOWN;
|
|
|
|
|
|
|
|
// Shift/Control/Alt behave strangely when e.g. ShiftRight is held down and ShiftLeft is pressed
|
|
|
|
// and released. It looks like neither key is released in this case, or that the wrong key is
|
|
|
|
// released in the case of Control and Alt.
|
|
|
|
// To combat this, we are going to release both keys when either is released. Hacky, but should work.
|
|
|
|
// Win95 does not distinguish left/right key constants (GetAsyncKeyState returns 0).
|
|
|
|
// In this case, both keys will be reported as pressed.
|
|
|
|
|
|
|
|
bool extended = (lParam.ToInt64() & ExtendedBit) != 0;
|
|
|
|
switch ((VirtualKeys)wParam)
|
|
|
|
{
|
|
|
|
case VirtualKeys.SHIFT:
|
|
|
|
// The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit
|
|
|
|
// to distinguish between left and right keys. Moreover, pressing both keys and releasing one
|
|
|
|
// may result in both keys being held down (but not always).
|
|
|
|
// The only reliably way to solve this was reported by BlueMonkMN at the forums: we should
|
|
|
|
// check the scancodes. It looks like GLFW does the same thing, so it should be reliable.
|
|
|
|
|
|
|
|
// TODO: Not 100% reliable, when both keys are pressed at once.
|
|
|
|
if (ShiftRightScanCode != 0)
|
|
|
|
{
|
|
|
|
unchecked
|
|
|
|
{
|
|
|
|
if (((lParam.ToInt64() >> 16) & 0xFF) == ShiftRightScanCode)
|
|
|
|
keyboard[Input.Key.ShiftRight] = pressed;
|
|
|
|
else
|
|
|
|
keyboard[Input.Key.ShiftLeft] = pressed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Should only fall here on Windows 9x and NT4.0-
|
|
|
|
keyboard[Input.Key.ShiftLeft] = pressed;
|
|
|
|
}
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
|
|
|
case VirtualKeys.CONTROL:
|
|
|
|
if (extended)
|
|
|
|
keyboard[Input.Key.ControlRight] = pressed;
|
|
|
|
else
|
|
|
|
keyboard[Input.Key.ControlLeft] = pressed;
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
|
|
|
case VirtualKeys.MENU:
|
|
|
|
if (extended)
|
|
|
|
keyboard[Input.Key.AltRight] = pressed;
|
|
|
|
else
|
|
|
|
keyboard[Input.Key.AltLeft] = pressed;
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
|
|
|
case VirtualKeys.RETURN:
|
|
|
|
if (extended)
|
|
|
|
keyboard[Key.KeypadEnter] = pressed;
|
|
|
|
else
|
|
|
|
keyboard[Key.Enter] = pressed;
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!WMInput.KeyMap.ContainsKey((VirtualKeys)wParam))
|
|
|
|
{
|
2010-10-28 08:42:20 +00:00
|
|
|
Debug.Print("Virtual key {0} ({1}) not mapped.", (VirtualKeys)wParam, (long)lParam);
|
2009-06-02 15:49:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
keyboard[WMInput.KeyMap[(VirtualKeys)wParam]] = pressed;
|
|
|
|
}
|
|
|
|
return IntPtr.Zero;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-10-20 11:35:35 +00:00
|
|
|
case WindowMessage.SYSCHAR:
|
|
|
|
return IntPtr.Zero;
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
case WindowMessage.KILLFOCUS:
|
|
|
|
keyboard.ClearKeys();
|
|
|
|
break;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Creation / Destruction events
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
case WindowMessage.CREATE:
|
2009-06-02 15:49:39 +00:00
|
|
|
CreateStruct cs = (CreateStruct)Marshal.PtrToStructure(lParam, typeof(CreateStruct));
|
|
|
|
if (cs.hwndParent == IntPtr.Zero)
|
|
|
|
{
|
|
|
|
bounds.X = cs.x;
|
|
|
|
bounds.Y = cs.y;
|
|
|
|
bounds.Width = cs.cx;
|
|
|
|
bounds.Height = cs.cy;
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
Win32Rectangle rect;
|
2009-06-02 15:49:39 +00:00
|
|
|
Functions.GetClientRect(handle, out rect);
|
|
|
|
client_rectangle = rect.ToRectangle();
|
2010-02-03 19:04:42 +00:00
|
|
|
|
2010-03-11 22:53:11 +00:00
|
|
|
invisible_since_creation = true;
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
case WindowMessage.CLOSE:
|
2009-06-02 15:49:39 +00:00
|
|
|
System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs();
|
2010-03-11 22:53:11 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
Closing(this, e);
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
if (!e.Cancel)
|
|
|
|
{
|
|
|
|
DestroyWindow();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IntPtr.Zero;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
case WindowMessage.DESTROY:
|
|
|
|
exists = false;
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
Functions.UnregisterClass(ClassName, Instance);
|
|
|
|
window.Dispose();
|
|
|
|
child_window.Dispose();
|
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
Closed(this, EventArgs.Empty);
|
2010-03-11 22:53:11 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
return Functions.DefWindowProc(handle, message, wParam, lParam);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
private void EnableMouseTracking()
|
|
|
|
{
|
|
|
|
TrackMouseEventStructure me = new TrackMouseEventStructure();
|
|
|
|
me.Size = TrackMouseEventStructure.SizeInBytes;
|
|
|
|
me.TrackWindowHandle = child_window.WindowHandle;
|
|
|
|
me.Flags = TrackMouseEventFlags.LEAVE;
|
|
|
|
|
|
|
|
if (!Functions.TrackMouseEvent(ref me))
|
|
|
|
Debug.Print("[Warning] Failed to enable mouse tracking, error: {0}.",
|
|
|
|
Marshal.GetLastWin32Error());
|
|
|
|
}
|
|
|
|
|
2009-11-04 18:35:32 +00:00
|
|
|
private void StartTimer(IntPtr handle)
|
|
|
|
{
|
|
|
|
if (timer_handle == UIntPtr.Zero)
|
|
|
|
{
|
2010-03-11 22:53:11 +00:00
|
|
|
timer_handle = Functions.SetTimer(handle, new UIntPtr(1), ModalLoopTimerPeriod, ModalLoopCallback);
|
2009-11-04 18:35:32 +00:00
|
|
|
if (timer_handle == UIntPtr.Zero)
|
|
|
|
Debug.Print("[Warning] Failed to set modal loop timer callback ({0}:{1}->{2}).",
|
|
|
|
GetType().Name, handle, Marshal.GetLastWin32Error());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void StopTimer(IntPtr handle)
|
|
|
|
{
|
|
|
|
if (timer_handle != UIntPtr.Zero)
|
|
|
|
{
|
|
|
|
if (!Functions.KillTimer(handle, timer_handle))
|
|
|
|
Debug.Print("[Warning] Failed to kill modal loop timer callback ({0}:{1}->{2}).",
|
|
|
|
GetType().Name, handle, Marshal.GetLastWin32Error());
|
|
|
|
timer_handle = UIntPtr.Zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region IsIdle
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2010-03-11 22:53:11 +00:00
|
|
|
bool IsIdle
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
MSG message = new MSG();
|
|
|
|
return !Functions.PeekMessage(ref message, window.WindowHandle, 0, 0, 0);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region CreateWindow
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
// Use win32 to create the native window.
|
|
|
|
// Keep in mind that some construction code runs in the WM_CREATE message handler.
|
|
|
|
|
2009-09-08 13:04:22 +00:00
|
|
|
// The style of a parent window is different than that of a child window.
|
|
|
|
// Note: the child window should always be visible, even if the parent isn't.
|
|
|
|
WindowStyle style = 0;
|
|
|
|
ExtendedWindowStyle ex_style = 0;
|
|
|
|
if (parentHandle == IntPtr.Zero)
|
|
|
|
{
|
|
|
|
style |= WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
|
|
|
|
ex_style = ParentStyleEx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
style |= WindowStyle.Visible | WindowStyle.Child | WindowStyle.ClipSiblings;
|
|
|
|
ex_style = ChildStyleEx;
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
// Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
|
2009-11-01 12:44:38 +00:00
|
|
|
Win32Rectangle rect = new Win32Rectangle();
|
2009-06-02 15:49:39 +00:00
|
|
|
rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
|
|
|
|
Functions.AdjustWindowRectEx(ref rect, style, false, ex_style);
|
|
|
|
|
|
|
|
// Create the window class that we will use for this window.
|
|
|
|
// The current approach is to register a new class for each top-level WinGLWindow we create.
|
|
|
|
if (!class_registered)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
ExtendedWindowClass wc = new ExtendedWindowClass();
|
|
|
|
wc.Size = ExtendedWindowClass.SizeInBytes;
|
2009-11-03 23:42:06 +00:00
|
|
|
wc.Style = DefaultClassStyle;
|
2009-06-02 15:49:39 +00:00
|
|
|
wc.Instance = Instance;
|
|
|
|
wc.WndProc = WindowProcedureDelegate;
|
|
|
|
wc.ClassName = ClassName;
|
2009-10-14 21:50:40 +00:00
|
|
|
wc.Icon = Icon != null ? Icon.Handle : IntPtr.Zero;
|
2009-11-04 09:21:41 +00:00
|
|
|
#warning "This seems to resize one of the 'large' icons, rather than using a small icon directly (multi-icon files). Investigate!"
|
|
|
|
wc.IconSm = Icon != null ? new Icon(Icon, 16, 16).Handle : IntPtr.Zero;
|
2009-10-21 20:08:04 +00:00
|
|
|
wc.Cursor = Functions.LoadCursor(CursorName.Arrow);
|
2009-06-02 15:49:39 +00:00
|
|
|
ushort atom = Functions.RegisterClassEx(ref wc);
|
|
|
|
|
|
|
|
if (atom == 0)
|
2009-11-04 09:21:41 +00:00
|
|
|
throw new PlatformException(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error()));
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
class_registered = true;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
IntPtr window_name = Marshal.StringToHGlobalAuto(title);
|
|
|
|
IntPtr handle = Functions.CreateWindowEx(
|
|
|
|
ex_style, ClassName, window_name, style,
|
|
|
|
rect.left, rect.top, rect.Width, rect.Height,
|
|
|
|
parentHandle, IntPtr.Zero, Instance, IntPtr.Zero);
|
|
|
|
|
|
|
|
if (handle == IntPtr.Zero)
|
|
|
|
throw new PlatformException(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error()));
|
|
|
|
|
|
|
|
return handle;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region DestroyWindow
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2009-06-02 15:49:39 +00:00
|
|
|
/// Starts the teardown sequence for the current window.
|
2009-02-22 10:43:35 +00:00
|
|
|
/// </summary>
|
2009-06-02 15:49:39 +00:00
|
|
|
void DestroyWindow()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
if (Exists)
|
|
|
|
{
|
|
|
|
Debug.Print("Destroying window: {0}", window.ToString());
|
|
|
|
Functions.DestroyWindow(window.WindowHandle);
|
|
|
|
exists = false;
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2010-03-11 22:53:11 +00:00
|
|
|
void HideBorder()
|
|
|
|
{
|
|
|
|
suppress_resize++;
|
|
|
|
WindowBorder = WindowBorder.Hidden;
|
|
|
|
ProcessEvents();
|
|
|
|
suppress_resize--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreBorder()
|
|
|
|
{
|
|
|
|
suppress_resize++;
|
|
|
|
WindowBorder =
|
|
|
|
deferred_window_border.HasValue ? deferred_window_border.Value :
|
|
|
|
previous_window_border.HasValue ? previous_window_border.Value :
|
|
|
|
WindowBorder;
|
|
|
|
ProcessEvents();
|
|
|
|
suppress_resize--;
|
|
|
|
deferred_window_border = previous_window_border = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetWindowState()
|
|
|
|
{
|
|
|
|
suppress_resize++;
|
|
|
|
WindowState = WindowState.Normal;
|
|
|
|
ProcessEvents();
|
|
|
|
suppress_resize--;
|
|
|
|
}
|
|
|
|
|
2010-10-22 13:36:05 +00:00
|
|
|
void GrabCursor()
|
|
|
|
{
|
|
|
|
Win32Rectangle rect = Win32Rectangle.From(ClientRectangle);
|
|
|
|
Point pos = PointToScreen(new Point(rect.left, rect.top));
|
|
|
|
rect.left = pos.X;
|
|
|
|
rect.top = pos.Y;
|
|
|
|
if (!Functions.ClipCursor(ref rect))
|
|
|
|
Debug.WriteLine(String.Format("Failed to grab cursor. Error: {0}",
|
|
|
|
Marshal.GetLastWin32Error()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UngrabCursor()
|
|
|
|
{
|
|
|
|
if (!Functions.ClipCursor(IntPtr.Zero))
|
|
|
|
Debug.WriteLine(String.Format("Failed to ungrab cursor. Error: {0}",
|
|
|
|
Marshal.GetLastWin32Error()));
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region INativeWindow Members
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Bounds
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Rectangle Bounds
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get { return bounds; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
// Note: the bounds variable is updated when the resize/move message arrives.
|
|
|
|
Functions.SetWindowPos(window.WindowHandle, IntPtr.Zero, value.X, value.Y, value.Width, value.Height, 0);
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Location
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public Point Location
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get { return Bounds.Location; }
|
|
|
|
set
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
// Note: the bounds variable is updated when the resize/move message arrives.
|
|
|
|
Functions.SetWindowPos(window.WindowHandle, IntPtr.Zero, value.X, value.Y, 0, 0, SetWindowPosFlags.NOSIZE);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Size
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public Size Size
|
|
|
|
{
|
|
|
|
get { return Bounds.Size; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
// Note: the bounds variable is updated when the resize/move message arrives.
|
|
|
|
Functions.SetWindowPos(window.WindowHandle, IntPtr.Zero, 0, 0, value.Width, value.Height, SetWindowPosFlags.NOMOVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ClientRectangle
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Rectangle ClientRectangle
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
if (client_rectangle.Width == 0)
|
|
|
|
client_rectangle.Width = 1;
|
|
|
|
if (client_rectangle.Height == 0)
|
|
|
|
client_rectangle.Height = 1;
|
|
|
|
return client_rectangle;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2010-02-03 19:04:42 +00:00
|
|
|
ClientSize = value.Size;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region ClientSize
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public Size ClientSize
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
return ClientRectangle.Size;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
WindowStyle style = (WindowStyle)Functions.GetWindowLong(window.WindowHandle, GetWindowLongOffsets.STYLE);
|
2009-11-01 12:44:38 +00:00
|
|
|
Win32Rectangle rect = Win32Rectangle.From(value);
|
2009-06-02 15:49:39 +00:00
|
|
|
Functions.AdjustWindowRect(ref rect, style, false);
|
|
|
|
Size = new Size(rect.Width, rect.Height);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Width
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public int Width
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get { return ClientRectangle.Width; }
|
2010-03-11 22:53:11 +00:00
|
|
|
set { ClientRectangle = new Rectangle(0, 0, value, Height); }
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Height
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public int Height
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get { return ClientRectangle.Height; }
|
2010-03-11 22:53:11 +00:00
|
|
|
set { ClientRectangle = new Rectangle(0, 0, Width, value); }
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region X
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public int X
|
|
|
|
{
|
2010-03-11 22:53:11 +00:00
|
|
|
get { return Location.X; }
|
|
|
|
set { Location = new Point(value, Y); }
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Y
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public int Y
|
|
|
|
{
|
2010-03-11 22:53:11 +00:00
|
|
|
get { return Location.Y; }
|
|
|
|
set { Location = new Point(X, value); }
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Icon
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-11-02 09:33:53 +00:00
|
|
|
public Icon Icon
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
if (value != icon)
|
2009-11-02 09:33:53 +00:00
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
icon = value;
|
|
|
|
if (window.WindowHandle != IntPtr.Zero)
|
|
|
|
{
|
|
|
|
Functions.SendMessage(window.WindowHandle, WindowMessage.SETICON, (IntPtr)0, icon == null ? IntPtr.Zero : value.Handle);
|
|
|
|
Functions.SendMessage(window.WindowHandle, WindowMessage.SETICON, (IntPtr)1, icon == null ? IntPtr.Zero : value.Handle);
|
|
|
|
}
|
|
|
|
IconChanged(this, EventArgs.Empty);
|
2009-11-02 09:33:53 +00:00
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Focused
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public bool Focused
|
|
|
|
{
|
2009-10-18 15:11:41 +00:00
|
|
|
get { return focused; }
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Title
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
StringBuilder sb_title = new StringBuilder(256);
|
|
|
|
public string Title
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get
|
|
|
|
{
|
|
|
|
sb_title.Remove(0, sb_title.Length);
|
2010-10-28 10:36:28 +00:00
|
|
|
if (Functions.GetWindowText(window.WindowHandle, sb_title, sb_title.Capacity) == 0)
|
|
|
|
Debug.Print("Failed to retrieve window title (window:{0}, reason:{1}).", window.WindowHandle, Marshal.GetLastWin32Error());
|
2009-06-02 15:49:39 +00:00
|
|
|
return sb_title.ToString();
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
if (Title != value)
|
|
|
|
{
|
|
|
|
if (!Functions.SetWindowText(window.WindowHandle, value))
|
|
|
|
Debug.Print("Failed to change window title (window:{0}, new title:{1}, reason:{2}).", window.WindowHandle, value, Marshal.GetLastWin32Error());
|
|
|
|
TitleChanged(this, EventArgs.Empty);
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Visible
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public bool Visible
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-09-19 20:30:12 +00:00
|
|
|
return Functions.IsWindowVisible(window.WindowHandle);
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
if (value != Visible)
|
2009-06-02 15:49:39 +00:00
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
if (value)
|
2010-03-11 22:53:11 +00:00
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
Functions.ShowWindow(window.WindowHandle, ShowWindowCommand.SHOW);
|
|
|
|
if (invisible_since_creation)
|
|
|
|
{
|
|
|
|
Functions.BringWindowToTop(window.WindowHandle);
|
|
|
|
Functions.SetForegroundWindow(window.WindowHandle);
|
|
|
|
}
|
2010-03-11 22:53:11 +00:00
|
|
|
}
|
2010-10-28 09:31:00 +00:00
|
|
|
else if (!value)
|
|
|
|
{
|
|
|
|
Functions.ShowWindow(window.WindowHandle, ShowWindowCommand.HIDE);
|
|
|
|
}
|
|
|
|
|
|
|
|
VisibleChanged(this, EventArgs.Empty);
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Exists
|
2009-05-07 19:48:22 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public bool Exists { get { return exists; } }
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2010-10-18 15:25:25 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CursorVisible
|
|
|
|
|
|
|
|
public bool CursorVisible
|
|
|
|
{
|
2010-10-22 13:36:05 +00:00
|
|
|
get { return cursor_visible_count >= 0; } // Not used
|
2010-10-19 09:20:59 +00:00
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value && cursor_visible_count < 0)
|
|
|
|
{
|
2010-10-19 09:25:09 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
cursor_visible_count = Functions.ShowCursor(true);
|
|
|
|
}
|
|
|
|
while (cursor_visible_count < 0);
|
2010-10-19 09:20:59 +00:00
|
|
|
|
2010-10-22 13:36:05 +00:00
|
|
|
UngrabCursor();
|
2010-10-19 09:20:59 +00:00
|
|
|
}
|
|
|
|
else if (!value && cursor_visible_count >= 0)
|
|
|
|
{
|
2010-10-19 09:25:09 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
cursor_visible_count = Functions.ShowCursor(false);
|
|
|
|
}
|
|
|
|
while (cursor_visible_count >= 0);
|
2010-10-19 09:20:59 +00:00
|
|
|
|
2010-10-22 13:36:05 +00:00
|
|
|
GrabCursor();
|
2010-10-19 09:20:59 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-18 15:25:25 +00:00
|
|
|
}
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Close
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public void Close()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-10-07 16:18:48 +00:00
|
|
|
Functions.PostMessage(window.WindowHandle, WindowMessage.CLOSE, IntPtr.Zero, IntPtr.Zero);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public WindowState WindowState
|
|
|
|
|
|
|
|
public WindowState WindowState
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
return windowState;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (WindowState == value)
|
|
|
|
return;
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
ShowWindowCommand command = 0;
|
2009-10-18 14:56:53 +00:00
|
|
|
bool exiting_fullscreen = false;
|
2009-10-18 09:42:41 +00:00
|
|
|
borderless_maximized_window_state = false;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case WindowState.Normal:
|
|
|
|
command = ShowWindowCommand.RESTORE;
|
2009-10-18 09:42:41 +00:00
|
|
|
|
2009-10-18 14:56:53 +00:00
|
|
|
// If we are leaving fullscreen mode we need to restore the border.
|
2009-10-18 09:42:41 +00:00
|
|
|
if (WindowState == WindowState.Fullscreen)
|
2009-10-18 14:56:53 +00:00
|
|
|
exiting_fullscreen = true;
|
2009-06-02 15:49:39 +00:00
|
|
|
break;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
case WindowState.Maximized:
|
2009-10-18 09:42:41 +00:00
|
|
|
// Note: if we use the MAXIMIZE command and the window border is Hidden (i.e. WS_POPUP),
|
|
|
|
// we will enter fullscreen mode - we don't want that! As a workaround, we'll resize the window
|
|
|
|
// manually to cover the whole working area of the current monitor.
|
|
|
|
|
|
|
|
// Reset state to avoid strange interactions with fullscreen/minimized windows.
|
2010-03-11 22:53:11 +00:00
|
|
|
ResetWindowState();
|
2009-10-18 09:42:41 +00:00
|
|
|
|
|
|
|
if (WindowBorder == WindowBorder.Hidden)
|
|
|
|
{
|
|
|
|
IntPtr current_monitor = Functions.MonitorFromWindow(window.WindowHandle, MonitorFrom.Nearest);
|
|
|
|
MonitorInfo info = new MonitorInfo();
|
|
|
|
info.Size = MonitorInfo.SizeInBytes;
|
|
|
|
Functions.GetMonitorInfo(current_monitor, ref info);
|
|
|
|
|
|
|
|
previous_bounds = Bounds;
|
|
|
|
borderless_maximized_window_state = true;
|
|
|
|
Bounds = info.Work.ToRectangle();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
command = ShowWindowCommand.MAXIMIZE;
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowState.Minimized:
|
2009-06-02 15:49:39 +00:00
|
|
|
command = ShowWindowCommand.MINIMIZE;
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowState.Fullscreen:
|
2009-10-18 09:42:41 +00:00
|
|
|
// We achieve fullscreen by hiding the window border and sending the MAXIMIZE command.
|
|
|
|
// We cannot use the WindowState.Maximized directly, as that will not send the MAXIMIZE
|
|
|
|
// command for windows with hidden borders.
|
|
|
|
|
|
|
|
// Reset state to avoid strange side-effects from maximized/minimized windows.
|
2010-03-11 22:53:11 +00:00
|
|
|
ResetWindowState();
|
2009-10-18 09:42:41 +00:00
|
|
|
|
2009-10-14 19:46:39 +00:00
|
|
|
previous_bounds = Bounds;
|
2009-10-18 09:42:41 +00:00
|
|
|
previous_window_border = WindowBorder;
|
2010-03-11 22:53:11 +00:00
|
|
|
HideBorder();
|
2009-10-18 09:42:41 +00:00
|
|
|
command = ShowWindowCommand.MAXIMIZE;
|
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
Functions.SetForegroundWindow(window.WindowHandle);
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
if (command != 0)
|
|
|
|
Functions.ShowWindow(window.WindowHandle, command);
|
2009-10-14 19:46:39 +00:00
|
|
|
|
2010-03-11 22:53:11 +00:00
|
|
|
// Restore previous window border or apply pending border change when leaving fullscreen mode.
|
|
|
|
if (exiting_fullscreen)
|
|
|
|
{
|
|
|
|
RestoreBorder();
|
|
|
|
}
|
|
|
|
|
2009-10-18 14:56:53 +00:00
|
|
|
// Restore previous window size/location if necessary
|
2009-11-01 12:44:38 +00:00
|
|
|
if (command == ShowWindowCommand.RESTORE && previous_bounds != Rectangle.Empty)
|
2009-10-14 19:46:39 +00:00
|
|
|
{
|
|
|
|
Bounds = previous_bounds;
|
2009-11-01 12:44:38 +00:00
|
|
|
previous_bounds = Rectangle.Empty;
|
2009-10-14 19:46:39 +00:00
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public WindowBorder WindowBorder
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
public WindowBorder WindowBorder
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return windowBorder;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2009-10-18 14:56:53 +00:00
|
|
|
// Do not allow border changes during fullscreen mode.
|
|
|
|
// Defer them for when we leave fullscreen.
|
|
|
|
if (WindowState == WindowState.Fullscreen)
|
|
|
|
{
|
|
|
|
deferred_window_border = value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
if (windowBorder == value)
|
|
|
|
return;
|
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
// We wish to avoid making an invisible window visible just to change the border.
|
|
|
|
// However, it's a good idea to make a visible window invisible temporarily, to
|
|
|
|
// avoid garbage caused by the border change.
|
|
|
|
bool was_visible = Visible;
|
|
|
|
|
2009-10-18 14:56:53 +00:00
|
|
|
// To ensure maximized/minimized windows work correctly, reset state to normal,
|
|
|
|
// change the border, then go back to maximized/minimized.
|
|
|
|
WindowState state = WindowState;
|
2010-03-11 22:53:11 +00:00
|
|
|
ResetWindowState();
|
2009-10-18 14:56:53 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
WindowStyle style = WindowStyle.ClipChildren | WindowStyle.ClipSiblings;
|
|
|
|
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case WindowBorder.Resizable:
|
|
|
|
style |= WindowStyle.OverlappedWindow;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowBorder.Fixed:
|
2009-06-02 15:49:39 +00:00
|
|
|
style |= WindowStyle.OverlappedWindow &
|
|
|
|
~(WindowStyle.ThickFrame | WindowStyle.MaximizeBox | WindowStyle.SizeBox);
|
2009-02-22 10:43:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WindowBorder.Hidden:
|
|
|
|
style |= WindowStyle.Popup;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
// Make sure client size doesn't change when changing the border style.
|
|
|
|
Size client_size = ClientSize;
|
2009-11-01 12:44:38 +00:00
|
|
|
Win32Rectangle rect = Win32Rectangle.From(client_size);
|
2009-06-02 15:49:39 +00:00
|
|
|
Functions.AdjustWindowRectEx(ref rect, style, false, ParentStyleEx);
|
|
|
|
|
|
|
|
// This avoids leaving garbage on the background window.
|
2010-02-03 19:04:42 +00:00
|
|
|
if (was_visible)
|
|
|
|
Visible = false;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
Functions.SetWindowLong(window.WindowHandle, GetWindowLongOffsets.STYLE, (IntPtr)(int)style);
|
|
|
|
Functions.SetWindowPos(window.WindowHandle, IntPtr.Zero, 0, 0, rect.Width, rect.Height,
|
|
|
|
SetWindowPosFlags.NOMOVE | SetWindowPosFlags.NOZORDER |
|
|
|
|
SetWindowPosFlags.FRAMECHANGED);
|
|
|
|
|
2009-11-07 10:44:31 +00:00
|
|
|
// Force window to redraw update its borders, but only if it's
|
|
|
|
// already visible (invisible windows will change borders when
|
|
|
|
// they become visible, so no need to make them visiable prematurely).
|
2010-02-03 19:04:42 +00:00
|
|
|
if (was_visible)
|
2009-11-07 10:44:31 +00:00
|
|
|
Visible = true;
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2009-10-18 14:56:53 +00:00
|
|
|
WindowState = state;
|
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
WindowBorderChanged(this, EventArgs.Empty);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region PointToClient
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public Point PointToClient(Point point)
|
|
|
|
{
|
|
|
|
if (!Functions.ScreenToClient(window.WindowHandle, ref point))
|
|
|
|
throw new InvalidOperationException(String.Format(
|
2010-10-22 13:22:28 +00:00
|
|
|
"Could not convert point {0} from screen to client coordinates. Windows error: {1}",
|
2009-06-02 15:49:39 +00:00
|
|
|
point.ToString(), Marshal.GetLastWin32Error()));
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
return point;
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region PointToScreen
|
|
|
|
|
2010-10-22 13:22:28 +00:00
|
|
|
public Point PointToScreen(Point point)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2010-10-22 13:22:28 +00:00
|
|
|
if (!Functions.ClientToScreen(window.WindowHandle, ref point))
|
|
|
|
throw new InvalidOperationException(String.Format(
|
|
|
|
"Could not convert point {0} from screen to client coordinates. Windows error: {1}",
|
|
|
|
point.ToString(), Marshal.GetLastWin32Error()));
|
|
|
|
|
|
|
|
return point;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Events
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> Move = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> Resize = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<System.ComponentModel.CancelEventArgs> Closing = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> Closed = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> Disposed = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> IconChanged = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> TitleChanged = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> VisibleChanged = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> FocusedChanged = delegate { };
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> WindowBorderChanged = delegate { };
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> WindowStateChanged = delegate { };
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<KeyPressEventArgs> KeyPress = delegate { };
|
2009-10-27 23:57:44 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> MouseEnter = delegate { };
|
2009-10-27 23:57:44 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> MouseLeave = delegate { };
|
2010-03-11 22:53:11 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region INativeGLWindow Members
|
|
|
|
|
|
|
|
#region public void ProcessEvents()
|
|
|
|
|
|
|
|
private int ret;
|
|
|
|
MSG msg;
|
|
|
|
public void ProcessEvents()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
while (!IsIdle)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
ret = Functions.GetMessage(ref msg, window.WindowHandle, 0, 0);
|
|
|
|
if (ret == -1)
|
|
|
|
{
|
|
|
|
throw new PlatformException(String.Format(
|
|
|
|
"An error happened while processing the message queue. Windows error: {0}",
|
|
|
|
Marshal.GetLastWin32Error()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Functions.TranslateMessage(ref msg);
|
|
|
|
Functions.DispatchMessage(ref msg);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region public IInputDriver InputDriver
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public IInputDriver InputDriver
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get { return this; }
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public IWindowInfo WindowInfo
|
|
|
|
|
|
|
|
public IWindowInfo WindowInfo
|
|
|
|
{
|
|
|
|
get { return child_window; }
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IInputDriver Members
|
|
|
|
|
|
|
|
public void Poll()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
joystick_driver.Poll();
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IKeyboardDriver Members
|
|
|
|
|
|
|
|
public IList<KeyboardDevice> Keyboard
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get { return keyboards; }
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2010-10-20 14:33:23 +00:00
|
|
|
public KeyboardState GetState()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public KeyboardState GetState(int index)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IMouseDriver Members
|
|
|
|
|
|
|
|
public IList<MouseDevice> Mouse
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
get { return mice; }
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2010-10-20 14:58:38 +00:00
|
|
|
MouseState IMouseDriver.GetState()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseState IMouseDriver.GetState(int index)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region IJoystickDriver Members
|
|
|
|
|
|
|
|
public IList<JoystickDevice> Joysticks
|
|
|
|
{
|
|
|
|
get { return joystick_driver.Joysticks; }
|
|
|
|
}
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
#endregion
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#region IDisposable Members
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
this.Dispose(true);
|
2009-06-02 15:49:39 +00:00
|
|
|
GC.SuppressFinalize(this);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
void Dispose(bool calledManually)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
if (!disposed)
|
|
|
|
{
|
|
|
|
if (calledManually)
|
|
|
|
{
|
|
|
|
// Safe to clean managed resources
|
2009-06-02 15:49:39 +00:00
|
|
|
DestroyWindow();
|
2009-10-14 21:50:40 +00:00
|
|
|
if (Icon != null)
|
|
|
|
Icon.Dispose();
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.Print("[Warning] INativeWindow leaked ({0}). Did you forget to call INativeWindow.Dispose()?", this);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
Disposed(this, EventArgs.Empty);
|
2009-02-22 10:43:35 +00:00
|
|
|
disposed = true;
|
|
|
|
}
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
~WinGLNative()
|
|
|
|
{
|
|
|
|
Dispose(false);
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|