From: Holger Schemel Date: Thu, 1 Dec 2016 22:36:28 +0000 (+0100) Subject: added overlay graphics for virtual buttons for touch devices (Android) X-Git-Tag: 4.0.0.0~9 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=67b32ebb347487d2d3a9d926ad8d1c4ed3d9aec6 added overlay graphics for virtual buttons for touch devices (Android) --- diff --git a/graphics/gfx_classic/Makefile b/graphics/gfx_classic/Makefile index 041f3c8f..194e6e6b 100644 --- a/graphics/gfx_classic/Makefile +++ b/graphics/gfx_classic/Makefile @@ -20,25 +20,26 @@ RM = rm -f # EXT = pcx EXT = png -FILES = RocksBusy.$(EXT) \ - RocksDC.$(EXT) \ - RocksDC2.$(EXT) \ - RocksDoor.$(EXT) \ - RocksDoor2.$(EXT) \ - RocksEMC.$(EXT) \ - RocksElements.$(EXT) \ - RocksFontBig.$(EXT) \ - RocksFontDC.$(EXT) \ - RocksFontEM.$(EXT) \ - RocksFontMedium.$(EXT) \ - RocksFontSmall.$(EXT) \ - RocksHeroes.$(EXT) \ - RocksMore.$(EXT) \ - RocksSP.$(EXT) \ - RocksScreen.$(EXT) \ - RocksToons.$(EXT) \ - \ - RocksCE.$(EXT) # dynamically generated from template +FILES = RocksBusy.$(EXT) \ + RocksDC.$(EXT) \ + RocksDC2.$(EXT) \ + RocksDoor.$(EXT) \ + RocksDoor2.$(EXT) \ + RocksEMC.$(EXT) \ + RocksElements.$(EXT) \ + RocksFontBig.$(EXT) \ + RocksFontDC.$(EXT) \ + RocksFontEM.$(EXT) \ + RocksFontMedium.$(EXT) \ + RocksFontSmall.$(EXT) \ + RocksHeroes.$(EXT) \ + RocksMore.$(EXT) \ + RocksSP.$(EXT) \ + RocksScreen.$(EXT) \ + RocksToons.$(EXT) \ + overlay/VirtualButtons.$(EXT) \ + \ + RocksCE.$(EXT) # dynamically generated from template # ----------------------------------------------------------------------------- diff --git a/graphics/gfx_classic/overlay/VirtualButtons.ilbm b/graphics/gfx_classic/overlay/VirtualButtons.ilbm new file mode 100644 index 00000000..75892ef2 Binary files /dev/null and b/graphics/gfx_classic/overlay/VirtualButtons.ilbm differ diff --git a/src/init.c b/src/init.c index 8595288c..5e996f33 100644 --- a/src/init.c +++ b/src/init.c @@ -5926,6 +5926,8 @@ void OpenAll() InitVideoDisplay(); InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen); + InitOverlayInfo(); + print_timestamp_time("[init video stuff]"); InitElementPropertiesStatic(); diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 661bf6fb..9ed0e49d 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -37,6 +37,9 @@ static boolean limit_screen_updates = FALSE; /* functions from SGE library */ void sge_Line(SDL_Surface *, Sint16, Sint16, Sint16, Sint16, Uint32); +/* functions to draw overlay graphics for touch device input */ +static void DrawTouchInputOverlay(); + void SDLLimitScreenUpdates(boolean enable) { limit_screen_updates = enable; @@ -201,6 +204,9 @@ static void UpdateScreenExt(SDL_Rect *rect, boolean with_frame_delay) SDL_SetRenderTarget(sdl_renderer, NULL); SDL_RenderCopy(sdl_renderer, sdl_texture_target, src_rect2, dst_rect2); } + + // draw overlay graphics for touch device input, if needed + DrawTouchInputOverlay(); #endif // global synchronization point of the game to align video frame delay @@ -910,7 +916,7 @@ void SDLSetScreenSizeAndOffsets(int width, int height) video.screen_xoffset = 0; video.screen_yoffset = 0; -#if defined(PLATFORM_ANDROID) +#if defined(USE_COMPLETE_DISPLAY) float ratio_video = (float) width / height; float ratio_display = (float) video.display_width / video.display_height; @@ -2678,3 +2684,78 @@ boolean SDLReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2) return TRUE; } + +static void DrawTouchInputOverlay() +{ +#if defined(USE_TOUCH_INPUT_OVERLAY) + static SDL_Texture *texture = NULL; + static boolean initialized = FALSE; + static boolean deactivated = TRUE; + static int width = 0, height = 0; + static int alpha_max = SDL_ALPHA_OPAQUE / 2; + static int alpha_step = 5; + static int alpha_last = 0; + static int alpha = 0; + + if (!overlay.active && deactivated) + return; + + if (overlay.active) + { + if (alpha < alpha_max) + alpha = MIN(alpha + alpha_step, alpha_max); + + deactivated = FALSE; + } + else + { + alpha = MAX(0, alpha - alpha_step); + + if (alpha == 0) + deactivated = TRUE; + } + + if (!initialized) + { + char *basename = "overlay/VirtualButtons.png"; + char *filename = getCustomImageFilename(basename); + + if (filename == NULL) + Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename); + + SDL_Surface *surface; + + if ((surface = IMG_Load(filename)) == NULL) + Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError()); + + width = surface->w; + height = surface->h; + + /* set black pixel to transparent if no alpha channel / transparent color */ + if (!SDLHasAlpha(surface) && + !SDLHasColorKey(surface)) + SDL_SetColorKey(surface, SET_TRANSPARENT_PIXEL, + SDL_MapRGB(surface->format, 0x00, 0x00, 0x00)); + + if ((texture = SDLCreateTextureFromSurface(surface)) == NULL) + Error(ERR_EXIT, "SDLCreateTextureFromSurface() failed"); + + SDL_FreeSurface(surface); + + SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); + SDL_SetTextureAlphaMod(texture, alpha_max); + + initialized = TRUE; + } + + if (alpha != alpha_last) + SDL_SetTextureAlphaMod(texture, alpha); + + alpha_last = alpha; + + SDL_Rect src_rect = { 0, 0, width, height }; + SDL_Rect dst_rect = { 0, 0, video.screen_width, video.screen_height }; + + SDL_RenderCopy(sdl_renderer, texture, &src_rect, &dst_rect); +#endif +} diff --git a/src/libgame/system.c b/src/libgame/system.c index 98ccd70c..5443e87d 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -33,6 +33,7 @@ struct OptionInfo options; struct VideoSystemInfo video; struct AudioSystemInfo audio; struct GfxInfo gfx; +struct OverlayInfo overlay; struct ArtworkInfo artwork; struct JoystickInfo joystick; struct SetupInfo setup; @@ -270,6 +271,21 @@ void InitGfxOtherSettings() gfx.cursor_mode = CURSOR_DEFAULT; } +void InitOverlayInfo() +{ + overlay.active = FALSE; +} + +void SetOverlayActive(boolean active) +{ + overlay.active = active; +} + +boolean GetOverlayActive() +{ + return overlay.active; +} + void SetDrawDeactivationMask(int draw_deactivation_mask) { gfx.draw_deactivation_mask = draw_deactivation_mask; diff --git a/src/libgame/system.h b/src/libgame/system.h index 3b51f91d..b6cea7b5 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -93,8 +93,10 @@ #define TOUCH_DROP_DISTANCE_DEFAULT 5 -/* values for screen keyboard on mobile devices */ +/* values for special settings for mobile devices */ #if defined(PLATFORM_ANDROID) +#define USE_TOUCH_INPUT_OVERLAY +#define USE_COMPLETE_DISPLAY #define HAS_SCREEN_KEYBOARD #define SCREEN_KEYBOARD_POS(h) ((h) / 2) #endif @@ -910,6 +912,11 @@ struct GfxInfo int cursor_mode; }; +struct OverlayInfo +{ + boolean active; +}; + struct JoystickInfo { int status; @@ -1373,6 +1380,7 @@ extern struct OptionInfo options; extern struct VideoSystemInfo video; extern struct AudioSystemInfo audio; extern struct GfxInfo gfx; +extern struct OverlayInfo overlay; extern struct AnimInfo anim; extern struct ArtworkInfo artwork; extern struct JoystickInfo joystick; @@ -1427,6 +1435,9 @@ void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(int, int)); void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int)); void InitGfxCustomArtworkInfo(); void InitGfxOtherSettings(); +void InitOverlayInfo(); +void SetOverlayActive(boolean); +boolean GetOverlayActive(); void SetDrawDeactivationMask(int); void SetDrawBackgroundMask(int); void SetWindowBackgroundBitmap(Bitmap *); diff --git a/src/tools.c b/src/tools.c index 133a8265..794174c1 100644 --- a/src/tools.c +++ b/src/tools.c @@ -926,6 +926,10 @@ void FadeIn(int fade_mask) FADE_SXSIZE = FULL_SXSIZE; FADE_SYSIZE = FULL_SYSIZE; + if (game_status == GAME_MODE_PLAYING && + strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS)) + SetOverlayActive(TRUE); + SetScreenStates_AfterFadingIn(); // force update of global animation status in case of rapid screen changes @@ -941,6 +945,8 @@ void FadeOut(int fade_mask) SetScreenStates_BeforeFadingOut(); + SetOverlayActive(FALSE); + #if 0 DrawMaskedBorder(REDRAW_ALL); #endif @@ -4211,10 +4217,19 @@ static boolean RequestEnvelope(char *text, unsigned int req_state) boolean Request(char *text, unsigned int req_state) { + boolean overlay_active = GetOverlayActive(); + boolean result; + + SetOverlayActive(FALSE); + if (global.use_envelope_request) - return RequestEnvelope(text, req_state); + result = RequestEnvelope(text, req_state); else - return RequestDoor(text, req_state); + result = RequestDoor(text, req_state); + + SetOverlayActive(overlay_active); + + return result; } static int compareDoorPartOrderInfo(const void *object1, const void *object2)