Added glfwCreateStandardCursor.

This function allows the creation of cursor objects using one of several
standard cursor shapes from the current system cursor theme.
This commit is contained in:
Camilla Berglund
2014-09-02 16:52:16 +02:00
parent 1495134398
commit 2a1375e97c
11 changed files with 246 additions and 8 deletions
+36
View File
@@ -32,6 +32,29 @@
#include <crt_externs.h>
// Returns the specified standard cursor
//
static NSCursor* getStandardCursor(int shape)
{
switch (shape)
{
case GLFW_ARROW_CURSOR:
return [NSCursor arrowCursor];
case GLFW_IBEAM_CURSOR:
return [NSCursor IBeamCursor];
case GLFW_CROSSHAIR_CURSOR:
return [NSCursor crosshairCursor];
case GLFW_HAND_CURSOR:
return [NSCursor pointingHandCursor];
case GLFW_HRESIZE_CURSOR:
return [NSCursor resizeLeftRightCursor];
case GLFW_VRESIZE_CURSOR:
return [NSCursor resizeUpDownCursor];
}
return nil;
}
// Center the cursor in the view of the window
//
static void centerCursor(_GLFWwindow *window)
@@ -1161,6 +1184,19 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
return GL_TRUE;
}
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
{
cursor->ns.object = getStandardCursor(shape);
if (!cursor->ns.object)
{
_glfwInputError(GLFW_INVALID_ENUM, "Cocoa: Invalid standard cursor");
return GL_FALSE;
}
[cursor->ns.object retain];
return GL_TRUE;
}
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{
if (cursor->ns.object)
+19
View File
@@ -382,6 +382,25 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
return (GLFWcursor*) cursor;
}
GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape)
{
_GLFWcursor* cursor;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
cursor = calloc(1, sizeof(_GLFWcursor));
cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor;
if (!_glfwPlatformCreateStandardCursor(cursor, shape))
{
glfwDestroyCursor((GLFWcursor*) cursor);
return NULL;
}
return (GLFWcursor*) cursor;
}
GLFWAPI void glfwDestroyCursor(GLFWcursor* handle)
{
_GLFWcursor* cursor = (_GLFWcursor*) handle;
+5
View File
@@ -625,6 +625,11 @@ GLFWglproc _glfwPlatformGetProcAddress(const char* procname);
*/
int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot);
/*! @copydoc glfwCreateStandardCursor
* @ingroup platform
*/
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape);
/*! @copydoc glfwDestroyCursor
* @ingroup platform
*/
+8
View File
@@ -610,6 +610,14 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
return GL_FALSE;
}
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
return GL_FALSE;
}
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
+43
View File
@@ -112,6 +112,29 @@ static void restoreCursor(_GLFWwindow* window)
}
}
// Translates a GLFW standard cursor to a resource ID
//
static LPWSTR translateCursorShape(int shape)
{
switch (shape)
{
case GLFW_ARROW_CURSOR:
return IDC_ARROW;
case GLFW_IBEAM_CURSOR:
return IDC_IBEAM;
case GLFW_CROSSHAIR_CURSOR:
return IDC_CROSS;
case GLFW_HAND_CURSOR:
return IDC_HAND;
case GLFW_HRESIZE_CURSOR:
return IDC_SIZEWE;
case GLFW_VRESIZE_CURSOR:
return IDC_SIZENS;
}
return NULL;
}
// Retrieves and translates modifier keys
//
static int getKeyMods(void)
@@ -1176,6 +1199,26 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
return GL_TRUE;
}
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
{
LPCWSTR native = translateCursorShape(shape);
if (!native)
{
_glfwInputError(GLFW_INVALID_ENUM, "Win32: Invalid standard cursor");
return GL_FALSE;
}
cursor->win32.handle = CopyCursor(LoadCursorW(NULL, native));
if (!cursor->win32.handle)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve shared cursor");
return GL_FALSE;
}
return GL_TRUE;
}
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{
if (cursor->win32.handle)
+7
View File
@@ -422,6 +422,13 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
return GL_TRUE;
}
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
{
// TODO
fprintf(stderr, "_glfwPlatformCreateStandardCursor not implemented yet\n");
return GL_FALSE;
}
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{
wl_buffer_destroy(cursor->wl.buffer);
+46 -1
View File
@@ -27,6 +27,8 @@
#include "internal.h"
#include <X11/cursorfont.h>
#include <sys/select.h>
#include <string.h>
@@ -66,6 +68,29 @@ static Bool isFrameExtentsEvent(Display* display, XEvent* event, XPointer pointe
event->xproperty.atom == _glfw.x11.NET_FRAME_EXTENTS;
}
// Translates a GLFW standard cursor to a font cursor shape
//
static int translateCursorShape(int shape)
{
switch (shape)
{
case GLFW_ARROW_CURSOR:
return XC_arrow;
case GLFW_IBEAM_CURSOR:
return XC_xterm;
case GLFW_CROSSHAIR_CURSOR:
return XC_crosshair;
case GLFW_HAND_CURSOR:
return XC_hand1;
case GLFW_HRESIZE_CURSOR:
return XC_sb_h_double_arrow;
case GLFW_VRESIZE_CURSOR:
return XC_sb_v_double_arrow;
}
return 0;
}
// Translates an X event modifier state mask
//
static int translateState(int state)
@@ -1731,12 +1756,32 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
int xhot, int yhot)
{
cursor->x11.handle = _glfwCreateCursor(image, xhot, yhot);
if (cursor->x11.handle == None)
if (!cursor->x11.handle)
return GL_FALSE;
return GL_TRUE;
}
int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
{
const unsigned int native = translateCursorShape(shape);
if (!native)
{
_glfwInputError(GLFW_INVALID_ENUM, "X11: Invalid standard cursor");
return GL_FALSE;
}
cursor->x11.handle = XCreateFontCursor(_glfw.x11.display, native);
if (!cursor->x11.handle)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to create standard cursor");
return GL_FALSE;
}
return GL_TRUE;
}
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{
if (cursor->x11.handle)