Merge pull request #283 from dariomanesku/master
Entry-SDL now also sends char events.
This commit is contained in:
Коммит
a60ad41cb1
|
@ -34,6 +34,43 @@ namespace entry
|
|||
}
|
||||
#endif // ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR
|
||||
|
||||
char keyToAscii(Key::Enum _key, uint8_t _modifiers)
|
||||
{
|
||||
const bool isAscii = (Key::Key0 <= _key && _key <= Key::KeyZ)
|
||||
|| (Key::Esc <= _key && _key <= Key::Minus);
|
||||
if (!isAscii)
|
||||
{
|
||||
return '\0';
|
||||
}
|
||||
|
||||
const bool isNumber = (Key::Key0 <= _key && _key <= Key::Key9);
|
||||
if (isNumber)
|
||||
{
|
||||
return '0' + (_key - Key::Key0);
|
||||
}
|
||||
|
||||
const bool isChar = (Key::KeyA <= _key && _key <= Key::KeyZ);
|
||||
if (isChar)
|
||||
{
|
||||
enum { ShiftMask = Modifier::LeftShift|Modifier::RightShift };
|
||||
|
||||
const bool shift = !!(_modifiers&ShiftMask);
|
||||
return (shift ? 'A' : 'a') + (_key - Key::KeyA);
|
||||
}
|
||||
|
||||
switch (_key)
|
||||
{
|
||||
case Key::Esc: { return 0x1b; } break;
|
||||
case Key::Return: { return 0x0d; } break;
|
||||
case Key::Tab: { return 0x09; } break;
|
||||
case Key::Space: { return 0xa0; } break;
|
||||
case Key::Backspace: { return 0x08; } break;
|
||||
case Key::Plus: { return 0x2b; } break;
|
||||
case Key::Minus: { return 0x2d; } break;
|
||||
default: { return '\0'; } break;
|
||||
}
|
||||
}
|
||||
|
||||
bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
|
||||
{
|
||||
if (0 == strcmp(_argv[_first], _name) )
|
||||
|
|
|
@ -56,6 +56,8 @@ namespace entry
|
|||
|
||||
int main(int _argc, char** _argv);
|
||||
|
||||
char keyToAscii(Key::Enum _key, uint8_t _modifiers);
|
||||
|
||||
struct Event
|
||||
{
|
||||
enum Enum
|
||||
|
|
|
@ -412,6 +412,32 @@ namespace entry
|
|||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
const SDL_KeyboardEvent& kev = event.key;
|
||||
WindowHandle handle = findHandle(kev.windowID);
|
||||
if (isValid(handle) )
|
||||
{
|
||||
uint8_t modifiers = translateKeyModifiers(kev.keysym.mod);
|
||||
Key::Enum key = translateKey(kev.keysym.scancode);
|
||||
|
||||
const uint8_t shiftMask = Modifier::LeftShift|Modifier::RightShift;
|
||||
const bool nonShiftModifiers = (0 != (modifiers&(~shiftMask) ) );
|
||||
const bool isCharPressed = (Key::Key0 <= key && key <= Key::KeyZ) || (Key::Esc <= key && key <= Key::Minus);
|
||||
const bool isText = isCharPressed && !nonShiftModifiers;
|
||||
|
||||
if (isText)
|
||||
{
|
||||
uint8_t pressedChar[4];
|
||||
pressedChar[0] = keyToAscii(key, modifiers);
|
||||
m_eventQueue.postCharEvent(handle, 1, pressedChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
const SDL_KeyboardEvent& kev = event.key;
|
||||
|
@ -679,19 +705,6 @@ namespace entry
|
|||
m_width = _width;
|
||||
m_height = _height;
|
||||
|
||||
if (m_width < m_height)
|
||||
{
|
||||
float aspectRatio = 1.0f/m_aspectRatio;
|
||||
m_width = bx::uint32_max(ENTRY_DEFAULT_WIDTH/4, m_width);
|
||||
m_height = uint32_t(float(m_width)*aspectRatio);
|
||||
}
|
||||
else
|
||||
{
|
||||
float aspectRatio = m_aspectRatio;
|
||||
m_height = bx::uint32_max(ENTRY_DEFAULT_HEIGHT/4, m_height);
|
||||
m_width = uint32_t(float(m_height)*aspectRatio);
|
||||
}
|
||||
|
||||
SDL_SetWindowSize(m_window[_handle.idx], m_width, m_height);
|
||||
m_eventQueue.postSizeEvent(_handle, m_width, m_height);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче