mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 13:04:35 +00:00
Added two-dimensional scrolling API and X11 implementation.
This commit is contained in:
parent
9fc3fe644b
commit
007766bd91
@ -389,7 +389,7 @@ 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 (* GLFWmousewheelfun)(GLFWwindow,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);
|
||||||
|
|
||||||
@ -443,13 +443,12 @@ 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 int glfwGetMouseWheel(GLFWwindow window);
|
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* x, int* y);
|
||||||
GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos);
|
|
||||||
GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun);
|
GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun);
|
||||||
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun);
|
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun);
|
||||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun);
|
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun);
|
||||||
GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun);
|
GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun);
|
||||||
GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfun);
|
GLFWAPI void glfwSetScrollCallback(GLFWwindow window, GLFWscrollfun cbfun);
|
||||||
|
|
||||||
/* Joystick input */
|
/* Joystick input */
|
||||||
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
||||||
|
@ -276,6 +276,7 @@ version of GLFW.</p>
|
|||||||
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
|
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
|
||||||
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
|
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
|
||||||
<li>Replaced ad hoc build system with CMake</li>
|
<li>Replaced ad hoc build system with CMake</li>
|
||||||
|
<li>Replaced mouse wheel interface with two-dimensional scrolling interface</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>
|
||||||
<li>Removed the entire threading API</li>
|
<li>Removed the entire threading API</li>
|
||||||
|
36
src/input.c
36
src/input.c
@ -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)
|
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* x, int* y)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
@ -175,7 +159,11 @@ GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos)
|
|||||||
return;
|
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)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
@ -262,11 +250,11 @@ GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set callback function
|
// Set callback function
|
||||||
window->mouseWheelCallback = cbfun;
|
window->scrollCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
// Call the callback function to let the application know the current
|
||||||
// mouse wheel position
|
// scroll offset
|
||||||
if (cbfun)
|
if (cbfun)
|
||||||
cbfun(window, window->wheelPos);
|
cbfun(window, window->scrollX, window->scrollY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ typedef struct _GLFWwindow
|
|||||||
GLFWwindowiconifyfun windowIconifyCallback;
|
GLFWwindowiconifyfun windowIconifyCallback;
|
||||||
GLFWmousebuttonfun mouseButtonCallback;
|
GLFWmousebuttonfun mouseButtonCallback;
|
||||||
GLFWmouseposfun mousePosCallback;
|
GLFWmouseposfun mousePosCallback;
|
||||||
GLFWmousewheelfun mouseWheelCallback;
|
GLFWscrollfun scrollCallback;
|
||||||
GLFWkeyfun keyCallback;
|
GLFWkeyfun keyCallback;
|
||||||
GLFWcharfun charCallback;
|
GLFWcharfun charCallback;
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ typedef struct _GLFWwindow
|
|||||||
GLboolean stickyMouseButtons;
|
GLboolean stickyMouseButtons;
|
||||||
GLboolean keyRepeat;
|
GLboolean keyRepeat;
|
||||||
int mousePosX, mousePosY;
|
int mousePosX, mousePosY;
|
||||||
int wheelPos;
|
int 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];
|
||||||
|
|
||||||
|
17
src/window.c
17
src/window.c
@ -91,7 +91,8 @@ void clearInputState(_GLFWwindow* window)
|
|||||||
window->mousePosY = 0;
|
window->mousePosY = 0;
|
||||||
|
|
||||||
// Set mouse wheel position to 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
|
// The default is to use non sticky keys and mouse buttons
|
||||||
window->stickyKeys = GL_FALSE;
|
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
|
// Register mouse button clicks
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -41,6 +41,9 @@
|
|||||||
#define _NET_WM_STATE_ADD 1
|
#define _NET_WM_STATE_ADD 1
|
||||||
#define _NET_WM_STATE_TOGGLE 2
|
#define _NET_WM_STATE_TOGGLE 2
|
||||||
|
|
||||||
|
// Additional mouse button names for XButtonEvent
|
||||||
|
#define Button6 6
|
||||||
|
#define Button7 7
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW internal API //////
|
////// GLFW internal API //////
|
||||||
@ -1094,17 +1097,15 @@ 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);
|
||||||
window->wheelPos++; // To verify: is this up or down?
|
|
||||||
if (window->mouseWheelCallback)
|
|
||||||
window->mouseWheelCallback(window, window->wheelPos);
|
|
||||||
}
|
|
||||||
else if (event.xbutton.button == Button5)
|
else if (event.xbutton.button == Button5)
|
||||||
{
|
_glfwInputScroll(window, 0, -1);
|
||||||
window->wheelPos--;
|
|
||||||
if (window->mouseWheelCallback)
|
else if (event.xbutton.button == Button6)
|
||||||
window->mouseWheelCallback(window, window->wheelPos);
|
_glfwInputScroll(window, -1, 0);
|
||||||
}
|
else if (event.xbutton.button == Button7)
|
||||||
|
_glfwInputScroll(window, 1, 0);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1741,8 +1742,15 @@ void _glfwPlatformPollEvents(void)
|
|||||||
{
|
{
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
|
||||||
|
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||||
|
{
|
||||||
|
window->scrollX = 0;
|
||||||
|
window->scrollY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Flag that the cursor has not moved
|
// Flag that the cursor has not moved
|
||||||
if (window = _glfwLibrary.cursorLockWindow)
|
window = _glfwLibrary.cursorLockWindow;
|
||||||
|
if (window)
|
||||||
window->X11.mouseMoved = GL_FALSE;
|
window->X11.mouseMoved = GL_FALSE;
|
||||||
|
|
||||||
// Process all pending events
|
// Process all pending events
|
||||||
@ -1750,7 +1758,8 @@ void _glfwPlatformPollEvents(void)
|
|||||||
processSingleEvent();
|
processSingleEvent();
|
||||||
|
|
||||||
// Did we get mouse movement in fully enabled hidden cursor mode?
|
// 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)
|
if (window->X11.mouseMoved && window->X11.pointerHidden)
|
||||||
{
|
{
|
||||||
|
@ -218,9 +218,9 @@ static void mouse_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: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_wheel_callback(GLFWwindow window, int position)
|
static void scroll_callback(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
printf("%08x at %0.3f: Mouse wheel: %i\n", counter++, glfwGetTime(), position);
|
printf("%08x at %0.3f: Scroll: %i %i\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)
|
||||||
@ -310,7 +310,7 @@ int main(void)
|
|||||||
glfwSetWindowIconifyCallback(window, window_iconify_callback);
|
glfwSetWindowIconifyCallback(window, window_iconify_callback);
|
||||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||||
glfwSetMousePosCallback(window, mouse_position_callback);
|
glfwSetMousePosCallback(window, mouse_position_callback);
|
||||||
glfwSetMouseWheelCallback(window, mouse_wheel_callback);
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(window, key_callback);
|
||||||
glfwSetCharCallback(window, char_callback);
|
glfwSetCharCallback(window, char_callback);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user