* Source/OpenTK/Platform/X11/X11GLNative.cs: Refactored empty cursor

creation into its own function. Create one empty cursor for the
  lifetime of the window.
This commit is contained in:
the_fiddler 2010-10-20 09:19:34 +00:00
parent 63b35badee
commit 527cdf8622

View file

@ -113,6 +113,8 @@ namespace OpenTK.Platform.X11
readonly char[] chars = new char[16]; readonly char[] chars = new char[16];
readonly KeyPressEventArgs KPEventArgs = new KeyPressEventArgs('\0'); readonly KeyPressEventArgs KPEventArgs = new KeyPressEventArgs('\0');
readonly IntPtr EmptyCursor;
#endregion #endregion
#region Constructors #region Constructors
@ -195,6 +197,8 @@ namespace OpenTK.Platform.X11
driver = new X11Input(window); driver = new X11Input(window);
EmptyCursor = CreateEmptyCursor(window);
Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle)); Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle));
Debug.Unindent(); Debug.Unindent();
@ -677,6 +681,22 @@ namespace OpenTK.Platform.X11
} }
} }
static IntPtr CreateEmptyCursor(X11WindowInfo window)
{
IntPtr cursor = IntPtr.Zero;
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 } });
cursor = Functions.XCreatePixmapCursor(window.Display,
bmp_empty, bmp_empty, ref black, ref black, 0, 0);
}
return cursor;
}
#endregion #endregion
#region INativeWindow Members #region INativeWindow Members
@ -1302,7 +1322,7 @@ namespace OpenTK.Platform.X11
public bool CursorVisible public bool CursorVisible
{ {
get { return true; } get { return true; } // Not used
set set
{ {
if (value) if (value)
@ -1316,17 +1336,7 @@ namespace OpenTK.Platform.X11
{ {
using (new XLock(window.Display)) using (new XLock(window.Display))
{ {
XColor black, dummy; Functions.XDefineCursor(window.Display, window.WindowHandle, EmptyCursor);
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);
} }
} }
} }
@ -1553,6 +1563,7 @@ namespace OpenTK.Platform.X11
{ {
using (new XLock(window.Display)) using (new XLock(window.Display))
{ {
Functions.XFreeCursor(window.Display, EmptyCursor);
Functions.XDestroyWindow(window.Display, window.WindowHandle); Functions.XDestroyWindow(window.Display, window.WindowHandle);
} }