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
+32
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;
}
+4
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);
+19
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 //////
+33 -1
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