mirror of
https://github.com/glfw/glfw.git
synced 2024-11-13 14:03:52 +00:00
Added API and X11 implementation of cursor enter and leave callbacks.
This commit is contained in:
parent
cd1caded8d
commit
0b752b84c3
@ -474,6 +474,8 @@ 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 (* 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);
|
||||||
@ -574,6 +576,8 @@ 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 glfwSetScrollCallback(GLFWscrollfun cbfun);
|
GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun);
|
||||||
|
GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun);
|
||||||
|
GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun);
|
||||||
|
|
||||||
/* Joystick input */
|
/* Joystick input */
|
||||||
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
||||||
|
32
src/input.c
32
src/input.c
@ -436,3 +436,35 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
|
|||||||
_glfwLibrary.scrollCallback = 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -240,6 +240,8 @@ struct _GLFWlibrary
|
|||||||
GLFWscrollfun scrollCallback;
|
GLFWscrollfun scrollCallback;
|
||||||
GLFWkeyfun keyCallback;
|
GLFWkeyfun keyCallback;
|
||||||
GLFWcharfun charCallback;
|
GLFWcharfun charCallback;
|
||||||
|
GLFWcursorenterfun cursorEnterCallback;
|
||||||
|
GLFWcursorleavefun cursorLeaveCallback;
|
||||||
|
|
||||||
GLFWthreadmodel threading;
|
GLFWthreadmodel threading;
|
||||||
GLFWallocator allocator;
|
GLFWallocator allocator;
|
||||||
@ -352,6 +354,8 @@ 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 _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);
|
||||||
|
19
src/window.c
19
src/window.c
@ -205,6 +205,25 @@ void _glfwInputWindowDamage(_GLFWwindow* window)
|
|||||||
_glfwLibrary.windowRefreshCallback(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 //////
|
////// GLFW public API //////
|
||||||
|
@ -679,7 +679,8 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
wa.border_pixel = 0;
|
wa.border_pixel = 0;
|
||||||
wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask |
|
wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask |
|
||||||
PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
|
PointerMotionMask | ButtonPressMask | ButtonReleaseMask |
|
||||||
ExposureMask | FocusChangeMask | VisibilityChangeMask;
|
ExposureMask | FocusChangeMask | VisibilityChangeMask |
|
||||||
|
EnterWindowMask | LeaveWindowMask;
|
||||||
|
|
||||||
if (wndconfig->mode == GLFW_WINDOWED)
|
if (wndconfig->mode == GLFW_WINDOWED)
|
||||||
{
|
{
|
||||||
@ -1180,6 +1181,37 @@ static void processSingleEvent(void)
|
|||||||
break;
|
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:
|
case MotionNotify:
|
||||||
{
|
{
|
||||||
// The mouse cursor was moved
|
// The mouse cursor was moved
|
||||||
|
Loading…
Reference in New Issue
Block a user