X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=882aa11cd2647031bd972c5390e0796b1bc15cd2;hp=877bb16eb3bdd35d0dff071a389a1cdbb95b2746;hb=115ce6f2da1914d68b0fe0e5f9082973190dacdd;hpb=164e6c72eba4eac8002bd6b334579e78e5010d0f diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 877bb16e..882aa11c 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -245,6 +245,20 @@ static void UpdateScreen_WithoutFrameDelay(SDL_Rect *rect) UpdateScreenExt(rect, FALSE); } +void Delay_WithScreenUpdates(unsigned int delay) +{ + unsigned int time_current = SDL_GetTicks(); + unsigned int time_delayed = time_current + delay; + + while (time_current < time_delayed) + { + // updating the screen contains waiting for frame delay (non-busy) + UpdateScreen_WithFrameDelay(NULL); + + time_current = SDL_GetTicks(); + } +} + static void SDLSetWindowIcon(char *basename) { /* (setting the window icon on Mac OS X would replace the high-quality @@ -541,7 +555,7 @@ inline static void SDLInitVideoBuffer_VideoBuffer(boolean fullscreen) SDLSetWindowTitle(); } -inline static void SDLInitVideoBuffer_DrawBuffer() +inline static void SDLInitVideoBuffer_DrawBuffer(void) { /* SDL cannot directly draw to the visible video framebuffer like X11, but always uses a backbuffer, which is then blitted to the visible @@ -829,7 +843,7 @@ boolean SDLSetVideoMode(boolean fullscreen) return success; } -void SDLSetWindowTitle() +void SDLSetWindowTitle(void) { #if defined(TARGET_SDL2) if (sdl_window == NULL) @@ -922,7 +936,7 @@ void SDLSetWindowFullscreen(boolean fullscreen) } } -void SDLSetDisplaySize() +void SDLSetDisplaySize(void) { SDL_Rect display_bounds; @@ -976,7 +990,7 @@ void SDLSetScreenSizeForRenderer(int width, int height) SDL_RenderSetLogicalSize(sdl_renderer, width, height); } -void SDLSetScreenProperties() +void SDLSetScreenProperties(void) { SDLSetScreenSizeAndOffsets(video.width, video.height); SDLSetScreenSizeForRenderer(video.screen_width, video.screen_height); @@ -999,7 +1013,7 @@ void SDLSetScreenRenderingMode(char *screen_rendering_mode) #endif } -void SDLRedrawWindow() +void SDLRedrawWindow(void) { UpdateScreen_WithoutFrameDelay(NULL); } @@ -1389,20 +1403,7 @@ void SDLFadeRectangle(int x, int y, int width, int height, } if (post_delay > 0) - { - unsigned int time_post_delay; - - time_current = SDL_GetTicks(); - time_post_delay = time_current + post_delay; - - while (time_current < time_post_delay) - { - // updating the screen contains waiting for frame delay (non-busy) - UpdateScreen_WithFrameDelay(NULL); - - time_current = SDL_GetTicks(); - } - } + Delay_WithScreenUpdates(post_delay); // restore function for drawing global masked border gfx.draw_global_border_function = draw_global_border_function; @@ -2606,7 +2607,7 @@ static int sdl_js_axis[MAX_PLAYERS][2]; static int sdl_js_button[MAX_PLAYERS][2]; static boolean sdl_is_controller[MAX_PLAYERS]; -void SDLClearJoystickState() +void SDLClearJoystickState(void) { int i, j; @@ -2847,7 +2848,7 @@ void HandleJoystickEvent(Event *event) } } -void SDLInitJoysticks() +void SDLInitJoysticks(void) { static boolean sdl_joystick_subsystem_initialized = FALSE; boolean print_warning = !sdl_joystick_subsystem_initialized; @@ -3012,12 +3013,19 @@ static void DrawTouchInputOverlay_ShowGrid(int alpha) SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 255); } +static void RenderFillRectangle(int x, int y, int width, int height) +{ + SDL_Rect rect = { x, y, width, height }; + + SDL_RenderFillRect(sdl_renderer, &rect); +} + static void DrawTouchInputOverlay_ShowGridButtons(int alpha) { - static int alpha_max = SDL_ALPHA_OPAQUE / 2; - static int alpha_step = 5; static int alpha_direction = 0; static int alpha_highlight = 0; + int alpha_max = ALPHA_FROM_TRANSPARENCY(setup.touch.transparency); + int alpha_step = ALPHA_FADING_STEPSIZE(alpha_max); SDL_Rect rect; int grid_xsize = overlay.grid_xsize; int grid_ysize = overlay.grid_ysize; @@ -3050,38 +3058,110 @@ static void DrawTouchInputOverlay_ShowGridButtons(int alpha) for (x = 0; x < grid_xsize; x++) { - rect.x = (x + 0) * video.screen_width / grid_xsize; - rect.w = (x + 1) * video.screen_width / grid_xsize - rect.x; - for (y = 0; y < grid_ysize; y++) { + int grid_button = overlay.grid_button[x][y]; + int grid_button_action = GET_ACTION_FROM_GRID_BUTTON(grid_button); + int alpha_draw = alpha; + int outline_border = MV_NONE; + int border_size = 2; + boolean draw_outlined = setup.touch.draw_outlined; + boolean draw_pressed = setup.touch.draw_pressed; + + if (grid_button == CHAR_GRID_BUTTON_NONE) + continue; + + if (grid_button == overlay.grid_button_highlight) + alpha_draw = alpha_highlight; + + if (draw_pressed && overlay.grid_button_action & grid_button_action) + { + if (draw_outlined) + draw_outlined = FALSE; + else + alpha_draw = MIN((float)alpha_draw * 1.5, SDL_ALPHA_OPAQUE); + } + + SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha_draw); + + rect.x = (x + 0) * video.screen_width / grid_xsize; rect.y = (y + 0) * video.screen_height / grid_ysize; + rect.w = (x + 1) * video.screen_width / grid_xsize - rect.x; rect.h = (y + 1) * video.screen_height / grid_ysize - rect.y; - if (overlay.grid_button[x][y] == overlay.grid_button_highlight) - SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha_highlight); - else - SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha); + if (x == 0 || overlay.grid_button[x - 1][y] != grid_button) + { + rect.x += border_size; + rect.w -= border_size; + + outline_border |= MV_LEFT; + } + + if (x == grid_xsize - 1 || overlay.grid_button[x + 1][y] != grid_button) + { + rect.w -= border_size; + + outline_border |= MV_RIGHT; + } + + if (y == 0 || overlay.grid_button[x][y - 1] != grid_button) + { + rect.y += border_size; + rect.h -= border_size; + + outline_border |= MV_UP; + } + + if (y == grid_ysize - 1 || overlay.grid_button[x][y + 1] != grid_button) + { + rect.h -= border_size; + + outline_border |= MV_DOWN; + } + + if (draw_outlined) + { + int rect_x = rect.x + + (outline_border & MV_LEFT ? border_size : 0); + int rect_w = rect.w - + (outline_border & MV_LEFT ? border_size : 0) - + (outline_border & MV_RIGHT ? border_size : 0); - if (overlay.grid_button[x][y] != CHAR_GRID_BUTTON_NONE) + if (outline_border & MV_LEFT) + RenderFillRectangle(rect.x, rect.y, border_size, rect.h); + + if (outline_border & MV_RIGHT) + RenderFillRectangle(rect.x + rect.w - border_size, rect.y, + border_size, rect.h); + + if (outline_border & MV_UP) + RenderFillRectangle(rect_x, rect.y, rect_w, border_size); + + if (outline_border & MV_DOWN) + RenderFillRectangle(rect_x, rect.y + rect.h - border_size, + rect_w, border_size); + } + else + { SDL_RenderFillRect(sdl_renderer, &rect); + } } } SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 255); } -static void DrawTouchInputOverlay() +static void DrawTouchInputOverlay(void) { static SDL_Texture *texture = NULL; static boolean initialized = FALSE; static boolean deactivated = TRUE; static boolean show_grid = FALSE; static int width = 0, height = 0; - static int alpha_max = SDL_ALPHA_OPAQUE / 2; - static int alpha_step = 5; static int alpha_last = -1; static int alpha = 0; + int alpha_max = ALPHA_FROM_TRANSPARENCY(setup.touch.transparency); + int alpha_step = ALPHA_FADING_STEPSIZE(alpha_max); boolean active = (overlay.enabled && overlay.active); if (!active && deactivated)