* Source/OpenTK/NativeWindow.cs:
* Source/OpenTK/INativeWindow.cs: * Source/OpenTK/Platform/X11/API.cs: * Source/OpenTK/Platform/X11/X11GLNative.cs: * Source/OpenTK/Platform/Windows/WinGLNative.cs: * Source/OpenTK/Platform/MacOS/CarbonGLNative.cs: * Source/Examples/OpenTK/Test/GameWindowStates.cs: Initial implementation of CursorVisible API. See issue [#1560].
This commit is contained in:
parent
d4d9d58a8a
commit
42e0880cbb
7 changed files with 127 additions and 2 deletions
|
@ -23,6 +23,7 @@ namespace Examples.Tests
|
|||
bool mouse_in_window = false;
|
||||
bool viewport_changed = true;
|
||||
bool refresh_text = true;
|
||||
bool move_window = false;
|
||||
|
||||
public GameWindowStates()
|
||||
: base(800, 600)
|
||||
|
@ -38,7 +39,8 @@ namespace Examples.Tests
|
|||
Resize += delegate { refresh_text = true; };
|
||||
WindowBorderChanged += delegate { refresh_text = true; };
|
||||
WindowStateChanged += delegate { refresh_text = true; };
|
||||
Mouse.Move += delegate { refresh_text = true; };
|
||||
Mouse.Move += MouseMoveHandler;
|
||||
Mouse.ButtonDown += MouseButtonHandler;
|
||||
}
|
||||
|
||||
void KeyDownHandler(object sender, KeyboardKeyEventArgs e)
|
||||
|
@ -69,6 +71,32 @@ namespace Examples.Tests
|
|||
}
|
||||
}
|
||||
|
||||
void MouseMoveHandler(object sender, MouseMoveEventArgs e)
|
||||
{
|
||||
refresh_text = true;
|
||||
|
||||
if (move_window)
|
||||
{
|
||||
Location = new Point(X + e.XDelta, Y + e.YDelta);
|
||||
}
|
||||
}
|
||||
|
||||
void MouseButtonHandler(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
refresh_text = true;
|
||||
|
||||
if (e.IsPressed)
|
||||
{
|
||||
CursorVisible = false;
|
||||
move_window = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
CursorVisible = true;
|
||||
move_window = false;
|
||||
}
|
||||
}
|
||||
|
||||
static int Clamp(int val, int min, int max)
|
||||
{
|
||||
return val > max ? max : val < min ? min : val;
|
||||
|
@ -97,6 +125,7 @@ namespace Examples.Tests
|
|||
DrawString(gfx, String.Format("Focused: {0}.", this.Focused), line++);
|
||||
DrawString(gfx, String.Format("Mouse {0} window.", mouse_in_window ? "inside" : "outside of"), line++);
|
||||
DrawString(gfx, String.Format("Mouse position: {0}", new Vector3(Mouse.X, Mouse.Y, Mouse.Wheel)), line++);
|
||||
DrawString(gfx, String.Format("Mouse visible: {0}", CursorVisible), line++);
|
||||
DrawString(gfx, String.Format("Window.Bounds: {0}", Bounds), line++);
|
||||
DrawString(gfx, String.Format("Window.Location: {0}, Size: {1}", Location, Size), line++);
|
||||
DrawString(gfx, String.Format("Window.{{X={0}, Y={1}, Width={2}, Height={3}}}", X, Y, Width, Height), line++);
|
||||
|
|
|
@ -132,6 +132,16 @@ namespace OpenTK
|
|||
[Obsolete]
|
||||
OpenTK.Input.IInputDriver InputDriver { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value, indicating whether the mouse cursor is visible.
|
||||
/// </summary>
|
||||
bool CursorVisible { get; set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets or sets a value, indicating whether the mouse cursor is confined inside the window size.
|
||||
// /// </summary>
|
||||
// bool CursorGrabbed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Closes this window.
|
||||
/// </summary>
|
||||
|
|
|
@ -49,6 +49,7 @@ namespace OpenTK
|
|||
private readonly INativeWindow implementation;
|
||||
|
||||
private bool disposed, events;
|
||||
private bool cursor_visible = true;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -541,6 +542,23 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region CursorVisible
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the mouse cursor is visible.
|
||||
/// </summary>
|
||||
public bool CursorVisible
|
||||
{
|
||||
get { return cursor_visible; }
|
||||
set
|
||||
{
|
||||
cursor_visible = value;
|
||||
implementation.CursorVisible = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
|
|
@ -925,6 +925,12 @@ namespace OpenTK.Platform.MacOS
|
|||
}
|
||||
}
|
||||
|
||||
public bool CursorVisible
|
||||
{
|
||||
get { return true; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
CancelEventArgs e = new CancelEventArgs();
|
||||
|
|
|
@ -838,6 +838,16 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
#endregion
|
||||
|
||||
#region CursorVisible
|
||||
|
||||
public bool CursorVisible
|
||||
{
|
||||
get { return true; }
|
||||
set { }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Close
|
||||
|
||||
public void Close()
|
||||
|
|
|
@ -1562,6 +1562,26 @@ XF86VidModeGetGammaRampSize(
|
|||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
public static Pixmap XCreateBitmapFromData(Display display, Window d, byte[,] data)
|
||||
{
|
||||
if (data == null)
|
||||
throw new ArgumentNullException("data");
|
||||
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* pdata = data)
|
||||
{
|
||||
return XCreateBitmapFromData(display, d, pdata, data.GetLength(0), data.GetLength(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport(X11Library)]
|
||||
unsafe public static extern Pixmap XCreateBitmapFromData(Display display, Window d, byte* data, int width, int height);
|
||||
|
||||
[DllImport("libX11", EntryPoint = "XAllocColor")]
|
||||
public static extern Status XAllocNamedColor(Display display, Colormap colormap, string color_name, out XColor screen_def_return, out XColor exact_def_return);
|
||||
}
|
||||
/*
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
|
|
|
@ -1300,6 +1300,38 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
#endregion
|
||||
|
||||
public bool CursorVisible
|
||||
{
|
||||
get { return true; }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
using (new XLock(window.Display))
|
||||
{
|
||||
Functions.XUndefineCursor(window.Display, window.WindowHandle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (new XLock(window.Display))
|
||||
{
|
||||
XColor black, dummy;
|
||||
IntPtr cmap = Functions.XDefaultColormap(window.Display, window.Screen);
|
||||
Functions.XAllocNamedColor(window.Display, cmap, "black", out black, out dummy);
|
||||
IntPtr bmp_empty = Functions.XCreateBitmapFromData(window.Display,
|
||||
window.WindowHandle, new byte[,] { { 0 } });
|
||||
IntPtr cursor_empty = Functions.XCreatePixmapCursor(window.Display,
|
||||
bmp_empty, bmp_empty, ref black, ref black, 0, 0);
|
||||
|
||||
Functions.XDefineCursor(window.Display, window.WindowHandle, cursor_empty);
|
||||
|
||||
Functions.XFreeCursor(window.Display, cursor_empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- INativeGLWindow Members ---
|
||||
|
|
Loading…
Reference in a new issue