projects
/
rocksndiamonds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fixed not closing doors simultaneously after solving a level
[rocksndiamonds.git]
/
src
/
events.c
diff --git
a/src/events.c
b/src/events.c
index 5a3d0ca8c3bf75653ddfb5bdbc0877cda6d586a4..3346055722afa7566fa7f249ade02584d18a4f15 100644
(file)
--- 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 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);
// forward declarations for internal use
static void HandleNoEvent(void);
@@
-56,13
+58,11
@@
static int FilterEvents(const Event *event)
{
MotionEvent *motion;
{
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;
// 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)
if (event->type == EVENT_BUTTONPRESS ||
event->type == EVENT_BUTTONRELEASE)
@@
-185,7
+185,6
@@
static void HandleEvents(void)
HandleMotionEvent((MotionEvent *) &event);
break;
HandleMotionEvent((MotionEvent *) &event);
break;
-#if defined(TARGET_SDL2)
case EVENT_WHEELMOTION:
HandleWheelEvent((WheelEvent *) &event);
break;
case EVENT_WHEELMOTION:
HandleWheelEvent((WheelEvent *) &event);
break;
@@
-210,7
+209,6
@@
static void HandleEvents(void)
case SDL_APP_DIDENTERFOREGROUND:
HandlePauseResumeEvent((PauseResumeEvent *) &event);
break;
case SDL_APP_DIDENTERFOREGROUND:
HandlePauseResumeEvent((PauseResumeEvent *) &event);
break;
-#endif
case EVENT_KEYPRESS:
case EVENT_KEYRELEASE:
case EVENT_KEYPRESS:
case EVENT_KEYRELEASE:
@@
-253,8
+251,6
@@
void HandleOtherEvents(Event *event)
HandleClientMessageEvent((ClientMessageEvent *) event);
break;
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
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:
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_CONTROLLERAXISMOTION:
-#endif
case SDL_JOYAXISMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_JOYAXISMOTION:
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
@@
-276,7
+271,6
@@
void HandleOtherEvents(Event *event)
case SDL_SYSWMEVENT:
HandleWindowManagerEvent(event);
break;
case SDL_SYSWMEVENT:
HandleWindowManagerEvent(event);
break;
-#endif
default:
break;
default:
break;
@@
-349,7
+343,6
@@
void EventLoop(void)
void ClearAutoRepeatKeyEvents(void)
{
void ClearAutoRepeatKeyEvents(void)
{
-#if defined(TARGET_SDL2)
while (PendingEvent())
{
Event next_event;
while (PendingEvent())
{
Event next_event;
@@
-363,7
+356,6
@@
void ClearAutoRepeatKeyEvents(void)
else
break;
}
else
break;
}
-#endif
}
void ClearEventQueue(void)
}
void ClearEventQueue(void)
@@
-382,12
+374,10
@@
void ClearEventQueue(void)
ClearPlayerAction();
break;
ClearPlayerAction();
break;
-#if defined(TARGET_SDL2)
case SDL_CONTROLLERBUTTONUP:
HandleJoystickEvent(&event);
ClearPlayerAction();
break;
case SDL_CONTROLLERBUTTONUP:
HandleJoystickEvent(&event);
ClearPlayerAction();
break;
-#endif
default:
HandleOtherEvents(&event);
default:
HandleOtherEvents(&event);
@@
-467,12
+457,10
@@
void SleepWhileUnmapped(void)
key_joystick_mapping = 0;
break;
key_joystick_mapping = 0;
break;
-#if defined(TARGET_SDL2)
case SDL_CONTROLLERBUTTONUP:
HandleJoystickEvent(&event);
key_joystick_mapping = 0;
break;
case SDL_CONTROLLERBUTTONUP:
HandleJoystickEvent(&event);
key_joystick_mapping = 0;
break;
-#endif
case EVENT_MAPNOTIFY:
window_unmapped = FALSE;
case EVENT_MAPNOTIFY:
window_unmapped = FALSE;
@@
-540,8
+528,6
@@
void HandleMotionEvent(MotionEvent *event)
HandleButton(event->x, event->y, button_status, button_status);
}
HandleButton(event->x, event->y, button_status, button_status);
}
-#if defined(TARGET_SDL2)
-
void HandleWheelEvent(WheelEvent *event)
{
int button_nr;
void HandleWheelEvent(WheelEvent *event)
{
int button_nr;
@@
-738,6
+724,8
@@
static void HandleFingerEvent_VirtualButtons(FingerEvent *event)
"KEY_PRESSED");
int i;
"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);
// for any touch input event, enable overlay buttons (if activated)
SetOverlayEnabled(TRUE);
@@
-1037,8
+1025,6
@@
void HandleFingerEvent(FingerEvent *event)
HandleFingerEvent_WipeGestures(event);
}
HandleFingerEvent_WipeGestures(event);
}
-#endif
-
static void HandleButtonOrFinger_WipeGestures_MM(int mx, int my, int button)
{
static int old_mx = 0, old_my = 0;
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
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);
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;
}
// 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
{
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);
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);
// 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)
}
void HandleFocusEvent(FocusChangeEvent *event)
@@
-1540,9
+1524,7
@@
void HandleClientMessageEvent(ClientMessageEvent *event)
void HandleWindowManagerEvent(Event *event)
{
void HandleWindowManagerEvent(Event *event)
{
-#if defined(TARGET_SDL)
SDLHandleWindowManagerEvent(event);
SDLHandleWindowManagerEvent(event);
-#endif
}
void HandleButton(int mx, int my, int button, int button_nr)
}
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
#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 ||
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))
#endif
if (HandleGlobalAnimClicks(mx, my, button))
@@
-1806,11
+1791,14
@@
static void HandleKeysSpecial(Key key)
}
}
}
}
-
void HandleKeysDebug(Key key
)
+
boolean HandleKeysDebug(Key key, int key_status
)
{
#ifdef DEBUG
int i;
{
#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);
if (game_status == GAME_MODE_PLAYING || !setup.debug.frame_delay_game_only)
{
boolean mod_key_pressed = ((GetKeyModState() & KMOD_Valid) != KMOD_None);
@@
-1837,7
+1825,7
@@
void HandleKeysDebug(Key key)
else
Error(ERR_DEBUG, "frame delay == 0 ms (maximum speed)");
else
Error(ERR_DEBUG, "frame delay == 0 ms (maximum speed)");
-
break
;
+
return TRUE
;
}
}
}
}
}
}
@@
-1850,14
+1838,20
@@
void HandleKeysDebug(Key key)
Error(ERR_DEBUG, "debug mode %s",
(options.debug ? "enabled" : "disabled"));
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);
}
else if (key == KSYM_v)
{
Error(ERR_DEBUG, "currently using game engine version %d",
game.engine_version);
+
+ return TRUE;
}
}
#endif
}
}
#endif
+
+ return FALSE;
}
void HandleKey(Key key, int key_status)
}
void HandleKey(Key key, int key_status)
@@
-1884,13
+1878,14
@@
void HandleKey(Key key, int key_status)
int joy = 0;
int i;
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;
// 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);
HandleSpecialGameControllerKeys(key, key_status);
@@
-2111,10
+2106,7
@@
void HandleKey(Key key, int key_status)
HandleKeysSpecial(key);
if (HandleGadgetsKeyInput(key))
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)
{
switch (game_status)
{
@@
-2231,8
+2223,6
@@
void HandleKey(Key key, int key_status)
return;
}
}
return;
}
}
-
- HandleKeysDebug(key);
}
void HandleNoEvent(void)
}
void HandleNoEvent(void)
@@
-2471,7
+2461,6
@@
void HandleJoystick(void)
void HandleSpecialGameControllerButtons(Event *event)
{
void HandleSpecialGameControllerButtons(Event *event)
{
-#if defined(TARGET_SDL2)
int key_status;
Key key;
int key_status;
Key key;
@@
-2504,12
+2493,10
@@
void HandleSpecialGameControllerButtons(Event *event)
}
HandleKey(key, key_status);
}
HandleKey(key, key_status);
-#endif
}
void HandleSpecialGameControllerKeys(Key key, int key_status)
{
}
void HandleSpecialGameControllerKeys(Key key, int key_status)
{
-#if defined(TARGET_SDL2)
#if defined(KSYM_Rewind) && defined(KSYM_FastForward)
int button = SDL_CONTROLLER_BUTTON_INVALID;
#if defined(KSYM_Rewind) && defined(KSYM_FastForward)
int button = SDL_CONTROLLER_BUTTON_INVALID;
@@
-2534,7
+2521,6
@@
void HandleSpecialGameControllerKeys(Key key, int key_status)
HandleJoystickEvent(&event);
}
#endif
HandleJoystickEvent(&event);
}
#endif
-#endif
}
boolean DoKeysymAction(int keysym)
}
boolean DoKeysymAction(int keysym)