mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 04:54:35 +00:00
Unified nomenclature for cursor positions.
This commit is contained in:
parent
e6896a499c
commit
cef9dea1d2
@ -379,7 +379,7 @@ static void windowRefreshFun(GLFWwindow window)
|
|||||||
// Mouse position callback function
|
// Mouse position callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void mousePosFun(GLFWwindow window, int x, int y)
|
static void cursorPosFun(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
// Depending on which view was selected, rotate around different axes
|
// Depending on which view was selected, rotate around different axes
|
||||||
switch (active_view)
|
switch (active_view)
|
||||||
@ -404,7 +404,7 @@ static void mousePosFun(GLFWwindow window, int x, int y)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember mouse position
|
// Remember cursor position
|
||||||
xpos = x;
|
xpos = x;
|
||||||
ypos = y;
|
ypos = y;
|
||||||
}
|
}
|
||||||
@ -472,7 +472,7 @@ int main(void)
|
|||||||
// Set callback functions
|
// Set callback functions
|
||||||
glfwSetWindowSizeCallback(windowSizeFun);
|
glfwSetWindowSizeCallback(windowSizeFun);
|
||||||
glfwSetWindowRefreshCallback(windowRefreshFun);
|
glfwSetWindowRefreshCallback(windowRefreshFun);
|
||||||
glfwSetMousePosCallback(mousePosFun);
|
glfwSetCursorPosCallback(cursorPosFun);
|
||||||
glfwSetMouseButtonCallback(mouseButtonFun);
|
glfwSetMouseButtonCallback(mouseButtonFun);
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
|
@ -39,7 +39,7 @@ int main(void)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
double t = glfwGetTime();
|
double t = glfwGetTime();
|
||||||
glfwGetMousePos(window, &x, NULL);
|
glfwGetCursorPos(window, &x, NULL);
|
||||||
|
|
||||||
// Get window size (may be different than the requested size)
|
// Get window size (may be different than the requested size)
|
||||||
glfwGetWindowSize(window, &width, &height);
|
glfwGetWindowSize(window, &width, &height);
|
||||||
|
@ -323,10 +323,10 @@ void mouse_button_callback(GLFWwindow window, int button, int action)
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Callback function for mouse motion events
|
// Callback function for cursor motion events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void mouse_position_callback(GLFWwindow window, int x, int y)
|
void cursor_position_callback(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
if (locked)
|
if (locked)
|
||||||
{
|
{
|
||||||
@ -403,7 +403,7 @@ int main(int argc, char* argv[])
|
|||||||
// Window resize handler
|
// Window resize handler
|
||||||
glfwSetWindowSizeCallback(window_resize_callback);
|
glfwSetWindowSizeCallback(window_resize_callback);
|
||||||
glfwSetMouseButtonCallback(mouse_button_callback);
|
glfwSetMouseButtonCallback(mouse_button_callback);
|
||||||
glfwSetMousePosCallback(mouse_position_callback);
|
glfwSetCursorPosCallback(cursor_position_callback);
|
||||||
glfwSetScrollCallback(scroll_callback);
|
glfwSetScrollCallback(scroll_callback);
|
||||||
|
|
||||||
// Initialize OpenGL
|
// Initialize OpenGL
|
||||||
|
@ -480,7 +480,7 @@ typedef void (* GLFWwindowrefreshfun)(GLFWwindow);
|
|||||||
typedef void (* GLFWwindowfocusfun)(GLFWwindow,int);
|
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 (* GLFWcursorposfun)(GLFWwindow,int,int);
|
||||||
typedef void (* GLFWcursorenterfun)(GLFWwindow,int);
|
typedef void (* GLFWcursorenterfun)(GLFWwindow,int);
|
||||||
typedef void (* GLFWscrollfun)(GLFWwindow,double,double);
|
typedef void (* GLFWscrollfun)(GLFWwindow,double,double);
|
||||||
typedef void (* GLFWkeyfun)(GLFWwindow,int,int);
|
typedef void (* GLFWkeyfun)(GLFWwindow,int,int);
|
||||||
@ -559,13 +559,13 @@ GLFWAPI int glfwGetInputMode(GLFWwindow window, int mode);
|
|||||||
GLFWAPI void glfwSetInputMode(GLFWwindow window, int mode, int value);
|
GLFWAPI void glfwSetInputMode(GLFWwindow window, int mode, int value);
|
||||||
GLFWAPI int glfwGetKey(GLFWwindow window, int key);
|
GLFWAPI int glfwGetKey(GLFWwindow window, int key);
|
||||||
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button);
|
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button);
|
||||||
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
|
GLFWAPI void glfwGetCursorPos(GLFWwindow window, int* xpos, int* ypos);
|
||||||
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos);
|
GLFWAPI void glfwSetCursorPos(GLFWwindow window, int xpos, int ypos);
|
||||||
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, double* xoffset, double* yoffset);
|
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, double* xoffset, double* yoffset);
|
||||||
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
|
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
|
||||||
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
|
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
|
||||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun);
|
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun);
|
||||||
GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun);
|
GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun);
|
||||||
GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun);
|
GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun);
|
||||||
GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun);
|
GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun);
|
||||||
|
|
||||||
|
@ -299,6 +299,7 @@ version of GLFW.</p>
|
|||||||
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
|
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
|
||||||
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
|
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
|
||||||
<li>Renamed <code>GLFW_NO_GLU</code> to <code>GLFW_INCLUDE_GLU</code> and made it disabled by default</li>
|
<li>Renamed <code>GLFW_NO_GLU</code> to <code>GLFW_INCLUDE_GLU</code> and made it disabled by default</li>
|
||||||
|
<li>Renamed mouse position functions to cursor position equivalents</li>
|
||||||
<li>Replaced ad hoc build system with CMake</li>
|
<li>Replaced ad hoc build system with CMake</li>
|
||||||
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
|
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
|
||||||
<li>Replaced mouse wheel interface with two-dimensional, floating point scrolling interface</li>
|
<li>Replaced mouse wheel interface with two-dimensional, floating point scrolling interface</li>
|
||||||
|
@ -1152,12 +1152,12 @@ void _glfwPlatformWaitEvents( void )
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor position
|
// Set physical cursor position
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
|
||||||
{
|
{
|
||||||
// The library seems to assume that after calling this the mouse won't move,
|
// The library seems to assume that after calling this the cursor won't move,
|
||||||
// but obviously it will, and escape the app's window, and activate other apps,
|
// but obviously it will, and escape the app's window, and activate other apps,
|
||||||
// and other badness in pain. I think the API's just silly, but maybe I'm
|
// and other badness in pain. I think the API's just silly, but maybe I'm
|
||||||
// misunderstanding it...
|
// misunderstanding it...
|
||||||
|
26
src/input.c
26
src/input.c
@ -55,7 +55,7 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
|
|||||||
centerPosY = window->height / 2;
|
centerPosY = window->height / 2;
|
||||||
|
|
||||||
if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED)
|
if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED)
|
||||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
_glfwPlatformSetCursorPos(window, centerPosX, centerPosY);
|
||||||
|
|
||||||
_glfwPlatformSetCursorMode(window, newMode);
|
_glfwPlatformSetCursorMode(window, newMode);
|
||||||
window->cursorMode = newMode;
|
window->cursorMode = newMode;
|
||||||
@ -249,11 +249,11 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
|||||||
window->cursorPosY = y;
|
window->cursorPosY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_glfwLibrary.mousePosCallback)
|
if (_glfwLibrary.cursorPosCallback)
|
||||||
{
|
{
|
||||||
_glfwLibrary.mousePosCallback(window,
|
_glfwLibrary.cursorPosCallback(window,
|
||||||
window->cursorPosX,
|
window->cursorPosX,
|
||||||
window->cursorPosY);
|
window->cursorPosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button)
|
|||||||
// Returns the last reported cursor position for the specified window
|
// Returns the last reported cursor position for the specified window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
|
GLFWAPI void glfwGetCursorPos(GLFWwindow handle, int* xpos, int* ypos)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|
||||||
@ -435,7 +435,7 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
|
|||||||
// the specified window
|
// the specified window
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
|
GLFWAPI void glfwSetCursorPos(GLFWwindow handle, int xpos, int ypos)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|
||||||
@ -451,11 +451,11 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't do anything if the mouse position did not change
|
// Don't do anything if the cursor position did not change
|
||||||
if (xpos == window->cursorPosX && ypos == window->cursorPosY)
|
if (xpos == window->cursorPosX && ypos == window->cursorPosY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Set GLFW mouse position
|
// Set GLFW cursor position
|
||||||
window->cursorPosX = xpos;
|
window->cursorPosX = xpos;
|
||||||
window->cursorPosY = ypos;
|
window->cursorPosY = ypos;
|
||||||
|
|
||||||
@ -464,7 +464,7 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Update physical cursor position
|
// Update physical cursor position
|
||||||
_glfwPlatformSetMouseCursorPos(window, xpos, ypos);
|
_glfwPlatformSetCursorPos(window, xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -542,7 +542,7 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun)
|
|||||||
// Set callback function for mouse moves
|
// Set callback function for mouse moves
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
@ -550,10 +550,10 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwLibrary.mousePosCallback = cbfun;
|
_glfwLibrary.cursorPosCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
// Call the callback function to let the application know the current
|
||||||
// mouse position
|
// cursor position
|
||||||
if (cbfun)
|
if (cbfun)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
@ -241,7 +241,7 @@ struct _GLFWlibrary
|
|||||||
GLFWwindowfocusfun windowFocusCallback;
|
GLFWwindowfocusfun windowFocusCallback;
|
||||||
GLFWwindowiconifyfun windowIconifyCallback;
|
GLFWwindowiconifyfun windowIconifyCallback;
|
||||||
GLFWmousebuttonfun mouseButtonCallback;
|
GLFWmousebuttonfun mouseButtonCallback;
|
||||||
GLFWmouseposfun mousePosCallback;
|
GLFWcursorposfun cursorPosCallback;
|
||||||
GLFWcursorenterfun cursorEnterCallback;
|
GLFWcursorenterfun cursorEnterCallback;
|
||||||
GLFWscrollfun scrollCallback;
|
GLFWscrollfun scrollCallback;
|
||||||
GLFWkeyfun keyCallback;
|
GLFWkeyfun keyCallback;
|
||||||
@ -284,7 +284,7 @@ const char* _glfwPlatformGetVersionString(void);
|
|||||||
// Input
|
// Input
|
||||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
||||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
||||||
void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y);
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y);
|
||||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
|
||||||
|
|
||||||
// Fullscreen
|
// Fullscreen
|
||||||
|
@ -165,7 +165,7 @@ typedef struct _GLFWwindowWin32
|
|||||||
int desiredRefreshRate; // Desired vertical monitor refresh rate
|
int desiredRefreshRate; // Desired vertical monitor refresh rate
|
||||||
GLboolean cursorCentered;
|
GLboolean cursorCentered;
|
||||||
GLboolean cursorInside;
|
GLboolean cursorInside;
|
||||||
int oldMouseX, oldMouseY;
|
int oldCursorX, oldCursorY;
|
||||||
} _GLFWwindowWin32;
|
} _GLFWwindowWin32;
|
||||||
|
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
// Hide mouse cursor
|
// Hide mouse cursor
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void hideMouseCursor(_GLFWwindow* window)
|
static void hideCursor(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ static void hideMouseCursor(_GLFWwindow* window)
|
|||||||
// Capture mouse cursor
|
// Capture mouse cursor
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void captureMouseCursor(_GLFWwindow* window)
|
static void captureCursor(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
RECT ClipWindowRect;
|
RECT ClipWindowRect;
|
||||||
|
|
||||||
@ -477,7 +477,7 @@ static void captureMouseCursor(_GLFWwindow* window)
|
|||||||
// Show mouse cursor
|
// Show mouse cursor
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void showMouseCursor(_GLFWwindow* window)
|
static void showCursor(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
// Un-capture cursor
|
// Un-capture cursor
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
@ -784,7 +784,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
// The window was deactivated (or iconified, see above)
|
// The window was deactivated (or iconified, see above)
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
showMouseCursor(window);
|
showCursor(window);
|
||||||
|
|
||||||
if (window->mode == GLFW_FULLSCREEN)
|
if (window->mode == GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
@ -807,7 +807,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
// The window was activated
|
// The window was activated
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
captureMouseCursor(window);
|
captureCursor(window);
|
||||||
|
|
||||||
if (window->mode == GLFW_FULLSCREEN)
|
if (window->mode == GLFW_FULLSCREEN)
|
||||||
{
|
{
|
||||||
@ -962,14 +962,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
|
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
{
|
{
|
||||||
int newMouseX, newMouseY;
|
int newCursorX, newCursorY;
|
||||||
|
|
||||||
// Get signed (!) mouse position
|
// Get signed (!) cursor position
|
||||||
newMouseX = (int)((short)LOWORD(lParam));
|
newCursorX = (int)((short)LOWORD(lParam));
|
||||||
newMouseY = (int)((short)HIWORD(lParam));
|
newCursorY = (int)((short)HIWORD(lParam));
|
||||||
|
|
||||||
if (newMouseX != window->Win32.oldMouseX ||
|
if (newCursorX != window->Win32.oldCursorX ||
|
||||||
newMouseY != window->Win32.oldMouseY)
|
newCursorY != window->Win32.oldCursorY)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
@ -978,17 +978,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
if (_glfwLibrary.activeWindow != window)
|
if (_glfwLibrary.activeWindow != window)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
x = newMouseX - window->Win32.oldMouseX;
|
x = newCursorX - window->Win32.oldCursorX;
|
||||||
y = newMouseY - window->Win32.oldMouseY;
|
y = newCursorY - window->Win32.oldCursorY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
x = newMouseX;
|
x = newCursorX;
|
||||||
y = newMouseY;
|
y = newCursorY;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->Win32.oldMouseX = newMouseX;
|
window->Win32.oldCursorX = newCursorX;
|
||||||
window->Win32.oldMouseY = newMouseY;
|
window->Win32.oldCursorY = newCursorY;
|
||||||
window->Win32.cursorCentered = GL_FALSE;
|
window->Win32.cursorCentered = GL_FALSE;
|
||||||
|
|
||||||
_glfwInputCursorMotion(window, x, y);
|
_glfwInputCursorMotion(window, x, y);
|
||||||
@ -1372,11 +1372,11 @@ static int createWindow(_GLFWwindow* window,
|
|||||||
|
|
||||||
initWGLExtensions(window);
|
initWGLExtensions(window);
|
||||||
|
|
||||||
// Initialize mouse position data
|
// Initialize cursor position data
|
||||||
GetCursorPos(&pos);
|
GetCursorPos(&pos);
|
||||||
ScreenToClient(window->Win32.handle, &pos);
|
ScreenToClient(window->Win32.handle, &pos);
|
||||||
window->Win32.oldMouseX = window->cursorPosX = pos.x;
|
window->Win32.oldCursorX = window->cursorPosX = pos.x;
|
||||||
window->Win32.oldMouseY = window->cursorPosY = pos.y;
|
window->Win32.oldCursorY = window->cursorPosY = pos.y;
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
@ -1782,13 +1782,13 @@ void _glfwPlatformPollEvents(void)
|
|||||||
if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
window->Win32.cursorCentered = GL_FALSE;
|
window->Win32.cursorCentered = GL_FALSE;
|
||||||
window->Win32.oldMouseX = window->width / 2;
|
window->Win32.oldCursorX = window->width / 2;
|
||||||
window->Win32.oldMouseY = window->height / 2;
|
window->Win32.oldCursorY = window->height / 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//window->Win32.oldMouseX = window->cursorPosX;
|
//window->Win32.oldCursorX = window->cursorPosX;
|
||||||
//window->Win32.oldMouseY = window->cursorPosY;
|
//window->Win32.oldCursorY = window->cursorPosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||||
@ -1845,9 +1845,9 @@ void _glfwPlatformPollEvents(void)
|
|||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
|
||||||
!window->Win32.cursorCentered)
|
!window->Win32.cursorCentered)
|
||||||
{
|
{
|
||||||
_glfwPlatformSetMouseCursorPos(window,
|
_glfwPlatformSetCursorPos(window,
|
||||||
window->width / 2,
|
window->width / 2,
|
||||||
window->height / 2);
|
window->height / 2);
|
||||||
window->Win32.cursorCentered = GL_TRUE;
|
window->Win32.cursorCentered = GL_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1867,10 +1867,10 @@ void _glfwPlatformWaitEvents(void)
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor position
|
// Set physical cursor position
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
|
||||||
{
|
{
|
||||||
POINT pos;
|
POINT pos;
|
||||||
|
|
||||||
@ -1892,13 +1892,13 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case GLFW_CURSOR_NORMAL:
|
case GLFW_CURSOR_NORMAL:
|
||||||
showMouseCursor(window);
|
showCursor(window);
|
||||||
break;
|
break;
|
||||||
case GLFW_CURSOR_HIDDEN:
|
case GLFW_CURSOR_HIDDEN:
|
||||||
hideMouseCursor(window);
|
hideCursor(window);
|
||||||
break;
|
break;
|
||||||
case GLFW_CURSOR_CAPTURED:
|
case GLFW_CURSOR_CAPTURED:
|
||||||
captureMouseCursor(window);
|
captureCursor(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,10 +251,10 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Hide mouse cursor
|
// Hide cursor
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void hideMouseCursor(_GLFWwindow* window)
|
static void hideCursor(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
if (!window->X11.cursorHidden)
|
if (!window->X11.cursorHidden)
|
||||||
{
|
{
|
||||||
@ -267,12 +267,12 @@ static void hideMouseCursor(_GLFWwindow* window)
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Capture mouse cursor
|
// Capture cursor
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void captureMouseCursor(_GLFWwindow* window)
|
static void captureCursor(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
hideMouseCursor(window);
|
hideCursor(window);
|
||||||
|
|
||||||
if (!window->X11.cursorGrabbed)
|
if (!window->X11.cursorGrabbed)
|
||||||
{
|
{
|
||||||
@ -290,13 +290,13 @@ static void captureMouseCursor(_GLFWwindow* window)
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Show mouse cursor
|
// Show cursor
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void showMouseCursor(_GLFWwindow* window)
|
static void showCursor(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
// Un-grab cursor (only in windowed mode: in fullscreen mode we still
|
// Un-grab cursor (only in windowed mode: in fullscreen mode we still
|
||||||
// want the mouse grabbed in order to confine the cursor to the window
|
// want the cursor grabbed in order to confine the cursor to the window
|
||||||
// area)
|
// area)
|
||||||
if (window->X11.cursorGrabbed)
|
if (window->X11.cursorGrabbed)
|
||||||
{
|
{
|
||||||
@ -401,7 +401,7 @@ static void enterFullscreenMode(_GLFWwindow* window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HACK: Try to get window inside viewport (for virtual displays) by moving
|
// HACK: Try to get window inside viewport (for virtual displays) by moving
|
||||||
// the mouse cursor to the upper left corner (and then to the center)
|
// the cursor to the upper left corner (and then to the center)
|
||||||
// This hack should be harmless on saner systems as well
|
// This hack should be harmless on saner systems as well
|
||||||
XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, 0,0);
|
XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, 0,0);
|
||||||
XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0,
|
XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0,
|
||||||
@ -615,7 +615,7 @@ static void processSingleEvent(void)
|
|||||||
|
|
||||||
case EnterNotify:
|
case EnterNotify:
|
||||||
{
|
{
|
||||||
// The mouse cursor enters the Window
|
// The cursor entered the window
|
||||||
window = findWindow(event.xcrossing.window);
|
window = findWindow(event.xcrossing.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
@ -624,7 +624,7 @@ static void processSingleEvent(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
||||||
hideMouseCursor(window);
|
hideCursor(window);
|
||||||
|
|
||||||
_glfwInputCursorEnter(window, GL_TRUE);
|
_glfwInputCursorEnter(window, GL_TRUE);
|
||||||
break;
|
break;
|
||||||
@ -632,7 +632,7 @@ static void processSingleEvent(void)
|
|||||||
|
|
||||||
case LeaveNotify:
|
case LeaveNotify:
|
||||||
{
|
{
|
||||||
// The mouse cursor leave the Window
|
// The cursor left the window
|
||||||
window = findWindow(event.xcrossing.window);
|
window = findWindow(event.xcrossing.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
@ -641,7 +641,7 @@ static void processSingleEvent(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
||||||
showMouseCursor(window);
|
showCursor(window);
|
||||||
|
|
||||||
_glfwInputCursorEnter(window, GL_FALSE);
|
_glfwInputCursorEnter(window, GL_FALSE);
|
||||||
break;
|
break;
|
||||||
@ -649,7 +649,7 @@ static void processSingleEvent(void)
|
|||||||
|
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
{
|
{
|
||||||
// The mouse cursor was moved
|
// The cursor was moved
|
||||||
window = findWindow(event.xmotion.window);
|
window = findWindow(event.xmotion.window);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
@ -660,7 +660,7 @@ static void processSingleEvent(void)
|
|||||||
if (event.xmotion.x != window->X11.cursorPosX ||
|
if (event.xmotion.x != window->X11.cursorPosX ||
|
||||||
event.xmotion.y != window->X11.cursorPosY)
|
event.xmotion.y != window->X11.cursorPosY)
|
||||||
{
|
{
|
||||||
// The mouse cursor was moved and we didn't do it
|
// The cursor was moved and we didn't do it
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
@ -783,7 +783,7 @@ static void processSingleEvent(void)
|
|||||||
_glfwInputWindowFocus(window, GL_TRUE);
|
_glfwInputWindowFocus(window, GL_TRUE);
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
captureMouseCursor(window);
|
captureCursor(window);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -801,7 +801,7 @@ static void processSingleEvent(void)
|
|||||||
_glfwInputWindowFocus(window, GL_FALSE);
|
_glfwInputWindowFocus(window, GL_FALSE);
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
showMouseCursor(window);
|
showCursor(window);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1197,9 +1197,9 @@ void _glfwPlatformPollEvents(void)
|
|||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED &&
|
||||||
!window->X11.cursorCentered)
|
!window->X11.cursorCentered)
|
||||||
{
|
{
|
||||||
_glfwPlatformSetMouseCursorPos(window,
|
_glfwPlatformSetCursorPos(window,
|
||||||
window->width / 2,
|
window->width / 2,
|
||||||
window->height / 2);
|
window->height / 2);
|
||||||
window->X11.cursorCentered = GL_TRUE;
|
window->X11.cursorCentered = GL_TRUE;
|
||||||
|
|
||||||
// NOTE: This is a temporary fix. It works as long as you use
|
// NOTE: This is a temporary fix. It works as long as you use
|
||||||
@ -1228,10 +1228,10 @@ void _glfwPlatformWaitEvents(void)
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor position
|
// Set physical cursor position
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
|
||||||
{
|
{
|
||||||
// Store the new position so we can recognise it later
|
// Store the new position so we can recognise it later
|
||||||
window->X11.cursorPosX = x;
|
window->X11.cursorPosX = x;
|
||||||
@ -1242,7 +1242,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor mode
|
// Set physical cursor mode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
||||||
@ -1250,13 +1250,13 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case GLFW_CURSOR_NORMAL:
|
case GLFW_CURSOR_NORMAL:
|
||||||
showMouseCursor(window);
|
showCursor(window);
|
||||||
break;
|
break;
|
||||||
case GLFW_CURSOR_HIDDEN:
|
case GLFW_CURSOR_HIDDEN:
|
||||||
hideMouseCursor(window);
|
hideCursor(window);
|
||||||
break;
|
break;
|
||||||
case GLFW_CURSOR_CAPTURED:
|
case GLFW_CURSOR_CAPTURED:
|
||||||
captureMouseCursor(window);
|
captureCursor(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
|
|||||||
gluOrtho2D(0.f, window_width, 0.f, window_height);
|
gluOrtho2D(0.f, window_width, 0.f, window_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
static void cursor_position_callback(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
cursor_x = x;
|
cursor_x = x;
|
||||||
cursor_y = y;
|
cursor_y = y;
|
||||||
@ -75,7 +75,7 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetMousePosCallback(mouse_position_callback);
|
glfwSetCursorPosCallback(cursor_position_callback);
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
|
@ -270,9 +270,9 @@ static void mouse_button_callback(GLFWwindow window, int button, int action)
|
|||||||
printf(" was %s\n", get_action_name(action));
|
printf(" was %s\n", get_action_name(action));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
static void cursor_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: Cursor position: %i %i\n", counter++, glfwGetTime(), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cursor_enter_callback(GLFWwindow window, int entered)
|
static void cursor_enter_callback(GLFWwindow window, int entered)
|
||||||
@ -361,7 +361,7 @@ int main(void)
|
|||||||
glfwSetWindowFocusCallback(window_focus_callback);
|
glfwSetWindowFocusCallback(window_focus_callback);
|
||||||
glfwSetWindowIconifyCallback(window_iconify_callback);
|
glfwSetWindowIconifyCallback(window_iconify_callback);
|
||||||
glfwSetMouseButtonCallback(mouse_button_callback);
|
glfwSetMouseButtonCallback(mouse_button_callback);
|
||||||
glfwSetMousePosCallback(mouse_position_callback);
|
glfwSetCursorPosCallback(cursor_position_callback);
|
||||||
glfwSetCursorEnterCallback(cursor_enter_callback);
|
glfwSetCursorEnterCallback(cursor_enter_callback);
|
||||||
glfwSetScrollCallback(scroll_callback);
|
glfwSetScrollCallback(scroll_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//========================================================================
|
//========================================================================
|
||||||
// Mouse cursor bug test
|
// Cursor input bug test
|
||||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||||
//
|
//
|
||||||
// This software is provided 'as-is', without any express or implied
|
// This software is provided 'as-is', without any express or implied
|
||||||
@ -41,7 +41,7 @@ static int cursor_y;
|
|||||||
|
|
||||||
static GLboolean open_window(void);
|
static GLboolean open_window(void);
|
||||||
|
|
||||||
static void toggle_mouse_cursor(GLFWwindow window)
|
static void toggle_cursor(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED)
|
if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
{
|
||||||
@ -55,9 +55,9 @@ static void toggle_mouse_cursor(GLFWwindow window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
static void cursor_position_callback(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
printf("Mouse moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y);
|
printf("Cursor moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y);
|
||||||
cursor_x = x;
|
cursor_x = x;
|
||||||
cursor_y = y;
|
cursor_y = y;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
|||||||
case GLFW_KEY_SPACE:
|
case GLFW_KEY_SPACE:
|
||||||
{
|
{
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
toggle_mouse_cursor(window);
|
toggle_cursor(window);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -98,11 +98,11 @@ static GLboolean open_window(void)
|
|||||||
if (!window_handle)
|
if (!window_handle)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
glfwGetMousePos(window_handle, &cursor_x, &cursor_y);
|
glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
|
||||||
printf("Mouse position: %i %i\n", cursor_x, cursor_y);
|
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetMousePosCallback(mouse_position_callback);
|
glfwSetCursorPosCallback(cursor_position_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user