X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fevents.c;h=3346055722afa7566fa7f249ade02584d18a4f15;hp=ef78d9c9b09979d7d376a29cb772694be6d83b14;hb=7732b3bda99e3cafc7db8718f2cac1f507c978e8;hpb=bf88ae3e5f7cc53fec7a06298f6632368c6c8e0c diff --git a/src/events.c b/src/events.c index ef78d9c9..33460557 100644 --- a/src/events.c +++ b/src/events.c @@ -39,6 +39,8 @@ static int cursor_mode_last = CURSOR_DEFAULT; static unsigned int special_cursor_delay = 0; static unsigned int special_cursor_delay_value = 1000; +static boolean virtual_button_pressed = FALSE; + // forward declarations for internal use static void HandleNoEvent(void); @@ -56,13 +58,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 +185,6 @@ static void HandleEvents(void) HandleMotionEvent((MotionEvent *) &event); break; -#if defined(TARGET_SDL2) case EVENT_WHEELMOTION: HandleWheelEvent((WheelEvent *) &event); break; @@ -210,7 +209,6 @@ static void HandleEvents(void) case SDL_APP_DIDENTERFOREGROUND: HandlePauseResumeEvent((PauseResumeEvent *) &event); break; -#endif case EVENT_KEYPRESS: case EVENT_KEYRELEASE: @@ -253,8 +251,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 +262,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 +271,6 @@ void HandleOtherEvents(Event *event) case SDL_SYSWMEVENT: HandleWindowManagerEvent(event); break; -#endif default: break; @@ -349,7 +343,6 @@ void EventLoop(void) void ClearAutoRepeatKeyEvents(void) { -#if defined(TARGET_SDL2) while (PendingEvent()) { Event next_event; @@ -363,7 +356,6 @@ void ClearAutoRepeatKeyEvents(void) else break; } -#endif } void ClearEventQueue(void) @@ -382,12 +374,10 @@ void ClearEventQueue(void) ClearPlayerAction(); break; -#if defined(TARGET_SDL2) case SDL_CONTROLLERBUTTONUP: HandleJoystickEvent(&event); ClearPlayerAction(); break; -#endif default: HandleOtherEvents(&event); @@ -467,12 +457,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 +528,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; @@ -738,6 +724,8 @@ static void HandleFingerEvent_VirtualButtons(FingerEvent *event) "KEY_PRESSED"); int i; + virtual_button_pressed = (key_status == KEY_PRESSED && key != KSYM_UNDEFINED); + // for any touch input event, enable overlay buttons (if activated) SetOverlayEnabled(TRUE); @@ -1037,8 +1025,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 +1384,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 +1432,6 @@ void HandlePauseResumeEvent(PauseResumeEvent *event) } } -#endif - void HandleKeyEvent(KeyEvent *event) { int key_status = (event->type == EVENT_KEYPRESS ? KEY_PRESSED : KEY_RELEASED); @@ -1474,22 +1456,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 +1524,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) @@ -1567,10 +1549,13 @@ void HandleButton(int mx, int my, int button, int button_nr) #if defined(PLATFORM_ANDROID) // when playing, only handle gadgets when using "follow finger" controls // or when using touch controls in combination with the MM game engine + // or when using gadgets that do not overlap with virtual buttons handle_gadgets = (game_status != GAME_MODE_PLAYING || level.game_engine_type == GAME_ENGINE_TYPE_MM || - strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER)); + strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER) || + (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS) && + !virtual_button_pressed)); #endif if (HandleGlobalAnimClicks(mx, my, button)) @@ -1778,6 +1763,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 +1791,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 +1825,7 @@ void HandleKeysDebug(Key key) else Error(ERR_DEBUG, "frame delay == 0 ms (maximum speed)"); - break; + return TRUE; } } } @@ -1834,14 +1838,20 @@ 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; } } #endif + + return FALSE; } void HandleKey(Key key, int key_status) @@ -1868,13 +1878,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 +2106,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 +2223,6 @@ void HandleKey(Key key, int key_status) return; } } - - HandleKeysDebug(key); } void HandleNoEvent(void) @@ -2455,7 +2461,6 @@ void HandleJoystick(void) void HandleSpecialGameControllerButtons(Event *event) { -#if defined(TARGET_SDL2) int key_status; Key key; @@ -2488,12 +2493,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 +2521,6 @@ void HandleSpecialGameControllerKeys(Key key, int key_status) HandleJoystickEvent(&event); } #endif -#endif } boolean DoKeysymAction(int keysym)