/** * @brief Check call to SDL_GetModState and SDL_SetModState * * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState */ int keyboard_getSetModState(void *arg) { SDL_Keymod result; SDL_Keymod currentState; SDL_Keymod newState; SDL_Keymod allStates = KMOD_NONE | KMOD_LSHIFT | KMOD_RSHIFT | KMOD_LCTRL | KMOD_RCTRL | KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI | KMOD_NUM | KMOD_CAPS | KMOD_MODE | KMOD_RESERVED; /* Get state, cache for later reset */ result = SDL_GetModState(); SDLTest_AssertPass("Call to SDL_GetModState()"); SDLTest_AssertCheck(result >=0 && result <= allStates, "Verify result from call is valid, expected: 0 <= result <= %i, got: %i", allStates, result); currentState = result; /* Set random state */ newState = SDLTest_RandomIntegerInRange(0, allStates); SDL_SetModState(newState); SDLTest_AssertPass("Call to SDL_SetModState(%i)", newState); result = SDL_GetModState(); SDLTest_AssertPass("Call to SDL_GetModState()"); SDLTest_AssertCheck(result == newState, "Verify result from call is valid, expected: %i, got: %i", newState, result); /* Set zero state */ SDL_SetModState(0); SDLTest_AssertPass("Call to SDL_SetModState(0)"); result = SDL_GetModState(); SDLTest_AssertPass("Call to SDL_GetModState()"); SDLTest_AssertCheck(result == 0, "Verify result from call is valid, expected: 0, got: %i", result); /* Revert back to cached current state if needed */ if (currentState != 0) { SDL_SetModState(currentState); SDLTest_AssertPass("Call to SDL_SetModState(%i)", currentState); result = SDL_GetModState(); SDLTest_AssertPass("Call to SDL_GetModState()"); SDLTest_AssertCheck(result == currentState, "Verify result from call is valid, expected: %i, got: %i", currentState, result); } return TEST_COMPLETED; }
static int filter(const SDL_Event *event) { if(event->type == SDL_KEYDOWN) { if(event->key.keysym.sym == SDLK_SCROLLOCK) SDL_SetModState(SDL_GetModState() ^ KMOD_SCROLL); else if(event->key.keysym.sym == SDLK_INSERT) SDL_SetModState(SDL_GetModState() ^ KMOD_INSERT); } if((event->type == SDL_KEYDOWN || event->type == SDL_KEYUP) && event->key.keysym.sym >= SDLK_NUMLOCK) return(0); return(1); }
void enter_screen(void) { if (world_view->overhead_map_active) set_overhead_map_status(false); if (world_view->terminal_mode_active) set_terminal_status(false); // Adding this view-effect resetting here since initialize_world_view() no longer resets it world_view->effect = NONE; // Set screen to selected size in_game = true; change_screen_mode(&screen_mode, true); PrevFullscreen = screen_mode.fullscreen; #if defined(HAVE_OPENGL) && !defined(MUST_RELOAD_VIEW_CONTEXT) // if MUST_RELOAD_VIEW_CONTEXT, we know this just happened in // change_screen_mode if (screen_mode.acceleration == _opengl_acceleration) OGL_StartRun(); #endif #ifdef HAVE_OPENGL if (OGL_IsActive()) OGL_HUDActive = true; else OGL_HUDActive = false; #endif // Reset modifier key status SDL_SetModState(KMOD_NONE); }
// // I_Shutdown // // Added as an atexit handler. // void I_Shutdown() { SDL_SetModState(oldmod); // haleyjd 04/15/02: shutdown joystick I_ShutdownGamePads(); }
LOCAL_C TInt ModifiersChangedEvent(const TWsEvent& aWsEvent) { TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged(); TUint modstate = KMOD_NONE; if (modEvent->iModifiers & EModifierLeftShift) modstate |= KMOD_LSHIFT; if (modEvent->iModifiers & EModifierRightShift) modstate |= KMOD_RSHIFT; if (modEvent->iModifiers & EModifierLeftCtrl) modstate |= KMOD_LCTRL; if (modEvent->iModifiers & EModifierRightCtrl) modstate |= KMOD_RCTRL; if (modEvent->iModifiers & EModifierLeftAlt) modstate |= KMOD_LALT; if (modEvent->iModifiers & EModifierRightAlt) modstate |= KMOD_RALT; if (modEvent->iModifiers & EModifierLeftFunc) modstate |= KMOD_LMETA; if (modEvent->iModifiers & EModifierRightFunc) modstate |= KMOD_RMETA; if (modEvent->iModifiers & EModifierCapsLock) modstate |= KMOD_CAPS; SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT))); return 0; }
static mrb_value mrb_sdl2_keyboard_set_mod_state(mrb_state *mrb, mrb_value mod) { mrb_int kmod; mrb_get_args(mrb, "i", &kmod); SDL_SetModState((SDL_Keymod)kmod); return mod; }
void es_setModState(sdl_data *sd, int len,char *buff) { char *bp; Uint16 state; bp = buff; state = get16be(bp); SDL_SetModState(state); }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize () { if (!ParseCmdLine ()) return false; #ifdef WIN32 // Initialize crash reporting Install( (LPGETLOGFILE) crashCallback, "*****@*****.**", "TA Spring Crashreport"); #endif // Initialize class system creg::ClassBinder::InitializeClasses (); #ifndef NO_LUA // Initialize lua bindings CLuaBinder lua; if (!lua.LoadScript("testscript.lua")) handleerror(NULL, lua.lastError.c_str(), "lua",MBF_OK|MBF_EXCL); #endif InitVFS (); if (!InitWindow ("RtsSpring")) { SDL_Quit (); return false; } // Global structures ENTER_SYNCED; gs=new CGlobalSyncedStuff(); ENTER_UNSYNCED; gu=new CGlobalUnsyncedStuff(); InitOpenGL(); palette.Init(); // Initialize keyboard SDL_EnableUNICODE(1); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_SetModState (KMOD_NONE); keys = new Uint8[SDLK_LAST]; memset (keys,0,sizeof(Uint8)*SDLK_LAST); // Initialize font font = new CglFont(32,223); LoadExtensions(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapBuffers(); CreateGameSetup (); return true; }
static PyObject* key_set_mods (PyObject* self, PyObject* args) { int mods; if (!PyArg_ParseTuple (args, "i", &mods)) return NULL; VIDEO_INIT_CHECK (); SDL_SetModState (mods); Py_RETURN_NONE; }
void toggle_full_screen() { #ifdef WINDOWS full_screen=!full_screen; set_var_unsaved("full_screen", INI_FILE_VAR); LOG_TO_CONSOLE(c_green2, video_restart_str); #else reload_tab_map = 1; full_screen=!full_screen; switch_video(video_mode, full_screen); build_video_mode_array(); if (!disable_gamma_adjust) SDL_SetGamma(gamma_var, gamma_var, gamma_var); SDL_SetModState(KMOD_NONE); // force ALL keys up #endif }
int BlackBerry_OnKey(SDL_Keysym keysym, Uint8 state) { int scancode; SDL_SetModState(keysym.mod); if (keysym.scancode == SDL_SCANCODE_UNKNOWN) { for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) { if (SDL_BlackBerry_keymap[scancode] == keysym.sym) { keysym.scancode = scancode; } } } return SDL_SendKeyboardKey(state, keysym.scancode); }
void PumpEvents() { #if 0 WPAD_ScanPads(); /* if (!keyboard_initialized) { wii_keyboard_init(); keyboard_initialized = 1; } */ WPADData *wd = WPAD_Data(0); #endif stat = KEYBOARD_getEvent(&ke); #if 0 mstat = MOUSE_getEvent(&me); int x, y; SDL_GetMouseState(&x, &y); if(wd->ir.valid) { //int x = (wd->ir.dot[0].rx*640)/1024; //int y = (wd->ir.dot[0].ry*480)/768; x = wd->ir.x; y = wd->ir.y; if(lastX!= x || lastY != y) { posted += SDL_PrivateMouseMotion(0, 0, x, y); lastX = x; lastY = y; } } Uint8 stateA = SDL_RELEASED; Uint8 stateB = SDL_RELEASED; if(wd->btns_h & WPAD_BUTTON_A) { stateA = SDL_PRESSED; } if(wd->btns_h & WPAD_BUTTON_B) { stateB = SDL_PRESSED; } if(stateA != lastButtonStateA) { lastButtonStateA = stateA; posted += SDL_PrivateMouseButton(stateA, SDL_BUTTON_LEFT, x, y); } if(stateB != lastButtonStateB) { lastButtonStateB = stateB; posted += SDL_PrivateMouseButton(stateB, SDL_BUTTON_RIGHT, x, y); } Uint8 stateHome = SDL_RELEASED; if(wd->btns_h & WPAD_BUTTON_HOME) { stateHome = SDL_PRESSED; } if(stateHome != lastButtonStateHome) { lastButtonStateHome = stateHome; /* SDL_keysym keysym; SDL_memset(&keysym, 0, (sizeof keysym)); keysym.sym = SDLK_ESCAPE; SDL_PrivateKeyboard(stateHome, &keysym);*/ if (stateHome == SDL_RELEASED) { /* SDL_Event event; event.type = SDL_QUIT; SDL_PushEvent(&event); */ } } #endif if (stat && (ke.type==KEYBOARD_RELEASED || ke.type==KEYBOARD_PRESSED) ) { SDL_keysym keysym; memset(&keysym, 0, sizeof(keysym)); Uint8 keystate = (ke.type==KEYBOARD_PRESSED)?SDL_PRESSED:SDL_RELEASED; keysym.sym = ke.scancode; SDL_SetModState(to_SDL_Modifiers(ke.modifiers)); posted += SDL_PrivateKeyboard(keystate, &keysym); } #if 0 if (mstat) { int x, y; posted +=SDL_PrivateMouseMotion(me.button, 1, me.rx, me.ry); u8 button = me.button; if ( button & 0x1 ) { if ( !(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1)) ) { posted +=SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0); } } else { if ( (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1)) ) { posted +=SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0); } } if ( button & 0x2 ) { if ( !(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)) ) { posted +=SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0); } } else { if ( (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)) ) { posted +=SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0); } } } #endif }
int EPOC_HandleWsEvent(_THIS, const TWsEvent& aWsEvent) { int posted = 0; SDL_keysym keysym; // SDL_TRACE1("hws %d", aWsEvent.Type()); switch (aWsEvent.Type()) { case EEventPointer: /* Mouse pointer events */ { const TPointerCursorMode mode = Private->EPOC_WsSession.PointerCursorMode(); if(mode == EPointerCursorNone) { return 0; //TODO: Find out why events are get despite of cursor should be off } const TPointerEvent* pointerEvent = aWsEvent.Pointer(); TPoint mousePos = pointerEvent->iPosition; /*!! TODO Pointer do not yet work properly //SDL_TRACE1("SDL: EPOC_HandleWsEvent, pointerEvent->iType=%d", pointerEvent->iType); //!! if (Private->EPOC_ShrinkedHeight) { mousePos.iY <<= 1; // Scale y coordinate to shrinked screen height } if (Private->EPOC_ShrinkedWidth) { mousePos.iX <<= 1; // Scale x coordinate to shrinked screen width } */ posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */ switch (pointerEvent->iType) { case TPointerEvent::EButton1Down: posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); break; case TPointerEvent::EButton1Up: posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); break; case TPointerEvent::EButton2Down: posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); break; case TPointerEvent::EButton2Up: posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); break; case TPointerEvent::EButton3Down: posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); break; case TPointerEvent::EButton3Up: posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); break; } // switch break; } case EEventKeyDown: /* Key events */ { #ifdef SYMBIAN_CRYSTAL // special case: 9300/9500 rocker down, simulate left mouse button if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA) { const TPointerCursorMode mode = Private->EPOC_WsSession.PointerCursorMode(); if(mode != EPointerCursorNone) posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); } #endif (void*)TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym); #ifndef DISABLE_JOYSTICK /* Special handling */ switch((int)keysym.sym) { case SDLK_CAPSLOCK: if (!isCursorVisible) { /* Enable virtual cursor */ HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible); } else { /* Disable virtual cursor */ HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible); } isCursorVisible = !isCursorVisible; break; } #endif posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym); break; } case EEventKeyUp: /* Key events */ { #ifdef SYMBIAN_CRYSTAL // special case: 9300/9500 rocker up, simulate left mouse button if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA) { posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); } #endif posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym)); break; } case EEventFocusGained: /* SDL window got focus */ { Private->EPOC_IsWindowFocused = ETrue; posted += SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); /* Draw window background and screen buffer */ DisableKeyBlocking(_this); //Markus: guess why:-) RedrawWindowL(_this); break; } case EEventFocusLost: /* SDL window lost focus */ { /* CFbsBitmap* bmp = new (ELeave) CFbsBitmap(); bmp->Create(Private->EPOC_ScreenSize, Private->EPOC_DisplayMode); Private->EPOC_WsScreen->CopyScreenToBitmap(bmp); Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow); Private->EPOC_WsWindow.BeginRedraw(TRect(Private->EPOC_WsWindow.Size())); Private->EPOC_WindowGc->BitBlt(TPoint(0, 0), bmp); Private->EPOC_WsWindow.EndRedraw(); Private->EPOC_WindowGc->Deactivate(); bmp->Save(_L("C:\\scr.mbm")); delete bmp; */ Private->EPOC_IsWindowFocused = EFalse; posted += SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); RWsSession s; s.Connect(); RWindowGroup g(s); g.Construct(TUint32(&g), EFalse); g.EnableReceiptOfFocus(EFalse); RWindow w(s); w.Construct(g, TUint32(&w)); w.SetExtent(TPoint(0, 0), Private->EPOC_WsWindow.Size()); w.SetOrdinalPosition(0); w.Activate(); w.Close(); g.Close(); s.Close(); /* Private->EPOC_WsSession.SetWindowGroupOrdinalPosition(Private->EPOC_WsWindowGroupID, -1); SDL_Delay(500); TInt focus = -1; while(focus < 0) { const TInt curr = Private->EPOC_WsSession.GetFocusWindowGroup(); if(curr != Private->EPOC_WsWindowGroupID) focus = curr; else SDL_Delay(500); } if(1 < Private->EPOC_WsSession.GetWindowGroupOrdinalPriority(Private->EPOC_WsWindowGroupID)) { Private->EPOC_WsSession.SetWindowGroupOrdinalPosition(focus, -1); SDL_Delay(500); Private->EPOC_WsSession.SetWindowGroupOrdinalPosition(focus, 0); } */ /*//and the request redraw TRawEvent redrawEvent; redrawEvent.Set(TRawEvent::ERedraw); Private->EPOC_WsSession.SimulateRawEvent(redrawEvent); Private->EPOC_WsSession.Flush();*/ #if 0 //!! Not used // Wait and eat events until focus is gained again while (ETrue) { Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); User::WaitForRequest(Private->EPOC_WsEventStatus); Private->EPOC_WsSession.GetEvent(Private->EPOC_WsEvent); TInt eventType = Private->EPOC_WsEvent.Type(); Private->EPOC_WsEventStatus = KRequestPending; //Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); if (eventType == EEventFocusGained) { RedrawWindowL(_this); break; } } #endif break; } case EEventModifiersChanged: { TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged(); TUint modstate = KMOD_NONE; if (modEvent->iModifiers == EModifierLeftShift) modstate |= KMOD_LSHIFT; if (modEvent->iModifiers == EModifierRightShift) modstate |= KMOD_RSHIFT; if (modEvent->iModifiers == EModifierLeftCtrl) modstate |= KMOD_LCTRL; if (modEvent->iModifiers == EModifierRightCtrl) modstate |= KMOD_RCTRL; if (modEvent->iModifiers == EModifierLeftAlt) modstate |= KMOD_LALT; if (modEvent->iModifiers == EModifierRightAlt) modstate |= KMOD_RALT; if (modEvent->iModifiers == EModifierLeftFunc) modstate |= KMOD_LMETA; if (modEvent->iModifiers == EModifierRightFunc) modstate |= KMOD_RMETA; if (modEvent->iModifiers == EModifierCapsLock) modstate |= KMOD_CAPS; SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT))); break; } default: break; } return posted; }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize () { logOutput.SetMirrorToStdout(!!configHandler.GetInt("StdoutDebug",0)); // Initialize class system creg::System::InitializeClasses (); // Initialize crash reporting #ifdef _WIN32 #if defined(_CRASHRPT_H_) Install( (LPGETLOGFILE) crashCallback, "*****@*****.**", "Spring Crashreport"); if (!GetInstance()) { ErrorMessageBox("Error installing crash reporter", "CrashReport error:", MBF_OK); return false; } #elif defined(CRASHHANDLER_H) CrashHandler::Install(); #endif InitializeSEH(); #endif ParseCmdLine(); FileSystemHandler::Initialize(true); if (!InitWindow ("RtsSpring")) { SDL_Quit (); return false; } mouseInput = IMouseInput::Get (); // Global structures ENTER_SYNCED; gs=SAFE_NEW CGlobalSyncedStuff(); ENTER_UNSYNCED; gu=SAFE_NEW CGlobalUnsyncedStuff(); if (cmdline->result("minimise")) { gu->active = false; SDL_WM_IconifyWindow(); } // Enable auto quit? int quit_time; if (cmdline->result("quit", quit_time)) { gu->autoQuit = true; gu->quitTime = quit_time; } InitOpenGL(); palette.Init(); // Initialize keyboard SDL_EnableUNICODE(1); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_SetModState (KMOD_NONE); keys = SAFE_NEW Uint8[SDLK_LAST]; memset (keys,0,sizeof(Uint8)*SDLK_LAST); // Initialize font const int charFirst = configHandler.GetInt("FontCharFirst", 32); const int charLast = configHandler.GetInt("FontCharLast", 255); std::string fontFile = configHandler.GetString("FontFile", "fonts/Luxi.ttf"); try { font = SAFE_NEW CglFont(charFirst, charLast, fontFile.c_str()); } catch(content_error&) { // If the standard location fails, retry in fonts directory or vice versa. if (fontFile.substr(0, 6) == "fonts/") fontFile = fontFile.substr(6); else fontFile = "fonts/" + fontFile; font = SAFE_NEW CglFont(charFirst, charLast, fontFile.c_str()); } // Initialize GLEW LoadExtensions(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapBuffers(); // Initialize named texture handler CNamedTextures::Init(); // Initialize Lua GL LuaOpenGL::Init(); // Initialize ScriptHandler / LUA CScriptHandler::Instance().StartLua(); // Create CGameSetup and CPreGame objects CreateGameSetup (); return true; }
int EPOC_HandleWsEvent(_THIS, const TWsEvent& aWsEvent) { int posted = 0; SDL_keysym keysym; switch (aWsEvent.Type()) { case EEventPointer: /* Mouse pointer events */ { const TPointerEvent* pointerEvent = aWsEvent.Pointer(); TPoint mousePos = pointerEvent->iPosition; //SDL_TRACE1("SDL: EPOC_HandleWsEvent, pointerEvent->iType=%d", pointerEvent->iType); //!! if (Private->EPOC_ShrinkedHeight) { mousePos.iY <<= 1; /* Scale y coordinate to shrinked screen height */ } posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */ if (pointerEvent->iType==TPointerEvent::EButton1Down) { posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); } else if (pointerEvent->iType==TPointerEvent::EButton1Up) { posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); } else if (pointerEvent->iType==TPointerEvent::EButton2Down) { posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); } else if (pointerEvent->iType==TPointerEvent::EButton2Up) { posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); } //!!posted += SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(aWsEvent.Key()->iScanCode, &keysym)); break; } case EEventKeyDown: /* Key events */ { (void*)TranslateKey(aWsEvent.Key()->iScanCode, &keysym); /* Special handling */ switch((int)keysym.sym) { case SDLK_CAPSLOCK: if (!isCursorVisible) { /* Enable virtual cursor */ HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible); } else { /* Disable virtual cursor */ HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible); } isCursorVisible = !isCursorVisible; break; } posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym); break; } case EEventKeyUp: /* Key events */ { posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(aWsEvent.Key()->iScanCode, &keysym)); break; } case EEventFocusGained: /* SDL window got focus */ { //Private->EPOC_IsWindowFocused = ETrue; /* Draw window background and screen buffer */ RedrawWindowL(_this); break; } case EEventFocusLost: /* SDL window lost focus */ { //Private->EPOC_IsWindowFocused = EFalse; // Wait and eat events until focus is gained again /* while (ETrue) { Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); User::WaitForRequest(Private->EPOC_WsEventStatus); Private->EPOC_WsSession.GetEvent(Private->EPOC_WsEvent); TInt eventType = Private->EPOC_WsEvent.Type(); Private->EPOC_WsEventStatus = KRequestPending; //Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); if (eventType == EEventFocusGained) { RedrawWindowL(_this); break; } } */ break; } case EEventModifiersChanged: { TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged(); TUint modstate = KMOD_NONE; if (modEvent->iModifiers == EModifierLeftShift) modstate |= KMOD_LSHIFT; if (modEvent->iModifiers == EModifierRightShift) modstate |= KMOD_RSHIFT; if (modEvent->iModifiers == EModifierLeftCtrl) modstate |= KMOD_LCTRL; if (modEvent->iModifiers == EModifierRightCtrl) modstate |= KMOD_RCTRL; if (modEvent->iModifiers == EModifierLeftAlt) modstate |= KMOD_LALT; if (modEvent->iModifiers == EModifierRightAlt) modstate |= KMOD_RALT; if (modEvent->iModifiers == EModifierLeftFunc) modstate |= KMOD_LMETA; if (modEvent->iModifiers == EModifierRightFunc) modstate |= KMOD_RMETA; if (modEvent->iModifiers == EModifierCapsLock) modstate |= KMOD_CAPS; SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT))); break; } default: break; } return posted; }
/** * @brief Initializes the SpringApp instance * @return whether initialization was successful */ bool SpringApp::Initialize () { logOutput.SetMirrorToStdout(!!configHandler.GetInt("StdoutDebug",0)); // Initialize class system creg::ClassBinder::InitializeClasses (); // Initialize crash reporting #ifdef _MSC_VER Install( (LPGETLOGFILE) crashCallback, "*****@*****.**", "TA Spring Crashreport"); if (!GetInstance()) { ErrorMessageBox("Error installing crash reporter", "CrashReport error:", MBF_OK); return false; } #endif // _MSC_VER #ifdef __MINGW32__ CrashHandler::Install(); #endif // __MINGW32__ FileSystemHandler::Initialize(true); if (!ParseCmdLine ()) return false; if (!InitWindow ("RtsSpring")) { SDL_Quit (); return false; } mouseInput = IMouseInput::Get (); // Global structures ENTER_SYNCED; gs=SAFE_NEW CGlobalSyncedStuff(); ENTER_UNSYNCED; gu=SAFE_NEW CGlobalUnsyncedStuff(); if (cmdline->result("minimise")) { gu->active = false; SDL_WM_IconifyWindow(); } // Enable auto quit? int quit_time; if (cmdline->result("quit", quit_time)) { gu->autoQuit = true; gu->quitTime = quit_time; } InitOpenGL(); palette.Init(); // Initialize keyboard SDL_EnableUNICODE(1); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_SetModState (KMOD_NONE); keys = SAFE_NEW Uint8[SDLK_LAST]; memset (keys,0,sizeof(Uint8)*SDLK_LAST); // Initialize font font = SAFE_NEW CglFont(configHandler.GetInt("FontCharFirst", 32), configHandler.GetInt("FontCharLast", 223), configHandler.GetString("FontFile", "Luxi.ttf").c_str()); // Initialize GLEW LoadExtensions(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapBuffers(); // Initialize ScriptHandler / LUA CScriptHandler::Instance().StartLua(); // Create CGameSetup and CPreGame objects CreateGameSetup (); return true; }
/* ================ Sys_GetEvent ================ */ sysEvent_t Sys_GetEvent() { SDL_Event ev; sysEvent_t res = { }; byte key; static const sysEvent_t res_none = { SE_NONE, 0, 0, 0, NULL }; // process any overflow. if (event_overflow.Num() > 0) { res = event_overflow[0]; event_overflow.RemoveIndex(0); return res; } // overflow text input. static char *s = NULL; static size_t s_pos = 0; if (s) { res.evType = SE_CHAR; res.evValue = s[s_pos]; s_pos++; if (!s[s_pos]) { free(s); s = NULL; s_pos = 0; } return res; } static byte c = 0; if (c) { res.evType = SE_CHAR; res.evValue = c; c = 0; return res; } bool getNext = true; while (SDL_PollEvent(&ev) && getNext) { getNext = false; switch (ev.type) { #ifdef __WINDOWS__ // on windows we need to grab the hwnd. case SDL_SYSWMEVENT: if (win32.hWnd == NULL) { win32.hWnd = ev.syswm.msg->msg.win.hwnd; } getNext = true; // try to get a decent event. break; #endif case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: { // unset modifier, in case alt-tab was used to leave window and ALT is still set // as that can cause fullscreen-toggling when pressing enter... SDL_Keymod currentmod = SDL_GetModState(); int newmod = KMOD_NONE; if (currentmod & KMOD_CAPS) // preserve capslock newmod |= KMOD_CAPS; SDL_SetModState((SDL_Keymod)newmod); } // new context because visual studio complains about newmod and currentmod not initialized because of the case SDL_WINDOWEVENT_FOCUS_LOST GLimp_GrabInput(GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR); break; case SDL_WINDOWEVENT_FOCUS_LOST: GLimp_GrabInput(0); break; } return res_none; case SDL_KEYDOWN: if (ev.key.keysym.sym == SDLK_RETURN && (ev.key.keysym.mod & KMOD_ALT) > 0) { cvarSystem->SetCVarBool("r_fullscreen", !renderSystem->IsFullScreen()); PushConsoleEvent("vid_restart"); return res_none; } // fall through case SDL_KEYUP: key = mapkey(ev.key.keysym.sym); if(!key) { if (ev.key.keysym.scancode == SDL_SCANCODE_GRAVE) { key = Sys_GetConsoleKey(true); } else { if (ev.type == SDL_KEYDOWN) { common->Warning("unmapped SDL key %d", ev.key.keysym.sym); getNext = true; // try to get a decent event. break; } } } res.evType = SE_KEY; res.evValue = key; res.evValue2 = ev.key.state == SDL_PRESSED ? 1 : 0; kbd_polls.Append(kbd_poll_t(key, ev.key.state == SDL_PRESSED)); if ( (key == K_BACKSPACE && ev.key.state == SDL_PRESSED) || SDL_GetEventState(SDL_TEXTINPUT) == SDL_DISABLE) c = key; return res; case SDL_TEXTINPUT: if (ev.text.text && *ev.text.text) { res.evType = SE_CHAR; res.evValue = *ev.text.text; // if there are more characters hold onto them for later events. if (ev.text.text[1] != 0) s = strdup(ev.text.text+1); return res; } getNext = true; // try to get a decent event. break; case SDL_MOUSEMOTION: if (g_inputGrabbed) { res.evType = SE_MOUSE; res.evValue = ev.motion.xrel; res.evValue2 = ev.motion.yrel; mouse_polls.Append(mouse_poll_t(M_DELTAX, ev.motion.xrel)); mouse_polls.Append(mouse_poll_t(M_DELTAY, ev.motion.yrel)); return res; } getNext = true; break; case SDL_MOUSEWHEEL: if (g_inputGrabbed) { res.evType = SE_KEY; if (ev.wheel.y > 0) { res.evValue = K_MWHEELUP; mouse_polls.Append(mouse_poll_t(M_DELTAZ, 1)); } else { res.evValue = K_MWHEELDOWN; mouse_polls.Append(mouse_poll_t(M_DELTAZ, -1)); } res.evValue2 = 1; return res; } getNext = true; break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (g_inputGrabbed) { res.evType = SE_KEY; switch (ev.button.button) { case SDL_BUTTON_LEFT: res.evValue = K_MOUSE1; mouse_polls.Append(mouse_poll_t(M_ACTION1, ev.button.state == SDL_PRESSED ? 1 : 0)); break; case SDL_BUTTON_MIDDLE: res.evValue = K_MOUSE3; mouse_polls.Append(mouse_poll_t(M_ACTION3, ev.button.state == SDL_PRESSED ? 1 : 0)); break; case SDL_BUTTON_RIGHT: res.evValue = K_MOUSE2; mouse_polls.Append(mouse_poll_t(M_ACTION2, ev.button.state == SDL_PRESSED ? 1 : 0)); break; } res.evValue2 = ev.button.state == SDL_PRESSED ? 1 : 0; return res; } getNext = true; break; case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: { sys_jEvents jEvent = mapjoybutton( (SDL_GameControllerButton)ev.cbutton.button); joystick_polls.Append(joystick_poll_t( jEvent, ev.cbutton.state == SDL_PRESSED ? 1 : 0) ); res.evType = SE_KEY; res.evValue2 = ev.cbutton.state == SDL_PRESSED ? 1 : 0; if ( ( jEvent >= J_ACTION1 ) && ( jEvent <= J_ACTION_MAX ) ) { res.evValue = K_JOY1 + ( jEvent - J_ACTION1 ); return res; } else if ( ( jEvent >= J_DPAD_UP ) && ( jEvent <= J_DPAD_RIGHT ) ) { res.evValue = K_JOY_DPAD_UP + ( jEvent - J_DPAD_UP ); return res; } getNext = true; // try to get a decent event. } break; case SDL_CONTROLLERAXISMOTION: { const int range = 16384; sys_jEvents jEvent = mapjoyaxis( (SDL_GameControllerAxis)ev.caxis.axis); joystick_polls.Append(joystick_poll_t( jEvent, ev.caxis.value) ); if ( jEvent == J_AXIS_LEFT_X ) { PushButton( K_JOY_STICK1_LEFT, ( ev.caxis.value < -range ) ); PushButton( K_JOY_STICK1_RIGHT, ( ev.caxis.value > range ) ); } else if ( jEvent == J_AXIS_LEFT_Y ) { PushButton( K_JOY_STICK1_UP, ( ev.caxis.value < -range ) ); PushButton( K_JOY_STICK1_DOWN, ( ev.caxis.value > range ) ); } else if ( jEvent == J_AXIS_RIGHT_X ) { PushButton( K_JOY_STICK2_LEFT, ( ev.caxis.value < -range ) ); PushButton( K_JOY_STICK2_RIGHT, ( ev.caxis.value > range ) ); } else if ( jEvent == J_AXIS_RIGHT_Y ) { PushButton( K_JOY_STICK2_UP, ( ev.caxis.value < -range ) ); PushButton( K_JOY_STICK2_DOWN, ( ev.caxis.value > range ) ); } else if ( jEvent == J_AXIS_LEFT_TRIG ) { PushButton( K_JOY_TRIGGER1, ( ev.caxis.value > range ) ); } else if ( jEvent == J_AXIS_RIGHT_TRIG ) { PushButton( K_JOY_TRIGGER2, ( ev.caxis.value > range ) ); } if ( jEvent >= J_AXIS_MIN && jEvent <= J_AXIS_MAX ) { int axis = jEvent - J_AXIS_MIN; int percent = ( ev.caxis.value * 16 ) / range; if ( joyAxis[axis] != percent ) { joyAxis[axis] = percent; res.evType = SE_JOYSTICK; res.evValue = axis; res.evValue2 = percent; return res; } } getNext = true; // try to get a decent event. } break; case SDL_JOYDEVICEADDED: SDL_GameControllerOpen( ev.jdevice.which ); // TODO: hot swapping maybe. //lbOnControllerPlugIn(event.jdevice.which); break; case SDL_JOYDEVICEREMOVED: // TODO: hot swapping maybe. //lbOnControllerUnPlug(event.jdevice.which); break; case SDL_QUIT: PushConsoleEvent("quit"); return res_none; case SDL_USEREVENT: switch (ev.user.code) { case SE_CONSOLE: res.evType = SE_CONSOLE; res.evPtrLength = (intptr_t)ev.user.data1; res.evPtr = ev.user.data2; return res; default: common->Warning("unknown user event %u", ev.user.code); getNext = true; // try to get a decent event. break; } default: getNext = true; // try to get a decent event. break; } } return res_none; }
/* ================= main ================= */ int main( int argc, char **argv ) { int i; char commandLine[ MAX_STRING_CHARS ] = { 0 }; extern void Sys_LaunchAutoupdater(int argc, char **argv); Sys_LaunchAutoupdater(argc, argv); #ifndef DEDICATED // SDL version check // Compile time # if !SDL_VERSION_ATLEAST(MINSDL_MAJOR,MINSDL_MINOR,MINSDL_PATCH) # error A more recent version of SDL is required # endif // Run time SDL_version ver; SDL_GetVersion( &ver ); #define MINSDL_VERSION \ XSTRING(MINSDL_MAJOR) "." \ XSTRING(MINSDL_MINOR) "." \ XSTRING(MINSDL_PATCH) if( SDL_VERSIONNUM( ver.major, ver.minor, ver.patch ) < SDL_VERSIONNUM( MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH ) ) { Sys_Dialog( DT_ERROR, va( "SDL version " MINSDL_VERSION " or greater is required, " "but only version %d.%d.%d was found. You may be able to obtain a more recent copy " "from http://www.libsdl.org/.", ver.major, ver.minor, ver.patch ), "SDL Library Too Old" ); Sys_Exit( 1 ); } SDL_EventState( SDL_DROPFILE, SDL_ENABLE ); #endif Sys_PlatformInit( ); // Set the initial time base Sys_Milliseconds( ); #ifdef __APPLE__ // This is passed if we are launched by double-clicking if ( argc >= 2 && Q_strncmp ( argv[1], "-psn", 4 ) == 0 ) argc = 1; #endif Sys_ParseArgs( argc, argv ); Sys_SetBinaryPath( Sys_Dirname( argv[ 0 ] ) ); Sys_SetDefaultInstallPath( DEFAULT_BASEDIR ); // Concatenate the command line for passing to Com_Init for( i = 1; i < argc; i++ ) { const qboolean containsSpaces = strchr(argv[i], ' ') != NULL; if (containsSpaces) Q_strcat( commandLine, sizeof( commandLine ), "\"" ); Q_strcat( commandLine, sizeof( commandLine ), argv[ i ] ); if (containsSpaces) Q_strcat( commandLine, sizeof( commandLine ), "\"" ); Q_strcat( commandLine, sizeof( commandLine ), " " ); } CON_Init( ); Com_Init( commandLine ); NET_Init( ); signal( SIGILL, Sys_SigHandler ); signal( SIGFPE, Sys_SigHandler ); signal( SIGSEGV, Sys_SigHandler ); signal( SIGTERM, Sys_SigHandler ); signal( SIGINT, Sys_SigHandler ); #if !defined DEDICATED && !defined __APPLE__ && !defined WIN32 // HACK: Before SDL 2.0.4, Linux (X11) did not set numlock or capslock state // so I made the engine always assumed num lock was on. // NOTE: The SDL mod state on X11 is not set at this point even when it's fixed // and will be corrected regardless of what is done here, // but limit to SDL 2.0.3 and earlier so that the message isn't shown. if( SDL_VERSIONNUM( ver.major, ver.minor, ver.patch ) < SDL_VERSIONNUM( 2, 0, 4 ) ) { if ( !( SDL_GetModState() & KMOD_NUM ) ) { Com_Printf("INFO: Forcing NUMLOCK modifier state to enabled (actual state unknown)!\n"); SDL_SetModState( SDL_GetModState() | KMOD_NUM ); } } #endif while( 1 ) { Com_Frame( ); } return 0; }
void Runtime::pollEvents(bool blocking) { if (isActive() && !isRestart()) { SDL_Event ev; SDL_Keymod mod; if (blocking ? SDL_WaitEvent(&ev) : SDL_PollEvent(&ev)) { MAEvent *maEvent = NULL; switch (ev.type) { case SDL_TEXTINPUT: // pre-transformed/composted text mod = SDL_GetModState(); if (!mod || (mod & (KMOD_SHIFT|KMOD_CAPS))) { // ALT + CTRL keys handled in SDL_KEYDOWN for (int i = 0; ev.text.text[i] != 0; i++) { MAEvent *keyEvent = new MAEvent(); keyEvent->type = EVENT_TYPE_KEY_PRESSED; keyEvent->key = ev.text.text[i]; keyEvent->nativeKey = 0; pushEvent(keyEvent); } } break; case SDL_QUIT: setExit(true); break; case SDL_KEYDOWN: if (!isEditing() && ev.key.keysym.sym == SDLK_c && (ev.key.keysym.mod & KMOD_CTRL)) { setExit(true); } else if (ev.key.keysym.sym == SDLK_m && (ev.key.keysym.mod & KMOD_CTRL)) { showMenu(); } else if (ev.key.keysym.sym == SDLK_b && (ev.key.keysym.mod & KMOD_CTRL)) { setBack(); } else if (ev.key.keysym.sym == SDLK_BACKSPACE && get_focus_edit() == NULL && ((ev.key.keysym.mod & KMOD_CTRL) || !isRunning())) { setBack(); } else if (!isEditing() && ev.key.keysym.sym == SDLK_PAGEUP && (ev.key.keysym.mod & KMOD_CTRL)) { _output->scroll(true, true); } else if (!isEditing() && ev.key.keysym.sym == SDLK_PAGEDOWN && (ev.key.keysym.mod & KMOD_CTRL)) { _output->scroll(false, true); } else if (!isEditing() && ev.key.keysym.sym == SDLK_UP && (ev.key.keysym.mod & KMOD_CTRL)) { _output->scroll(true, false); } else if (!isEditing() && ev.key.keysym.sym == SDLK_DOWN && (ev.key.keysym.mod & KMOD_CTRL)) { _output->scroll(false, false); } else if (ev.key.keysym.sym == SDLK_p && (ev.key.keysym.mod & KMOD_CTRL)) { ::screen_dump(); } else { int lenMap = sizeof(keymap) / sizeof(keymap[0]); for (int i = 0; i < lenMap; i++) { if (ev.key.keysym.sym == keymap[i][0]) { maEvent = new MAEvent(); maEvent->type = EVENT_TYPE_KEY_PRESSED; maEvent->key = keymap[i][1]; maEvent->nativeKey = ev.key.keysym.mod; break; } } if (maEvent == NULL && ((ev.key.keysym.sym >= SDLK_KP_1 && ev.key.keysym.sym <= SDLK_KP_9) || ((ev.key.keysym.mod & KMOD_CTRL) && ev.key.keysym.sym != SDLK_LSHIFT && ev.key.keysym.sym != SDLK_RSHIFT && ev.key.keysym.sym != SDLK_LCTRL && ev.key.keysym.sym != SDLK_RCTRL) || (ev.key.keysym.mod & KMOD_ALT))) { maEvent = new MAEvent(); maEvent->type = EVENT_TYPE_KEY_PRESSED; maEvent->key = ev.key.keysym.sym; maEvent->nativeKey = ev.key.keysym.mod; } } break; case SDL_MOUSEBUTTONDOWN: if (ev.button.button == SDL_BUTTON_RIGHT) { _menuX = ev.motion.x; _menuY = ev.motion.y; showMenu(); } else if (ev.motion.x != 0 && ev.motion.y != 0) { // avoid phantom down message when launching in windows maEvent = getMotionEvent(EVENT_TYPE_POINTER_PRESSED, &ev); } break; case SDL_MOUSEMOTION: maEvent = getMotionEvent(EVENT_TYPE_POINTER_DRAGGED, &ev); break; case SDL_MOUSEBUTTONUP: SDL_SetCursor(_cursorArrow); maEvent = getMotionEvent(EVENT_TYPE_POINTER_RELEASED, &ev); break; case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: SDL_SetModState(KMOD_NONE); break; case SDL_WINDOWEVENT_RESIZED: onResize(ev.window.data1, ev.window.data2); break; case SDL_WINDOWEVENT_EXPOSED: _graphics->redraw(); break; case SDL_WINDOWEVENT_LEAVE: _output->removeHover(); break; } break; case SDL_DROPFILE: setLoadPath(ev.drop.file); setExit(false); SDL_free(ev.drop.file); break; case SDL_MOUSEWHEEL: if (!_output->scroll(ev.wheel.y == 1, false)) { maEvent = new MAEvent(); maEvent->type = EVENT_TYPE_KEY_PRESSED; maEvent->key = ev.wheel.y == 1 ? SB_KEY_UP : SB_KEY_DN; maEvent->nativeKey = KMOD_CTRL; } break; } if (maEvent != NULL) { pushEvent(maEvent); } } } }
int EPOC_HandleWsEvent(_THIS, const TWsEvent& aWsEvent) { int posted = 0; SDL_keysym keysym; // SDL_TRACE1("hws %d", aWsEvent.Type()); switch (aWsEvent.Type()) { case EEventPointer: /* Mouse pointer events */ { /* const TPointerCursorMode mode = EpocSdlEnv::PointerMode(); if(mode == EPointerCursorNone) { return 0; //TODO: Find out why events are get despite of cursor should be off } */ const TPointerEvent* pointerEvent = aWsEvent.Pointer(); const TPoint mousePos = EpocSdlEnv::WindowCoordinates(pointerEvent->iPosition); /*!! TODO Pointer do not yet work properly //SDL_TRACE1("SDL: EPOC_HandleWsEvent, pointerEvent->iType=%d", pointerEvent->iType); //!! if (Private->EPOC_ShrinkedHeight) { mousePos.iY <<= 1; // Scale y coordinate to shrinked screen height } if (Private->EPOC_ShrinkedWidth) { mousePos.iX <<= 1; // Scale x coordinate to shrinked screen width } */ posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */ switch (pointerEvent->iType) { case TPointerEvent::EButton1Down: posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); break; case TPointerEvent::EButton1Up: posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); break; case TPointerEvent::EButton2Down: posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); break; case TPointerEvent::EButton2Up: posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); break; case TPointerEvent::EButton3Down: posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); break; case TPointerEvent::EButton3Up: posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); break; } // switch break; } case EEventKeyDown: /* Key events */ { #ifdef SYMBIAN_CRYSTAL // special case: 9300/9500 rocker down, simulate left mouse button if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA) { const TPointerCursorMode mode = Private->EPOC_WsSession.PointerCursorMode(); if(mode != EPointerCursorNone) posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); } #endif (void*)TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym); #ifndef DISABLE_JOYSTICK /* Special handling */ switch((int)keysym.sym) { case SDLK_CAPSLOCK: if (!isCursorVisible) { /* Enable virtual cursor */ HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible); } else { /* Disable virtual cursor */ HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible); } isCursorVisible = !isCursorVisible; break; } #endif posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym); break; } case EEventKeyUp: /* Key events */ { #ifdef SYMBIAN_CRYSTAL // special case: 9300/9500 rocker up, simulate left mouse button if (aWsEvent.Key()->iScanCode == EStdKeyDeviceA) { posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); } #endif posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(_this, aWsEvent.Key()->iScanCode, &keysym)); break; } case EEventFocusGained: /* SDL window got focus */ { Private->iIsWindowFocused = ETrue; posted += SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); /* Draw window background and screen buffer */ DisableKeyBlocking(_this); //Markus: guess why:-) //RedrawWindowL(_this); break; } case EEventFocusLost: /* SDL window lost focus */ { Private->iIsWindowFocused = EFalse; posted += SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); break; } case EEventModifiersChanged: { TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged(); TUint modstate = KMOD_NONE; if (modEvent->iModifiers == EModifierLeftShift) modstate |= KMOD_LSHIFT; if (modEvent->iModifiers == EModifierRightShift) modstate |= KMOD_RSHIFT; if (modEvent->iModifiers == EModifierLeftCtrl) modstate |= KMOD_LCTRL; if (modEvent->iModifiers == EModifierRightCtrl) modstate |= KMOD_RCTRL; if (modEvent->iModifiers == EModifierLeftAlt) modstate |= KMOD_LALT; if (modEvent->iModifiers == EModifierRightAlt) modstate |= KMOD_RALT; if (modEvent->iModifiers == EModifierLeftFunc) modstate |= KMOD_LMETA; if (modEvent->iModifiers == EModifierRightFunc) modstate |= KMOD_RMETA; if (modEvent->iModifiers == EModifierCapsLock) modstate |= KMOD_CAPS; SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT))); break; } case EEventScreenDeviceChanged: { EpocSdlEnv::WaitDeviceChange(); } break; default: break; } return posted; }
/* ================ Sys_GetEvent ================ */ sysEvent_t Sys_GetEvent() { SDL_Event ev; sysEvent_t res = { }; byte key; static const sysEvent_t res_none = { SE_NONE, 0, 0, 0, NULL }; #if SDL_VERSION_ATLEAST(2, 0, 0) static char s[SDL_TEXTINPUTEVENT_TEXT_SIZE] = {0}; static size_t s_pos = 0; if (s[0] != '\0') { res.evType = SE_CHAR; res.evValue = s[s_pos]; ++s_pos; if (!s[s_pos] || s_pos == SDL_TEXTINPUTEVENT_TEXT_SIZE) { memset(s, 0, sizeof(s)); s_pos = 0; } return res; } #endif static byte c = 0; if (c) { res.evType = SE_CHAR; res.evValue = c; c = 0; return res; } // loop until there is an event we care about (will return then) or no more events while(SDL_PollEvent(&ev)) { switch (ev.type) { #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: { // unset modifier, in case alt-tab was used to leave window and ALT is still set // as that can cause fullscreen-toggling when pressing enter... SDL_Keymod currentmod = SDL_GetModState(); int newmod = KMOD_NONE; if (currentmod & KMOD_CAPS) // preserve capslock newmod |= KMOD_CAPS; SDL_SetModState((SDL_Keymod)newmod); } // new context because visual studio complains about newmod and currentmod not initialized because of the case SDL_WINDOWEVENT_FOCUS_LOST GLimp_GrabInput(GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR); break; case SDL_WINDOWEVENT_FOCUS_LOST: GLimp_GrabInput(0); break; } continue; // handle next event #else case SDL_ACTIVEEVENT: { int flags = 0; if (ev.active.gain) { flags = GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR; // unset modifier, in case alt-tab was used to leave window and ALT is still set // as that can cause fullscreen-toggling when pressing enter... SDLMod currentmod = SDL_GetModState(); int newmod = KMOD_NONE; if (currentmod & KMOD_CAPS) // preserve capslock newmod |= KMOD_CAPS; SDL_SetModState((SDLMod)newmod); } GLimp_GrabInput(flags); } continue; // handle next event case SDL_VIDEOEXPOSE: continue; // handle next event #endif case SDL_KEYDOWN: if (ev.key.keysym.sym == SDLK_RETURN && (ev.key.keysym.mod & KMOD_ALT) > 0) { cvarSystem->SetCVarBool("r_fullscreen", !renderSystem->IsFullScreen()); PushConsoleEvent("vid_restart"); return res_none; } // fall through case SDL_KEYUP: key = mapkey(ev.key.keysym.sym); #if !SDL_VERSION_ATLEAST(2, 0, 0) if (!key) { unsigned char c; // check if its an unmapped console key if (ev.key.keysym.unicode == (c = Sys_GetConsoleKey(false))) { key = c; } else if (ev.key.keysym.unicode == (c = Sys_GetConsoleKey(true))) { key = c; } else { if (ev.type == SDL_KEYDOWN) common->Warning("unmapped SDL key %d (0x%x)", ev.key.keysym.sym, ev.key.keysym.unicode); continue; // handle next event } } #else if(!key) { if (ev.key.keysym.scancode == SDL_SCANCODE_GRAVE) { // TODO: always do this check? key = Sys_GetConsoleKey(true); } else { if (ev.type == SDL_KEYDOWN) { common->Warning("unmapped SDL key %d", ev.key.keysym.sym); } continue; // handle next event } } #endif res.evType = SE_KEY; res.evValue = key; res.evValue2 = ev.key.state == SDL_PRESSED ? 1 : 0; kbd_polls.Append(kbd_poll_t(key, ev.key.state == SDL_PRESSED)); #if SDL_VERSION_ATLEAST(2, 0, 0) if (key == K_BACKSPACE && ev.key.state == SDL_PRESSED) c = key; #else if (ev.key.state == SDL_PRESSED && (ev.key.keysym.unicode & 0xff00) == 0) c = ev.key.keysym.unicode & 0xff; #endif return res; #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_TEXTINPUT: if (ev.text.text[0]) { res.evType = SE_CHAR; res.evValue = ev.text.text[0]; if (ev.text.text[1] != '\0') { memcpy(s, ev.text.text, SDL_TEXTINPUTEVENT_TEXT_SIZE); s_pos = 1; // pos 0 is returned } return res; } continue; // handle next event #endif case SDL_MOUSEMOTION: res.evType = SE_MOUSE; res.evValue = ev.motion.xrel; res.evValue2 = ev.motion.yrel; mouse_polls.Append(mouse_poll_t(M_DELTAX, ev.motion.xrel)); mouse_polls.Append(mouse_poll_t(M_DELTAY, ev.motion.yrel)); return res; #if SDL_VERSION_ATLEAST(2, 0, 0) case SDL_MOUSEWHEEL: res.evType = SE_KEY; if (ev.wheel.y > 0) { res.evValue = K_MWHEELUP; mouse_polls.Append(mouse_poll_t(M_DELTAZ, 1)); } else { res.evValue = K_MWHEELDOWN; mouse_polls.Append(mouse_poll_t(M_DELTAZ, -1)); } res.evValue2 = 1; return res; #endif case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: res.evType = SE_KEY; switch (ev.button.button) { case SDL_BUTTON_LEFT: res.evValue = K_MOUSE1; mouse_polls.Append(mouse_poll_t(M_ACTION1, ev.button.state == SDL_PRESSED ? 1 : 0)); break; case SDL_BUTTON_MIDDLE: res.evValue = K_MOUSE3; mouse_polls.Append(mouse_poll_t(M_ACTION3, ev.button.state == SDL_PRESSED ? 1 : 0)); break; case SDL_BUTTON_RIGHT: res.evValue = K_MOUSE2; mouse_polls.Append(mouse_poll_t(M_ACTION2, ev.button.state == SDL_PRESSED ? 1 : 0)); break; #if !SDL_VERSION_ATLEAST(2, 0, 0) case SDL_BUTTON_WHEELUP: res.evValue = K_MWHEELUP; if (ev.button.state == SDL_PRESSED) mouse_polls.Append(mouse_poll_t(M_DELTAZ, 1)); break; case SDL_BUTTON_WHEELDOWN: res.evValue = K_MWHEELDOWN; if (ev.button.state == SDL_PRESSED) mouse_polls.Append(mouse_poll_t(M_DELTAZ, -1)); break; #endif } res.evValue2 = ev.button.state == SDL_PRESSED ? 1 : 0; return res; case SDL_QUIT: PushConsoleEvent("quit"); return res_none; case SDL_USEREVENT: switch (ev.user.code) { case SE_CONSOLE: res.evType = SE_CONSOLE; res.evPtrLength = (intptr_t)ev.user.data1; res.evPtr = ev.user.data2; return res; default: common->Warning("unknown user event %u", ev.user.code); continue; // handle next event } default: common->Warning("unknown event %u", ev.type); continue; // handle next event } } return res_none; }
/** * @brief Init the SDL window */ bool R_InitGraphics (const viddefContext_t* context) { uint32_t flags; int i; SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); if (context->multisample > 0) { Com_Printf("I: set multisample buffers to %i\n", context->multisample); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, context->multisample); } else { Com_Printf("I: disable multisample buffers\n"); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); } #if SDL_VERSION_ATLEAST(2,0,0) /* valid values are between -1 and 1 */ i = std::min(1, std::max(-1, context->swapinterval)); Com_Printf("I: set swap control to %i\n", i); SDL_GL_SetSwapInterval(i); flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; if (context->fullscreen) flags |= SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS; const int videoDrivers = SDL_GetNumVideoDrivers(); for (int i = 0; i < videoDrivers; ++i) { Com_Printf("available driver: %s\n", SDL_GetVideoDriver(i)); } SDL_DisplayMode displayMode; SDL_GetDesktopDisplayMode(0, &displayMode); const char* name = SDL_GetPixelFormatName(displayMode.format); Com_Printf("current desktop mode: %dx%d@%dHz (%s)\n", displayMode.w, displayMode.h, displayMode.refresh_rate, name); SDL_VideoInit(nullptr); SDL_SetModState(KMOD_NONE); SDL_StopTextInput(); Com_Printf("driver: %s\n", SDL_GetCurrentVideoDriver()); const int displays = SDL_GetNumVideoDisplays(); Com_Printf("found %i display(s)\n", displays); int width = context->width; int height = context->height; if (context->fullscreen && displays > 1) { width = displayMode.w; height = displayMode.h; Com_Printf("use fake fullscreen for the first display: %i:%i\n", width, height); } cls.window = SDL_CreateWindow(GAME_TITLE_LONG, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags); if (!cls.window) { const char* error = SDL_GetError(); Com_Printf("SDL SDL_CreateWindow failed: %s\n", error); SDL_ClearError(); return -1; } cls.context = SDL_GL_CreateContext(cls.window); #else /* valid values are between 0 and 2 */ i = std::min(2, std::max(0, context->swapinterval)); Com_Printf("I: set swap control to %i\n", i); SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, i); flags = SDL_OPENGL; if (context->fullscreen) flags |= SDL_FULLSCREEN; /*flags |= SDL_NOFRAME;*/ SDL_Surface* screen = SDL_SetVideoMode(context->width, context->height, 0, flags); if (!screen) { const char* error = SDL_GetError(); Com_Printf("SDL SetVideoMode failed: %s\n", error); SDL_ClearError(); return false; } #endif SDL_ShowCursor(SDL_DISABLE); return true; }
bool SpringApp::MainEventHandler(const SDL_Event& event) { switch (event.type) { case SDL_WINDOWEVENT: { switch (event.window.event) { case SDL_WINDOWEVENT_MOVED: { SaveWindowPosition(); } break; //case SDL_WINDOWEVENT_RESIZED: //this is event is always preceded by: case SDL_WINDOWEVENT_SIZE_CHANGED: { Watchdog::ClearTimer(WDT_MAIN, true); SaveWindowPosition(); InitOpenGL(); activeController->ResizeEvent(); mouseInput->InstallWndCallback(); } break; case SDL_WINDOWEVENT_SHOWN: { // reactivate sounds and other globalRendering->active = true; if (ISound::IsInitialized()) { sound->Iconified(false); } if (globalRendering->fullScreen) { FBO::GLContextReinit(); } } break; case SDL_WINDOWEVENT_HIDDEN: { // deactivate sounds and other globalRendering->active = false; if (ISound::IsInitialized()) { sound->Iconified(true); } if (globalRendering->fullScreen) { FBO::GLContextLost(); } } break; case SDL_WINDOWEVENT_FOCUS_GAINED: { // update keydown table KeyInput::Update(0, ((keyBindings != NULL)? keyBindings->GetFakeMetaKey(): -1)); } break; case SDL_WINDOWEVENT_FOCUS_LOST: { Watchdog::ClearTimer(WDT_MAIN, true); // SDL has some bug and does not update modstate on alt+tab/minimize etc. //FIXME check if still happens with SDL2 (2013) SDL_SetModState((SDL_Keymod)(SDL_GetModState() & (KMOD_NUM | KMOD_CAPS | KMOD_MODE))); // release all keyboard keys KeyInput::ReleaseAllKeys(); // simulate mouse release to prevent hung buttons for (int i = 1; i <= NUM_BUTTONS; ++i) { if (!mouse) continue; if (!mouse->buttons[i].pressed) continue; SDL_Event event; event.type = event.button.type = SDL_MOUSEBUTTONUP; event.button.state = SDL_RELEASED; event.button.which = 0; event.button.button = i; event.button.x = -1; event.button.y = -1; SDL_PushEvent(&event); } // unlock mouse if (mouse && mouse->locked) { mouse->ToggleMiddleClickScroll(); } // and make sure to un-capture mouse if (SDL_GetWindowGrab(window)) SDL_SetWindowGrab(window, SDL_FALSE); break; } case SDL_WINDOWEVENT_CLOSE: { gu->globalQuit = true; break; } }; } break; case SDL_QUIT: { gu->globalQuit = true; } break; case SDL_TEXTEDITING: { //FIXME don't known when this is called } break; case SDL_TEXTINPUT: { if (!activeController) { break; } std::string utf8Text = event.text.text; const bool catched = eventHandler.TextInput(utf8Text); if (activeController->userWriting && !catched){ auto ac = activeController; if (ac->ignoreNextChar) { utf8Text = utf8Text.substr(Utf8NextChar(utf8Text, 0)); } ac->writingPos = Clamp<int>(ac->writingPos, 0, ac->userInput.length()); ac->userInput.insert(ac->writingPos, utf8Text); ac->writingPos += utf8Text.length(); } } break; case SDL_KEYDOWN: { KeyInput::Update(event.key.keysym.sym, ((keyBindings != NULL)? keyBindings->GetFakeMetaKey(): -1)); if (activeController) { activeController->KeyPressed(KeyInput::GetNormalizedKeySymbol(event.key.keysym.sym), event.key.repeat); } } break; case SDL_KEYUP: { KeyInput::Update(event.key.keysym.sym, ((keyBindings != NULL)? keyBindings->GetFakeMetaKey(): -1)); if (activeController) { if (activeController->ignoreNextChar) { activeController->ignoreNextChar = false; } activeController->KeyReleased(KeyInput::GetNormalizedKeySymbol(event.key.keysym.sym)); } } break; }; return false; }
/* ================ Sys_GetEvent ================ */ sysEvent_t Sys_GetEvent() { SDL_Event ev; sysEvent_t res = { }; byte key; static const sysEvent_t res_none = { SE_NONE, 0, 0, 0, NULL }; static char *s = NULL; static size_t s_pos = 0; if (s) { res.evType = SE_CHAR; res.evValue = s[s_pos]; s_pos++; if (!s[s_pos]) { free(s); s = NULL; s_pos = 0; } return res; } static byte c = 0; if (c) { res.evType = SE_CHAR; res.evValue = c; c = 0; return res; } if (SDL_PollEvent(&ev)) { switch (ev.type) { case SDL_WINDOWEVENT: switch (ev.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: { // unset modifier, in case alt-tab was used to leave window and ALT is still set // as that can cause fullscreen-toggling when pressing enter... SDL_Keymod currentmod = SDL_GetModState(); int newmod = KMOD_NONE; if (currentmod & KMOD_CAPS) // preserve capslock newmod |= KMOD_CAPS; SDL_SetModState((SDL_Keymod)newmod); GLimp_GrabInput(GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR); break; } case SDL_WINDOWEVENT_FOCUS_LOST: GLimp_GrabInput(0); break; } return res_none; case SDL_KEYDOWN: if (ev.key.keysym.sym == SDLK_RETURN && (ev.key.keysym.mod & KMOD_ALT) > 0) { cvarSystem->SetCVarBool("r_fullscreen", !renderSystem->IsFullScreen()); PushConsoleEvent("vid_restart"); return res_none; } // fall through case SDL_KEYUP: key = mapkey(ev.key.keysym.sym); if (!key) { unsigned char c; // check if its an unmapped console key if (ev.key.keysym.unicode == (c = Sys_GetConsoleKey(false))) { key = c; } else if (ev.key.keysym.unicode == (c = Sys_GetConsoleKey(true))) { key = c; } else { if (ev.type == SDL_KEYDOWN) common->Warning("unmapped SDL key %d (0x%x)", ev.key.keysym.sym, ev.key.keysym.unicode); return res_none; } } res.evType = SE_KEY; res.evValue = key; res.evValue2 = ev.key.state == SDL_PRESSED ? 1 : 0; kbd_polls.Append(kbd_poll_t(key, ev.key.state == SDL_PRESSED)); if (key == K_BACKSPACE && ev.key.state == SDL_PRESSED) c = key; return res; case SDL_TEXTINPUT: if (ev.text.text && *ev.text.text) { if (!ev.text.text[1]) c = *ev.text.text; else s = strdup(ev.text.text); } return res_none; case SDL_MOUSEMOTION: res.evType = SE_MOUSE; res.evValue = ev.motion.xrel; res.evValue2 = ev.motion.yrel; mouse_polls.Append(mouse_poll_t(M_DELTAX, ev.motion.xrel)); mouse_polls.Append(mouse_poll_t(M_DELTAY, ev.motion.yrel)); return res; case SDL_MOUSEWHEEL: res.evType = SE_KEY; if (ev.wheel.y > 0) { res.evValue = K_MWHEELUP; mouse_polls.Append(mouse_poll_t(M_DELTAZ, 1)); } else { res.evValue = K_MWHEELDOWN; mouse_polls.Append(mouse_poll_t(M_DELTAZ, -1)); } res.evValue2 = 1; return res; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: res.evType = SE_KEY; switch (ev.button.button) { case SDL_BUTTON_LEFT: res.evValue = K_MOUSE1; mouse_polls.Append(mouse_poll_t(M_ACTION1, ev.button.state == SDL_PRESSED ? 1 : 0)); break; case SDL_BUTTON_MIDDLE: res.evValue = K_MOUSE3; mouse_polls.Append(mouse_poll_t(M_ACTION3, ev.button.state == SDL_PRESSED ? 1 : 0)); break; case SDL_BUTTON_RIGHT: res.evValue = K_MOUSE2; mouse_polls.Append(mouse_poll_t(M_ACTION2, ev.button.state == SDL_PRESSED ? 1 : 0)); break; } res.evValue2 = ev.button.state == SDL_PRESSED ? 1 : 0; return res; case SDL_QUIT: PushConsoleEvent("quit"); return res_none; case SDL_USEREVENT: switch (ev.user.code) { case SE_CONSOLE: res.evType = SE_CONSOLE; res.evPtrLength = (intptr_t)ev.user.data1; res.evPtr = ev.user.data2; return res; default: common->Warning("unknown user event %u", ev.user.code); return res_none; } default: common->Warning("unknown event %u", ev.type); return res_none; } } return res_none; }