X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fevents.c;h=f3330a7ee318ece3e7578f01551a509161c4396f;hp=ef78d9c9b09979d7d376a29cb772694be6d83b14;hb=0732b0680b5ce9468facaef0b7d9a50fc0894515;hpb=bf88ae3e5f7cc53fec7a06298f6632368c6c8e0c diff --git a/src/events.c b/src/events.c index ef78d9c9..f3330a7e 100644 --- a/src/events.c +++ b/src/events.c @@ -56,13 +56,11 @@ static int FilterEvents(const Event *event) { MotionEvent *motion; -#if defined(TARGET_SDL2) // skip repeated key press events if keyboard auto-repeat is disabled if (event->type == EVENT_KEYPRESS && event->key.repeat && !keyrepeat_status) return 0; -#endif if (event->type == EVENT_BUTTONPRESS || event->type == EVENT_BUTTONRELEASE) @@ -185,7 +183,6 @@ static void HandleEvents(void) HandleMotionEvent((MotionEvent *) &event); break; -#if defined(TARGET_SDL2) case EVENT_WHEELMOTION: HandleWheelEvent((WheelEvent *) &event); break; @@ -210,7 +207,6 @@ static void HandleEvents(void) case SDL_APP_DIDENTERFOREGROUND: HandlePauseResumeEvent((PauseResumeEvent *) &event); break; -#endif case EVENT_KEYPRESS: case EVENT_KEYRELEASE: @@ -253,8 +249,6 @@ void HandleOtherEvents(Event *event) HandleClientMessageEvent((ClientMessageEvent *) event); break; -#if defined(TARGET_SDL) -#if defined(TARGET_SDL2) case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: // for any game controller button event, disable overlay buttons @@ -266,7 +260,6 @@ void HandleOtherEvents(Event *event) case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEREMOVED: case SDL_CONTROLLERAXISMOTION: -#endif case SDL_JOYAXISMOTION: case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: @@ -276,7 +269,6 @@ void HandleOtherEvents(Event *event) case SDL_SYSWMEVENT: HandleWindowManagerEvent(event); break; -#endif default: break; @@ -349,7 +341,6 @@ void EventLoop(void) void ClearAutoRepeatKeyEvents(void) { -#if defined(TARGET_SDL2) while (PendingEvent()) { Event next_event; @@ -363,7 +354,6 @@ void ClearAutoRepeatKeyEvents(void) else break; } -#endif } void ClearEventQueue(void) @@ -382,12 +372,10 @@ void ClearEventQueue(void) ClearPlayerAction(); break; -#if defined(TARGET_SDL2) case SDL_CONTROLLERBUTTONUP: HandleJoystickEvent(&event); ClearPlayerAction(); break; -#endif default: HandleOtherEvents(&event); @@ -467,12 +455,10 @@ void SleepWhileUnmapped(void) key_joystick_mapping = 0; break; -#if defined(TARGET_SDL2) case SDL_CONTROLLERBUTTONUP: HandleJoystickEvent(&event); key_joystick_mapping = 0; break; -#endif case EVENT_MAPNOTIFY: window_unmapped = FALSE; @@ -540,8 +526,6 @@ void HandleMotionEvent(MotionEvent *event) HandleButton(event->x, event->y, button_status, button_status); } -#if defined(TARGET_SDL2) - void HandleWheelEvent(WheelEvent *event) { int button_nr; @@ -1037,8 +1021,6 @@ void HandleFingerEvent(FingerEvent *event) HandleFingerEvent_WipeGestures(event); } -#endif - static void HandleButtonOrFinger_WipeGestures_MM(int mx, int my, int button) { static int old_mx = 0, old_my = 0; @@ -1398,8 +1380,6 @@ static void HandleButtonOrFinger(int mx, int my, int button) } } -#if defined(TARGET_SDL2) - static boolean checkTextInputKeyModState(void) { // when playing, only handle raw key events and ignore text input @@ -1448,8 +1428,6 @@ void HandlePauseResumeEvent(PauseResumeEvent *event) } } -#endif - void HandleKeyEvent(KeyEvent *event) { int key_status = (event->type == EVENT_KEYPRESS ? KEY_PRESSED : KEY_RELEASED); @@ -1474,22 +1452,24 @@ void HandleKeyEvent(KeyEvent *event) // always map the "back" button to the "escape" key on Android devices key = KSYM_Escape; } + else if (key == KSYM_Menu) + { + // the "menu" button can be used to toggle displaying virtual buttons + if (key_status == KEY_PRESSED) + SetOverlayEnabled(!GetOverlayEnabled()); + } else { - // for any key event other than "back" button, disable overlay buttons + // for any other "real" key event, disable virtual buttons SetOverlayEnabled(FALSE); } #endif HandleKeyModState(keymod, key_status); -#if defined(TARGET_SDL2) // only handle raw key input without text modifier keys pressed if (!checkTextInputKeyModState()) HandleKey(key, key_status); -#else - HandleKey(key, key_status); -#endif } void HandleFocusEvent(FocusChangeEvent *event) @@ -1540,9 +1520,7 @@ void HandleClientMessageEvent(ClientMessageEvent *event) void HandleWindowManagerEvent(Event *event) { -#if defined(TARGET_SDL) SDLHandleWindowManagerEvent(event); -#endif } void HandleButton(int mx, int my, int button, int button_nr) @@ -1778,6 +1756,22 @@ static void HandleKeysSpecial(Key key) { DumpBrush_Small(); } + + if (GetKeyModState() & (KMOD_Control | KMOD_Meta)) + { + if (letter == 'x') // copy brush to clipboard (small size) + { + CopyBrushToClipboard_Small(); + } + else if (letter == 'c') // copy brush to clipboard (normal size) + { + CopyBrushToClipboard(); + } + else if (letter == 'v') // paste brush from Clipboard + { + CopyClipboardToBrush(); + } + } } // special key shortcuts for all game modes @@ -1790,11 +1784,14 @@ static void HandleKeysSpecial(Key key) } } -void HandleKeysDebug(Key key) +boolean HandleKeysDebug(Key key, int key_status) { #ifdef DEBUG int i; + if (key_status != KEY_PRESSED) + return FALSE; + if (game_status == GAME_MODE_PLAYING || !setup.debug.frame_delay_game_only) { boolean mod_key_pressed = ((GetKeyModState() & KMOD_Valid) != KMOD_None); @@ -1821,7 +1818,7 @@ void HandleKeysDebug(Key key) else Error(ERR_DEBUG, "frame delay == 0 ms (maximum speed)"); - break; + return TRUE; } } } @@ -1834,13 +1831,19 @@ void HandleKeysDebug(Key key) Error(ERR_DEBUG, "debug mode %s", (options.debug ? "enabled" : "disabled")); + + return TRUE; } else if (key == KSYM_v) { Error(ERR_DEBUG, "currently using game engine version %d", game.engine_version); + + return TRUE; } } + + return FALSE; #endif } @@ -1868,13 +1871,14 @@ void HandleKey(Key key, int key_status) int joy = 0; int i; -#if defined(TARGET_SDL2) + if (HandleKeysDebug(key, key_status)) + return; // do not handle already processed keys again + // map special keys (media keys / remote control buttons) to default keys if (key == KSYM_PlayPause) key = KSYM_space; else if (key == KSYM_Select) key = KSYM_Return; -#endif HandleSpecialGameControllerKeys(key, key_status); @@ -2095,10 +2099,7 @@ void HandleKey(Key key, int key_status) HandleKeysSpecial(key); if (HandleGadgetsKeyInput(key)) - { - if (key != KSYM_Escape) // always allow ESC key to be handled - key = KSYM_UNDEFINED; - } + return; // do not handle already processed keys again switch (game_status) { @@ -2215,8 +2216,6 @@ void HandleKey(Key key, int key_status) return; } } - - HandleKeysDebug(key); } void HandleNoEvent(void) @@ -2455,7 +2454,6 @@ void HandleJoystick(void) void HandleSpecialGameControllerButtons(Event *event) { -#if defined(TARGET_SDL2) int key_status; Key key; @@ -2488,12 +2486,10 @@ void HandleSpecialGameControllerButtons(Event *event) } HandleKey(key, key_status); -#endif } void HandleSpecialGameControllerKeys(Key key, int key_status) { -#if defined(TARGET_SDL2) #if defined(KSYM_Rewind) && defined(KSYM_FastForward) int button = SDL_CONTROLLER_BUTTON_INVALID; @@ -2518,7 +2514,6 @@ void HandleSpecialGameControllerKeys(Key key, int key_status) HandleJoystickEvent(&event); } #endif -#endif } boolean DoKeysymAction(int keysym)