[All] Initial implementation of INativeWindow.Cursor property

Affects issue #9
This commit is contained in:
thefiddler 2014-02-18 16:44:28 +01:00
parent f545bd512b
commit dd55cea489
6 changed files with 158 additions and 1 deletions

View file

@ -132,6 +132,12 @@ namespace OpenTK
[Obsolete("Use OpenTK.Input.Mouse/Keybord/Joystick/GamePad instead.")]
OpenTK.Input.IInputDriver InputDriver { get; }
/// <summary>
/// Gets or sets the <see cref="OpenTK.MouseCursor"/> for this window.
/// </summary>
/// <value>The cursor.</value>
MouseCursor Cursor { get; set; }
/// <summary>
/// Gets or sets a value, indicating whether the mouse cursor is visible.
/// </summary>

View file

@ -259,6 +259,30 @@ namespace OpenTK
#endregion
#region Cursor
/// <summary>
/// Gets or sets the <see cref="OpenTK.MouseCursor"/> for this window.
/// </summary>
public MouseCursor Cursor
{
get
{
EnsureUndisposed();
return implementation.Cursor;
}
set
{
EnsureUndisposed();
if (value == null)
throw new ArgumentNullException();
implementation.Cursor = value;
}
}
#endregion
#region Exists
/// <summary>

View file

@ -83,6 +83,8 @@ namespace OpenTK.Platform.MacOS
float mouse_rel_x;
float mouse_rel_y;
MouseCursor cursor = MouseCursor.Default;
#endregion
#region AGL Device Hack
@ -935,6 +937,18 @@ namespace OpenTK.Platform.MacOS
}
}
public MouseCursor Cursor
{
get
{
return cursor;
}
set
{
Debug.Print("[Warning] CarbonGLNative.Cursor property not implemented");
}
}
public bool CursorVisible
{
get { return CG.CursorIsVisible(); }

View file

@ -58,6 +58,8 @@ namespace OpenTK.Platform.SDL2
WindowState previous_window_state = WindowState.Normal;
WindowBorder window_border = WindowBorder.Resizable;
Icon icon;
MouseCursor cursor = MouseCursor.Default;
IntPtr sdl_cursor = IntPtr.Zero;
string window_title;
// Used in KeyPress event to decode SDL UTF8 text strings
@ -458,6 +460,78 @@ namespace OpenTK.Platform.SDL2
public event EventHandler<EventArgs> MouseEnter = delegate { };
public event EventHandler<EventArgs> MouseLeave = delegate { };
public MouseCursor Cursor
{
get
{
return cursor;
}
set
{
lock (sync)
{
if (value != MouseCursor.Default)
{
// Free the previous cursor,
// if one has been set.
if (sdl_cursor != IntPtr.Zero)
{
SDL.FreeCursor(sdl_cursor);
sdl_cursor = IntPtr.Zero;
cursor = MouseCursor.Default;
}
// Set the new cursor
if (value == MouseCursor.Default)
{
// Reset to default cursor
SDL.SetCursor(SDL.GetDefaultCursor());
}
else
{
// Create and set a new cursor using
// the rgba values supplied by the user
unsafe
{
fixed (byte* pixels = value.Rgba)
{
IntPtr cursor_surface =
SDL.CreateRGBSurfaceFrom(
new IntPtr(pixels),
cursor.Width,
cursor.Height,
32,
cursor.Width * 4,
0xff000000,
0x00ff0000,
0x0000ff00,
0x000000ff);
sdl_cursor = SDL.CreateColorCursor(
cursor_surface,
cursor.Width,
cursor.Height,
cursor.X,
cursor.Y);
if (sdl_cursor != IntPtr.Zero)
{
SDL.SetCursor(sdl_cursor);
cursor = value;
}
if (cursor_surface != IntPtr.Zero)
{
SDL.FreeSurface(cursor_surface);
}
}
}
}
}
}
}
}
public void Close()
{
lock (sync)

View file

@ -101,6 +101,7 @@ namespace OpenTK.Platform.Windows
KeyboardKeyEventArgs key_up = new KeyboardKeyEventArgs();
KeyPressEventArgs key_press = new KeyPressEventArgs((char)0);
MouseCursor cursor = MouseCursor.Default;
int cursor_visible_count = 0;
static readonly object SyncRoot = new object();
@ -1165,6 +1166,22 @@ namespace OpenTK.Platform.Windows
#endregion
#region Cursor
public MouseCursor Cursor
{
get
{
return cursor;
}
set
{
Debug.Print("[Warning] WinGLNative.Cursor property not implemented");
}
}
#endregion
#region CursorVisible
public bool CursorVisible

View file

@ -115,6 +115,8 @@ namespace OpenTK.Platform.X11
bool isExiting;
bool _decorations_hidden = false;
MouseCursor cursor = MouseCursor.Default;
bool cursor_visible = true;
int mouse_rel_x, mouse_rel_y;
@ -1460,6 +1462,24 @@ namespace OpenTK.Platform.X11
#endregion
#region Cursor
public MouseCursor Cursor
{
get
{
return cursor;
}
set
{
Debug.Print("[Warning] X11GLNative.Cursor property not implemented");
}
}
#endregion
#region CursorVisible
public bool CursorVisible
{
get { return cursor_visible; }
@ -1486,6 +1506,8 @@ namespace OpenTK.Platform.X11
#endregion
#endregion
#region --- INativeGLWindow Members ---
#region public IInputDriver InputDriver