mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 12:02:00 +00:00
Unified X11 cursor creation.
This commit is contained in:
parent
215924f797
commit
9b6c14b7ae
@ -576,40 +576,16 @@ static GLboolean initExtensions(void)
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
// Create a blank cursor (for locked mouse mode)
|
||||
// Create a blank cursor for hidden and disabled cursor modes
|
||||
//
|
||||
static Cursor createNULLCursor(void)
|
||||
{
|
||||
Pixmap cursormask;
|
||||
XGCValues xgc;
|
||||
GC gc;
|
||||
XColor col;
|
||||
Cursor cursor;
|
||||
unsigned char pixels[16 * 16 * 4];
|
||||
GLFWimage image = { 16, 16, pixels };
|
||||
|
||||
_glfwGrabXErrorHandler();
|
||||
memset(pixels, 0, sizeof(pixels));
|
||||
|
||||
cursormask = XCreatePixmap(_glfw.x11.display, _glfw.x11.root, 1, 1, 1);
|
||||
xgc.function = GXclear;
|
||||
gc = XCreateGC(_glfw.x11.display, cursormask, GCFunction, &xgc);
|
||||
XFillRectangle(_glfw.x11.display, cursormask, gc, 0, 0, 1, 1);
|
||||
col.pixel = 0;
|
||||
col.red = 0;
|
||||
col.flags = 4;
|
||||
cursor = XCreatePixmapCursor(_glfw.x11.display,
|
||||
cursormask, cursormask,
|
||||
&col, &col, 0, 0);
|
||||
XFreePixmap(_glfw.x11.display, cursormask);
|
||||
XFreeGC(_glfw.x11.display, gc);
|
||||
|
||||
_glfwReleaseXErrorHandler();
|
||||
|
||||
if (cursor == None)
|
||||
{
|
||||
_glfwInputXError(GLFW_PLATFORM_ERROR,
|
||||
"X11: Failed to create null cursor");
|
||||
}
|
||||
|
||||
return cursor;
|
||||
return _glfwCreateCursor(&image, 0, 0);
|
||||
}
|
||||
|
||||
// Terminate X11 display
|
||||
@ -664,6 +640,37 @@ void _glfwInputXError(int error, const char* message)
|
||||
_glfwInputError(error, "%s: %s", message, buffer);
|
||||
}
|
||||
|
||||
// Create a cursor object
|
||||
//
|
||||
Cursor _glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
|
||||
{
|
||||
int i;
|
||||
Cursor cursor;
|
||||
|
||||
XcursorImage* native = XcursorImageCreate(image->width, image->height);
|
||||
if (native == NULL)
|
||||
return None;
|
||||
|
||||
native->xhot = xhot;
|
||||
native->yhot = yhot;
|
||||
|
||||
unsigned char* source = (unsigned char*) image->pixels;
|
||||
XcursorPixel* target = native->pixels;
|
||||
|
||||
for (i = 0; i < image->width * image->height; i++, target++, source += 4)
|
||||
{
|
||||
*target = (source[3] << 24) |
|
||||
(source[0] << 16) |
|
||||
(source[1] << 8) |
|
||||
source[2];
|
||||
}
|
||||
|
||||
cursor = XcursorImageLoadCursor(_glfw.x11.display, native);
|
||||
XcursorImageDestroy(native);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
|
@ -256,6 +256,8 @@ void _glfwHandleSelectionClear(XEvent* event);
|
||||
void _glfwHandleSelectionRequest(XEvent* event);
|
||||
void _glfwPushSelectionToManager(_GLFWwindow* window);
|
||||
|
||||
Cursor _glfwCreateCursor(const GLFWimage* image, int xhot, int yhot);
|
||||
|
||||
// Window support
|
||||
_GLFWwindow* _glfwFindWindowByHandle(Window handle);
|
||||
unsigned long _glfwGetWindowProperty(Window window,
|
||||
|
@ -1454,29 +1454,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
||||
const GLFWimage* image,
|
||||
int xhot, int yhot)
|
||||
{
|
||||
int i;
|
||||
|
||||
XcursorImage* native = XcursorImageCreate(image->width, image->height);
|
||||
if (native == NULL)
|
||||
return GL_FALSE;
|
||||
|
||||
native->xhot = xhot;
|
||||
native->yhot = yhot;
|
||||
|
||||
unsigned char* source = (unsigned char*) image->pixels;
|
||||
XcursorPixel* target = native->pixels;
|
||||
|
||||
for (i = 0; i < image->width * image->height; i++, target++, source += 4)
|
||||
{
|
||||
*target = (source[3] << 24) |
|
||||
(source[0] << 16) |
|
||||
(source[1] << 8) |
|
||||
source[2];
|
||||
}
|
||||
|
||||
cursor->x11.handle = XcursorImageLoadCursor(_glfw.x11.display, native);
|
||||
XcursorImageDestroy(native);
|
||||
|
||||
cursor->x11.handle = _glfwCreateCursor(image, xhot, yhot);
|
||||
if (cursor->x11.handle == None)
|
||||
return GL_FALSE;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user