X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=a11452bb32b42de9f8774f21541b6313c6d28042;hp=9ed0e49da6bc6367e88ae84be0c781780abd2fe1;hb=31f32eb8fe7e5e39fb449968afce809c13509099;hpb=67b32ebb347487d2d3a9d926ad8d1c4ed3d9aec6 diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 9ed0e49d..a11452bb 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -37,8 +37,10 @@ static boolean limit_screen_updates = FALSE; /* functions from SGE library */ void sge_Line(SDL_Surface *, Sint16, Sint16, Sint16, Sint16, Uint32); +#if defined(USE_TOUCH_INPUT_OVERLAY) /* functions to draw overlay graphics for touch device input */ static void DrawTouchInputOverlay(); +#endif void SDLLimitScreenUpdates(boolean enable) { @@ -205,8 +207,11 @@ static void UpdateScreenExt(SDL_Rect *rect, boolean with_frame_delay) SDL_RenderCopy(sdl_renderer, sdl_texture_target, src_rect2, dst_rect2); } +#if defined(USE_TOUCH_INPUT_OVERLAY) // draw overlay graphics for touch device input, if needed DrawTouchInputOverlay(); +#endif + #endif // global synchronization point of the game to align video frame delay @@ -565,10 +570,10 @@ static boolean SDLCreateScreen(boolean fullscreen) it will crash if flags are *not* set to SDL_RENDERER_SOFTWARE (because it will try to use accelerated graphics and apparently fails miserably) */ int renderer_flags = SDL_RENDERER_SOFTWARE; -#endif #endif SDLSetScreenSizeAndOffsets(video.width, video.height); +#endif int width = video.width; int height = video.height; @@ -2685,9 +2690,9 @@ boolean SDLReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2) return TRUE; } +#if defined(USE_TOUCH_INPUT_OVERLAY) static void DrawTouchInputOverlay() { -#if defined(USE_TOUCH_INPUT_OVERLAY) static SDL_Texture *texture = NULL; static boolean initialized = FALSE; static boolean deactivated = TRUE; @@ -2753,9 +2758,29 @@ static void DrawTouchInputOverlay() alpha_last = alpha; + float ratio_overlay = (float) width / height; + float ratio_screen = (float) video.screen_width / video.screen_height; + int width_scaled, height_scaled; + int xpos, ypos; + + if (ratio_overlay > ratio_screen) + { + width_scaled = video.screen_width; + height_scaled = video.screen_height * ratio_screen / ratio_overlay; + xpos = 0; + ypos = video.screen_height - height_scaled; + } + else + { + width_scaled = video.screen_width * ratio_overlay / ratio_screen; + height_scaled = video.screen_height; + xpos = (video.screen_width - width_scaled) / 2; + ypos = 0; + } + SDL_Rect src_rect = { 0, 0, width, height }; - SDL_Rect dst_rect = { 0, 0, video.screen_width, video.screen_height }; + SDL_Rect dst_rect = { xpos, ypos, width_scaled, height_scaled }; SDL_RenderCopy(sdl_renderer, texture, &src_rect, &dst_rect); -#endif } +#endif