[sdl2] on/off => up/down
This commit is contained in:
parent
e374ba61a7
commit
571c449a9a
1 changed files with 88 additions and 80 deletions
168
src/ui_sdl2.c
168
src/ui_sdl2.c
|
@ -40,8 +40,8 @@
|
||||||
/* typedef */
|
/* typedef */
|
||||||
/***********/
|
/***********/
|
||||||
typedef struct on_off_sdl_textures_struct_t {
|
typedef struct on_off_sdl_textures_struct_t {
|
||||||
SDL_Texture* on;
|
SDL_Texture* up;
|
||||||
SDL_Texture* off;
|
SDL_Texture* down;
|
||||||
} on_off_sdl_textures_struct_t;
|
} on_off_sdl_textures_struct_t;
|
||||||
|
|
||||||
/*************/
|
/*************/
|
||||||
|
@ -55,7 +55,7 @@ static on_off_sdl_textures_struct_t annunciators_textures[ NB_ANNUNCIATORS ];
|
||||||
|
|
||||||
// State to displayed zoomed last pressed key
|
// State to displayed zoomed last pressed key
|
||||||
/* static SDL_Texture* showkeylast_texture = 0; */
|
/* static SDL_Texture* showkeylast_texture = 0; */
|
||||||
/* static int showkeylastx, showkeylasty, showkeylastkey; */
|
static int showkeylastx, showkeylasty, showkeylastkey;
|
||||||
|
|
||||||
static SDL_Window* window;
|
static SDL_Window* window;
|
||||||
static SDL_Renderer* renderer;
|
static SDL_Renderer* renderer;
|
||||||
|
@ -193,8 +193,8 @@ static void colors_setup( void )
|
||||||
static void create_annunciators_textures( void )
|
static void create_annunciators_textures( void )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < NB_ANNUNCIATORS; i++ ) {
|
for ( int i = 0; i < NB_ANNUNCIATORS; i++ ) {
|
||||||
annunciators_textures[ i ].on = bitmap_to_texture( ann_tbl[ i ].width, ann_tbl[ i ].height, ann_tbl[ i ].bits, PIXEL, LCD );
|
annunciators_textures[ i ].up = bitmap_to_texture( ann_tbl[ i ].width, ann_tbl[ i ].height, ann_tbl[ i ].bits, PIXEL, LCD );
|
||||||
annunciators_textures[ i ].off = bitmap_to_texture( ann_tbl[ i ].width, ann_tbl[ i ].height, ann_tbl[ i ].bits, LCD, LCD );
|
annunciators_textures[ i ].down = bitmap_to_texture( ann_tbl[ i ].width, ann_tbl[ i ].height, ann_tbl[ i ].bits, LCD, LCD );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,11 +542,11 @@ static void create_buttons_textures( void )
|
||||||
|
|
||||||
for ( int i = FIRST_HPKEY; i <= LAST_HPKEY; i++ ) {
|
for ( int i = FIRST_HPKEY; i <= LAST_HPKEY; i++ ) {
|
||||||
// Create surfaces for each button
|
// Create surfaces for each button
|
||||||
if ( !buttons_textures[ i ].on )
|
if ( !buttons_textures[ i ].up )
|
||||||
buttons_textures[ i ].on =
|
buttons_textures[ i ].up =
|
||||||
SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, BUTTONS[ i ].w, BUTTONS[ i ].h );
|
SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, BUTTONS[ i ].w, BUTTONS[ i ].h );
|
||||||
|
|
||||||
SDL_SetRenderTarget( renderer, buttons_textures[ i ].on );
|
SDL_SetRenderTarget( renderer, buttons_textures[ i ].up );
|
||||||
|
|
||||||
// Fill the button and outline
|
// Fill the button and outline
|
||||||
__draw_rect( 0, 0, BUTTONS[ i ].w, BUTTONS[ i ].h, TRANSPARENT );
|
__draw_rect( 0, 0, BUTTONS[ i ].w, BUTTONS[ i ].h, TRANSPARENT );
|
||||||
|
@ -607,11 +607,11 @@ static void create_buttons_textures( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw the depressed button
|
// draw the depressed button
|
||||||
if ( !buttons_textures[ i ].off )
|
if ( !buttons_textures[ i ].down )
|
||||||
buttons_textures[ i ].off =
|
buttons_textures[ i ].down =
|
||||||
SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, BUTTONS[ i ].w, BUTTONS[ i ].h );
|
SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, BUTTONS[ i ].w, BUTTONS[ i ].h );
|
||||||
|
|
||||||
SDL_SetRenderTarget( renderer, buttons_textures[ i ].off );
|
SDL_SetRenderTarget( renderer, buttons_textures[ i ].down );
|
||||||
|
|
||||||
__draw_rect( 0, 0, BUTTONS[ i ].w, BUTTONS[ i ].h, TRANSPARENT );
|
__draw_rect( 0, 0, BUTTONS[ i ].w, BUTTONS[ i ].h, TRANSPARENT );
|
||||||
__draw_rect( 1, 1, BUTTONS[ i ].w - 2, BUTTONS[ i ].h - 2, BUTTON );
|
__draw_rect( 1, 1, BUTTONS[ i ].w - 2, BUTTONS[ i ].h - 2, BUTTON );
|
||||||
|
@ -679,11 +679,22 @@ static void create_buttons_textures( void )
|
||||||
SDL_SetRenderTarget( renderer, main_texture );
|
SDL_SetRenderTarget( renderer, main_texture );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _draw_key( int hpkey )
|
||||||
|
{
|
||||||
|
int x = KEYBOARD_OFFSET_X + BUTTONS[ hpkey ].x;
|
||||||
|
int y = KEYBOARD_OFFSET_Y + BUTTONS[ hpkey ].y;
|
||||||
|
if ( keyboard[ hpkey ].pressed ) {
|
||||||
|
x += 1;
|
||||||
|
y += 2;
|
||||||
|
}
|
||||||
|
__draw_texture( x, y, BUTTONS[ hpkey ].w, BUTTONS[ hpkey ].h,
|
||||||
|
keyboard[ hpkey ].pressed ? buttons_textures[ hpkey ].down : buttons_textures[ hpkey ].up );
|
||||||
|
}
|
||||||
|
|
||||||
static void _draw_keys( void )
|
static void _draw_keys( void )
|
||||||
{
|
{
|
||||||
for ( int i = FIRST_HPKEY; i <= LAST_HPKEY; i++ )
|
for ( int i = FIRST_HPKEY; i <= LAST_HPKEY; i++ )
|
||||||
__draw_texture( KEYBOARD_OFFSET_X + BUTTONS[ i ].x, KEYBOARD_OFFSET_Y + BUTTONS[ i ].y, BUTTONS[ i ].w, BUTTONS[ i ].h,
|
_draw_key( i );
|
||||||
keyboard[ i ].pressed ? buttons_textures[ i ].off : buttons_textures[ i ].on );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _draw_keypad( void )
|
static void _draw_keypad( void )
|
||||||
|
@ -762,9 +773,8 @@ static void _draw_keypad( void )
|
||||||
if ( BUTTONS[ i ].left == ( char* )0 ) {
|
if ( BUTTONS[ i ].left == ( char* )0 ) {
|
||||||
right_label_width = SmallTextWidth( BUTTONS[ i ].right, strlen( BUTTONS[ i ].right ) );
|
right_label_width = SmallTextWidth( BUTTONS[ i ].right, strlen( BUTTONS[ i ].right ) );
|
||||||
total_top_labels_width = right_label_width;
|
total_top_labels_width = right_label_width;
|
||||||
} else {
|
} else
|
||||||
x += space_char_width + left_label_width;
|
x += space_char_width + left_label_width;
|
||||||
}
|
|
||||||
|
|
||||||
x += ( 1 + BUTTONS[ i ].w - total_top_labels_width ) / 2;
|
x += ( 1 + BUTTONS[ i ].w - total_top_labels_width ) / 2;
|
||||||
|
|
||||||
|
@ -833,79 +843,79 @@ static void _draw_background( int width, int height, int w_top, int h_top )
|
||||||
|
|
||||||
static void _draw_background_LCD( void ) { __draw_rect( display_offset_x, display_offset_y, DISPLAY_WIDTH, DISPLAY_HEIGHT, LCD ); }
|
static void _draw_background_LCD( void ) { __draw_rect( display_offset_x, display_offset_y, DISPLAY_WIDTH, DISPLAY_HEIGHT, LCD ); }
|
||||||
|
|
||||||
/* // Show the hp key which is being pressed */
|
// Show the hp key which is being pressed
|
||||||
/* static void _show_key( int hpkey ) */
|
static void _show_key( int hpkey )
|
||||||
/* { */
|
{
|
||||||
/* SDL_Rect srect, drect; */
|
if ( hpkey < 0 )
|
||||||
/* SDL_Surface* ssurf; */
|
return;
|
||||||
/* int x; */
|
|
||||||
/* int y; */
|
|
||||||
|
|
||||||
/* // If we're called with the same key as before, do nothing */
|
// If we're called with the same key as before, do nothing
|
||||||
/* if ( showkeylastkey == hpkey ) */
|
if ( showkeylastkey == hpkey )
|
||||||
/* return; */
|
return;
|
||||||
|
|
||||||
/* showkeylastkey = hpkey; */
|
showkeylastkey = hpkey;
|
||||||
|
|
||||||
/* // Starts by hiding last */
|
/* SDL_Rect srect, drect; */
|
||||||
/* if ( showkeylast_texture != 0 ) { */
|
/* SDL_Surface* ssurf; */
|
||||||
/* drect.x = showkeylastx; */
|
int x = 0;
|
||||||
/* drect.y = showkeylasty; */
|
int y = 0;
|
||||||
/* SDL_BlitSurface( showkeylast_texture, 0, window, &drect ); */
|
|
||||||
|
|
||||||
/* // Update */
|
/* // Starts by hiding last */
|
||||||
/* SDL_UpdateRect( window, showkeylastx, showkeylasty, showkeylast_texture->w, showkeylast_texture->h ); */
|
/* if ( showkeylast_texture != 0 ) { */
|
||||||
|
/* drect.x = showkeylastx; */
|
||||||
|
/* drect.y = showkeylasty; */
|
||||||
|
/* SDL_BlitSurface( showkeylast_texture, 0, window, &drect ); */
|
||||||
|
|
||||||
/* // Free */
|
/* // Update */
|
||||||
/* SDL_FreeSurface( showkeylast_texture ); */
|
/* SDL_UpdateRect( window, showkeylastx, showkeylasty, showkeylast_texture->w, showkeylast_texture->h ); */
|
||||||
/* showkeylast_texture = 0; */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/* if ( hpkey == -1 ) */
|
/* // Free */
|
||||||
/* return; */
|
/* SDL_FreeSurface( showkeylast_texture ); */
|
||||||
|
/* showkeylast_texture = 0; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
/* // Which surface to show */
|
/* // Which surface to show */
|
||||||
/* ssurf = ( keyboard[ hpkey ].pressed ) ? buttons_textures[ hpkey ].off : buttons_textures[ hpkey ].on; */
|
/* ssurf = ( keyboard[ hpkey ].pressed ) ? buttons_textures[ hpkey ].down : buttons_textures[ hpkey ].up; */
|
||||||
|
|
||||||
/* // Background backup */
|
/* // Background backup */
|
||||||
/* showkeylast_texture = SDL_CreateRGBSurface( SDL_SWSURFACE, ssurf->w, ssurf->h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
|
/* showkeylast_texture = SDL_CreateRGBSurface( SDL_SWSURFACE, ssurf->w, ssurf->h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* // Where to */
|
/* // Where to */
|
||||||
/* x = KEYBOARD_OFFSET_X + BUTTONS[ hpkey ].x - ( ssurf->w - ssurf->w + 1 ) / 2; */
|
/* x = KEYBOARD_OFFSET_X + BUTTONS[ hpkey ].x - ( ssurf->w - ssurf->w + 1 ) / 2; */
|
||||||
/* y = KEYBOARD_OFFSET_Y + BUTTONS[ hpkey ].y - ( ssurf->h - ssurf->h + 1 ) / 2; */
|
/* y = KEYBOARD_OFFSET_Y + BUTTONS[ hpkey ].y - ( ssurf->h - ssurf->h + 1 ) / 2; */
|
||||||
/* // blitting does not clip to screen, so if we are out of the screen we */
|
/* // blitting does not clip to screen, so if we are out of the screen we */
|
||||||
/* // shift the button to fit */
|
/* // shift the button to fit */
|
||||||
/* if ( x < 0 ) */
|
/* if ( x < 0 ) */
|
||||||
/* x = 0; */
|
/* x = 0; */
|
||||||
/* if ( y < 0 ) */
|
/* if ( y < 0 ) */
|
||||||
/* y = 0; */
|
/* y = 0; */
|
||||||
/* if ( x + ssurf->w > window->w ) */
|
/* if ( x + ssurf->w > window->w ) */
|
||||||
/* x = window->w - ssurf->w; */
|
/* x = window->w - ssurf->w; */
|
||||||
/* 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; */
|
||||||
/* srect.y = y; */
|
/* srect.y = y; */
|
||||||
/* srect.w = ssurf->w; */
|
/* srect.w = ssurf->w; */
|
||||||
/* srect.h = ssurf->h; */
|
/* srect.h = ssurf->h; */
|
||||||
/* drect.x = 0; */
|
/* drect.x = 0; */
|
||||||
/* drect.y = 0; */
|
/* drect.y = 0; */
|
||||||
/* SDL_BlitSurface( window, &srect, showkeylast_texture, &drect ); */
|
/* SDL_BlitSurface( window, &srect, showkeylast_texture, &drect ); */
|
||||||
|
|
||||||
/* // Blit the button */
|
/* // Blit the button */
|
||||||
/* drect.x = x; */
|
/* drect.x = x; */
|
||||||
/* drect.y = y; */
|
/* drect.y = y; */
|
||||||
/* SDL_BlitSurface( ssurf, 0, window, &drect ); */
|
/* SDL_BlitSurface( ssurf, 0, window, &drect ); */
|
||||||
|
|
||||||
/* // Update */
|
/* // Update */
|
||||||
/* SDL_UpdateRect( window, x, y, ssurf->w, ssurf->h ); */
|
/* SDL_UpdateRect( window, x, y, ssurf->w, ssurf->h ); */
|
||||||
/* } */
|
}
|
||||||
|
|
||||||
static void _draw_serial_devices_path( void )
|
static void _draw_serial_devices_path( void )
|
||||||
{
|
{
|
||||||
|
@ -1062,10 +1072,8 @@ void sdl_get_event( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display button being pressed, if any
|
// Display button being pressed, if any
|
||||||
/* if ( !config.hide_chrome ) */
|
if ( !config.hide_chrome && pressed_hpkey != 1 )
|
||||||
/* _show_key( pressed_hpkey ); */
|
_show_key( pressed_hpkey );
|
||||||
if ( !config.hide_chrome && pressed_hpkey > 0 )
|
|
||||||
_draw_keys();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdl_update_LCD( void )
|
void sdl_update_LCD( void )
|
||||||
|
@ -1143,7 +1151,7 @@ void sdl_draw_annunc( void )
|
||||||
annunc_state = ( ( annunciators_bits[ i ] & saturn.annunc ) == annunciators_bits[ i ] );
|
annunc_state = ( ( annunciators_bits[ i ] & saturn.annunc ) == annunciators_bits[ i ] );
|
||||||
|
|
||||||
__draw_texture( display_offset_x + ann_tbl[ i ].x, display_offset_y + ann_tbl[ i ].y, ann_tbl[ i ].width, ann_tbl[ i ].height,
|
__draw_texture( display_offset_x + ann_tbl[ i ].x, display_offset_y + ann_tbl[ i ].y, ann_tbl[ i ].width, ann_tbl[ i ].height,
|
||||||
( annunc_state ) ? annunciators_textures[ i ].on : annunciators_textures[ i ].off );
|
( annunc_state ) ? annunciators_textures[ i ].up : annunciators_textures[ i ].down );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always immediately update annunciators
|
// Always immediately update annunciators
|
||||||
|
|
Loading…
Reference in a new issue