mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
Added GLFW_REPEAT.
This commit is contained in:
parent
919bc0679d
commit
253e0d6b23
|
@ -286,6 +286,7 @@ GLFW.
|
||||||
`GLES2/gl2.h` instead of `GL/gl.h`
|
`GLES2/gl2.h` instead of `GL/gl.h`
|
||||||
* Added `GLFW_VISIBLE` window hint and parameter for controlling and polling
|
* Added `GLFW_VISIBLE` window hint and parameter for controlling and polling
|
||||||
window visibility
|
window visibility
|
||||||
|
* Added `GLFW_REPEAT` key action for repeated keys
|
||||||
* Added `windows` simple multi-window test program
|
* Added `windows` simple multi-window test program
|
||||||
* Added `sharing` simple OpenGL object sharing test program
|
* Added `sharing` simple OpenGL object sharing test program
|
||||||
* Added `modes` video mode enumeration and setting test program
|
* Added `modes` video mode enumeration and setting test program
|
||||||
|
|
|
@ -242,6 +242,10 @@ extern "C" {
|
||||||
* @ingroup input
|
* @ingroup input
|
||||||
*/
|
*/
|
||||||
#define GLFW_PRESS 1
|
#define GLFW_PRESS 1
|
||||||
|
/*! @brief The key was held down until it repeated.
|
||||||
|
* @ingroup input
|
||||||
|
*/
|
||||||
|
#define GLFW_REPEAT 2
|
||||||
/*! @} */
|
/*! @} */
|
||||||
|
|
||||||
/* Keyboard raw key codes.
|
/* Keyboard raw key codes.
|
||||||
|
@ -676,7 +680,7 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,double,double);
|
||||||
* @param[in] window The window that received the event.
|
* @param[in] window The window that received the event.
|
||||||
* @param[in] key The @link keys keyboard key @endlink that was pressed or
|
* @param[in] key The @link keys keyboard key @endlink that was pressed or
|
||||||
* released.
|
* released.
|
||||||
* @param[in] action One of @c GLFW_PRESS or @c GLFW_RELEASE.
|
* @param[in] action @ref GLFW_PRESS, @ref GLFW_RELEASE or @ref GLFW_REPEAT.
|
||||||
* @ingroup input
|
* @ingroup input
|
||||||
*
|
*
|
||||||
* @sa glfwSetKeyCallback
|
* @sa glfwSetKeyCallback
|
||||||
|
|
|
@ -438,16 +438,14 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
{
|
{
|
||||||
NSUInteger i, length;
|
NSUInteger i, length;
|
||||||
NSString* characters;
|
NSString* characters;
|
||||||
int key = convertMacKeyCode([event keyCode]);
|
const int key = convertMacKeyCode([event keyCode]);
|
||||||
|
if (key == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
if (key != -1)
|
|
||||||
{
|
|
||||||
_glfwInputKey(window, key, GLFW_PRESS);
|
_glfwInputKey(window, key, GLFW_PRESS);
|
||||||
|
|
||||||
if ([event modifierFlags] & NSCommandKeyMask)
|
if ([event modifierFlags] & NSCommandKeyMask)
|
||||||
{
|
|
||||||
[super keyDown:event];
|
[super keyDown:event];
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
characters = [event characters];
|
characters = [event characters];
|
||||||
|
@ -457,7 +455,6 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||||
_glfwInputChar(window, [characters characterAtIndex:i]);
|
_glfwInputChar(window, [characters characterAtIndex:i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
- (void)flagsChanged:(NSEvent *)event
|
- (void)flagsChanged:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
|
19
src/input.c
19
src/input.c
|
@ -120,23 +120,18 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||||
if (key < 0 || key > GLFW_KEY_LAST)
|
if (key < 0 || key > GLFW_KEY_LAST)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Are we trying to release an already released key?
|
|
||||||
if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Register key action
|
|
||||||
if (action == GLFW_RELEASE && window->stickyKeys)
|
|
||||||
window->key[key] = _GLFW_STICK;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (action == GLFW_PRESS && window->key[key] == GLFW_PRESS)
|
if (action == GLFW_PRESS && window->key[key] == GLFW_PRESS)
|
||||||
repeated = GL_TRUE;
|
repeated = GL_TRUE;
|
||||||
|
|
||||||
|
if (action == GLFW_RELEASE && window->stickyKeys)
|
||||||
|
window->key[key] = _GLFW_STICK;
|
||||||
|
else
|
||||||
window->key[key] = (char) action;
|
window->key[key] = (char) action;
|
||||||
}
|
|
||||||
|
|
||||||
// Call user callback function
|
if (repeated)
|
||||||
if (window->callbacks.key && !repeated)
|
action = GLFW_REPEAT;
|
||||||
|
|
||||||
|
if (window->callbacks.key)
|
||||||
window->callbacks.key((GLFWwindow*) window, key, action);
|
window->callbacks.key((GLFWwindow*) window, key, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ typedef struct _GLFWmonitor _GLFWmonitor;
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
// Internal key state used for sticky keys
|
// Internal key state used for sticky keys
|
||||||
#define _GLFW_STICK 2
|
#define _GLFW_STICK 3
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
|
@ -488,11 +488,17 @@ static GLboolean initDisplay(void)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
XkbSetDetectableAutoRepeat(_glfw.x11.display, True, &supported);
|
if (!XkbSetDetectableAutoRepeat(_glfw.x11.display, True, &supported))
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"X11: Failed to set detectable key repeat");
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!supported)
|
if (!supported)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
"X11: Detectable key repeat is not available");
|
"X11: Detectable key repeat is not supported");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,8 @@ static const char* get_action_name(int action)
|
||||||
return "pressed";
|
return "pressed";
|
||||||
case GLFW_RELEASE:
|
case GLFW_RELEASE:
|
||||||
return "released";
|
return "released";
|
||||||
|
case GLFW_REPEAT:
|
||||||
|
return "repeated";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "caused unknown action";
|
return "caused unknown action";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user