From 67b32ebb347487d2d3a9d926ad8d1c4ed3d9aec6 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 1 Dec 2016 23:36:28 +0100 Subject: [PATCH] added overlay graphics for virtual buttons for touch devices (Android) --- graphics/gfx_classic/Makefile | 39 ++++---- .../gfx_classic/overlay/VirtualButtons.ilbm | Bin 0 -> 29624 bytes src/init.c | 2 + src/libgame/sdl.c | 83 +++++++++++++++++- src/libgame/system.c | 16 ++++ src/libgame/system.h | 13 ++- src/tools.c | 19 +++- 7 files changed, 149 insertions(+), 23 deletions(-) create mode 100644 graphics/gfx_classic/overlay/VirtualButtons.ilbm 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 0000000000000000000000000000000000000000..75892ef2b234710cec9c9582927c493fb32fa2e8 GIT binary patch literal 29624 zcmeI*u}>ON0LSs)*`#q~=-|+S(V@fr0Vb^=)h4}yBn+Ke2j(_y7#vKS7sIMk2L^R& z8Wx=yEJ;TOx^=;v|G}|2FucCULF1b{6v{V2;CE<(FL$5&oxB&HSL=!N@#@9PQc_Cx zb|gJ|a2!2xk9w%c-A9qnyD-216z0z-VLm+%^TlPDufB)5KMeEFG|abIsk-x8`k;~3c;xP*@xObj{*4rm z++J~`D4sqL84Y#@js;{uLL@{&Bt$|aL_#D)LL@{&Bt$|aL_#D)LL@{&Bt$|aL_#D) zLL@{&B>b-=oX$^~PZL?Np#IoRamvD(D{Pui>0u-o3675G>^2Ss4h0Sc4uxQjD=2^h zD1ZVea3M9n!et~F3I3)qTN6Yy)N z2r?Rs25XmCyTsZhBt$|aL_#D)LL@{&Bt$|aL_#D)LL@{&Bt$|aL_#D)LL@{&Bt$|a MTtW#K;eRjw1_n8o8vpw; + 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) -- 2.34.1