mirror of
https://github.com/glfw/glfw.git
synced 2026-09-21 16:44:11 +00:00
Added character with modifiers callback.
The undefined behaviour changed with #40 has been reverted, making the character-only callback again behave like a system text field. This behavior has now been documentated. Fixes #203. Fixes #305.
This commit is contained in:
+3
-1
@@ -605,13 +605,15 @@ static int translateKey(unsigned int key)
|
||||
{
|
||||
const int key = translateKey([event keyCode]);
|
||||
const int mods = translateFlags([event modifierFlags]);
|
||||
|
||||
_glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods);
|
||||
|
||||
NSString* characters = [event characters];
|
||||
NSUInteger i, length = [characters length];
|
||||
const int plain = !(mods & GLFW_MOD_SUPER);
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
_glfwInputChar(window, [characters characterAtIndex:i]);
|
||||
_glfwInputChar(window, [characters characterAtIndex:i], mods, plain);
|
||||
}
|
||||
|
||||
- (void)flagsChanged:(NSEvent *)event
|
||||
|
||||
+17
-3
@@ -153,13 +153,19 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m
|
||||
window->callbacks.key((GLFWwindow*) window, key, scancode, action, mods);
|
||||
}
|
||||
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint)
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, int plain)
|
||||
{
|
||||
if (codepoint < 32 || (codepoint > 126 && codepoint < 160))
|
||||
return;
|
||||
|
||||
if (window->callbacks.character)
|
||||
window->callbacks.character((GLFWwindow*) window, codepoint);
|
||||
if (window->callbacks.charmods)
|
||||
window->callbacks.charmods((GLFWwindow*) window, codepoint, mods);
|
||||
|
||||
if (plain)
|
||||
{
|
||||
if (window->callbacks.character)
|
||||
window->callbacks.character((GLFWwindow*) window, codepoint);
|
||||
}
|
||||
}
|
||||
|
||||
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
|
||||
@@ -439,6 +445,14 @@ GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun)
|
||||
return cbfun;
|
||||
}
|
||||
|
||||
GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* handle, GLFWcharmodsfun cbfun)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||
_GLFW_SWAP_POINTERS(window->callbacks.charmods, cbfun);
|
||||
return cbfun;
|
||||
}
|
||||
|
||||
GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle,
|
||||
GLFWmousebuttonfun cbfun)
|
||||
{
|
||||
|
||||
+5
-1
@@ -262,6 +262,7 @@ struct _GLFWwindow
|
||||
GLFWscrollfun scroll;
|
||||
GLFWkeyfun key;
|
||||
GLFWcharfun character;
|
||||
GLFWcharmodsfun charmods;
|
||||
GLFWdropfun drop;
|
||||
} callbacks;
|
||||
|
||||
@@ -700,9 +701,12 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m
|
||||
/*! @brief Notifies shared code of a Unicode character input event.
|
||||
* @param[in] window The window that received the event.
|
||||
* @param[in] codepoint The Unicode code point of the input character.
|
||||
* @param[in] mods Bit field describing which modifier keys were held down.
|
||||
* @param[in] plain `GL_TRUE` if the character is regular text input, or
|
||||
* `GL_FALSE` otherwise.
|
||||
* @ingroup event
|
||||
*/
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint);
|
||||
void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, int plain);
|
||||
|
||||
/*! @brief Notifies shared code of a scroll event.
|
||||
* @param[in] window The window that received the event.
|
||||
|
||||
+7
-2
@@ -526,9 +526,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
}
|
||||
|
||||
case WM_CHAR:
|
||||
{
|
||||
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_TRUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_SYSCHAR:
|
||||
{
|
||||
_glfwInputChar(window, (unsigned int) wParam);
|
||||
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_FALSE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -543,7 +548,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_glfwInputChar(window, (unsigned int) wParam);
|
||||
_glfwInputChar(window, (unsigned int) wParam, getKeyMods(), GL_TRUE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -609,7 +609,10 @@ static void processEvent(XEvent *event)
|
||||
_glfwInputKey(window, key, event->xkey.keycode, GLFW_PRESS, mods);
|
||||
|
||||
if (character != -1)
|
||||
_glfwInputChar(window, character);
|
||||
{
|
||||
const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT));
|
||||
_glfwInputChar(window, character, mods, plain);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user