Merged cursor enter/leave callbacks.

This commit is contained in:
Camilla Berglund 2012-01-30 22:59:38 +01:00
parent e5d85a5cc4
commit c4806b9532
5 changed files with 13 additions and 47 deletions

View File

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

View File

@ -147,24 +147,13 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
//======================================================================== //========================================================================
// Register cursor enter events // Register cursor enter/leave events
//======================================================================== //========================================================================
void _glfwInputCursorEnter(_GLFWwindow* window) void _glfwInputCursorEnter(_GLFWwindow* window, int entered)
{ {
if (_glfwLibrary.cursorEnterCallback) if (_glfwLibrary.cursorEnterCallback)
_glfwLibrary.cursorEnterCallback(window); _glfwLibrary.cursorEnterCallback(window, entered);
}
//========================================================================
// Register cursor leave events
//========================================================================
void _glfwInputCursorLeave(_GLFWwindow* window)
{
if (_glfwLibrary.cursorLeaveCallback)
_glfwLibrary.cursorLeaveCallback(window);
} }
@ -443,7 +432,7 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
//======================================================================== //========================================================================
// Set callback function for cursor enter events // Set callback function for cursor enter/leave events
//======================================================================== //========================================================================
GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun) GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun)
@ -458,22 +447,6 @@ GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun)
} }
//========================================================================
// Set callback function for cursor enter events
//========================================================================
GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return;
}
_glfwLibrary.cursorLeaveCallback = cbfun;
}
//======================================================================== //========================================================================
// Set callback function for scroll events // Set callback function for scroll events
//======================================================================== //========================================================================

View File

@ -238,7 +238,6 @@ struct _GLFWlibrary
GLFWmousebuttonfun mouseButtonCallback; GLFWmousebuttonfun mouseButtonCallback;
GLFWmouseposfun mousePosCallback; GLFWmouseposfun mousePosCallback;
GLFWcursorenterfun cursorEnterCallback; GLFWcursorenterfun cursorEnterCallback;
GLFWcursorleavefun cursorLeaveCallback;
GLFWscrollfun scrollCallback; GLFWscrollfun scrollCallback;
GLFWkeyfun keyCallback; GLFWkeyfun keyCallback;
GLFWcharfun charCallback; GLFWcharfun charCallback;
@ -354,8 +353,7 @@ void _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputScroll(_GLFWwindow* window, int x, int y); void _glfwInputScroll(_GLFWwindow* window, int x, int y);
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y); void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
void _glfwInputCursorEnter(_GLFWwindow* window); void _glfwInputCursorEnter(_GLFWwindow* window, int entered);
void _glfwInputCursorLeave(_GLFWwindow* window);
// OpenGL context helpers (opengl.c) // OpenGL context helpers (opengl.c)
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions); int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);

View File

@ -1194,7 +1194,7 @@ static void processSingleEvent(void)
if (window->cursorMode == GLFW_CURSOR_HIDDEN) if (window->cursorMode == GLFW_CURSOR_HIDDEN)
hideMouseCursor(window); hideMouseCursor(window);
_glfwInputCursorEnter(window); _glfwInputCursorEnter(window, GL_TRUE);
break; break;
} }
@ -1211,7 +1211,7 @@ static void processSingleEvent(void)
if (window->cursorMode == GLFW_CURSOR_HIDDEN) if (window->cursorMode == GLFW_CURSOR_HIDDEN)
showMouseCursor(window); showMouseCursor(window);
_glfwInputCursorLeave(window); _glfwInputCursorEnter(window, GL_FALSE);
break; break;
} }

View File

@ -274,14 +274,12 @@ static void mouse_position_callback(GLFWwindow window, int x, int y)
printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y); printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y);
} }
static void cursor_enter_callback(GLFWwindow window) static void cursor_enter_callback(GLFWwindow window, int entered)
{ {
printf("%08x at %0.3f: Cursor entered window\n", counter++, glfwGetTime()); printf("%08x at %0.3f: Cursor %s window\n",
} counter++,
glfwGetTime(),
static void cursor_leave_callback(GLFWwindow window) entered ? "entered" : "left");
{
printf("%08x at %0.3f: Cursor left window\n", counter++, glfwGetTime());
} }
static void scroll_callback(GLFWwindow window, int x, int y) static void scroll_callback(GLFWwindow window, int x, int y)
@ -362,7 +360,6 @@ int main(void)
glfwSetMouseButtonCallback(mouse_button_callback); glfwSetMouseButtonCallback(mouse_button_callback);
glfwSetMousePosCallback(mouse_position_callback); glfwSetMousePosCallback(mouse_position_callback);
glfwSetCursorEnterCallback(cursor_enter_callback); glfwSetCursorEnterCallback(cursor_enter_callback);
glfwSetCursorLeaveCallback(cursor_leave_callback);
glfwSetScrollCallback(scroll_callback); glfwSetScrollCallback(scroll_callback);
glfwSetKeyCallback(key_callback); glfwSetKeyCallback(key_callback);
glfwSetCharCallback(char_callback); glfwSetCharCallback(char_callback);