Changed cursor pos to double.

This commit is contained in:
Camilla Berglund
2013-04-04 16:16:21 +02:00
parent 4c0e946da3
commit 129e94da2e
12 changed files with 39 additions and 40 deletions
+1 -5
View File
@@ -365,11 +365,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
const NSPoint p = [event locationInWindow];
// Cocoa coordinate system has origin at lower left
const int x = lround(floor(p.x));
const int y = contentRect.size.height - lround(ceil(p.y));
_glfwInputCursorMotion(window, x, y);
_glfwInputCursorMotion(window, p.x, contentRect.size.height - p.y);
}
}
+8 -7
View File
@@ -38,7 +38,8 @@
//
static void setCursorMode(_GLFWwindow* window, int newMode)
{
int width, height, oldMode, centerPosX, centerPosY;
int width, height, oldMode;
double centerPosX, centerPosY;
if (newMode != GLFW_CURSOR_NORMAL &&
newMode != GLFW_CURSOR_HIDDEN &&
@@ -54,8 +55,8 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
_glfwPlatformGetWindowSize(window, &width, &height);
centerPosX = width / 2;
centerPosY = height / 2;
centerPosX = width / 2.0;
centerPosY = height / 2.0;
if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetCursorPos(window, centerPosX, centerPosY);
@@ -171,11 +172,11 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
window->callbacks.mouseButton((GLFWwindow*) window, button, action);
}
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y)
{
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
if (!x && !y)
if (x == 0.0 && y == 0.0)
return;
window->cursorPosX += x;
@@ -297,7 +298,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button)
return (int) window->mouseButton[button];
}
GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, int* xpos, int* ypos)
GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
@@ -310,7 +311,7 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, int* xpos, int* ypos)
*ypos = window->cursorPosY;
}
GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, int xpos, int ypos)
GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
+3 -3
View File
@@ -225,7 +225,7 @@ struct _GLFWwindow
// Window input state
GLboolean stickyKeys;
GLboolean stickyMouseButtons;
int cursorPosX, cursorPosY;
double cursorPosX, cursorPosY;
int cursorMode;
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
char key[GLFW_KEY_LAST + 1];
@@ -344,7 +344,7 @@ const char* _glfwPlatformGetVersionString(void);
/*! @copydoc glfwSetCursorPos
* @ingroup platform
*/
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int xpos, int ypos);
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
/*! @brief Sets up the specified cursor mode for the specified window.
* @param[in] window The window whose cursor mode to change.
@@ -614,7 +614,7 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
* of the client area of the window.
* @ingroup event
*/
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y);
/*! @brief Notifies shared code of a cursor enter/leave event.
* @param[in] window The window that received the event.
+2 -2
View File
@@ -1049,9 +1049,9 @@ void _glfwPlatformWaitEvents(void)
_glfwPlatformPollEvents();
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int xpos, int ypos)
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
{
POINT pos = { xpos, ypos };
POINT pos = { (int) xpos, (int) ypos };
ClientToScreen(window->win32.handle, &pos);
SetCursorPos(pos.x, pos.y);
}
+3 -2
View File
@@ -1004,13 +1004,14 @@ void _glfwPlatformWaitEvents(void)
_glfwPlatformPollEvents();
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
{
// Store the new position so it can be recognized later
window->x11.cursorPosX = x;
window->x11.cursorPosY = y;
XWarpPointer(_glfw.x11.display, None, window->x11.handle, 0,0,0,0, x, y);
XWarpPointer(_glfw.x11.display, None, window->x11.handle,
0,0,0,0, (int) x, (int) y);
}
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)