Partial implementation of Windows MouseCursor.

Very buggy, but starting to show results.
This commit is contained in:
Fraser 2014-02-21 00:24:24 +00:00 committed by thefiddler
parent 0dd82e1485
commit 8f9311ec8d

View file

@ -102,6 +102,7 @@ namespace OpenTK.Platform.Windows
KeyPressEventArgs key_press = new KeyPressEventArgs((char)0);
MouseCursor cursor = MouseCursor.Default;
IntPtr curson_handle = IntPtr.Zero;
int cursor_visible_count = 0;
static readonly object SyncRoot = new object();
@ -485,6 +486,11 @@ namespace OpenTK.Platform.Windows
mouse_last_timestamp = timestamp;
}
if (cursor != MouseCursor.Default)
{
Functions.SetCursor(curson_handle);
}
if (mouse_outside_window)
{
// Once we receive a mouse move event, it means that the mouse has
@ -1176,7 +1182,51 @@ namespace OpenTK.Platform.Windows
}
set
{
Debug.Print("[Warning] WinGLNative.Cursor property not implemented");
if (value != cursor)
{
var stride = value.Width *
(Bitmap.GetPixelFormatSize(System.Drawing.Imaging.PixelFormat.Format32bppArgb) / 8);
Bitmap bmp;
unsafe
{
fixed (byte* pixels = value.Rgba)
{
bmp = new Bitmap(value.Width, value.Height, stride,
System.Drawing.Imaging.PixelFormat.Format32bppArgb,
new IntPtr(pixels));
}
}
var iconInfo = new IconInfo();
var bmpIcon = bmp.GetHicon();
var success = Functions.GetIconInfo(bmpIcon, out iconInfo);
if (success)
{
iconInfo.xHotspot = value.X;
iconInfo.yHotspot = value.Y;
iconInfo.fIcon = false;
var icon = Functions.CreateIconIndirect(ref iconInfo);
if (icon != IntPtr.Zero)
{
// Currently using a custom cursor so destroy it
// once replaced
bool destoryOld = cursor != MouseCursor.Default;
cursor = value;
curson_handle = icon;
var oldCursor = Functions.SetCursor(icon);
if (destoryOld)
{
Functions.DestroyIcon(oldCursor);
}
}
}
}
}
}