Made scrolling deltas floating point.

This commit is contained in:
Camilla Berglund 2012-03-28 21:54:09 +02:00
parent a8bcae8efa
commit 4ef9aec7e0
10 changed files with 18 additions and 27 deletions

View File

@ -341,9 +341,9 @@ void mouse_position_callback(GLFWwindow window, int x, int y)
// Callback function for scroll events // Callback function for scroll events
//======================================================================== //========================================================================
void scroll_callback(GLFWwindow window, int x, int y) void scroll_callback(GLFWwindow window, double x, double y)
{ {
zoom += y / 4.f; zoom += (float) y / 4.f;
if (zoom < 0) if (zoom < 0)
zoom = 0; zoom = 0;
} }

View File

@ -482,7 +482,7 @@ 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,int); typedef void (* GLFWcursorenterfun)(GLFWwindow,int);
typedef void (* GLFWscrollfun)(GLFWwindow,int,int); typedef void (* GLFWscrollfun)(GLFWwindow,double,double);
typedef void (* GLFWkeyfun)(GLFWwindow,int,int); typedef void (* GLFWkeyfun)(GLFWwindow,int,int);
typedef void (* GLFWcharfun)(GLFWwindow,int); typedef void (* GLFWcharfun)(GLFWwindow,int);
@ -561,7 +561,7 @@ 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 glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos); GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos);
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* xoffset, int* 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);

View File

@ -292,7 +292,7 @@ version of GLFW.</p>
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li> <li>Renamed <code>version</code> test to <code>glfwinfo</code></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 scrolling interface</li> <li>Replaced mouse wheel interface with two-dimensional, floating point scrolling interface</li>
<li>Replaced <code>glfwEnable</code> and <code>glfwDisable</code> with <code>glfwGetInputMode</code> and <code>glfwSetInputMode</code></li> <li>Replaced <code>glfwEnable</code> and <code>glfwDisable</code> with <code>glfwGetInputMode</code> and <code>glfwSetInputMode</code></li>
<li>Made Unicode character input unaffected by <code>GLFW_KEY_REPEAT</code></li> <li>Made Unicode character input unaffected by <code>GLFW_KEY_REPEAT</code></li>
<li>Removed event auto-polling and the <code>GLFW_AUTO_POLL_EVENTS</code> window enable</li> <li>Removed event auto-polling and the <code>GLFW_AUTO_POLL_EVENTS</code> window enable</li>

View File

@ -75,8 +75,6 @@ typedef struct _GLFWwindowNS
id window; id window;
id delegate; id delegate;
unsigned int modifierFlags; unsigned int modifierFlags;
double fracScrollX;
double fracScrollY;
} _GLFWwindowNS; } _GLFWwindowNS;

View File

@ -479,14 +479,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
- (void)scrollWheel:(NSEvent *)event - (void)scrollWheel:(NSEvent *)event
{ {
double deltaX = window->NS.fracScrollX + [event deltaX]; _glfwInputScroll(window, [event deltaX], [event deltaY]);
double deltaY = window->NS.fracScrollY + [event deltaY];
if ((int) deltaX || (int) deltaY)
_glfwInputScroll(window, (int) deltaX, (int) deltaY);
window->NS.fracScrollX = (int) (deltaX - floor(deltaX));
window->NS.fracScrollY = (int) (deltaY - floor(deltaY));
} }
@end @end

View File

@ -200,7 +200,7 @@ void _glfwInputChar(_GLFWwindow* window, int character)
// Register scroll events // Register scroll events
//======================================================================== //========================================================================
void _glfwInputScroll(_GLFWwindow* window, int xoffset, int yoffset) void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
{ {
window->scrollX += xoffset; window->scrollX += xoffset;
window->scrollY += yoffset; window->scrollY += yoffset;
@ -476,7 +476,7 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
// Returns the scroll offset for the specified window // Returns the scroll offset for the specified window
//======================================================================== //========================================================================
GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset) GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, double* xoffset, double* yoffset)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;

View File

@ -186,7 +186,7 @@ struct _GLFWwindow
GLboolean systemKeys; // system keys enabled flag GLboolean systemKeys; // system keys enabled flag
int cursorPosX, cursorPosY; int cursorPosX, cursorPosY;
int cursorMode; int cursorMode;
int scrollX, scrollY; double scrollX, scrollY;
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1]; char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
char key[GLFW_KEY_LAST + 1]; char key[GLFW_KEY_LAST + 1];
@ -343,7 +343,7 @@ void _glfwInputWindowDamage(_GLFWwindow* window);
// Input event notification (input.c) // Input event notification (input.c)
void _glfwInputKey(_GLFWwindow* window, int key, int action); void _glfwInputKey(_GLFWwindow* window, int key, int action);
void _glfwInputChar(_GLFWwindow* window, int character); void _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputScroll(_GLFWwindow* window, int x, int y); void _glfwInputScroll(_GLFWwindow* window, double x, double 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, int entered); void _glfwInputCursorEnter(_GLFWwindow* window, int entered);

View File

@ -1022,7 +1022,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
_glfwInputScroll(window, 0, (((int) wParam) >> 16) / WHEEL_DELTA); _glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA);
return 0; return 0;
} }
@ -1030,7 +1030,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
{ {
// This message is only sent on Windows Vista and later // This message is only sent on Windows Vista and later
_glfwInputScroll(window, (((int) wParam) >> 16) / WHEEL_DELTA, 0); _glfwInputScroll(window, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA, 0.0);
return 0; return 0;
} }

View File

@ -1144,14 +1144,14 @@ static void processSingleEvent(void)
// XFree86 3.3.2 and later translates mouse wheel up/down into // XFree86 3.3.2 and later translates mouse wheel up/down into
// mouse button 4 & 5 presses // mouse button 4 & 5 presses
else if (event.xbutton.button == Button4) else if (event.xbutton.button == Button4)
_glfwInputScroll(window, 0, 1); _glfwInputScroll(window, 0.0, 1.0);
else if (event.xbutton.button == Button5) else if (event.xbutton.button == Button5)
_glfwInputScroll(window, 0, -1); _glfwInputScroll(window, 0.0, -1.0);
else if (event.xbutton.button == Button6) else if (event.xbutton.button == Button6)
_glfwInputScroll(window, -1, 0); _glfwInputScroll(window, -1.0, 0.0);
else if (event.xbutton.button == Button7) else if (event.xbutton.button == Button7)
_glfwInputScroll(window, 1, 0); _glfwInputScroll(window, 1.0, 0.0);
break; break;
} }

View File

@ -283,9 +283,9 @@ static void cursor_enter_callback(GLFWwindow window, int entered)
entered ? "entered" : "left"); entered ? "entered" : "left");
} }
static void scroll_callback(GLFWwindow window, int x, int y) static void scroll_callback(GLFWwindow window, double x, double y)
{ {
printf("%08x at %0.3f: Scroll: %i %i\n", counter++, glfwGetTime(), x, y); printf("%08x at %0.3f: Scroll: %0.3f %0.3f\n", counter++, glfwGetTime(), x, y);
} }
static void key_callback(GLFWwindow window, int key, int action) static void key_callback(GLFWwindow window, int key, int action)