]> git.lizzy.rs Git - irrlicht.git/blobdiff - source/Irrlicht/CIrrDeviceSDL.cpp
Add debug handler
[irrlicht.git] / source / Irrlicht / CIrrDeviceSDL.cpp
index 83c763c61d91a3260b85e98110ca0a0034103c81..a5ba6f690904d3210f446a59ab45c4ecee4e4099 100644 (file)
@@ -2,12 +2,13 @@
 // This file is part of the "Irrlicht Engine".\r
 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
 \r
-#include "IrrCompileConfig.h"\r
 \r
 #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_\r
 \r
 #include "CIrrDeviceSDL.h"\r
 #include "IEventReceiver.h"\r
+#include "IGUIElement.h"\r
+#include "IGUIEnvironment.h"\r
 #include "os.h"\r
 #include "CTimer.h"\r
 #include "irrString.h"\r
@@ -46,6 +47,10 @@ namespace irr
                #ifdef _IRR_COMPILE_WITH_WEBGL1_\r
                IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
                #endif\r
+\r
+               #ifdef ENABLE_OPENGL3\r
+               IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #endif\r
        } // end namespace video\r
 \r
 } // end namespace irr\r
@@ -105,6 +110,98 @@ EM_BOOL CIrrDeviceSDL::MouseLeaveCallback(int eventType, const EmscriptenMouseEv
 }\r
 #endif\r
 \r
+\r
+bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE key)\r
+{\r
+       switch ( key )\r
+       {\r
+               // keys which are known to have safe special character interpretation\r
+               // could need changes over time (removals and additions!)\r
+               case KEY_RETURN:\r
+               case KEY_PAUSE:\r
+               case KEY_ESCAPE:\r
+               case KEY_PRIOR:\r
+               case KEY_NEXT:\r
+               case KEY_HOME:\r
+               case KEY_END:\r
+               case KEY_LEFT:\r
+               case KEY_UP:\r
+               case KEY_RIGHT:\r
+               case KEY_DOWN:\r
+               case KEY_TAB:\r
+               case KEY_PRINT:\r
+               case KEY_SNAPSHOT:\r
+               case KEY_INSERT:\r
+               case KEY_BACK:\r
+               case KEY_DELETE:\r
+               case KEY_HELP:\r
+               case KEY_APPS:\r
+               case KEY_SLEEP:\r
+               case KEY_F1:\r
+               case KEY_F2:\r
+               case KEY_F3:\r
+               case KEY_F4:\r
+               case KEY_F5:\r
+               case KEY_F6:\r
+               case KEY_F7:\r
+               case KEY_F8:\r
+               case KEY_F9:\r
+               case KEY_F10:\r
+               case KEY_F11:\r
+               case KEY_F12:\r
+               case KEY_F13:\r
+               case KEY_F14:\r
+               case KEY_F15:\r
+               case KEY_F16:\r
+               case KEY_F17:\r
+               case KEY_F18:\r
+               case KEY_F19:\r
+               case KEY_F20:\r
+               case KEY_F21:\r
+               case KEY_F22:\r
+               case KEY_F23:\r
+               case KEY_F24:\r
+               case KEY_NUMLOCK:\r
+               case KEY_SCROLL:\r
+               case KEY_LCONTROL:\r
+               case KEY_RCONTROL:\r
+                       return true;\r
+\r
+               default:\r
+                       return false;\r
+       }\r
+}\r
+\r
+int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key) {\r
+       // SDL in-place ORs values with no character representation with 1<<30\r
+       // https://wiki.libsdl.org/SDL2/SDLKeycodeLookup\r
+       if (assumedChar & (1<<30))\r
+               return 0;\r
+\r
+       switch (key) {\r
+               case KEY_PRIOR:\r
+               case KEY_NEXT:\r
+               case KEY_HOME:\r
+               case KEY_END:\r
+               case KEY_LEFT:\r
+               case KEY_UP:\r
+               case KEY_RIGHT:\r
+               case KEY_DOWN:\r
+               case KEY_NUMLOCK:\r
+                       return 0;\r
+               default:\r
+                       return assumedChar;\r
+       }\r
+}\r
+\r
+void CIrrDeviceSDL::resetReceiveTextInputEvents() {\r
+       gui::IGUIElement *elem = GUIEnvironment->getFocus();\r
+       if (elem && elem->acceptsIME())\r
+               SDL_StartTextInput();\r
+       else\r
+               SDL_StopTextInput();\r
+}\r
+\r
 //! constructor\r
 CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)\r
        : CIrrDeviceStub(param),\r
@@ -293,6 +390,10 @@ bool CIrrDeviceSDL::createWindow()
                return false;\r
 \r
        if (CreationParams.DriverType == video::EDT_OPENGL) {\r
+               SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);\r
+               SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);\r
+               SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);\r
+               SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG);\r
                if (CreationParams.Bits == 16) {\r
                        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4);\r
                        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4);\r
@@ -364,23 +465,10 @@ void CIrrDeviceSDL::createDriver()
 {\r
        switch(CreationParams.DriverType)\r
        {\r
-       case video::DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS:\r
-               os::Printer::log("DIRECT3D8 Driver is no longer supported in Irrlicht. Try another one.", ELL_ERROR);\r
-               break;\r
-\r
-       case video::EDT_DIRECT3D9:\r
-               #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_\r
-               os::Printer::log("SDL device does not support DIRECT3D9 driver. Try another one.", ELL_ERROR);\r
-               #else\r
-               os::Printer::log("DIRECT3D9 Driver was not compiled into this dll. Try another one.", ELL_ERROR);\r
-               #endif // _IRR_COMPILE_WITH_DIRECT3D_9_\r
-\r
-               break;\r
-\r
        case video::EDT_OPENGL:\r
                #ifdef _IRR_COMPILE_WITH_OPENGL_\r
                ContextManager = new video::CSDLManager(this);\r
-               VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager);\r
+               VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager);\r
                #else\r
                os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);\r
                #endif\r
@@ -611,6 +699,10 @@ bool CIrrDeviceSDL::run()
                                else\r
                                        key = (EKEY_CODE)KeyMap[idx].Win32Key;\r
 \r
+                               // Make sure to only input special characters if something is in focus, as SDL_TEXTINPUT handles normal unicode already\r
+                               if (SDL_IsTextInputActive() && !keyIsKnownSpecial(key) && (SDL_event.key.keysym.mod & KMOD_CTRL) == 0)\r
+                                       break;\r
+\r
 #ifdef _IRR_WINDOWS_API_\r
                                // handle alt+f4 in Windows, because SDL seems not to\r
                                if ( (SDL_event.key.keysym.mod & KMOD_LALT) && key == KEY_F4)\r
@@ -624,12 +716,7 @@ bool CIrrDeviceSDL::run()
                                irrevent.KeyInput.PressedDown = (SDL_event.type == SDL_KEYDOWN);\r
                                irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;\r
                                irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL ) != 0;\r
-                               // These keys are handled differently in CGUIEditBox.cpp (may become out of date!)\r
-                               // Control key is used in special character combinations, so keep that too\r
-                               // Pass through the keysym only then so no extra text gets input\r
-                               irrevent.KeyInput.Char = 0;\r
-                               if (mp.SDLKey == SDLK_DELETE || mp.SDLKey == SDLK_RETURN || mp.SDLKey == SDLK_BACKSPACE || irrevent.KeyInput.Control)\r
-                                       irrevent.KeyInput.Char = mp.SDLKey;\r
+                               irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key);\r
                                postEventFromUser(irrevent);\r
                        }\r
                        break;\r
@@ -663,7 +750,7 @@ bool CIrrDeviceSDL::run()
                default:\r
                        break;\r
                } // end switch\r
-\r
+       resetReceiveTextInputEvents();\r
        } // end while\r
 \r
 #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)\r