mirror of
https://github.com/glfw/glfw.git
synced 2026-09-20 08:23:13 +00:00
Added two-dimensional scrolling API and X11 implementation.
This commit is contained in:
+12
-24
@@ -148,26 +148,10 @@ GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos)
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Returns the mouse wheel "position" for the specified window
|
||||
// Returns the scroll offset for the specified window
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwGetMouseWheel(GLFWwindow window)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return window->wheelPos;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Sets the mouse wheel "position" for the specified window
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos)
|
||||
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* x, int* y)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
@@ -175,7 +159,11 @@ GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos)
|
||||
return;
|
||||
}
|
||||
|
||||
window->wheelPos = pos;
|
||||
if (x)
|
||||
*x = window->scrollX;
|
||||
|
||||
if (y)
|
||||
*y = window->scrollY;
|
||||
}
|
||||
|
||||
|
||||
@@ -250,10 +238,10 @@ GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun)
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set callback function for mouse wheel
|
||||
// Set callback function for scroll events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfun)
|
||||
GLFWAPI void glfwSetScrollCallback(GLFWwindow window, GLFWscrollfun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
@@ -262,11 +250,11 @@ GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfu
|
||||
}
|
||||
|
||||
// Set callback function
|
||||
window->mouseWheelCallback = cbfun;
|
||||
window->scrollCallback = cbfun;
|
||||
|
||||
// Call the callback function to let the application know the current
|
||||
// mouse wheel position
|
||||
// scroll offset
|
||||
if (cbfun)
|
||||
cbfun(window, window->wheelPos);
|
||||
cbfun(window, window->scrollX, window->scrollY);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -152,7 +152,7 @@ typedef struct _GLFWwindow
|
||||
GLFWwindowiconifyfun windowIconifyCallback;
|
||||
GLFWmousebuttonfun mouseButtonCallback;
|
||||
GLFWmouseposfun mousePosCallback;
|
||||
GLFWmousewheelfun mouseWheelCallback;
|
||||
GLFWscrollfun scrollCallback;
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
|
||||
@@ -172,7 +172,7 @@ typedef struct _GLFWwindow
|
||||
GLboolean stickyMouseButtons;
|
||||
GLboolean keyRepeat;
|
||||
int mousePosX, mousePosY;
|
||||
int wheelPos;
|
||||
int scrollX, scrollY;
|
||||
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
|
||||
char key[GLFW_KEY_LAST + 1];
|
||||
|
||||
|
||||
+16
-1
@@ -91,7 +91,8 @@ void clearInputState(_GLFWwindow* window)
|
||||
window->mousePosY = 0;
|
||||
|
||||
// Set mouse wheel position to 0
|
||||
window->wheelPos = 0;
|
||||
window->scrollX = 0;
|
||||
window->scrollY = 0;
|
||||
|
||||
// The default is to use non sticky keys and mouse buttons
|
||||
window->stickyKeys = GL_FALSE;
|
||||
@@ -163,6 +164,20 @@ void _glfwInputChar(_GLFWwindow* window, int character)
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Register scroll events
|
||||
//========================================================================
|
||||
|
||||
void _glfwInputScroll(_GLFWwindow* window, int x, int y)
|
||||
{
|
||||
window->scrollX += x;
|
||||
window->scrollY += y;
|
||||
|
||||
if (window->scrollCallback)
|
||||
window->scrollCallback(window, x, y);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Register mouse button clicks
|
||||
//========================================================================
|
||||
|
||||
+21
-12
@@ -41,6 +41,9 @@
|
||||
#define _NET_WM_STATE_ADD 1
|
||||
#define _NET_WM_STATE_TOGGLE 2
|
||||
|
||||
// Additional mouse button names for XButtonEvent
|
||||
#define Button6 6
|
||||
#define Button7 7
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
@@ -1094,17 +1097,15 @@ static void processSingleEvent(void)
|
||||
// XFree86 3.3.2 and later translates mouse wheel up/down into
|
||||
// mouse button 4 & 5 presses
|
||||
else if (event.xbutton.button == Button4)
|
||||
{
|
||||
window->wheelPos++; // To verify: is this up or down?
|
||||
if (window->mouseWheelCallback)
|
||||
window->mouseWheelCallback(window, window->wheelPos);
|
||||
}
|
||||
_glfwInputScroll(window, 0, 1);
|
||||
else if (event.xbutton.button == Button5)
|
||||
{
|
||||
window->wheelPos--;
|
||||
if (window->mouseWheelCallback)
|
||||
window->mouseWheelCallback(window, window->wheelPos);
|
||||
}
|
||||
_glfwInputScroll(window, 0, -1);
|
||||
|
||||
else if (event.xbutton.button == Button6)
|
||||
_glfwInputScroll(window, -1, 0);
|
||||
else if (event.xbutton.button == Button7)
|
||||
_glfwInputScroll(window, 1, 0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1741,8 +1742,15 @@ void _glfwPlatformPollEvents(void)
|
||||
{
|
||||
_GLFWwindow* window;
|
||||
|
||||
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||
{
|
||||
window->scrollX = 0;
|
||||
window->scrollY = 0;
|
||||
}
|
||||
|
||||
// Flag that the cursor has not moved
|
||||
if (window = _glfwLibrary.cursorLockWindow)
|
||||
window = _glfwLibrary.cursorLockWindow;
|
||||
if (window)
|
||||
window->X11.mouseMoved = GL_FALSE;
|
||||
|
||||
// Process all pending events
|
||||
@@ -1750,7 +1758,8 @@ void _glfwPlatformPollEvents(void)
|
||||
processSingleEvent();
|
||||
|
||||
// Did we get mouse movement in fully enabled hidden cursor mode?
|
||||
if (window = _glfwLibrary.cursorLockWindow)
|
||||
window = _glfwLibrary.cursorLockWindow;
|
||||
if (window)
|
||||
{
|
||||
if (window->X11.mouseMoved && window->X11.pointerHidden)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user