From 205fa041e9c2fc91652fc3bf5ed875e33dcf06a6 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 9 Mar 2015 03:21:33 +0100 Subject: [PATCH 1/3] Cleanup. --- examples/common/entry/entry_osx.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/common/entry/entry_osx.mm b/examples/common/entry/entry_osx.mm index 8b1a7004f..b46fbdb4b 100644 --- a/examples/common/entry/entry_osx.mm +++ b/examples/common/entry/entry_osx.mm @@ -312,7 +312,7 @@ namespace entry { enum { 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 isCharPressed = (Key::Key0 <= key && key <= Key::KeyZ) || (Key::Esc <= key && key <= Key::Minus); const bool isText = isCharPressed && !nonShiftModifiers; if (isText) { From 9ea92d4a4736ccbcc375e3ea0f8de13af0ba8723 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 9 Mar 2015 03:52:09 +0100 Subject: [PATCH 2/3] Added char events for entry-sdl. --- examples/common/entry/entry.cpp | 37 +++++++++++++++++++++++++++++ examples/common/entry/entry_p.h | 2 ++ examples/common/entry/entry_sdl.cpp | 26 ++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index 947d42046..1007787a0 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -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) ) diff --git a/examples/common/entry/entry_p.h b/examples/common/entry/entry_p.h index 39a289ed7..74d4756b5 100644 --- a/examples/common/entry/entry_p.h +++ b/examples/common/entry/entry_p.h @@ -56,6 +56,8 @@ namespace entry int main(int _argc, char** _argv); + char keyToAscii(Key::Enum _key, uint8_t _modifiers); + struct Event { enum Enum diff --git a/examples/common/entry/entry_sdl.cpp b/examples/common/entry/entry_sdl.cpp index 8d9b5b1c6..4aea10440 100644 --- a/examples/common/entry/entry_sdl.cpp +++ b/examples/common/entry/entry_sdl.cpp @@ -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; From 4c2a653de6e3ec737c163a6274293462b1b5a3d3 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 9 Mar 2015 04:03:15 +0100 Subject: [PATCH 3/3] Removing minimal window size limit from entry-sdl. --- examples/common/entry/entry_sdl.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/examples/common/entry/entry_sdl.cpp b/examples/common/entry/entry_sdl.cpp index 4aea10440..c279f0fd2 100644 --- a/examples/common/entry/entry_sdl.cpp +++ b/examples/common/entry/entry_sdl.cpp @@ -705,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); }