1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Added API and X11 implementation of cursor enter and leave callbacks.

This commit is contained in:
Hanmac 2012-01-30 22:18:05 +01:00 committed by Camilla Berglund
parent cd1caded8d
commit 0b752b84c3
5 changed files with 92 additions and 1 deletions

View File

@ -474,6 +474,8 @@ typedef void (* GLFWwindowfocusfun)(GLFWwindow,int);
typedef void (* GLFWwindowiconifyfun)(GLFWwindow,int);
typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int);
typedef void (* GLFWmouseposfun)(GLFWwindow,int,int);
typedef void (* GLFWcursorenterfun)(GLFWwindow);
typedef void (* GLFWcursorleavefun)(GLFWwindow);
typedef void (* GLFWscrollfun)(GLFWwindow,int,int);
typedef void (* GLFWkeyfun)(GLFWwindow,int,int);
typedef void (* GLFWcharfun)(GLFWwindow,int);
@ -574,6 +576,8 @@ GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun);
GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun);
GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun);
GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun);
GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun);
/* Joystick input */
GLFWAPI int glfwGetJoystickParam(int joy, int param);

View File

@ -436,3 +436,35 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
_glfwLibrary.scrollCallback = cbfun;
}
//========================================================================
// Set callback function for cursor enter events
//========================================================================
GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwLibrary.cursorEnterCallback = cbfun;
}
//========================================================================
// Set callback function for cursor enter events
//========================================================================
GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwLibrary.cursorLeaveCallback = cbfun;
}

View File

@ -240,6 +240,8 @@ struct _GLFWlibrary
GLFWscrollfun scrollCallback;
GLFWkeyfun keyCallback;
GLFWcharfun charCallback;
GLFWcursorenterfun cursorEnterCallback;
GLFWcursorleavefun cursorLeaveCallback;
GLFWthreadmodel threading;
GLFWallocator allocator;
@ -352,6 +354,8 @@ void _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
void _glfwInputCursorEnter(_GLFWwindow* window);
void _glfwInputCursorLeave(_GLFWwindow* window);
// OpenGL context helpers (opengl.c)
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);

View File

@ -205,6 +205,25 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
_glfwLibrary.windowRefreshCallback(window);
}
//========================================================================
// Register cursor enter events
//========================================================================
void _glfwInputCursorEnter(_GLFWwindow* window)
{
if (_glfwLibrary.cursorEnterCallback)
_glfwLibrary.cursorEnterCallback(window);
}
//========================================================================
// Register cursor leave events
//========================================================================
void _glfwInputCursorLeave(_GLFWwindow* window)
{
if (_glfwLibrary.cursorLeaveCallback)
_glfwLibrary.cursorLeaveCallback(window);
}
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////

View File

@ -679,7 +679,8 @@ static GLboolean createWindow(_GLFWwindow* window,
wa.border_pixel = 0;
wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask |
PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
ExposureMask | FocusChangeMask | VisibilityChangeMask;
ExposureMask | FocusChangeMask | VisibilityChangeMask |
EnterWindowMask | LeaveWindowMask;
if (wndconfig->mode == GLFW_WINDOWED)
{
@ -1180,6 +1181,37 @@ static void processSingleEvent(void)
break;
}
case EnterNotify:
{
// The mouse cursor enters the Window
window = findWindow(event.xcrossing.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for EnterNotify event\n");
return;
}
if(window->cursorMode == GLFW_CURSOR_HIDDEN)
{
hideMouseCursor(window);
}
_glfwInputCursorEnter(window);
break;
}
case LeaveNotify:
{
// The mouse cursor leave the Window
window = findWindow(event.xcrossing.window);
if (window == NULL)
{
fprintf(stderr, "Cannot find GLFW window structure for LeaveNotify event\n");
return;
}
showMouseCursor(window);
_glfwInputCursorLeave(window);
break;
}
case MotionNotify:
{
// The mouse cursor was moved