#571 hide touch input after 10 sec

This commit is contained in:
Vadim Grigoruk 2018-08-09 20:41:11 +03:00
parent 56a6737131
commit 679a91c622
1 changed files with 23 additions and 2 deletions

View File

@ -63,6 +63,8 @@ static struct
} keyboard; } keyboard;
u32 touchCounter;
struct struct
{ {
GPU_Image* texture; GPU_Image* texture;
@ -439,6 +441,8 @@ static bool checkTouch(const SDL_Rect* rect, s32* x, s32* y)
static void processTouchKeyboard() static void processTouchKeyboard()
{ {
if(platform.touchCounter == 0) return;
enum{Cols=KBD_COLS, Rows=KBD_ROWS}; enum{Cols=KBD_COLS, Rows=KBD_ROWS};
s32 w, h; s32 w, h;
@ -496,9 +500,11 @@ static void processTouchKeyboard()
} }
static void processTouchGamepad() static void processTouchGamepad()
{ {
platform.gamepad.touch.data = 0; platform.gamepad.touch.data = 0;
if(platform.touchCounter == 0) return;
const s32 size = platform.gamepad.part.size; const s32 size = platform.gamepad.part.size;
s32 x = 0, y = 0; s32 x = 0, y = 0;
@ -666,6 +672,16 @@ static void processJoysticks()
static void processGamepad() static void processGamepad()
{ {
#if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__) #if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__)
{
s32 devices = SDL_GetNumTouchDevices();
for (s32 i = 0; i < devices; i++)
if(SDL_GetNumTouchFingers(SDL_GetTouchDevice(i)) > 0)
platform.touchCounter = 10 * TIC_FRAMERATE;
if(platform.touchCounter)
platform.touchCounter--;
}
processTouchGamepad(); processTouchGamepad();
processTouchKeyboard(); processTouchKeyboard();
#endif #endif
@ -804,10 +820,11 @@ static void blitSound()
static void renderKeyboard() static void renderKeyboard()
{ {
if(platform.touchCounter == 0) return;
SDL_Rect rect; SDL_Rect rect;
SDL_GetWindowSize(platform.window, &rect.w, &rect.h); SDL_GetWindowSize(platform.window, &rect.w, &rect.h);
GPU_Rect src = {OFFSET_LEFT, OFFSET_TOP, KBD_COLS*TIC_SPRITESIZE, KBD_ROWS*TIC_SPRITESIZE}; GPU_Rect src = {OFFSET_LEFT, OFFSET_TOP, KBD_COLS*TIC_SPRITESIZE, KBD_ROWS*TIC_SPRITESIZE};
float scale = rect.w/src.w; float scale = rect.w/src.w;
GPU_Rect dst = (GPU_Rect){0, rect.h - KBD_ROWS*TIC_SPRITESIZE*scale, scale, scale}; GPU_Rect dst = (GPU_Rect){0, rect.h - KBD_ROWS*TIC_SPRITESIZE*scale, scale, scale};
@ -853,6 +870,8 @@ static void renderKeyboard()
static void renderGamepad() static void renderGamepad()
{ {
if(platform.touchCounter == 0) return;
const s32 tileSize = platform.gamepad.part.size; const s32 tileSize = platform.gamepad.part.size;
const SDL_Point axis = platform.gamepad.part.axis; const SDL_Point axis = platform.gamepad.part.axis;
typedef struct { bool press; s32 x; s32 y;} Tile; typedef struct { bool press; s32 x; s32 y;} Tile;
@ -1292,9 +1311,11 @@ static void gpuTick()
renderCursor(); renderCursor();
#if !defined(__EMSCRIPTEN__) && !defined(__MACOSX__)
platform.studio->isGamepadMode() platform.studio->isGamepadMode()
? renderGamepad() ? renderGamepad()
: renderKeyboard(); : renderKeyboard();
#endif
} }
GPU_Flip(platform.gpu.screen); GPU_Flip(platform.gpu.screen);