X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fevents.c;h=abf74ba51b1385dbf1eefe283f34da81880042b7;hp=647446226abd3a975acf79ffe6c047209c03f5bd;hb=00383dd409fde133c6738231abfcee662c03087c;hpb=19b0eb2d9f297c73cae1e57fc7774ae5ce97daf7 diff --git a/src/events.c b/src/events.c index 64744622..abf74ba5 100644 --- a/src/events.c +++ b/src/events.c @@ -58,6 +58,18 @@ static int FilterEvents(const Event *event) return 0; #endif + if (event->type == EVENT_BUTTONPRESS || + event->type == EVENT_BUTTONRELEASE) + { + ((ButtonEvent *)event)->x -= video.screen_xoffset; + ((ButtonEvent *)event)->y -= video.screen_yoffset; + } + else if (event->type == EVENT_MOTIONNOTIFY) + { + ((MotionEvent *)event)->x -= video.screen_xoffset; + ((MotionEvent *)event)->y -= video.screen_yoffset; + } + /* non-motion events are directly passed to event handler functions */ if (event->type != EVENT_MOTIONNOTIFY) return 1; @@ -509,32 +521,52 @@ void HandleWindowEvent(WindowEvent *event) SDLRedrawWindow(); #endif - if (event->event == SDL_WINDOWEVENT_RESIZED && !video.fullscreen_enabled) + if (event->event == SDL_WINDOWEVENT_RESIZED) { - int new_window_width = event->data1; - int new_window_height = event->data2; - - // if window size has changed after resizing, calculate new scaling factor - if (new_window_width != video.window_width || - new_window_height != video.window_height) + if (!video.fullscreen_enabled) { - int new_xpercent = (100 * new_window_width / video.width); - int new_ypercent = (100 * new_window_height / video.height); + int new_window_width = event->data1; + int new_window_height = event->data2; + + // if window size has changed after resizing, calculate new scaling factor + if (new_window_width != video.window_width || + new_window_height != video.window_height) + { + int new_xpercent = (100 * new_window_width / video.screen_width); + int new_ypercent = (100 * new_window_height / video.screen_height); - // (extreme window scaling allowed, but cannot be saved permanently) - video.window_scaling_percent = MIN(new_xpercent, new_ypercent); - setup.window_scaling_percent = - MIN(MAX(MIN_WINDOW_SCALING_PERCENT, video.window_scaling_percent), - MAX_WINDOW_SCALING_PERCENT); + // (extreme window scaling allowed, but cannot be saved permanently) + video.window_scaling_percent = MIN(new_xpercent, new_ypercent); + setup.window_scaling_percent = + MIN(MAX(MIN_WINDOW_SCALING_PERCENT, video.window_scaling_percent), + MAX_WINDOW_SCALING_PERCENT); - video.window_width = new_window_width; - video.window_height = new_window_height; + video.window_width = new_window_width; + video.window_height = new_window_height; - if (game_status == GAME_MODE_SETUP) - RedrawSetupScreenAfterFullscreenToggle(); + if (game_status == GAME_MODE_SETUP) + RedrawSetupScreenAfterFullscreenToggle(); - SetWindowTitle(); + SetWindowTitle(); + } } +#if defined(PLATFORM_ANDROID) + else + { + int new_display_width = event->data1; + int new_display_height = event->data2; + + // if fullscreen display size has changed, device has been rotated + if (new_display_width != video.display_width || + new_display_height != video.display_height) + { + video.display_width = new_display_width; + video.display_height = new_display_height; + + SDLSetScreenProperties(); + } + } +#endif } } @@ -585,15 +617,30 @@ void HandleFingerEvent(FingerEvent *event) { int key_status = (event->type == EVENT_FINGERRELEASE ? KEY_RELEASED : KEY_PRESSED); - Key key = (event->x < 1.0 / 3.0 ? - (event->y < 1.0 / 2.0 ? setup.input[0].key.snap : - setup.input[0].key.drop) : - event->x > 2.0 / 3.0 ? - (event->y < 1.0 / 3.0 ? setup.input[0].key.up : - event->y > 2.0 / 3.0 ? setup.input[0].key.down : - event->x < 5.0 / 6.0 ? setup.input[0].key.left : - setup.input[0].key.right) : + float ypos = 1.0 - 1.0 / 3.0 * video.display_width / video.display_height; + + event_y = (event_y - ypos) / (1 - ypos); + + Key key = (event_x > 0 && event_x < 1.0 / 6.0 && + event_y > 2.0 / 3.0 && event_y < 1 ? + setup.input[0].key.snap : + event_x > 1.0 / 6.0 && event_x < 1.0 / 3.0 && + event_y > 2.0 / 3.0 && event_y < 1 ? + setup.input[0].key.drop : + event_x > 7.0 / 9.0 && event_x < 8.0 / 9.0 && + event_y > 0 && event_y < 1.0 / 3.0 ? + setup.input[0].key.up : + event_x > 6.0 / 9.0 && event_x < 7.0 / 9.0 && + event_y > 1.0 / 3.0 && event_y < 2.0 / 3.0 ? + setup.input[0].key.left : + event_x > 8.0 / 9.0 && event_x < 1 && + event_y > 1.0 / 3.0 && event_y < 2.0 / 3.0 ? + setup.input[0].key.right : + event_x > 7.0 / 9.0 && event_x < 8.0 / 9.0 && + event_y > 2.0 / 3.0 && event_y < 1 ? + setup.input[0].key.down : KSYM_UNDEFINED); + char *key_status_name = (key_status == KEY_RELEASED ? "KEY_RELEASED" : "KEY_PRESSED"); int i;