mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Unicode characters outside the BMP (> 0xFFFF) are now correctly handled on Windows (#366)
This commit is contained in:
parent
11837e9fc8
commit
83ffe11709
@ -73,7 +73,8 @@ m_icon (NULL),
|
||||
m_keyRepeatEnabled(true),
|
||||
m_isCursorIn (false),
|
||||
m_lastSize (0, 0),
|
||||
m_resizing (false)
|
||||
m_resizing (false),
|
||||
m_surrogate (0)
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
@ -93,7 +94,8 @@ m_icon (NULL),
|
||||
m_keyRepeatEnabled(true),
|
||||
m_isCursorIn (false),
|
||||
m_lastSize (mode.width, mode.height),
|
||||
m_resizing (false)
|
||||
m_resizing (false),
|
||||
m_surrogate (0)
|
||||
{
|
||||
// Register the window class at first call
|
||||
if (windowCount == 0)
|
||||
@ -510,10 +512,33 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (m_keyRepeatEnabled || ((lParam & (1 << 30)) == 0))
|
||||
{
|
||||
Event event;
|
||||
event.type = Event::TextEntered;
|
||||
event.text.unicode = static_cast<Uint32>(wParam);
|
||||
pushEvent(event);
|
||||
// Get the code of the typed character
|
||||
Uint32 character = static_cast<Uint32>(wParam);
|
||||
|
||||
// Check if it is the first part of a surrogate pair, or a regular character
|
||||
if ((character >= 0xD800) && (character <= 0xDBFF))
|
||||
{
|
||||
// First part of a surrogate pair: store it and wait for the second one
|
||||
m_surrogate = static_cast<Uint16>(character);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// Check if it is the second part of a surrogate pair, or a regular character
|
||||
if ((character >= 0xDC00) && (character <= 0xDFFF))
|
||||
{
|
||||
// Convert the UTF-16 surrogate pair to a single UTF-32 value
|
||||
Uint16 utf16[] = {m_surrogate, static_cast<Uint16>(character)};
|
||||
sf::Utf16::toUtf32(utf16, utf16 + 2, &character);
|
||||
m_surrogate = 0;
|
||||
}
|
||||
|
||||
// Send a TextEntered event
|
||||
Event event;
|
||||
event.type = Event::TextEntered;
|
||||
event.text.unicode = character;
|
||||
pushEvent(event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -238,6 +238,7 @@ private :
|
||||
bool m_isCursorIn; ///< Is the mouse cursor in the window's area ?
|
||||
Vector2u m_lastSize; ///< The last handled size of the window
|
||||
bool m_resizing; ///< Is the window being resized ?
|
||||
Uint16 m_surrogate; ///< First half of the surrogate pair, in case we're receiving a Unicode character in two events
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
Loading…
Reference in New Issue
Block a user