MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / sdlKeyFilter

Function sdlKeyFilter

ddio/lnxkey_sdl.cpp:344–394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342}
343
344int sdlKeyFilter(const SDL_Event *event) {
345 uint8_t kc = 0;
346
347 if ((event->type != SDL_KEYUP) && (event->type != SDL_KEYDOWN))
348 return (1);
349
350 switch (event->key.state) {
351 case SDL_PRESSED:
352 if (event->key.repeat) break; // ignore these, we only want to know if it's a first time pressed, not a key-repeat.
353 kc = sdlkeycode_to_keycode(event->key.keysym.sym);
354 if (event->key.keysym.mod & KMOD_CTRL) {
355 switch (kc) {
356 case KEY_G: // toggle grabbed input.
357 ddio_mouseGrabbed = !ddio_mouseGrabbed;
358 SDL_SetRelativeMouseMode(ddio_mouseGrabbed ? SDL_TRUE : SDL_FALSE);
359 return 0;
360 } // switch
361 } // if
362
363 else if (event->key.keysym.mod & KMOD_ALT) {
364 if ((kc == KEY_ENTER) || (kc == KEY_PADENTER)) {
365 extern SDL_Window *GSDLWindow;
366 Uint32 flags = SDL_GetWindowFlags(GSDLWindow);
367 // (In SDL2, SDL_WINDOW_FULLSCREEN_DESKTOP is SDL_WINDOW_FULLSCREEN plus an extra bit set, so just check for _any_ fullscreen in this bitwise AND.)
368 if (flags & SDL_WINDOW_FULLSCREEN) {
369 flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
370 } else {
371 flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
372 }
373 SDL_SetWindowFullscreen(GSDLWindow, flags);
374 return(0);
375 } // if
376 } // else if
377
378 LKeys[kc].down_time = timer_GetTime();
379 LKeys[kc].status = true;
380 ddio_UpdateKeyState(kc, true);
381 break;
382
383 case SDL_RELEASED:
384 kc = sdlkeycode_to_keycode(event->key.keysym.sym);
385 if (LKeys[kc].status) {
386 LKeys[kc].up_time = timer_GetTime();
387 LKeys[kc].status = false;
388 ddio_UpdateKeyState(kc, false);
389 } // if
390 break;
391 } // switch
392
393 return (0);
394} // sdlKeyFilter
395
396bool ddio_sdl_InternalKeyInit(ddio_init_info *init_info) {
397 // reset key list

Callers 1

d3SDLEventFilterFunction · 0.85

Calls 2

sdlkeycode_to_keycodeFunction · 0.85
ddio_UpdateKeyStateFunction · 0.85

Tested by

no test coverage detected