\r
#include "CIrrDeviceSDL.h"\r
#include "IEventReceiver.h"\r
-#include "irrList.h"\r
#include "os.h"\r
#include "CTimer.h"\r
#include "irrString.h"\r
}\r
#endif\r
\r
-bool CIrrDeviceSDL::isNoUnicodeKey(EKEY_CODE key) const\r
-{\r
- switch ( key )\r
- {\r
- // keys which should not be mapped to a Unicode char\r
- case KEY_UNKNOWN:\r
- case KEY_SHIFT:\r
- case KEY_CONTROL:\r
- case KEY_MENU:\r
- case KEY_PAUSE:\r
- case KEY_CAPITAL:\r
- case KEY_ESCAPE:\r
- case KEY_PRIOR:\r
- case KEY_NEXT:\r
- case KEY_END:\r
- case KEY_HOME:\r
- case KEY_LEFT:\r
- case KEY_UP:\r
- case KEY_RIGHT:\r
- case KEY_DOWN:\r
- case KEY_PRINT:\r
- case KEY_SNAPSHOT:\r
- case KEY_INSERT:\r
- case KEY_DELETE:\r
- case KEY_HELP:\r
- case KEY_LWIN:\r
- case KEY_RWIN:\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_LSHIFT:\r
- case KEY_RSHIFT:\r
- case KEY_LCONTROL:\r
- case KEY_RCONTROL:\r
- case KEY_LMENU:\r
- case KEY_RMENU:\r
- return true;\r
-\r
- default:\r
- return false;\r
- }\r
-}\r
-\r
//! constructor\r
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)\r
: CIrrDeviceStub(param),\r
\r
if ( ++SDLDeviceInstances == 1 )\r
{\r
- // Initialize SDL... Timer for sleep, video for the obvious, and\r
- // noparachute prevents SDL from catching fatal errors.\r
- if (SDL_Init( SDL_INIT_TIMER|SDL_INIT_VIDEO|\r
+ u32 flags = SDL_INIT_TIMER | SDL_INIT_EVENTS;\r
+ if (CreationParams.DriverType != video::EDT_NULL)\r
+ flags |= SDL_INIT_VIDEO;\r
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)\r
- SDL_INIT_JOYSTICK|\r
+ flags |= SDL_INIT_JOYSTICK;\r
#endif\r
- SDL_INIT_NOPARACHUTE ) < 0)\r
+ if (SDL_Init(flags) < 0)\r
{\r
os::Printer::log( "Unable to initialize SDL!", SDL_GetError());\r
Close = true;\r
{\r
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);\r
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);\r
- } \r
+ }\r
\r
SDL_CreateWindowAndRenderer(0, 0, SDL_Flags, &Window, &Renderer); // 0,0 will use the canvas size\r
\r
\r
switch ( SDL_event.type )\r
{\r
- case SDL_MOUSEMOTION:\r
+ case SDL_MOUSEMOTION: {\r
+ SDL_Keymod keymod = SDL_GetModState();\r
+\r
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;\r
MouseX = irrevent.MouseInput.X = SDL_event.motion.x;\r
MouseXRel = SDL_event.motion.xrel;\r
MouseYRel = SDL_event.motion.yrel;\r
irrevent.MouseInput.ButtonStates = MouseButtonStates;\r
+ irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+ irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
\r
postEventFromUser(irrevent);\r
break;\r
- case SDL_MOUSEWHEEL:\r
+ }\r
+ case SDL_MOUSEWHEEL: {\r
+ SDL_Keymod keymod = SDL_GetModState();\r
+\r
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;\r
irrevent.MouseInput.Wheel = static_cast<float>(SDL_event.wheel.y);\r
+ irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+ irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
+ irrevent.MouseInput.X = MouseX;\r
+ irrevent.MouseInput.Y = MouseY;\r
+\r
postEventFromUser(irrevent);\r
break;\r
+ }\r
case SDL_MOUSEBUTTONDOWN:\r
- case SDL_MOUSEBUTTONUP:\r
+ case SDL_MOUSEBUTTONUP: {\r
+ SDL_Keymod keymod = SDL_GetModState();\r
+\r
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
irrevent.MouseInput.X = SDL_event.button.x;\r
irrevent.MouseInput.Y = SDL_event.button.y;\r
+ irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+ irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
\r
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;\r
\r
}\r
}\r
break;\r
+ }\r
+\r
+ case SDL_TEXTINPUT:\r
+ {\r
+ irrevent.EventType = irr::EET_STRING_INPUT_EVENT;\r
+ irrevent.StringInput.Str = new core::stringw();\r
+ irr::core::multibyteToWString(*irrevent.StringInput.Str, SDL_event.text.text);\r
+ postEventFromUser(irrevent);\r
+ delete irrevent.StringInput.Str;\r
+ irrevent.StringInput.Str = NULL;\r
+ }\r
+ break;\r
\r
case SDL_KEYDOWN:\r
case SDL_KEYUP:\r
}\r
#endif\r
irrevent.EventType = irr::EET_KEY_INPUT_EVENT;\r
-\r
- if (isNoUnicodeKey(key))\r
- irrevent.KeyInput.Char = 0;\r
- else\r
- irrevent.KeyInput.Char = SDL_event.key.keysym.sym;\r
-\r
irrevent.KeyInput.Key = key;\r
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
-\r
- // SDL2 no longer provides unicode character in the key event so we ensure the character is in the correct case\r
- // TODO: Unicode input doesn't work like this, should probably use SDL_TextInputEvent\r
- bool convertCharToUppercase =\r
- irrevent.KeyInput.Shift != !!(SDL_event.key.keysym.mod & KMOD_CAPS);\r
-\r
- if (convertCharToUppercase)\r
- irrevent.KeyInput.Char = irr::core::locale_upper(irrevent.KeyInput.Char);\r
-\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
postEventFromUser(irrevent);\r
}\r
break;\r
os::Printer::log("Resizable not available on the web." , ELL_WARNING);\r
return;\r
#else // !_IRR_EMSCRIPTEN_PLATFORM_\r
- if (resize != Resizable) { \r
+ if (resize != Resizable) {\r
if (resize)\r
SDL_Flags |= SDL_WINDOW_RESIZABLE;\r
else\r
}\r
\r
\r
-//! Set the current Gamma Value for the Display\r
-bool CIrrDeviceSDL::setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast )\r
-{\r
- /*\r
- // todo: Gamma in SDL takes ints, what does Irrlicht use?\r
- return (SDL_SetGamma(red, green, blue) != -1);\r
- */\r
- return false;\r
-}\r
-\r
-//! Get the current Gamma Value for the Display\r
-bool CIrrDeviceSDL::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast )\r
-{\r
-/* brightness = 0.f;\r
- contrast = 0.f;\r
- return (SDL_GetGamma(&red, &green, &blue) != -1);*/\r
- return false;\r
-}\r
-\r
//! returns color format of the window.\r
video::ECOLOR_FORMAT CIrrDeviceSDL::getColorFormat() const\r
{\r