[sdl2] better (but not quite there yet) key animation

This commit is contained in:
Gwenhael Le Moine 2024-09-06 21:56:22 +02:00
parent f0c27d9b5f
commit d3a181682c
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -683,12 +683,12 @@ static void _draw_key( int hpkey )
{ {
int x = KEYBOARD_OFFSET_X + BUTTONS[ hpkey ].x; int x = KEYBOARD_OFFSET_X + BUTTONS[ hpkey ].x;
int y = KEYBOARD_OFFSET_Y + BUTTONS[ hpkey ].y; int y = KEYBOARD_OFFSET_Y + BUTTONS[ hpkey ].y;
/* if ( keyboard[ hpkey ].pressed ) { */ if ( keyboard[ hpkey ].pressed ) {
/* x += 1; */ // x += 1;
/* y += 2; */ y += 1;
/* } */ }
__draw_texture( x, y, BUTTONS[ hpkey ].w, BUTTONS[ hpkey ].h, __draw_texture( x, y, BUTTONS[ hpkey ].w, BUTTONS[ hpkey ].h,
keyboard[ hpkey ].pressed ? buttons_textures[ hpkey ].down : buttons_textures[ hpkey ].up ); /* keyboard[ hpkey ].pressed ? buttons_textures[ hpkey ].down : */ buttons_textures[ hpkey ].up );
} }
static void _draw_keys( void ) static void _draw_keys( void )
@ -849,16 +849,25 @@ static void _show_key( int hpkey )
if ( hpkey < 0 ) if ( hpkey < 0 )
return; return;
// If we're called with the same key as before, do nothing SDL_SetRenderTarget( renderer, main_texture );
if ( showkeylastkey == hpkey )
return;
showkeylastkey = hpkey; _draw_key( hpkey );
/* SDL_Rect srect, drect; */ SDL_SetRenderTarget( renderer, NULL );
/* SDL_Surface* ssurf; */ SDL_RenderCopy( renderer, main_texture, NULL, NULL );
int x = 0; SDL_RenderPresent( renderer );
int y = 0;
return;
/* // If we're called with the same key as before, do nothing */
/* if ( showkeylastkey == hpkey ) */
/* return; */
/* showkeylastkey = hpkey; */
/* /\* SDL_Rect srect, drect; *\/ */
/* /\* SDL_Surface* ssurf; *\/ */
/* int x = 0; */
/* int y = 0; */
/* // Starts by hiding last */ /* // Starts by hiding last */
/* if ( showkeylast_texture != 0 ) { */ /* if ( showkeylast_texture != 0 ) { */
@ -895,9 +904,9 @@ static void _show_key( int hpkey )
/* if ( y + ssurf->h > window->h ) */ /* if ( y + ssurf->h > window->h ) */
/* y = window->h - ssurf->h; */ /* y = window->h - ssurf->h; */
// Backup where to /* // Backup where to */
showkeylastx = x; /* showkeylastx = x; */
showkeylasty = y; /* showkeylasty = y; */
/* // Backup old surface */ /* // Backup old surface */
/* srect.x = x; */ /* srect.x = x; */
@ -1028,9 +1037,10 @@ void sdl_get_event( void )
// React to mouse up/down when click over a button // React to mouse up/down when click over a button
if ( hpkey == -1 || keyboard[ hpkey ].pressed ) if ( hpkey == -1 || keyboard[ hpkey ].pressed )
break; break;
pressed_hpkey = hpkey; pressed_hpkey = hpkey;
press_key( hpkey ); press_key( hpkey );
_show_key( pressed_hpkey );
lasthpkey = hpkey; lasthpkey = hpkey;
// Start timer // Start timer
lastticks = SDL_GetTicks(); lastticks = SDL_GetTicks();
@ -1041,12 +1051,14 @@ void sdl_get_event( void )
if ( hpkey == -1 ) if ( hpkey == -1 )
break; break;
pressed_hpkey = -1;
if ( !lastislongpress ) { if ( !lastislongpress ) {
release_all_keys(); release_all_keys();
lasthpkey = -1; // No key is pressed anymore lasthpkey = -1; // No key is pressed anymore
} }
_show_key( pressed_hpkey );
pressed_hpkey = -1;
// Stop timer, clear long key press // Stop timer, clear long key press
lastticks = -1; lastticks = -1;
lastislongpress = false; lastislongpress = false;
@ -1059,21 +1071,24 @@ void sdl_get_event( void )
pressed_hpkey = hpkey; pressed_hpkey = hpkey;
press_key( hpkey ); press_key( hpkey );
_show_key( pressed_hpkey );
break; break;
case SDL_KEYUP: case SDL_KEYUP:
hpkey = sdlkey_to_hpkey( event.key.keysym.sym ); hpkey = sdlkey_to_hpkey( event.key.keysym.sym );
if ( hpkey == -1 ) if ( hpkey == -1 )
break; break;
pressed_hpkey = -1;
release_key( hpkey ); release_key( hpkey );
_show_key( pressed_hpkey );
pressed_hpkey = -1;
break; break;
} }
} }
// Display button being pressed, if any /* // Display button being pressed, if any */
if ( !config.hide_chrome && pressed_hpkey != 1 ) /* if ( !config.hide_chrome && pressed_hpkey != 1 ) */
_show_key( pressed_hpkey ); /* _show_key( pressed_hpkey ); */
} }
void sdl_update_LCD( void ) void sdl_update_LCD( void )