X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fevents.c;h=4c9ecc8b569b0629a879f0e41746c163f299d343;hp=6c8cf2f0aaecfceb87f894b8eb2577cb4c17b9f7;hb=a8816d6e5319f9ec26a45346b08250f61e95c011;hpb=5a5ca477c9e938c8fdc728798efab02298fd8055 diff --git a/src/events.c b/src/events.c index 6c8cf2f0..4c9ecc8b 100644 --- a/src/events.c +++ b/src/events.c @@ -29,17 +29,28 @@ static boolean cursor_inside_playfield = FALSE; static boolean playfield_cursor_set = FALSE; -static unsigned long playfield_cursor_delay = 0; +static unsigned int playfield_cursor_delay = 0; /* event filter especially needed for SDL event filtering due to delay problems with lots of mouse motion events when mouse button not pressed (X11 can handle this with 'PointerMotionHintMask') */ -int FilterMouseMotionEvents(const Event *event) +/* event filter addition for SDL2: as SDL2 does not have a function to enable + or disable keyboard auto-repeat, filter repeated keyboard events instead */ + +static int FilterEventsExt(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 + /* non-motion events are directly passed to event handler functions */ if (event->type != EVENT_MOTIONNOTIFY) return 1; @@ -59,10 +70,22 @@ int FilterMouseMotionEvents(const Event *event) if (button_status == MB_RELEASED && game_status != GAME_MODE_EDITOR && game_status != GAME_MODE_PLAYING) return 0; - else - return 1; + + return 1; } +#if defined(TARGET_SDL2) +int FilterEvents(void *userdata, Event *event) +{ + return FilterEventsExt(event); +} +#else +int FilterEvents(const Event *event) +{ + return FilterEventsExt(event); +} +#endif + /* to prevent delay problems, skip mouse motion events if the very next event is also a mouse motion event (and therefore effectively only handling the last of a row of mouse motion events in the event queue) */ @@ -104,7 +127,7 @@ static boolean NextValidEvent(Event *event) NextEvent(event); - if (FilterMouseMotionEvents(event)) + if (FilterEventsExt(event)) handle_this_event = TRUE; if (SkipPressedMouseMotionEvent(event)) @@ -137,7 +160,15 @@ void EventLoop(void) case EVENT_MOTIONNOTIFY: HandleMotionEvent((MotionEvent *) &event); break; - + +#if defined(TARGET_SDL2) + case EVENT_FINGERPRESS: + case EVENT_FINGERRELEASE: + case EVENT_FINGERMOTION: + HandleFingerEvent((FingerEvent *) &event); + break; +#endif + case EVENT_KEYPRESS: case EVENT_KEYRELEASE: HandleKeyEvent((KeyEvent *) &event); @@ -318,7 +349,7 @@ void SleepWhileUnmapped() void HandleExposeEvent(ExposeEvent *event) { -#ifndef TARGET_SDL +#if !defined(TARGET_SDL) RedrawPlayfield(FALSE, event->x, event->y, event->width, event->height); FlushDisplay(); #endif @@ -354,6 +385,33 @@ void HandleMotionEvent(MotionEvent *event) HandleButton(event->x, event->y, button_status, button_status); } +#if defined(TARGET_SDL2) +void HandleFingerEvent(FingerEvent *event) +{ + // #if DEBUG_EVENTS + Error(ERR_DEBUG, "FINGER EVENT: finger was %s, touch ID %lld, finger ID %lld, x/y %f/%f, dx/dy %f/%f, pressure %f", + (event->type == EVENT_FINGERPRESS ? "pressed" : + event->type == EVENT_FINGERRELEASE ? "released" : "moved"), + event->touchId, + event->fingerId, + event->x, event->y, + event->dx, event->dy, + event->pressure); + // #endif + +#if 1 + CloseAllAndExit(0); +#else + if (event->type == EVENT_FINGERPRESS) + button_status = event->button; + else + button_status = MB_RELEASED; + + HandleButton(event->x, event->y, button_status, event->button); +#endif +} +#endif + void HandleKeyEvent(KeyEvent *event) { int key_status = (event->type==EVENT_KEYPRESS ? KEY_PRESSED : KEY_RELEASED); @@ -465,7 +523,11 @@ void HandleButton(int mx, int my, int button, int button_nr) break; case GAME_MODE_LEVELS: - HandleChooseLevel(mx, my, 0, 0, button); + HandleChooseLevelSet(mx, my, 0, 0, button); + break; + + case GAME_MODE_LEVELNR: + HandleChooseLevelNr(mx, my, 0, 0, button); break; case GAME_MODE_SCORES: @@ -871,6 +933,7 @@ void HandleKey(Key key, int key_status) case GAME_MODE_TITLE: case GAME_MODE_MAIN: case GAME_MODE_LEVELS: + case GAME_MODE_LEVELNR: case GAME_MODE_SETUP: case GAME_MODE_INFO: case GAME_MODE_SCORES: @@ -883,7 +946,9 @@ void HandleKey(Key key, int key_status) else if (game_status == GAME_MODE_MAIN) HandleMainMenu(0, 0, 0, 0, MB_MENU_CHOICE); else if (game_status == GAME_MODE_LEVELS) - HandleChooseLevel(0, 0, 0, 0, MB_MENU_CHOICE); + HandleChooseLevelSet(0, 0, 0, 0, MB_MENU_CHOICE); + else if (game_status == GAME_MODE_LEVELNR) + HandleChooseLevelNr(0, 0, 0, 0, MB_MENU_CHOICE); else if (game_status == GAME_MODE_SETUP) HandleSetupScreen(0, 0, 0, 0, MB_MENU_CHOICE); else if (game_status == GAME_MODE_INFO) @@ -899,7 +964,9 @@ void HandleKey(Key key, int key_status) if (game_status == GAME_MODE_TITLE) HandleTitleScreen(0, 0, 0, 0, MB_MENU_LEAVE); else if (game_status == GAME_MODE_LEVELS) - HandleChooseLevel(0, 0, 0, 0, MB_MENU_LEAVE); + HandleChooseLevelSet(0, 0, 0, 0, MB_MENU_LEAVE); + else if (game_status == GAME_MODE_LEVELNR) + HandleChooseLevelNr(0, 0, 0, 0, MB_MENU_LEAVE); else if (game_status == GAME_MODE_SETUP) HandleSetupScreen(0, 0, 0, 0, MB_MENU_LEAVE); else if (game_status == GAME_MODE_INFO) @@ -910,7 +977,9 @@ void HandleKey(Key key, int key_status) case KSYM_Page_Up: if (game_status == GAME_MODE_LEVELS) - HandleChooseLevel(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK); + HandleChooseLevelSet(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK); + else if (game_status == GAME_MODE_LEVELNR) + HandleChooseLevelNr(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK); else if (game_status == GAME_MODE_SETUP) HandleSetupScreen(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK); else if (game_status == GAME_MODE_INFO) @@ -921,7 +990,9 @@ void HandleKey(Key key, int key_status) case KSYM_Page_Down: if (game_status == GAME_MODE_LEVELS) - HandleChooseLevel(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK); + HandleChooseLevelSet(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK); + else if (game_status == GAME_MODE_LEVELNR) + HandleChooseLevelNr(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK); else if (game_status == GAME_MODE_SETUP) HandleSetupScreen(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK); else if (game_status == GAME_MODE_INFO) @@ -999,7 +1070,7 @@ void HandleKey(Key key, int key_status) } break; - case KSYM_S: + case KSYM_s: if (!global.fps_slowdown) { global.fps_slowdown = TRUE; @@ -1020,17 +1091,17 @@ void HandleKey(Key key, int key_status) break; case KSYM_f: - ScrollStepSize = TILEX/8; + ScrollStepSize = TILEX / 8; printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize); break; case KSYM_g: - ScrollStepSize = TILEX/4; + ScrollStepSize = TILEX / 4; printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize); break; case KSYM_h: - ScrollStepSize = TILEX/2; + ScrollStepSize = TILEX / 2; printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize); break; @@ -1124,10 +1195,11 @@ void HandleJoystick() case GAME_MODE_TITLE: case GAME_MODE_MAIN: case GAME_MODE_LEVELS: + case GAME_MODE_LEVELNR: case GAME_MODE_SETUP: case GAME_MODE_INFO: { - static unsigned long joystickmove_delay = 0; + static unsigned int joystickmove_delay = 0; if (joystick && !button && !DelayReached(&joystickmove_delay, GADGET_FRAME_DELAY)) @@ -1138,7 +1210,9 @@ void HandleJoystick() else if (game_status == GAME_MODE_MAIN) HandleMainMenu(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); else if (game_status == GAME_MODE_LEVELS) - HandleChooseLevel(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); + HandleChooseLevelSet(0,0,dx,dy,newbutton?MB_MENU_CHOICE : MB_MENU_MARK); + else if (game_status == GAME_MODE_LEVELNR) + HandleChooseLevelNr(0,0,dx,dy,newbutton? MB_MENU_CHOICE : MB_MENU_MARK); else if (game_status == GAME_MODE_SETUP) HandleSetupScreen(0,0,dx,dy, newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); else if (game_status == GAME_MODE_INFO)