[sdl2] nicer buttons

This commit is contained in:
Gwenhael Le Moine 2024-09-10 11:18:34 +02:00
parent 22228dfbcd
commit 169d4d75ed
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -543,6 +543,7 @@ static SDL_Texture* create_button_texture( int hpkey, bool is_up )
{ {
bool is_down = !is_up; bool is_down = !is_up;
int x, y; int x, y;
int on_key_offset_y = ( hpkey == HPKEY_ON ) ? 1 : 0;
SDL_Texture* texture = SDL_Texture* texture =
SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, BUTTONS[ hpkey ].w, BUTTONS[ hpkey ].h ); SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, BUTTONS[ hpkey ].w, BUTTONS[ hpkey ].h );
SDL_SetRenderTarget( renderer, texture ); SDL_SetRenderTarget( renderer, texture );
@ -586,10 +587,7 @@ static SDL_Texture* create_button_texture( int hpkey, bool is_up )
__draw_line( 4, 4, BUTTONS[ hpkey ].w - 5, 4, BUT_TOP ); __draw_line( 4, 4, BUTTONS[ hpkey ].w - 5, 4, BUT_TOP );
} }
// top-left // top-left
if ( is_up ) __draw_pixel( 4, 3 + ( is_up ? 2 : 0 ), BUT_TOP );
__draw_pixel( 4, 5, BUT_TOP );
else
__draw_pixel( 4, 3, BUT_TOP );
// left // left
__draw_line( 1, BUTTONS[ hpkey ].h - 2, 1, 1, BUT_TOP ); __draw_line( 1, BUTTONS[ hpkey ].h - 2, 1, 1, BUT_TOP );
__draw_line( 2, BUTTONS[ hpkey ].h - 3, 2, 2, BUT_TOP ); __draw_line( 2, BUTTONS[ hpkey ].h - 3, 2, 2, BUT_TOP );
@ -620,18 +618,26 @@ static SDL_Texture* create_button_texture( int hpkey, bool is_up )
__draw_pixel( 1, BUTTONS[ hpkey ].h - 2, FRAME ); __draw_pixel( 1, BUTTONS[ hpkey ].h - 2, FRAME );
// bottom-right // bottom-right
__draw_pixel( BUTTONS[ hpkey ].w - 2, BUTTONS[ hpkey ].h - 2, FRAME ); __draw_pixel( BUTTONS[ hpkey ].w - 2, BUTTONS[ hpkey ].h - 2, FRAME );
if ( hpkey == HPKEY_ON ) {
// top
__draw_line( 2, 1, BUTTONS[ hpkey ].w - 3, 1, FRAME );
// top-left
__draw_pixel( 1, 1 + on_key_offset_y, FRAME );
// top-right
__draw_pixel( BUTTONS[ hpkey ].w - 2, 1 + on_key_offset_y, FRAME );
}
if ( is_down ) { if ( is_down ) {
// top // top
__draw_line( 2, 1, BUTTONS[ hpkey ].w - 3, 1, FRAME ); __draw_line( 2, 1 + on_key_offset_y, BUTTONS[ hpkey ].w - 3, 1 + on_key_offset_y, FRAME );
// left // left
__draw_line( 1, 2, 1, BUTTONS[ hpkey ].h / 1.5, FRAME ); __draw_line( 1, 2, 1, BUTTONS[ hpkey ].h, FRAME );
// right // right
__draw_line( BUTTONS[ hpkey ].w - 2, 2, BUTTONS[ hpkey ].w - 2, BUTTONS[ hpkey ].h / 1.5, FRAME ); __draw_line( BUTTONS[ hpkey ].w - 2, 2, BUTTONS[ hpkey ].w - 2, BUTTONS[ hpkey ].h, FRAME );
// top-left // top-left
__draw_pixel( 2, 2, FRAME ); __draw_pixel( 2, 2 + on_key_offset_y, FRAME );
// top-right // top-right
__draw_pixel( BUTTONS[ hpkey ].w - 3, 2, FRAME ); __draw_pixel( BUTTONS[ hpkey ].w - 3, 2 + on_key_offset_y, FRAME );
} }
return texture; return texture;