diff --git a/SDK/src/NDK/Application.cpp b/SDK/src/NDK/Application.cpp index a4fca055a..85757f33a 100644 --- a/SDK/src/NDK/Application.cpp +++ b/SDK/src/NDK/Application.cpp @@ -209,7 +209,7 @@ namespace Ndk overlay->keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&consoleRef] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event) { - if (event.code == Nz::Keyboard::F9) + if (event.virtualKey == Nz::Keyboard::VKey::F9) consoleRef.Show(!consoleRef.IsVisible()); }); diff --git a/SDK/src/NDK/Canvas.cpp b/SDK/src/NDK/Canvas.cpp index 3959f1765..7e74d5197 100644 --- a/SDK/src/NDK/Canvas.cpp +++ b/SDK/src/NDK/Canvas.cpp @@ -144,7 +144,7 @@ namespace Ndk if (m_widgetEntries[m_keyboardOwner].widget->OnKeyPressed(event)) return; - if (event.code == Nz::Keyboard::Tab) + if (event.virtualKey == Nz::Keyboard::VKey::Tab) { if (!event.shift) { diff --git a/SDK/src/NDK/Console.cpp b/SDK/src/NDK/Console.cpp index e5b4f1306..3dcdaca71 100644 --- a/SDK/src/NDK/Console.cpp +++ b/SDK/src/NDK/Console.cpp @@ -178,12 +178,12 @@ namespace Ndk case Nz::WindowEventType_KeyPressed: { - switch (event.key.code) + switch (event.key.virtualKey) { - case Nz::Keyboard::Down: - case Nz::Keyboard::Up: + case Nz::Keyboard::VKey::Down: + case Nz::Keyboard::VKey::Up: { - if (event.key.code == Nz::Keyboard::Up) + if (event.key.virtualKey == Nz::Keyboard::VKey::Up) m_historyPosition = std::min(m_commandHistory.size(), m_historyPosition + 1); else { diff --git a/SDK/src/NDK/Lua/LuaBinding_Platform.cpp b/SDK/src/NDK/Lua/LuaBinding_Platform.cpp index ac16f6fb3..24a218fae 100644 --- a/SDK/src/NDK/Lua/LuaBinding_Platform.cpp +++ b/SDK/src/NDK/Lua/LuaBinding_Platform.cpp @@ -17,8 +17,8 @@ namespace Ndk /*********************************** Nz::Keyboard **********************************/ keyboard.Reset("Keyboard"); { - keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName); - keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed); + //keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName); + //keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed); } } @@ -31,9 +31,9 @@ namespace Ndk { keyboard.Register(state); - keyboard.PushGlobalTable(state); + /*keyboard.PushGlobalTable(state); { - static_assert(Nz::Keyboard::Count == 124, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding"); + static_assert(Nz::Keyboard::Max == 123, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding"); state.PushField("Undefined", Nz::Keyboard::Undefined); @@ -119,7 +119,7 @@ namespace Ndk state.PushField("NumLock", Nz::Keyboard::NumLock); state.PushField("ScrollLock", Nz::Keyboard::ScrollLock); } - state.Pop(); + state.Pop();*/ static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding"); state.PushTable(0, Nz::WindowStyle_Max + 1); diff --git a/SDK/src/NDK/Widgets/TextAreaWidget.cpp b/SDK/src/NDK/Widgets/TextAreaWidget.cpp index 09355c09c..53d3929c4 100644 --- a/SDK/src/NDK/Widgets/TextAreaWidget.cpp +++ b/SDK/src/NDK/Widgets/TextAreaWidget.cpp @@ -207,9 +207,9 @@ namespace Ndk bool TextAreaWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) { - switch (key.code) + switch (key.virtualKey) { - case Nz::Keyboard::Delete: + case Nz::Keyboard::VKey::Delete: { if (HasSelection()) EraseSelection(); @@ -219,7 +219,7 @@ namespace Ndk return true; } - case Nz::Keyboard::Down: + case Nz::Keyboard::VKey::Down: { bool ignoreDefaultAction = false; OnTextAreaKeyDown(this, &ignoreDefaultAction); @@ -234,7 +234,7 @@ namespace Ndk return true; } - case Nz::Keyboard::End: + case Nz::Keyboard::VKey::End: { bool ignoreDefaultAction = false; OnTextAreaKeyEnd(this, &ignoreDefaultAction); @@ -251,7 +251,7 @@ namespace Ndk return true; } - case Nz::Keyboard::Home: + case Nz::Keyboard::VKey::Home: { bool ignoreDefaultAction = false; OnTextAreaKeyHome(this, &ignoreDefaultAction); @@ -263,7 +263,7 @@ namespace Ndk return true; } - case Nz::Keyboard::Left: + case Nz::Keyboard::VKey::Left: { bool ignoreDefaultAction = false; OnTextAreaKeyLeft(this, &ignoreDefaultAction); @@ -301,7 +301,7 @@ namespace Ndk return true; } - case Nz::Keyboard::Right: + case Nz::Keyboard::VKey::Right: { bool ignoreDefaultAction = false; OnTextAreaKeyRight(this, &ignoreDefaultAction); @@ -340,7 +340,7 @@ namespace Ndk return true; } - case Nz::Keyboard::Up: + case Nz::Keyboard::VKey::Up: { bool ignoreDefaultAction = false; OnTextAreaKeyUp(this, &ignoreDefaultAction); @@ -355,7 +355,7 @@ namespace Ndk return true; } - case Nz::Keyboard::Tab: + case Nz::Keyboard::VKey::Tab: { if (!m_tabEnabled) return false; @@ -425,7 +425,7 @@ namespace Ndk Nz::Vector2ui hoveredGlyph = GetHoveredGlyph(float(x) - 5.f, float(y) - 5.f); // Shift extends selection - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RShift)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RShift)) SetSelection(hoveredGlyph, m_selectionCursor); else { diff --git a/build/scripts/modules/platform.lua b/build/scripts/modules/platform.lua index 2768d1a28..d6201c526 100644 --- a/build/scripts/modules/platform.lua +++ b/build/scripts/modules/platform.lua @@ -7,7 +7,7 @@ MODULE.Libraries = { "NazaraUtility" } -if Config.PlatformSDL2 then +if (Config.PlatformSDL2) then table.insert(MODULE.Defines, "NAZARA_PLATFORM_SDL2") table.insert(MODULE.Files, "../src/Nazara/Platform/SDL2/**.hpp") diff --git a/build/scripts/modules/renderer.lua b/build/scripts/modules/renderer.lua index 800ca33b7..c9f65526f 100644 --- a/build/scripts/modules/renderer.lua +++ b/build/scripts/modules/renderer.lua @@ -12,12 +12,14 @@ MODULE.Libraries = { "NazaraPlatform" } -if Config.PlatformSDL2 then +if (Config.PlatformSDL2) then table.insert(MODULE.Defines, "NAZARA_PLATFORM_SDL2") table.insert(MODULE.Files, "../src/Nazara/Renderer/SDL2/**.hpp") table.insert(MODULE.Files, "../src/Nazara/Renderer/SDL2/**.cpp") + table.insert(MODULE.Libraries, "SDL2") + MODULE.FilesExcluded = { "../src/Nazara/Renderer/Win32/**", "../src/Nazara/Renderer/GLX/**.cpp" @@ -43,4 +45,4 @@ else "GL", "X11" } -end \ No newline at end of file +end diff --git a/examples/FirstScene/main.cpp b/examples/FirstScene/main.cpp index 0e3f8f8a2..d6759ea12 100644 --- a/examples/FirstScene/main.cpp +++ b/examples/FirstScene/main.cpp @@ -305,9 +305,9 @@ int main() eventHandler.OnKeyPressed.Connect([&targetPos, &cameraNode, &smoothMovement, &window](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event) { // Une touche a été pressée ! - if (event.code == Nz::Keyboard::Key::Escape) + if (event.virtualKey == Nz::Keyboard::VKey::Escape) window.Close(); - else if (event.code == Nz::Keyboard::F1) + else if (event.virtualKey == Nz::Keyboard::VKey::F1) { if (smoothMovement) { @@ -348,34 +348,34 @@ int main() if (move) { // Si la touche espace est enfoncée, notre vitesse de déplacement est multipliée par deux - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Space)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Space)) cameraSpeed *= 2.f; // Pour que nos déplacement soient liés à la rotation de la caméra, nous allons utiliser // les directions locales de la caméra // Si la flèche du haut ou la touche Z (vive ZQSD !!) est pressée, on avance - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z)) targetPos += cameraNode.GetForward() * cameraSpeed; // Si la flèche du bas ou la touche S est pressée, on recule - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Down) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Down) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::S)) targetPos += cameraNode.GetBackward() * cameraSpeed; // Etc... - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Left) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Q)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Left) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Q)) targetPos += cameraNode.GetLeft() * cameraSpeed; // Etc... - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Right) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Right) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::D)) targetPos += cameraNode.GetRight() * cameraSpeed; // Majuscule pour monter, notez l'utilisation d'une direction globale (Non-affectée par la rotation) - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RShift)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RShift)) targetPos += Nz::Vector3f::Up() * cameraSpeed; // Contrôle (Gauche ou droite) pour descendre dans l'espace global, etc... - if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LControl) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RControl)) + if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LControl) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RControl)) targetPos += Nz::Vector3f::Down() * cameraSpeed; } diff --git a/examples/Particles/SpacebattleDemo.cpp b/examples/Particles/SpacebattleDemo.cpp index 65336ad13..63b222599 100644 --- a/examples/Particles/SpacebattleDemo.cpp +++ b/examples/Particles/SpacebattleDemo.cpp @@ -677,7 +677,8 @@ void SpacebattleExample::Leave(Ndk::StateMachine& fsm) { m_ambientMusic.Stop(); m_onMouseMoved.Disconnect(); - m_shared.target->SetCursor(Nz::SystemCursor_Default); + if (m_shared.target) + m_shared.target->SetCursor(Nz::SystemCursor_Default); m_shared.world3D->RemoveSystem(); m_shared.world3D->RemoveSystem(); m_turretFireSound.Stop(); diff --git a/examples/Particles/main.cpp b/examples/Particles/main.cpp index e4940c63d..4738c5eb1 100644 --- a/examples/Particles/main.cpp +++ b/examples/Particles/main.cpp @@ -123,17 +123,17 @@ int main() { case Nz::WindowEventType_KeyPressed: { - switch (event.key.code) + switch (event.key.virtualKey) { - case Nz::Keyboard::Backspace: + case Nz::Keyboard::VKey::Backspace: stateMachine.ChangeState(shared.demos[demoIndex]); break; - case Nz::Keyboard::Escape: + case Nz::Keyboard::VKey::Escape: app.Quit(); break; - case Nz::Keyboard::Left: + case Nz::Keyboard::VKey::Left: { if (shared.demos.size() <= 1) break; @@ -146,7 +146,7 @@ int main() break; } - case Nz::Keyboard::Right: + case Nz::Keyboard::VKey::Right: { if (shared.demos.size() <= 1) break; @@ -159,14 +159,14 @@ int main() break; } - case Nz::Keyboard::Pause: + case Nz::Keyboard::VKey::Pause: { auto& velocitySystem = shared.world3D->GetSystem(); velocitySystem.Enable(!velocitySystem.IsEnabled()); break; } - case Nz::Keyboard::F5: + case Nz::Keyboard::VKey::F5: { Nz::Image screenshot; screenshot.Create(Nz::ImageType_2D, Nz::PixelFormatType_RGBA8, 1920, 1080); @@ -197,5 +197,7 @@ int main() window.Display(); } + shared.target = nullptr; + return EXIT_SUCCESS; } diff --git a/examples/Tut02/main.cpp b/examples/Tut02/main.cpp index 83de624c6..54e92993f 100644 --- a/examples/Tut02/main.cpp +++ b/examples/Tut02/main.cpp @@ -33,10 +33,10 @@ int main(int argc, char* argv[]) Nz::EventHandler& eventHandler = mainWindow.GetEventHandler(); eventHandler.OnKeyPressed.Connect([](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e) { - std::cout << Nz::Keyboard::GetKeyName(e.code) << std::endl; + std::cout << Nz::Keyboard::GetKeyName(e.virtualKey) << std::endl; // Profitons-en aussi pour nous donner un moyen de quitter le programme - if (e.code == Nz::Keyboard::Escape) + if (e.virtualKey == Nz::Keyboard::VKey::Escape) Ndk::Application::Instance()->Quit(); // Cette ligne casse la boucle Run() de l'application }); diff --git a/include/Nazara/Platform/Event.hpp b/include/Nazara/Platform/Event.hpp index 1fe219e8e..1c98f6b7f 100644 --- a/include/Nazara/Platform/Event.hpp +++ b/include/Nazara/Platform/Event.hpp @@ -22,7 +22,8 @@ namespace Nz // -WindowEventType_KeyReleased struct KeyEvent { - Keyboard::Key code; + Keyboard::Scancode scancode; + Keyboard::VKey virtualKey; bool alt; bool control; bool repeated; diff --git a/include/Nazara/Platform/Keyboard.hpp b/include/Nazara/Platform/Keyboard.hpp index c3ec5ac19..5a131b66f 100644 --- a/include/Nazara/Platform/Keyboard.hpp +++ b/include/Nazara/Platform/Keyboard.hpp @@ -18,7 +18,7 @@ namespace Nz class NAZARA_PLATFORM_API Keyboard { public: - enum Key + enum class Scancode { Undefined = -1, @@ -164,14 +164,167 @@ namespace Nz NumLock, ScrollLock, - Count + Max = ScrollLock + }; + + enum class VKey + { + Undefined = -1, + + // Lettres + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z, + + // Functional keys + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + + // Directional keys + Down, + Left, + Right, + Up, + + // Numerical pad + Add, + Decimal, + Divide, + Multiply, + NumpadReturn, + Numpad0, + Numpad1, + Numpad2, + Numpad3, + Numpad4, + Numpad5, + Numpad6, + Numpad7, + Numpad8, + Numpad9, + Subtract, + + // Various + Backslash, + Backspace, + Clear, + Comma, + Dash, + Delete, + End, + Equal, + Escape, + Home, + Insert, + LAlt, + LBracket, + LControl, + LShift, + LSystem, + Num0, + Num1, + Num2, + Num3, + Num4, + Num5, + Num6, + Num7, + Num8, + Num9, + PageDown, + PageUp, + Pause, + Period, + Print, + PrintScreen, + Quote, + RAlt, + RBracket, + RControl, + Return, + RShift, + RSystem, + Semicolon, + Slash, + Space, + Tab, + Tilde, + Menu, + ISOBackslash102, + + // Navigator keys + Browser_Back, + Browser_Favorites, + Browser_Forward, + Browser_Home, + Browser_Refresh, + Browser_Search, + Browser_Stop, + + // Lecture control keys + Media_Next, + Media_Play, + Media_Previous, + Media_Stop, + + // Volume control keys + Volume_Down, + Volume_Mute, + Volume_Up, + + // Locking keys + CapsLock, + NumLock, + ScrollLock, + + Max = ScrollLock }; Keyboard() = delete; ~Keyboard() = delete; - static String GetKeyName(Key key); - static bool IsKeyPressed(Key key); + static String GetKeyName(Scancode scancode); + static String GetKeyName(VKey key); + static bool IsKeyPressed(Scancode scancode); + static bool IsKeyPressed(VKey key); + static Scancode ToScanCode(VKey key); + static VKey ToVirtualKey(Scancode key); }; } diff --git a/include/Nazara/Renderer/OpenGL.hpp b/include/Nazara/Renderer/OpenGL.hpp index 35a851d00..5252bcfbe 100644 --- a/include/Nazara/Renderer/OpenGL.hpp +++ b/include/Nazara/Renderer/OpenGL.hpp @@ -6,9 +6,6 @@ #ifndef NAZARA_OPENGL_HPP #define NAZARA_OPENGL_HPP -#ifndef NAZARA_RENDERER_OPENGL -#define NAZARA_RENDERER_OPENGL -#endif #ifdef NAZARA_RENDERER_OPENGL #include @@ -25,7 +22,9 @@ #if defined(NAZARA_PLATFORM_SDL2) #include -#elif defined(NAZARA_PLATFORM_WINDOWS) +#endif + +#if defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_GLX) namespace GLX @@ -335,8 +334,7 @@ namespace Nz NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer; NAZARA_RENDERER_API extern PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer; NAZARA_RENDERER_API extern PFNGLVIEWPORTPROC glViewport; -#if defined(NAZARA_PLATFORM_SDL2) -#elif defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_WINDOWS) NAZARA_RENDERER_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat; NAZARA_RENDERER_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs; NAZARA_RENDERER_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; diff --git a/src/Nazara/Platform/Keyboard.cpp b/src/Nazara/Platform/Keyboard.cpp index 9fbf8fcdf..45435b818 100644 --- a/src/Nazara/Platform/Keyboard.cpp +++ b/src/Nazara/Platform/Keyboard.cpp @@ -18,13 +18,33 @@ namespace Nz { - String Keyboard::GetKeyName(Key key) + String Keyboard::GetKeyName(Scancode scancode) + { + return EventImpl::GetKeyName(scancode); + } + + String Keyboard::GetKeyName(VKey key) { return EventImpl::GetKeyName(key); } - bool Keyboard::IsKeyPressed(Key key) + bool Keyboard::IsKeyPressed(Scancode scancode) + { + return EventImpl::IsKeyPressed(scancode); + } + + bool Keyboard::IsKeyPressed(VKey key) { return EventImpl::IsKeyPressed(key); } + + Keyboard::Scancode Keyboard::ToScanCode(VKey key) + { + return EventImpl::ToScanCode(key); + } + + Keyboard::VKey Keyboard::ToVirtualKey(Scancode scancode) + { + return EventImpl::ToVirtualKey(scancode); + } } diff --git a/src/Nazara/Platform/SDL2/InputImpl.cpp b/src/Nazara/Platform/SDL2/InputImpl.cpp index 671f79d22..1ecbc8491 100644 --- a/src/Nazara/Platform/SDL2/InputImpl.cpp +++ b/src/Nazara/Platform/SDL2/InputImpl.cpp @@ -5,171 +5,34 @@ #include #include #include +#include #include - #include +#include #include namespace Nz { - namespace + String EventImpl::GetKeyName(Keyboard::Scancode key) { - SDL_Scancode nzKeyboardToSDLScanCode[Keyboard::Count] = { - // Lettres - SDL_SCANCODE_A, // Key::A - SDL_SCANCODE_B, // Key::B - SDL_SCANCODE_C, // Key::C - SDL_SCANCODE_D, // Key::D - SDL_SCANCODE_E, // Key::E - SDL_SCANCODE_F, // Key::F - SDL_SCANCODE_G, // Key::G - SDL_SCANCODE_H, // Key::H - SDL_SCANCODE_I, // Key::I - SDL_SCANCODE_J, // Key::J - SDL_SCANCODE_K, // Key::K - SDL_SCANCODE_L, // Key::L - SDL_SCANCODE_M, // Key::M - SDL_SCANCODE_N, // Key::N - SDL_SCANCODE_O, // Key::O - SDL_SCANCODE_P, // Key::P - SDL_SCANCODE_Q, // Key::Q - SDL_SCANCODE_R, // Key::R - SDL_SCANCODE_S, // Key::S - SDL_SCANCODE_T, // Key::T - SDL_SCANCODE_U, // Key::U - SDL_SCANCODE_V, // Key::V - SDL_SCANCODE_W, // Key::W - SDL_SCANCODE_X, // Key::X - SDL_SCANCODE_Y, // Key::Y - SDL_SCANCODE_Z, // Key::Z + SDL_Scancode scancode = SDLHelper::ToSDL(key); - // Touches de fonction - SDL_SCANCODE_F1, // Key::F1 - SDL_SCANCODE_F2, // Key::F2 - SDL_SCANCODE_F3, // Key::F3 - SDL_SCANCODE_F4, // Key::F4 - SDL_SCANCODE_F5, // Key::F5 - SDL_SCANCODE_F6, // Key::F6 - SDL_SCANCODE_F7, // Key::F7 - SDL_SCANCODE_F8, // Key::F8 - SDL_SCANCODE_F9, // Key::F9 - SDL_SCANCODE_F10, // Key::F10 - SDL_SCANCODE_F11, // Key::F11 - SDL_SCANCODE_F12, // Key::F12 - SDL_SCANCODE_F13, // Key::F13 - SDL_SCANCODE_F14, // Key::F14 - SDL_SCANCODE_F15, // Key::F15 + String name; + if (scancode != SDL_SCANCODE_UNKNOWN) + name = SDL_GetScancodeName(scancode); - // Flèches directionnelles - SDL_SCANCODE_DOWN, // Key::Down - SDL_SCANCODE_LEFT, // Key::Left - SDL_SCANCODE_RIGHT, // Key::Right - SDL_SCANCODE_UP, // Key::Up - - // Pavé numérique - SDL_SCANCODE_KP_PLUS, // Key::Add - SDL_SCANCODE_KP_PERIOD, // Key::Decimal - SDL_SCANCODE_KP_DIVIDE, // Key::Divide - SDL_SCANCODE_KP_MULTIPLY, // Key::Multiply - SDL_SCANCODE_KP_ENTER, // Key::NumpadReturn - SDL_SCANCODE_KP_0, // Key::Numpad0 - SDL_SCANCODE_KP_1, // Key::Numpad1 - SDL_SCANCODE_KP_2, // Key::Numpad2 - SDL_SCANCODE_KP_3, // Key::Numpad3 - SDL_SCANCODE_KP_4, // Key::Numpad4 - SDL_SCANCODE_KP_5, // Key::Numpad5 - SDL_SCANCODE_KP_6, // Key::Numpad6 - SDL_SCANCODE_KP_7, // Key::Numpad7 - SDL_SCANCODE_KP_8, // Key::Numpad8 - SDL_SCANCODE_KP_9, // Key::Numpad9 - SDL_SCANCODE_KP_MINUS, // Key::Subtract - - - // Diverss - SDL_SCANCODE_BACKSLASH, // Key::Backslash - SDL_SCANCODE_BACKSPACE, // Key::Backspace - SDL_SCANCODE_CLEAR, // Key::Clear - SDL_SCANCODE_COMMA, // Key::Comma, - SDL_SCANCODE_MINUS, // Key::Dash - SDL_SCANCODE_DELETE, // Key::Delete - SDL_SCANCODE_END, // Key::End - SDL_SCANCODE_EQUALS, // Key::Equal - SDL_SCANCODE_ESCAPE, // Key::Escape - SDL_SCANCODE_HOME, // Key::Home - SDL_SCANCODE_INSERT, // Key::Insert - SDL_SCANCODE_LALT, // Key::LAlt - SDL_SCANCODE_LEFTBRACKET, // Key::LBracket - SDL_SCANCODE_LCTRL, // Key::LControl - SDL_SCANCODE_LSHIFT, // Key::LShift - SDL_SCANCODE_LGUI, // Key::LSystem - SDL_SCANCODE_0, // Key::Num0 - SDL_SCANCODE_1, // Key::Num1 - SDL_SCANCODE_2, // Key::Num2 - SDL_SCANCODE_3, // Key::Num3 - SDL_SCANCODE_4, // Key::Num4 - SDL_SCANCODE_5, // Key::Num5 - SDL_SCANCODE_6, // Key::Num6 - SDL_SCANCODE_7, // Key::Num7 - SDL_SCANCODE_8, // Key::Num8 - SDL_SCANCODE_9, // Key::Num9 - SDL_SCANCODE_PAGEDOWN, // Key::PageDown - SDL_SCANCODE_PAGEUP, // Key::PageUp - SDL_SCANCODE_PAUSE, // Key::Pause - SDL_SCANCODE_PERIOD, // Key::Period - SDL_SCANCODE_SYSREQ, // Key::Print - SDL_SCANCODE_PRINTSCREEN, // Key::PrintScreen - SDL_SCANCODE_APOSTROPHE, // Key::Quote - SDL_SCANCODE_RALT, // Key::RAlt - SDL_SCANCODE_RIGHTBRACKET, // Key::RBracket - SDL_SCANCODE_RCTRL, // Key::RControl - SDL_SCANCODE_RETURN, // Key::Return - SDL_SCANCODE_RSHIFT, // Key::RShift - SDL_SCANCODE_RGUI, // Key::RSystem - SDL_SCANCODE_SEMICOLON, // Key::Semicolon - SDL_SCANCODE_SLASH, // Key::Slash - SDL_SCANCODE_SPACE, // Key::Space - SDL_SCANCODE_TAB, // Key::Tab - SDL_SCANCODE_GRAVE, // Key::Tilde - SDL_SCANCODE_APPLICATION, // Key::Menu - SDL_SCANCODE_NONUSBACKSLASH,// Key::ISOBackslash102 - - // Touches navigateur - SDL_SCANCODE_AC_BACK, // Key::Browser_Back - SDL_SCANCODE_AC_BOOKMARKS, // Key::Browser_Favorites - SDL_SCANCODE_AC_FORWARD, // Key::Browser_Forward - SDL_SCANCODE_AC_HOME, // Key::Browser_Home - SDL_SCANCODE_AC_REFRESH, // Key::Browser_Refresh - SDL_SCANCODE_AC_SEARCH, // Key::Browser_Search - SDL_SCANCODE_AC_STOP, // Key::Browser_Stop - - // Touches de contrôle - SDL_SCANCODE_AUDIONEXT, // Key::Media_Next, - SDL_SCANCODE_AUDIOPLAY, // Key::Media_PlayPause, - SDL_SCANCODE_AUDIOPREV, // Key::Media_Previous, - SDL_SCANCODE_AUDIOSTOP, // Key::Media_Stop, - - // Touches de contrôle du volume - SDL_SCANCODE_VOLUMEDOWN, // Key::Volume_Down - SDL_SCANCODE_MUTE, // Key::Volume_Mute - SDL_SCANCODE_VOLUMEUP, // Key::Volume_Up - - // Touches à verrouillage - SDL_SCANCODE_CAPSLOCK, // Key::CapsLock - SDL_SCANCODE_NUMLOCKCLEAR, // Key::NumLock - SDL_SCANCODE_SCROLLLOCK // Key::ScrollLock - }; + return !name.IsEmpty() ? name : String::Unicode("Unknown"); } - String EventImpl::GetKeyName(Keyboard::Key key) + String EventImpl::GetKeyName(Keyboard::VKey key) { - auto scancode = nzKeyboardToSDLScanCode[key]; + SDL_Keycode vkey = SDLHelper::ToSDL(key); - auto name = String::Unicode(SDL_GetKeyName(SDL_GetKeyFromScancode(scancode))); + String name; + if (vkey != SDLK_UNKNOWN) + name = SDL_GetKeyName(vkey); - if (name == "") - name = "\"" + String::Unicode(SDL_GetScancodeName(scancode)) + "\""; - - return name == "\"\"" ? String::Unicode("Unknown") : name; + return !name.IsEmpty() ? name : String::Unicode("Unknown"); } Vector2i EventImpl::GetMousePosition() @@ -199,9 +62,14 @@ namespace Nz } } - bool EventImpl::IsKeyPressed(Keyboard::Key key) + bool EventImpl::IsKeyPressed(Keyboard::Scancode key) { - return SDL_GetKeyboardState(nullptr)[nzKeyboardToSDLScanCode[key]]; + return SDL_GetKeyboardState(nullptr)[SDLHelper::ToSDL(key)]; + } + + bool EventImpl::IsKeyPressed(Keyboard::VKey key) + { + return IsKeyPressed(ToScanCode(key)); } bool EventImpl::IsMouseButtonPressed(Mouse::Button button) @@ -231,4 +99,14 @@ namespace Nz else NazaraError("Invalid window handle"); } + + Keyboard::Scancode EventImpl::ToScanCode(Keyboard::VKey key) + { + return SDLHelper::FromSDL(SDL_GetScancodeFromKey(SDLHelper::ToSDL(key))); + } + + Keyboard::VKey EventImpl::ToVirtualKey(Keyboard::Scancode scancode) + { + return SDLHelper::FromSDL(SDL_GetKeyFromScancode(SDLHelper::ToSDL(scancode))); + } } diff --git a/src/Nazara/Platform/SDL2/InputImpl.hpp b/src/Nazara/Platform/SDL2/InputImpl.hpp index 09f7802ec..9a21ed363 100644 --- a/src/Nazara/Platform/SDL2/InputImpl.hpp +++ b/src/Nazara/Platform/SDL2/InputImpl.hpp @@ -17,13 +17,17 @@ namespace Nz class EventImpl { public: - static String GetKeyName(Keyboard::Key key); + static String GetKeyName(Keyboard::Scancode scancode); + static String GetKeyName(Keyboard::VKey key); static Vector2i GetMousePosition(); static Vector2i GetMousePosition(const Window& relativeTo); - static bool IsKeyPressed(Keyboard::Key key); + static bool IsKeyPressed(Keyboard::Scancode key); + static bool IsKeyPressed(Keyboard::VKey key); static bool IsMouseButtonPressed(Mouse::Button button); static void SetMousePosition(int x, int y); static void SetMousePosition(int x, int y, const Window& relativeTo); + static Keyboard::Scancode ToScanCode(Keyboard::VKey key); + static Keyboard::VKey ToVirtualKey(Keyboard::Scancode scancode); }; } diff --git a/src/Nazara/Platform/SDL2/SDLHelper.cpp b/src/Nazara/Platform/SDL2/SDLHelper.cpp new file mode 100644 index 000000000..447e21c69 --- /dev/null +++ b/src/Nazara/Platform/SDL2/SDLHelper.cpp @@ -0,0 +1,586 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include + +namespace Nz +{ + namespace + { + SDL_Scancode nzScancodeToSDLScanCode[static_cast(Keyboard::VKey::Max) + 1] = { + // Lettres + SDL_SCANCODE_A, // Key::A + SDL_SCANCODE_B, // Key::B + SDL_SCANCODE_C, // Key::C + SDL_SCANCODE_D, // Key::D + SDL_SCANCODE_E, // Key::E + SDL_SCANCODE_F, // Key::F + SDL_SCANCODE_G, // Key::G + SDL_SCANCODE_H, // Key::H + SDL_SCANCODE_I, // Key::I + SDL_SCANCODE_J, // Key::J + SDL_SCANCODE_K, // Key::K + SDL_SCANCODE_L, // Key::L + SDL_SCANCODE_M, // Key::M + SDL_SCANCODE_N, // Key::N + SDL_SCANCODE_O, // Key::O + SDL_SCANCODE_P, // Key::P + SDL_SCANCODE_Q, // Key::Q + SDL_SCANCODE_R, // Key::R + SDL_SCANCODE_S, // Key::S + SDL_SCANCODE_T, // Key::T + SDL_SCANCODE_U, // Key::U + SDL_SCANCODE_V, // Key::V + SDL_SCANCODE_W, // Key::W + SDL_SCANCODE_X, // Key::X + SDL_SCANCODE_Y, // Key::Y + SDL_SCANCODE_Z, // Key::Z + + // Touches de fonction + SDL_SCANCODE_F1, // Key::F1 + SDL_SCANCODE_F2, // Key::F2 + SDL_SCANCODE_F3, // Key::F3 + SDL_SCANCODE_F4, // Key::F4 + SDL_SCANCODE_F5, // Key::F5 + SDL_SCANCODE_F6, // Key::F6 + SDL_SCANCODE_F7, // Key::F7 + SDL_SCANCODE_F8, // Key::F8 + SDL_SCANCODE_F9, // Key::F9 + SDL_SCANCODE_F10, // Key::F10 + SDL_SCANCODE_F11, // Key::F11 + SDL_SCANCODE_F12, // Key::F12 + SDL_SCANCODE_F13, // Key::F13 + SDL_SCANCODE_F14, // Key::F14 + SDL_SCANCODE_F15, // Key::F15 + + // Flèches directionnelles + SDL_SCANCODE_DOWN, // Key::Down + SDL_SCANCODE_LEFT, // Key::Left + SDL_SCANCODE_RIGHT, // Key::Right + SDL_SCANCODE_UP, // Key::Up + + // Pavé numérique + SDL_SCANCODE_KP_PLUS, // Key::Add + SDL_SCANCODE_KP_PERIOD, // Key::Decimal + SDL_SCANCODE_KP_DIVIDE, // Key::Divide + SDL_SCANCODE_KP_MULTIPLY, // Key::Multiply + SDL_SCANCODE_KP_ENTER, // Key::NumpadReturn + SDL_SCANCODE_KP_0, // Key::Numpad0 + SDL_SCANCODE_KP_1, // Key::Numpad1 + SDL_SCANCODE_KP_2, // Key::Numpad2 + SDL_SCANCODE_KP_3, // Key::Numpad3 + SDL_SCANCODE_KP_4, // Key::Numpad4 + SDL_SCANCODE_KP_5, // Key::Numpad5 + SDL_SCANCODE_KP_6, // Key::Numpad6 + SDL_SCANCODE_KP_7, // Key::Numpad7 + SDL_SCANCODE_KP_8, // Key::Numpad8 + SDL_SCANCODE_KP_9, // Key::Numpad9 + SDL_SCANCODE_KP_MINUS, // Key::Subtract + + // Divers + SDL_SCANCODE_BACKSLASH, // Key::Backslash + SDL_SCANCODE_BACKSPACE, // Key::Backspace + SDL_SCANCODE_CLEAR, // Key::Clear + SDL_SCANCODE_COMMA, // Key::Comma, + SDL_SCANCODE_MINUS, // Key::Dash + SDL_SCANCODE_DELETE, // Key::Delete + SDL_SCANCODE_END, // Key::End + SDL_SCANCODE_EQUALS, // Key::Equal + SDL_SCANCODE_ESCAPE, // Key::Escape + SDL_SCANCODE_HOME, // Key::Home + SDL_SCANCODE_INSERT, // Key::Insert + SDL_SCANCODE_LALT, // Key::LAlt + SDL_SCANCODE_LEFTBRACKET, // Key::LBracket + SDL_SCANCODE_LCTRL, // Key::LControl + SDL_SCANCODE_LSHIFT, // Key::LShift + SDL_SCANCODE_LGUI, // Key::LSystem + SDL_SCANCODE_0, // Key::Num0 + SDL_SCANCODE_1, // Key::Num1 + SDL_SCANCODE_2, // Key::Num2 + SDL_SCANCODE_3, // Key::Num3 + SDL_SCANCODE_4, // Key::Num4 + SDL_SCANCODE_5, // Key::Num5 + SDL_SCANCODE_6, // Key::Num6 + SDL_SCANCODE_7, // Key::Num7 + SDL_SCANCODE_8, // Key::Num8 + SDL_SCANCODE_9, // Key::Num9 + SDL_SCANCODE_PAGEDOWN, // Key::PageDown + SDL_SCANCODE_PAGEUP, // Key::PageUp + SDL_SCANCODE_PAUSE, // Key::Pause + SDL_SCANCODE_PERIOD, // Key::Period + SDL_SCANCODE_SYSREQ, // Key::Print + SDL_SCANCODE_PRINTSCREEN, // Key::PrintScreen + SDL_SCANCODE_APOSTROPHE, // Key::Quote + SDL_SCANCODE_RALT, // Key::RAlt + SDL_SCANCODE_RIGHTBRACKET, // Key::RBracket + SDL_SCANCODE_RCTRL, // Key::RControl + SDL_SCANCODE_RETURN, // Key::Return + SDL_SCANCODE_RSHIFT, // Key::RShift + SDL_SCANCODE_RGUI, // Key::RSystem + SDL_SCANCODE_SEMICOLON, // Key::Semicolon + SDL_SCANCODE_SLASH, // Key::Slash + SDL_SCANCODE_SPACE, // Key::Space + SDL_SCANCODE_TAB, // Key::Tab + SDL_SCANCODE_GRAVE, // Key::Tilde + SDL_SCANCODE_APPLICATION, // Key::Menu + SDL_SCANCODE_NONUSBACKSLASH,// Key::ISOBackslash102 + + // Touches navigateur + SDL_SCANCODE_AC_BACK, // Key::Browser_Back + SDL_SCANCODE_AC_BOOKMARKS, // Key::Browser_Favorites + SDL_SCANCODE_AC_FORWARD, // Key::Browser_Forward + SDL_SCANCODE_AC_HOME, // Key::Browser_Home + SDL_SCANCODE_AC_REFRESH, // Key::Browser_Refresh + SDL_SCANCODE_AC_SEARCH, // Key::Browser_Search + SDL_SCANCODE_AC_STOP, // Key::Browser_Stop + + // Touches de contrôle + SDL_SCANCODE_AUDIONEXT, // Key::Media_Next, + SDL_SCANCODE_AUDIOPLAY, // Key::Media_PlayPause, + SDL_SCANCODE_AUDIOPREV, // Key::Media_Previous, + SDL_SCANCODE_AUDIOSTOP, // Key::Media_Stop, + + // Touches de contrôle du volume + SDL_SCANCODE_VOLUMEDOWN, // Key::Volume_Down + SDL_SCANCODE_MUTE, // Key::Volume_Mute + SDL_SCANCODE_VOLUMEUP, // Key::Volume_Up + + // Touches à verrouillage + SDL_SCANCODE_CAPSLOCK, // Key::CapsLock + SDL_SCANCODE_NUMLOCKCLEAR, // Key::NumLock + SDL_SCANCODE_SCROLLLOCK // Key::ScrollLock + }; + SDL_Keycode nzVKeyToSDLVKey[static_cast(Keyboard::VKey::Max) + 1] = { + // Keys + SDLK_a, // VKey::A + SDLK_b, // VKey::B + SDLK_c, // VKey::C + SDLK_d, // VKey::D + SDLK_e, // VKey::E + SDLK_f, // VKey::F + SDLK_g, // VKey::G + SDLK_h, // VKey::H + SDLK_i, // VKey::I + SDLK_j, // VKey::J + SDLK_k, // VKey::K + SDLK_l, // VKey::L + SDLK_m, // VKey::M + SDLK_n, // VKey::N + SDLK_o, // VKey::O + SDLK_p, // VKey::P + SDLK_q, // VKey::Q + SDLK_r, // VKey::R + SDLK_s, // VKey::S + SDLK_t, // VKey::T + SDLK_u, // VKey::U + SDLK_v, // VKey::V + SDLK_w, // VKey::W + SDLK_x, // VKey::X + SDLK_y, // VKey::Y + SDLK_z, // VKey::Z + + // Function keys + SDLK_F1, // VKey::F1 + SDLK_F2, // VKey::F2 + SDLK_F3, // VKey::F3 + SDLK_F4, // VKey::F4 + SDLK_F5, // VKey::F5 + SDLK_F6, // VKey::F6 + SDLK_F7, // VKey::F7 + SDLK_F8, // VKey::F8 + SDLK_F9, // VKey::F9 + SDLK_F10, // VKey::F10 + SDLK_F11, // VKey::F11 + SDLK_F12, // VKey::F12 + SDLK_F13, // VKey::F13 + SDLK_F14, // VKey::F14 + SDLK_F15, // VKey::F15 + + // Arrows + SDLK_DOWN, // VKey::Down + SDLK_LEFT, // VKey::Left + SDLK_RIGHT, // VKey::Right + SDLK_UP, // VKey::Up + + // Keypad + SDLK_KP_PLUS, // VKey::Add + SDLK_KP_PERIOD, // VKey::Decimal + SDLK_KP_DIVIDE, // VKey::Divide + SDLK_KP_MULTIPLY, // VKey::Multiply + SDLK_KP_ENTER, // VKey::NumpadReturn + SDLK_KP_0, // VKey::Numpad0 + SDLK_KP_1, // VKey::Numpad1 + SDLK_KP_2, // VKey::Numpad2 + SDLK_KP_3, // VKey::Numpad3 + SDLK_KP_4, // VKey::Numpad4 + SDLK_KP_5, // VKey::Numpad5 + SDLK_KP_6, // VKey::Numpad6 + SDLK_KP_7, // VKey::Numpad7 + SDLK_KP_8, // VKey::Numpad8 + SDLK_KP_9, // VKey::Numpad9 + SDLK_KP_MINUS, // VKey::Subtract + + // Divers + SDLK_BACKSLASH, // VKey::Backslash + SDLK_BACKSPACE, // VKey::Backspace + SDLK_CLEAR, // VKey::Clear + SDLK_COMMA, // VKey::Comma, + SDLK_MINUS, // VKey::Dash + SDLK_DELETE, // VKey::Delete + SDLK_END, // VKey::End + SDLK_EQUALS, // VKey::Equal + SDLK_ESCAPE, // VKey::Escape + SDLK_HOME, // VKey::Home + SDLK_INSERT, // VKey::Insert + SDLK_LALT, // VKey::LAlt + SDLK_LEFTBRACKET, // VKey::LBracket + SDLK_LCTRL, // VKey::LControl + SDLK_LSHIFT, // VKey::LShift + SDLK_LGUI, // VKey::LSystem + SDLK_0, // VKey::Num0 + SDLK_1, // VKey::Num1 + SDLK_2, // VKey::Num2 + SDLK_3, // VKey::Num3 + SDLK_4, // VKey::Num4 + SDLK_5, // VKey::Num5 + SDLK_6, // VKey::Num6 + SDLK_7, // VKey::Num7 + SDLK_8, // VKey::Num8 + SDLK_9, // VKey::Num9 + SDLK_PAGEDOWN, // VKey::PageDown + SDLK_PAGEUP, // VKey::PageUp + SDLK_PAUSE, // VKey::Pause + SDLK_PERIOD, // VKey::Period + SDLK_SYSREQ, // VKey::Print + SDLK_PRINTSCREEN, // VKey::PrintScreen + SDLK_QUOTE, // VKey::Quote + SDLK_RALT, // VKey::RAlt + SDLK_RIGHTBRACKET, // VKey::RBracket + SDLK_RCTRL, // VKey::RControl + SDLK_RETURN, // VKey::Return + SDLK_RSHIFT, // VKey::RShift + SDLK_RGUI, // VKey::RSystem + SDLK_SEMICOLON, // VKey::Semicolon + SDLK_SLASH, // VKey::Slash + SDLK_SPACE, // VKey::Space + SDLK_TAB, // VKey::Tab + SDLK_BACKQUOTE, // VKey::Tilde + SDLK_APPLICATION, // VKey::Menu + SDLK_UNKNOWN, // VKey::ISOBackslash102 + + // Browser control + SDLK_AC_BACK, // VKey::Browser_Back + SDLK_AC_BOOKMARKS, // VKey::Browser_Favorites + SDLK_AC_FORWARD, // VKey::Browser_Forward + SDLK_AC_HOME, // VKey::Browser_Home + SDLK_AC_REFRESH, // VKey::Browser_Refresh + SDLK_AC_SEARCH, // VKey::Browser_Search + SDLK_AC_STOP, // VKey::Browser_Stop + + // Audio control + SDLK_AUDIONEXT, // VKey::Media_Next, + SDLK_AUDIOPLAY, // VKey::Media_PlayPause, + SDLK_AUDIOPREV, // VKey::Media_Previous, + SDLK_AUDIOSTOP, // VKey::Media_Stop, + + // Volume control + SDLK_VOLUMEDOWN, // VKey::Volume_Down + SDLK_MUTE, // VKey::Volume_Mute + SDLK_VOLUMEUP, // VKey::Volume_Up + + // Lock keys + SDLK_CAPSLOCK, // VKey::CapsLock + SDLK_NUMLOCKCLEAR, // VKey::NumLock + SDLK_SCROLLLOCK // VKey::ScrollLock + }; + } + + Keyboard::Scancode SDLHelper::FromSDL(SDL_Scancode scancode) + { + switch (scancode) + { + case SDL_SCANCODE_LCTRL: return Keyboard::Scancode::LControl; + case SDL_SCANCODE_RCTRL: return Keyboard::Scancode::RControl; + case SDL_SCANCODE_LALT: return Keyboard::Scancode::LAlt; + case SDL_SCANCODE_RALT: return Keyboard::Scancode::RAlt; + case SDL_SCANCODE_LSHIFT: return Keyboard::Scancode::LShift; + case SDL_SCANCODE_RSHIFT: return Keyboard::Scancode::RShift; + + case SDL_SCANCODE_0: return Keyboard::Scancode::Num0; + case SDL_SCANCODE_1: return Keyboard::Scancode::Num1; + case SDL_SCANCODE_2: return Keyboard::Scancode::Num2; + case SDL_SCANCODE_3: return Keyboard::Scancode::Num3; + case SDL_SCANCODE_4: return Keyboard::Scancode::Num4; + case SDL_SCANCODE_5: return Keyboard::Scancode::Num5; + case SDL_SCANCODE_6: return Keyboard::Scancode::Num6; + case SDL_SCANCODE_7: return Keyboard::Scancode::Num7; + case SDL_SCANCODE_8: return Keyboard::Scancode::Num8; + case SDL_SCANCODE_9: return Keyboard::Scancode::Num9; + case SDL_SCANCODE_A: return Keyboard::Scancode::A; + case SDL_SCANCODE_B: return Keyboard::Scancode::B; + case SDL_SCANCODE_C: return Keyboard::Scancode::C; + case SDL_SCANCODE_D: return Keyboard::Scancode::D; + case SDL_SCANCODE_E: return Keyboard::Scancode::E; + case SDL_SCANCODE_F: return Keyboard::Scancode::F; + case SDL_SCANCODE_G: return Keyboard::Scancode::G; + case SDL_SCANCODE_H: return Keyboard::Scancode::H; + case SDL_SCANCODE_I: return Keyboard::Scancode::I; + case SDL_SCANCODE_J: return Keyboard::Scancode::J; + case SDL_SCANCODE_K: return Keyboard::Scancode::K; + case SDL_SCANCODE_L: return Keyboard::Scancode::L; + case SDL_SCANCODE_M: return Keyboard::Scancode::M; + case SDL_SCANCODE_N: return Keyboard::Scancode::N; + case SDL_SCANCODE_O: return Keyboard::Scancode::O; + case SDL_SCANCODE_P: return Keyboard::Scancode::P; + case SDL_SCANCODE_Q: return Keyboard::Scancode::Q; + case SDL_SCANCODE_R: return Keyboard::Scancode::R; + case SDL_SCANCODE_S: return Keyboard::Scancode::S; + case SDL_SCANCODE_T: return Keyboard::Scancode::T; + case SDL_SCANCODE_U: return Keyboard::Scancode::U; + case SDL_SCANCODE_V: return Keyboard::Scancode::V; + case SDL_SCANCODE_W: return Keyboard::Scancode::W; + case SDL_SCANCODE_X: return Keyboard::Scancode::X; + case SDL_SCANCODE_Y: return Keyboard::Scancode::Y; + case SDL_SCANCODE_Z: return Keyboard::Scancode::Z; + case SDL_SCANCODE_KP_PLUS: return Keyboard::Scancode::Add; + case SDL_SCANCODE_BACKSPACE: return Keyboard::Scancode::Backspace; + case SDL_SCANCODE_AC_BACK: return Keyboard::Scancode::Browser_Back; + case SDL_SCANCODE_AC_BOOKMARKS: return Keyboard::Scancode::Browser_Favorites; + case SDL_SCANCODE_AC_FORWARD: return Keyboard::Scancode::Browser_Forward; + case SDL_SCANCODE_AC_HOME: return Keyboard::Scancode::Browser_Home; + case SDL_SCANCODE_AC_REFRESH: return Keyboard::Scancode::Browser_Refresh; + case SDL_SCANCODE_AC_SEARCH: return Keyboard::Scancode::Browser_Search; + case SDL_SCANCODE_AC_STOP: return Keyboard::Scancode::Browser_Stop; + case SDL_SCANCODE_CAPSLOCK: return Keyboard::Scancode::CapsLock; + case SDL_SCANCODE_CLEAR: return Keyboard::Scancode::Clear; + case SDL_SCANCODE_KP_PERIOD: return Keyboard::Scancode::Decimal; + case SDL_SCANCODE_DELETE: return Keyboard::Scancode::Delete; + case SDL_SCANCODE_KP_DIVIDE: return Keyboard::Scancode::Divide; + case SDL_SCANCODE_DOWN: return Keyboard::Scancode::Down; + case SDL_SCANCODE_END: return Keyboard::Scancode::End; + case SDL_SCANCODE_ESCAPE: return Keyboard::Scancode::Escape; + case SDL_SCANCODE_F1: return Keyboard::Scancode::F1; + case SDL_SCANCODE_F2: return Keyboard::Scancode::F2; + case SDL_SCANCODE_F3: return Keyboard::Scancode::F3; + case SDL_SCANCODE_F4: return Keyboard::Scancode::F4; + case SDL_SCANCODE_F5: return Keyboard::Scancode::F5; + case SDL_SCANCODE_F6: return Keyboard::Scancode::F6; + case SDL_SCANCODE_F7: return Keyboard::Scancode::F7; + case SDL_SCANCODE_F8: return Keyboard::Scancode::F8; + case SDL_SCANCODE_F9: return Keyboard::Scancode::F9; + case SDL_SCANCODE_F10: return Keyboard::Scancode::F10; + case SDL_SCANCODE_F11: return Keyboard::Scancode::F11; + case SDL_SCANCODE_F12: return Keyboard::Scancode::F12; + case SDL_SCANCODE_F13: return Keyboard::Scancode::F13; + case SDL_SCANCODE_F14: return Keyboard::Scancode::F14; + case SDL_SCANCODE_F15: return Keyboard::Scancode::F15; + case SDL_SCANCODE_HOME: return Keyboard::Scancode::Home; + case SDL_SCANCODE_INSERT: return Keyboard::Scancode::Insert; + case SDL_SCANCODE_LEFT: return Keyboard::Scancode::Left; + case SDL_SCANCODE_LGUI: return Keyboard::Scancode::LSystem; + case SDL_SCANCODE_AUDIONEXT: return Keyboard::Scancode::Media_Next; + case SDL_SCANCODE_AUDIOPLAY: return Keyboard::Scancode::Media_Play; + case SDL_SCANCODE_AUDIOPREV: return Keyboard::Scancode::Media_Previous; + case SDL_SCANCODE_AUDIOSTOP: return Keyboard::Scancode::Media_Stop; + case SDL_SCANCODE_KP_MULTIPLY: return Keyboard::Scancode::Multiply; + case SDL_SCANCODE_PAGEDOWN: return Keyboard::Scancode::PageDown; + case SDL_SCANCODE_KP_0: return Keyboard::Scancode::Numpad0; + case SDL_SCANCODE_KP_1: return Keyboard::Scancode::Numpad1; + case SDL_SCANCODE_KP_2: return Keyboard::Scancode::Numpad2; + case SDL_SCANCODE_KP_3: return Keyboard::Scancode::Numpad3; + case SDL_SCANCODE_KP_4: return Keyboard::Scancode::Numpad4; + case SDL_SCANCODE_KP_5: return Keyboard::Scancode::Numpad5; + case SDL_SCANCODE_KP_6: return Keyboard::Scancode::Numpad6; + case SDL_SCANCODE_KP_7: return Keyboard::Scancode::Numpad7; + case SDL_SCANCODE_KP_8: return Keyboard::Scancode::Numpad8; + case SDL_SCANCODE_KP_9: return Keyboard::Scancode::Numpad9; + case SDL_SCANCODE_NUMLOCKCLEAR: return Keyboard::Scancode::NumLock; + case SDL_SCANCODE_SEMICOLON: return Keyboard::Scancode::Semicolon; + case SDL_SCANCODE_SLASH: return Keyboard::Scancode::Slash; + case SDL_SCANCODE_GRAVE: return Keyboard::Scancode::Tilde; + case SDL_SCANCODE_APPLICATION: return Keyboard::Scancode::Menu; + case SDL_SCANCODE_NONUSBACKSLASH: return Keyboard::Scancode::ISOBackslash102; + case SDL_SCANCODE_LEFTBRACKET: return Keyboard::Scancode::LBracket; + case SDL_SCANCODE_BACKSLASH: return Keyboard::Scancode::Backslash; + case SDL_SCANCODE_RIGHTBRACKET: return Keyboard::Scancode::RBracket; + case SDL_SCANCODE_APOSTROPHE: return Keyboard::Scancode::Quote; + case SDL_SCANCODE_COMMA: return Keyboard::Scancode::Comma; + case SDL_SCANCODE_MINUS: return Keyboard::Scancode::Dash; + case SDL_SCANCODE_PERIOD: return Keyboard::Scancode::Period; + case SDL_SCANCODE_EQUALS: return Keyboard::Scancode::Equal; + case SDL_SCANCODE_RIGHT: return Keyboard::Scancode::Right; + case SDL_SCANCODE_PAGEUP: return Keyboard::Scancode::PageUp; + case SDL_SCANCODE_PAUSE: return Keyboard::Scancode::Pause; + case SDL_SCANCODE_SYSREQ: return Keyboard::Scancode::Print; + case SDL_SCANCODE_SCROLLLOCK: return Keyboard::Scancode::ScrollLock; + case SDL_SCANCODE_PRINTSCREEN: return Keyboard::Scancode::PrintScreen; + case SDL_SCANCODE_KP_MINUS: return Keyboard::Scancode::Subtract; + case SDL_SCANCODE_RETURN: return Keyboard::Scancode::Return; + case SDL_SCANCODE_KP_ENTER: return Keyboard::Scancode::NumpadReturn; + case SDL_SCANCODE_RGUI: return Keyboard::Scancode::RSystem; + case SDL_SCANCODE_SPACE: return Keyboard::Scancode::Space; + case SDL_SCANCODE_TAB: return Keyboard::Scancode::Tab; + case SDL_SCANCODE_UP: return Keyboard::Scancode::Up; + case SDL_SCANCODE_VOLUMEDOWN: return Keyboard::Scancode::Volume_Down; + case SDL_SCANCODE_MUTE: return Keyboard::Scancode::Volume_Mute; + case SDL_SCANCODE_AUDIOMUTE: return Keyboard::Scancode::Volume_Mute; + case SDL_SCANCODE_VOLUMEUP: return Keyboard::Scancode::Volume_Up; + + default: + return Keyboard::Scancode::Undefined; + } + } + + Keyboard::VKey SDLHelper::FromSDL(SDL_Keycode keycode) + { + switch (keycode) + { + case SDLK_LCTRL: return Keyboard::VKey::LControl; + case SDLK_RCTRL: return Keyboard::VKey::RControl; + case SDLK_LALT: return Keyboard::VKey::LAlt; + case SDLK_RALT: return Keyboard::VKey::RAlt; + case SDLK_LSHIFT: return Keyboard::VKey::LShift; + case SDLK_RSHIFT: return Keyboard::VKey::RShift; + + case SDLK_0: return Keyboard::VKey::Num0; + case SDLK_1: return Keyboard::VKey::Num1; + case SDLK_2: return Keyboard::VKey::Num2; + case SDLK_3: return Keyboard::VKey::Num3; + case SDLK_4: return Keyboard::VKey::Num4; + case SDLK_5: return Keyboard::VKey::Num5; + case SDLK_6: return Keyboard::VKey::Num6; + case SDLK_7: return Keyboard::VKey::Num7; + case SDLK_8: return Keyboard::VKey::Num8; + case SDLK_9: return Keyboard::VKey::Num9; + case SDLK_a: return Keyboard::VKey::A; + case SDLK_b: return Keyboard::VKey::B; + case SDLK_c: return Keyboard::VKey::C; + case SDLK_d: return Keyboard::VKey::D; + case SDLK_e: return Keyboard::VKey::E; + case SDLK_f: return Keyboard::VKey::F; + case SDLK_g: return Keyboard::VKey::G; + case SDLK_h: return Keyboard::VKey::H; + case SDLK_i: return Keyboard::VKey::I; + case SDLK_j: return Keyboard::VKey::J; + case SDLK_k: return Keyboard::VKey::K; + case SDLK_l: return Keyboard::VKey::L; + case SDLK_m: return Keyboard::VKey::M; + case SDLK_n: return Keyboard::VKey::N; + case SDLK_o: return Keyboard::VKey::O; + case SDLK_p: return Keyboard::VKey::P; + case SDLK_q: return Keyboard::VKey::Q; + case SDLK_r: return Keyboard::VKey::R; + case SDLK_s: return Keyboard::VKey::S; + case SDLK_t: return Keyboard::VKey::T; + case SDLK_u: return Keyboard::VKey::U; + case SDLK_v: return Keyboard::VKey::V; + case SDLK_w: return Keyboard::VKey::W; + case SDLK_x: return Keyboard::VKey::X; + case SDLK_y: return Keyboard::VKey::Y; + case SDLK_z: return Keyboard::VKey::Z; + case SDLK_KP_PLUS: return Keyboard::VKey::Add; + case SDLK_BACKSPACE: return Keyboard::VKey::Backspace; + case SDLK_AC_BACK: return Keyboard::VKey::Browser_Back; + case SDLK_AC_BOOKMARKS: return Keyboard::VKey::Browser_Favorites; + case SDLK_AC_FORWARD: return Keyboard::VKey::Browser_Forward; + case SDLK_AC_HOME: return Keyboard::VKey::Browser_Home; + case SDLK_AC_REFRESH: return Keyboard::VKey::Browser_Refresh; + case SDLK_AC_SEARCH: return Keyboard::VKey::Browser_Search; + case SDLK_AC_STOP: return Keyboard::VKey::Browser_Stop; + case SDLK_CAPSLOCK: return Keyboard::VKey::CapsLock; + case SDLK_CLEAR: return Keyboard::VKey::Clear; + case SDLK_KP_PERIOD: return Keyboard::VKey::Decimal; + case SDLK_DELETE: return Keyboard::VKey::Delete; + case SDLK_KP_DIVIDE: return Keyboard::VKey::Divide; + case SDLK_DOWN: return Keyboard::VKey::Down; + case SDLK_END: return Keyboard::VKey::End; + case SDLK_ESCAPE: return Keyboard::VKey::Escape; + case SDLK_F1: return Keyboard::VKey::F1; + case SDLK_F2: return Keyboard::VKey::F2; + case SDLK_F3: return Keyboard::VKey::F3; + case SDLK_F4: return Keyboard::VKey::F4; + case SDLK_F5: return Keyboard::VKey::F5; + case SDLK_F6: return Keyboard::VKey::F6; + case SDLK_F7: return Keyboard::VKey::F7; + case SDLK_F8: return Keyboard::VKey::F8; + case SDLK_F9: return Keyboard::VKey::F9; + case SDLK_F10: return Keyboard::VKey::F10; + case SDLK_F11: return Keyboard::VKey::F11; + case SDLK_F12: return Keyboard::VKey::F12; + case SDLK_F13: return Keyboard::VKey::F13; + case SDLK_F14: return Keyboard::VKey::F14; + case SDLK_F15: return Keyboard::VKey::F15; + case SDLK_HOME: return Keyboard::VKey::Home; + case SDLK_INSERT: return Keyboard::VKey::Insert; + case SDLK_LEFT: return Keyboard::VKey::Left; + case SDLK_LGUI: return Keyboard::VKey::LSystem; + case SDLK_AUDIONEXT: return Keyboard::VKey::Media_Next; + case SDLK_AUDIOPLAY: return Keyboard::VKey::Media_Play; + case SDLK_AUDIOPREV: return Keyboard::VKey::Media_Previous; + case SDLK_AUDIOSTOP: return Keyboard::VKey::Media_Stop; + case SDLK_KP_MULTIPLY: return Keyboard::VKey::Multiply; + case SDLK_PAGEDOWN: return Keyboard::VKey::PageDown; + case SDLK_KP_0: return Keyboard::VKey::Numpad0; + case SDLK_KP_1: return Keyboard::VKey::Numpad1; + case SDLK_KP_2: return Keyboard::VKey::Numpad2; + case SDLK_KP_3: return Keyboard::VKey::Numpad3; + case SDLK_KP_4: return Keyboard::VKey::Numpad4; + case SDLK_KP_5: return Keyboard::VKey::Numpad5; + case SDLK_KP_6: return Keyboard::VKey::Numpad6; + case SDLK_KP_7: return Keyboard::VKey::Numpad7; + case SDLK_KP_8: return Keyboard::VKey::Numpad8; + case SDLK_KP_9: return Keyboard::VKey::Numpad9; + case SDLK_NUMLOCKCLEAR: return Keyboard::VKey::NumLock; + case SDLK_SEMICOLON: return Keyboard::VKey::Semicolon; + case SDLK_SLASH: return Keyboard::VKey::Slash; + case SDLK_BACKQUOTE: return Keyboard::VKey::Tilde; + case SDLK_APPLICATION: return Keyboard::VKey::Menu; + case SDLK_LEFTBRACKET: return Keyboard::VKey::LBracket; + case SDLK_BACKSLASH: return Keyboard::VKey::Backslash; + case SDLK_RIGHTBRACKET: return Keyboard::VKey::RBracket; + case SDLK_QUOTE: return Keyboard::VKey::Quote; + case SDLK_COMMA: return Keyboard::VKey::Comma; + case SDLK_MINUS: return Keyboard::VKey::Dash; + case SDLK_PERIOD: return Keyboard::VKey::Period; + case SDLK_EQUALS: return Keyboard::VKey::Equal; + case SDLK_RIGHT: return Keyboard::VKey::Right; + case SDLK_PAGEUP: return Keyboard::VKey::PageUp; + case SDLK_PAUSE: return Keyboard::VKey::Pause; + case SDLK_SYSREQ: return Keyboard::VKey::Print; + case SDLK_SCROLLLOCK: return Keyboard::VKey::ScrollLock; + case SDLK_PRINTSCREEN: return Keyboard::VKey::PrintScreen; + case SDLK_KP_MINUS: return Keyboard::VKey::Subtract; + case SDLK_RETURN: return Keyboard::VKey::Return; + case SDLK_KP_ENTER: return Keyboard::VKey::NumpadReturn; + case SDLK_RGUI: return Keyboard::VKey::RSystem; + case SDLK_SPACE: return Keyboard::VKey::Space; + case SDLK_TAB: return Keyboard::VKey::Tab; + case SDLK_UP: return Keyboard::VKey::Up; + case SDLK_VOLUMEDOWN: return Keyboard::VKey::Volume_Down; + case SDLK_MUTE: return Keyboard::VKey::Volume_Mute; + case SDLK_AUDIOMUTE: return Keyboard::VKey::Volume_Mute; + case SDLK_VOLUMEUP: return Keyboard::VKey::Volume_Up; + + default: + return Keyboard::VKey::Undefined; + } + } + + SDL_Scancode SDLHelper::ToSDL(Keyboard::Scancode scancode) + { + if (scancode == Keyboard::Scancode::Undefined) + return SDL_SCANCODE_UNKNOWN; + + return nzScancodeToSDLScanCode[static_cast(scancode)]; + } + + SDL_Keycode SDLHelper::ToSDL(Keyboard::VKey keycode) + { + if (keycode == Keyboard::VKey::Undefined) + return SDLK_UNKNOWN; + + return nzVKeyToSDLVKey[static_cast(keycode)]; + } + +} diff --git a/src/Nazara/Platform/SDL2/SDLHelper.hpp b/src/Nazara/Platform/SDL2/SDLHelper.hpp new file mode 100644 index 000000000..700e111a8 --- /dev/null +++ b/src/Nazara/Platform/SDL2/SDLHelper.hpp @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Platform module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_SDL2_HELPER_HPP +#define NAZARA_SDL2_HELPER_HPP + +#include +#include +#include + +namespace Nz +{ + class SDLHelper + { + public: + static Keyboard::Scancode FromSDL(SDL_Scancode scancode); + static Keyboard::VKey FromSDL(SDL_Keycode keycode); + static SDL_Scancode ToSDL(Keyboard::Scancode scancode); + static SDL_Keycode ToSDL(Keyboard::VKey keycode); + }; +} + +#endif // NAZARA_SDL2_HELPER_HPP diff --git a/src/Nazara/Platform/SDL2/WindowImpl.cpp b/src/Nazara/Platform/SDL2/WindowImpl.cpp index f44ca8fe5..6b9b18f5e 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.cpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -315,7 +316,7 @@ namespace Nz if (SDL_GetWindowID(window->m_handle) != event->motion.windowID) return 0; - if (window->m_ignoreNextMouseMove && event->motion.x == window->m_mousePos.x && event->motion.y == window->m_mousePos.y) + if (window->m_ignoreNextMouseMove /*&& event->motion.x == window->m_mousePos.x && event->motion.y == window->m_mousePos.y*/) { window->m_ignoreNextMouseMove = false; @@ -378,7 +379,8 @@ namespace Nz evt.type = WindowEventType_KeyPressed; - evt.key.code = SDLKeySymToNazaraKey(event->key.keysym); + evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode); + evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym); evt.key.alt = (event->key.keysym.mod & KMOD_ALT) != 0; evt.key.control = (event->key.keysym.mod & KMOD_CTRL) != 0; evt.key.repeated = event->key.repeat != 0; @@ -393,7 +395,8 @@ namespace Nz evt.type = WindowEventType_KeyReleased; - evt.key.code = SDLKeySymToNazaraKey(event->key.keysym); + evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode); + evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym); evt.key.alt = (event->key.keysym.mod & KMOD_ALT) != 0; evt.key.control = (event->key.keysym.mod & KMOD_CTRL) != 0; evt.key.repeated = event->key.repeat != 0; @@ -533,144 +536,6 @@ namespace Nz SDL_Quit(); } - Keyboard::Key WindowImpl::SDLKeySymToNazaraKey(SDL_Keysym& keysym) - { - auto key = keysym.scancode; - - switch (key) - { - case SDL_SCANCODE_LCTRL: return Keyboard::LControl; - case SDL_SCANCODE_RCTRL: return Keyboard::RControl; - case SDL_SCANCODE_LALT: return Keyboard::LAlt; - case SDL_SCANCODE_RALT: return Keyboard::RAlt; - case SDL_SCANCODE_LSHIFT: return Keyboard::LShift; - case SDL_SCANCODE_RSHIFT: return Keyboard::RShift; - - case SDL_SCANCODE_0: return Keyboard::Num0; - case SDL_SCANCODE_1: return Keyboard::Num1; - case SDL_SCANCODE_2: return Keyboard::Num2; - case SDL_SCANCODE_3: return Keyboard::Num3; - case SDL_SCANCODE_4: return Keyboard::Num4; - case SDL_SCANCODE_5: return Keyboard::Num5; - case SDL_SCANCODE_6: return Keyboard::Num6; - case SDL_SCANCODE_7: return Keyboard::Num7; - case SDL_SCANCODE_8: return Keyboard::Num8; - case SDL_SCANCODE_9: return Keyboard::Num9; - case SDL_SCANCODE_A: return Keyboard::A; - case SDL_SCANCODE_B: return Keyboard::B; - case SDL_SCANCODE_C: return Keyboard::C; - case SDL_SCANCODE_D: return Keyboard::D; - case SDL_SCANCODE_E: return Keyboard::E; - case SDL_SCANCODE_F: return Keyboard::F; - case SDL_SCANCODE_G: return Keyboard::G; - case SDL_SCANCODE_H: return Keyboard::H; - case SDL_SCANCODE_I: return Keyboard::I; - case SDL_SCANCODE_J: return Keyboard::J; - case SDL_SCANCODE_K: return Keyboard::K; - case SDL_SCANCODE_L: return Keyboard::L; - case SDL_SCANCODE_M: return Keyboard::M; - case SDL_SCANCODE_N: return Keyboard::N; - case SDL_SCANCODE_O: return Keyboard::O; - case SDL_SCANCODE_P: return Keyboard::P; - case SDL_SCANCODE_Q: return Keyboard::Q; - case SDL_SCANCODE_R: return Keyboard::R; - case SDL_SCANCODE_S: return Keyboard::S; - case SDL_SCANCODE_T: return Keyboard::T; - case SDL_SCANCODE_U: return Keyboard::U; - case SDL_SCANCODE_V: return Keyboard::V; - case SDL_SCANCODE_W: return Keyboard::W; - case SDL_SCANCODE_X: return Keyboard::X; - case SDL_SCANCODE_Y: return Keyboard::Y; - case SDL_SCANCODE_Z: return Keyboard::Z; - case SDL_SCANCODE_KP_PLUS: return Keyboard::Add; - case SDL_SCANCODE_BACKSPACE: return Keyboard::Backspace; - case SDL_SCANCODE_AC_BACK: return Keyboard::Browser_Back; - case SDL_SCANCODE_AC_BOOKMARKS: return Keyboard::Browser_Favorites; - case SDL_SCANCODE_AC_FORWARD: return Keyboard::Browser_Forward; - case SDL_SCANCODE_AC_HOME: return Keyboard::Browser_Home; - case SDL_SCANCODE_AC_REFRESH: return Keyboard::Browser_Refresh; - case SDL_SCANCODE_AC_SEARCH: return Keyboard::Browser_Search; - case SDL_SCANCODE_AC_STOP: return Keyboard::Browser_Stop; - case SDL_SCANCODE_CAPSLOCK: return Keyboard::CapsLock; - case SDL_SCANCODE_CLEAR: return Keyboard::Clear; - case SDL_SCANCODE_KP_PERIOD: return Keyboard::Decimal; - case SDL_SCANCODE_DELETE: return Keyboard::Delete; - case SDL_SCANCODE_KP_DIVIDE: return Keyboard::Divide; - case SDL_SCANCODE_DOWN: return Keyboard::Down; - case SDL_SCANCODE_END: return Keyboard::End; - case SDL_SCANCODE_ESCAPE: return Keyboard::Escape; - case SDL_SCANCODE_F1: return Keyboard::F1; - case SDL_SCANCODE_F2: return Keyboard::F2; - case SDL_SCANCODE_F3: return Keyboard::F3; - case SDL_SCANCODE_F4: return Keyboard::F4; - case SDL_SCANCODE_F5: return Keyboard::F5; - case SDL_SCANCODE_F6: return Keyboard::F6; - case SDL_SCANCODE_F7: return Keyboard::F7; - case SDL_SCANCODE_F8: return Keyboard::F8; - case SDL_SCANCODE_F9: return Keyboard::F9; - case SDL_SCANCODE_F10: return Keyboard::F10; - case SDL_SCANCODE_F11: return Keyboard::F11; - case SDL_SCANCODE_F12: return Keyboard::F12; - case SDL_SCANCODE_F13: return Keyboard::F13; - case SDL_SCANCODE_F14: return Keyboard::F14; - case SDL_SCANCODE_F15: return Keyboard::F15; - case SDL_SCANCODE_HOME: return Keyboard::Home; - case SDL_SCANCODE_INSERT: return Keyboard::Insert; - case SDL_SCANCODE_LEFT: return Keyboard::Left; - case SDL_SCANCODE_LGUI: return Keyboard::LSystem; - case SDL_SCANCODE_AUDIONEXT: return Keyboard::Media_Next; - case SDL_SCANCODE_AUDIOPLAY: return Keyboard::Media_Play; - case SDL_SCANCODE_AUDIOPREV: return Keyboard::Media_Previous; - case SDL_SCANCODE_AUDIOSTOP: return Keyboard::Media_Stop; - case SDL_SCANCODE_KP_MULTIPLY: return Keyboard::Multiply; - case SDL_SCANCODE_PAGEDOWN: return Keyboard::PageDown; - case SDL_SCANCODE_KP_0: return Keyboard::Numpad0; - case SDL_SCANCODE_KP_1: return Keyboard::Numpad1; - case SDL_SCANCODE_KP_2: return Keyboard::Numpad2; - case SDL_SCANCODE_KP_3: return Keyboard::Numpad3; - case SDL_SCANCODE_KP_4: return Keyboard::Numpad4; - case SDL_SCANCODE_KP_5: return Keyboard::Numpad5; - case SDL_SCANCODE_KP_6: return Keyboard::Numpad6; - case SDL_SCANCODE_KP_7: return Keyboard::Numpad7; - case SDL_SCANCODE_KP_8: return Keyboard::Numpad8; - case SDL_SCANCODE_KP_9: return Keyboard::Numpad9; - case SDL_SCANCODE_NUMLOCKCLEAR: return Keyboard::NumLock; - case SDL_SCANCODE_SEMICOLON: return Keyboard::Semicolon; - case SDL_SCANCODE_SLASH: return Keyboard::Slash; - case SDL_SCANCODE_GRAVE: return Keyboard::Tilde; - case SDL_SCANCODE_APPLICATION: return Keyboard::Menu; - case SDL_SCANCODE_NONUSBACKSLASH: return Keyboard::ISOBackslash102; - case SDL_SCANCODE_LEFTBRACKET: return Keyboard::LBracket; - case SDL_SCANCODE_BACKSLASH: return Keyboard::Backslash; - case SDL_SCANCODE_RIGHTBRACKET: return Keyboard::RBracket; - case SDL_SCANCODE_APOSTROPHE: return Keyboard::Quote; - case SDL_SCANCODE_COMMA: return Keyboard::Comma; - case SDL_SCANCODE_MINUS: return Keyboard::Dash; - case SDL_SCANCODE_PERIOD: return Keyboard::Period; - case SDL_SCANCODE_EQUALS: return Keyboard::Equal; - case SDL_SCANCODE_RIGHT: return Keyboard::Right; - case SDL_SCANCODE_PAGEUP: return Keyboard::PageUp; - case SDL_SCANCODE_PAUSE: return Keyboard::Pause; - case SDL_SCANCODE_SYSREQ: return Keyboard::Print; - case SDL_SCANCODE_SCROLLLOCK: return Keyboard::ScrollLock; - case SDL_SCANCODE_PRINTSCREEN: return Keyboard::PrintScreen; - case SDL_SCANCODE_KP_MINUS: return Keyboard::Subtract; - case SDL_SCANCODE_RETURN: return Keyboard::Return; - case SDL_SCANCODE_KP_ENTER: return Keyboard::NumpadReturn; - case SDL_SCANCODE_RGUI: return Keyboard::RSystem; - case SDL_SCANCODE_SPACE: return Keyboard::Space; - case SDL_SCANCODE_TAB: return Keyboard::Tab; - case SDL_SCANCODE_UP: return Keyboard::Up; - case SDL_SCANCODE_VOLUMEDOWN: return Keyboard::Volume_Down; - case SDL_SCANCODE_MUTE: return Keyboard::Volume_Mute; - case SDL_SCANCODE_AUDIOMUTE: return Keyboard::Volume_Mute; - case SDL_SCANCODE_VOLUMEUP: return Keyboard::Volume_Up; - - default: - return Keyboard::Undefined; - } - } - // not implemented for now, wait for mainloop friendly input //void WindowImpl::WindowThread(SDL_Window* handle, /*DWORD styleEx,*/ const String& title, /*DWORD style,*/ bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition) //{ diff --git a/src/Nazara/Platform/SDL2/WindowImpl.hpp b/src/Nazara/Platform/SDL2/WindowImpl.hpp index b983d2881..7cccb5b1c 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.hpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.hpp @@ -85,7 +85,6 @@ namespace Nz void PrepareWindow(bool fullscreen); - static Keyboard::Key SDLKeySymToNazaraKey(SDL_Keysym& keysym); //static void WindowThread(SDL_Window* handle, /*DWORD styleEx,*/ const String& title, /*DWORD style,*/ bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition); SDL_Cursor* m_cursor; diff --git a/src/Nazara/Renderer/Context.cpp b/src/Nazara/Renderer/Context.cpp index 0efb6ec61..7b4c62c9a 100644 --- a/src/Nazara/Renderer/Context.cpp +++ b/src/Nazara/Renderer/Context.cpp @@ -14,7 +14,6 @@ #if defined(NAZARA_PLATFORM_SDL2) #include - #define CALLBACK #elif defined(NAZARA_PLATFORM_WINDOWS) #include #elif defined(NAZARA_PLATFORM_GLX) diff --git a/src/Nazara/Renderer/OpenGL.cpp b/src/Nazara/Renderer/OpenGL.cpp index aea268456..6228aebad 100644 --- a/src/Nazara/Renderer/OpenGL.cpp +++ b/src/Nazara/Renderer/OpenGL.cpp @@ -1045,8 +1045,7 @@ namespace Nz glInvalidateBufferData = reinterpret_cast(LoadEntry("glInvalidateBufferData", false)); glVertexAttribLPointer = reinterpret_cast(LoadEntry("glVertexAttribLPointer", false)); - #if defined(NAZARA_PLATFORM_SDL2) - #elif defined(NAZARA_PLATFORM_WINDOWS) + #if defined(NAZARA_PLATFORM_WINDOWS) wglGetExtensionsStringARB = reinterpret_cast(LoadEntry("wglGetExtensionsStringARB", false)); wglGetExtensionsStringEXT = reinterpret_cast(LoadEntry("wglGetExtensionsStringEXT", false)); wglSwapInterval = reinterpret_cast(LoadEntry("wglSwapIntervalEXT", false)); @@ -1064,7 +1063,7 @@ namespace Nz NazaraWarning("Failed to load extension system"); } - #ifdef NAZARA_PLATFORM_WINDOWS + #if defined(NAZARA_PLATFORM_WINDOWS) && !defined(NAZARA_PLATFORM_SDL2) { bool loaded; if (wglGetExtensionsStringARB) @@ -1247,7 +1246,11 @@ namespace Nz bool OpenGL::IsSupported(const String& string) { +#ifdef NAZARA_PLATFORM_SDL2 + return SDL_GL_ExtensionSupported(string.GetConstBuffer()); +#else return s_openGLextensionSet.find(string) != s_openGLextensionSet.end(); +#endif } void OpenGL::SetBuffer(BufferType type, GLuint id) @@ -2302,8 +2305,7 @@ namespace Nz PFNGLVERTEXATTRIBLPOINTERPROC glVertexAttribLPointer = nullptr; PFNGLVIEWPORTPROC glViewport = nullptr; -#if defined(NAZARA_PLATFORM_SDL2) -#elif defined(NAZARA_PLATFORM_WINDOWS) +#if defined(NAZARA_PLATFORM_WINDOWS) PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat = nullptr; PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr; PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = nullptr; diff --git a/src/Nazara/Renderer/SDL2/ContextImpl.cpp b/src/Nazara/Renderer/SDL2/ContextImpl.cpp index 35ebda856..0a125e58f 100644 --- a/src/Nazara/Renderer/SDL2/ContextImpl.cpp +++ b/src/Nazara/Renderer/SDL2/ContextImpl.cpp @@ -4,7 +4,6 @@ // Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila -#include #include #include #include @@ -13,6 +12,9 @@ #include #include #include +#include +#include + namespace Nz { ContextImpl::ContextImpl() diff --git a/tests/Engine/Platform/EventHandler/EventState.cpp b/tests/Engine/Platform/EventHandler/EventState.cpp index 1d6a6784a..c4ba22c3b 100644 --- a/tests/Engine/Platform/EventHandler/EventState.cpp +++ b/tests/Engine/Platform/EventHandler/EventState.cpp @@ -19,7 +19,7 @@ void EventState::Enter(Ndk::StateMachine& fsm) Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) { - if (key.code == Nz::Keyboard::Key::M && key.shift) + if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) { fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); } @@ -90,4 +90,4 @@ Nz::String EventState::ToString(const Nz::WindowEvent& event) const default: return "Not handled"; } -} \ No newline at end of file +} diff --git a/tests/Engine/Platform/EventHandler/FocusState.cpp b/tests/Engine/Platform/EventHandler/FocusState.cpp index ee5fd5f7e..65a845654 100644 --- a/tests/Engine/Platform/EventHandler/FocusState.cpp +++ b/tests/Engine/Platform/EventHandler/FocusState.cpp @@ -18,7 +18,7 @@ void FocusState::Enter(Ndk::StateMachine& fsm) Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) { - if (key.code == Nz::Keyboard::Key::M && key.shift) + if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) { fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); } @@ -38,4 +38,4 @@ void FocusState::Enter(Ndk::StateMachine& fsm) void FocusState::DrawMenu() { m_text.SetContent("Click outside the windows, this text should change !\nM for Menu"); -} \ No newline at end of file +} diff --git a/tests/Engine/Platform/EventHandler/KeyState.cpp b/tests/Engine/Platform/EventHandler/KeyState.cpp index 40bd785f1..705769b7f 100644 --- a/tests/Engine/Platform/EventHandler/KeyState.cpp +++ b/tests/Engine/Platform/EventHandler/KeyState.cpp @@ -35,16 +35,16 @@ void KeyState::DrawMenu() void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm) { - if (key.code == Nz::Keyboard::Key::M && key.shift) + if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); - else if (key.code == Nz::Keyboard::Key::N && key.shift) + else if (key.virtualKey == Nz::Keyboard::VKey::N && key.shift) { if (m_keyStatus == KeyStatus::Pressed) m_keyStatus = KeyStatus::Released; else m_keyStatus = KeyStatus::Pressed; } - else + else { Nz::String content; if (m_keyStatus == KeyStatus::Pressed) @@ -52,7 +52,7 @@ void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::Ke else content = "Released: "; - Nz::String keyName = Nz::Keyboard::GetKeyName(key.code); + Nz::String keyName = Nz::Keyboard::GetKeyName(key.virtualKey) + " (" + Nz::Keyboard::GetKeyName(key.scancode) + ")"; if (keyName.IsEmpty()) { m_text.SetContent("Unknown\nM for Menu"); @@ -74,4 +74,4 @@ void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::Ke m_text.SetContent(content + "\nM for Menu"); } } -} \ No newline at end of file +} diff --git a/tests/Engine/Platform/EventHandler/MenuState.cpp b/tests/Engine/Platform/EventHandler/MenuState.cpp index d1a244369..be0c77cd8 100644 --- a/tests/Engine/Platform/EventHandler/MenuState.cpp +++ b/tests/Engine/Platform/EventHandler/MenuState.cpp @@ -19,9 +19,9 @@ void MenuState::Enter(Ndk::StateMachine& fsm) Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [this] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) { - if (key.code >= Nz::Keyboard::Key::A && key.code < (Nz::Keyboard::Key::A + static_cast(EventStatus::Max) - 1)) + if (key.virtualKey >= Nz::Keyboard::VKey::A && key.virtualKey < static_cast(static_cast(Nz::Keyboard::VKey::A) + static_cast(EventStatus::Max) - 1)) { - m_selectedNextState = key.code - static_cast(Nz::Keyboard::Key::A); + m_selectedNextState = static_cast(key.virtualKey) - static_cast(Nz::Keyboard::VKey::A); } }); } @@ -44,4 +44,4 @@ bool MenuState::Update(Ndk::StateMachine& fsm, float /*elapsedTime*/) void MenuState::DrawMenu() { m_text.SetContent("a. Event\nb. Focus\nc. Key\nd. Mouse click\ne. Mouse enter\nf. Mouse move\ng. Text enter\nh. Window modification"); -} \ No newline at end of file +} diff --git a/tests/Engine/Platform/EventHandler/MouseClickState.cpp b/tests/Engine/Platform/EventHandler/MouseClickState.cpp index 74cb8ef79..b407d9c0e 100644 --- a/tests/Engine/Platform/EventHandler/MouseClickState.cpp +++ b/tests/Engine/Platform/EventHandler/MouseClickState.cpp @@ -18,7 +18,7 @@ void MouseClickState::Enter(Ndk::StateMachine& fsm) Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) { - if (key.code == Nz::Keyboard::Key::M && key.shift) + if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) { fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); } @@ -78,4 +78,4 @@ void MouseClickState::ManageInput(MouseStatus mouseStatus, const Nz::WindowEvent } m_text.SetContent(content + "\nM for Menu"); -} \ No newline at end of file +} diff --git a/tests/Engine/Platform/EventHandler/MouseEnterState.cpp b/tests/Engine/Platform/EventHandler/MouseEnterState.cpp index 1eb2ca9e2..a3225918f 100644 --- a/tests/Engine/Platform/EventHandler/MouseEnterState.cpp +++ b/tests/Engine/Platform/EventHandler/MouseEnterState.cpp @@ -18,7 +18,7 @@ void MouseEnterState::Enter(Ndk::StateMachine& fsm) Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) { - if (key.code == Nz::Keyboard::Key::M && key.shift) + if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) { fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); } @@ -38,4 +38,4 @@ void MouseEnterState::Enter(Ndk::StateMachine& fsm) void MouseEnterState::DrawMenu() { m_text.SetContent("Move your mouse outside the windows, this text should change !\nM for Menu"); -} \ No newline at end of file +} diff --git a/tests/Engine/Platform/EventHandler/MouseMoveState.cpp b/tests/Engine/Platform/EventHandler/MouseMoveState.cpp index f0fcb3659..15a9ac13b 100644 --- a/tests/Engine/Platform/EventHandler/MouseMoveState.cpp +++ b/tests/Engine/Platform/EventHandler/MouseMoveState.cpp @@ -18,7 +18,7 @@ void MouseMoveState::Enter(Ndk::StateMachine& fsm) Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) { - if (key.code == Nz::Keyboard::Key::M && key.shift) + if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) { fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); } @@ -38,4 +38,4 @@ void MouseMoveState::Enter(Ndk::StateMachine& fsm) void MouseMoveState::DrawMenu() { m_text.SetContent("Move your mouse or your wheel, this text should change !\nM for Menu"); -} \ No newline at end of file +} diff --git a/tests/Engine/Platform/EventHandler/TextEnterState.cpp b/tests/Engine/Platform/EventHandler/TextEnterState.cpp index 2aa58da69..c9e50ae35 100644 --- a/tests/Engine/Platform/EventHandler/TextEnterState.cpp +++ b/tests/Engine/Platform/EventHandler/TextEnterState.cpp @@ -18,7 +18,7 @@ void TextEnterState::Enter(Ndk::StateMachine& fsm) Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) { - if (key.code == Nz::Keyboard::Key::M && key.shift) + if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) { fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); } @@ -36,4 +36,4 @@ void TextEnterState::Enter(Ndk::StateMachine& fsm) void TextEnterState::DrawMenu() { m_text.SetContent("Enter some text, this text should change !\nM for Menu"); -} \ No newline at end of file +} diff --git a/tests/Engine/Platform/EventHandler/WindowModificationState.cpp b/tests/Engine/Platform/EventHandler/WindowModificationState.cpp index 027185fe6..f497dc62b 100644 --- a/tests/Engine/Platform/EventHandler/WindowModificationState.cpp +++ b/tests/Engine/Platform/EventHandler/WindowModificationState.cpp @@ -18,7 +18,7 @@ void WindowModificationState::Enter(Ndk::StateMachine& fsm) Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) { - if (key.code == Nz::Keyboard::Key::M && key.shift) + if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift) { fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); } @@ -38,4 +38,4 @@ void WindowModificationState::Enter(Ndk::StateMachine& fsm) void WindowModificationState::DrawMenu() { m_text.SetContent("Move the window or resize it, this text should change !\nM for Menu"); -} \ No newline at end of file +}