[ui_text] Wow, --tui --tiny was much easier then I feared!

This commit is contained in:
Gwenhael Le Moine 2023-10-19 11:11:34 +02:00
parent b6ddb9b8ea
commit 8be22aecec
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
6 changed files with 108 additions and 4 deletions

View file

@ -16,6 +16,10 @@ You can use the script `setup-x48ng-home.sh` or simply run `x48ng --rom=<romfile
![screenshot of x48ng --tui --small running in a terminal](./tui-small-screenshot.png?raw=true "screenshot of x48ng --tui running in a terminal") ![screenshot of x48ng --tui --small running in a terminal](./tui-small-screenshot.png?raw=true "screenshot of x48ng --tui running in a terminal")
### `--tui --tiny` version (ncurses)
![screenshot of x48ng --tui --tiny running in a terminal](./tui-tiny-screenshot.png?raw=true "screenshot of x48ng --tui running in a terminal")
### `--tui` version (ncurses) ### `--tui` version (ncurses)
![screenshot of x48ng --tui running in a terminal](./tui-screenshot.png?raw=true "screenshot of x48ng --tui running in a terminal") ![screenshot of x48ng --tui running in a terminal](./tui-screenshot.png?raw=true "screenshot of x48ng --tui running in a terminal")

2
dist/x48ng.man.1 vendored
View file

@ -112,6 +112,8 @@ where options include (depending on compiled front-ends):
\-\-gray make the UI grayscale (default: false) \-\-gray make the UI grayscale (default: false)
.br .br
\-\-small make the text UI small (2×2 pixels per character) (default: false) \-\-small make the text UI small (2×2 pixels per character) (default: false)
.br
\-\-tiny make the text UI tiny (2×4 pixels per character) (default: false)
.SH DESCRIPTION .SH DESCRIPTION
.I x48ng .I x48ng

View file

@ -42,6 +42,7 @@ bool gray = false;
/* tui */ /* tui */
bool small = false; bool small = false;
bool tiny = false;
/* sdl */ /* sdl */
bool hide_chrome = false; bool hide_chrome = false;
@ -238,6 +239,7 @@ int parse_args( int argc, char* argv[] )
int clopt_mono = -1; int clopt_mono = -1;
int clopt_gray = -1; int clopt_gray = -1;
int clopt_small = -1; int clopt_small = -1;
int clopt_tiny = -1;
char* optstring = "c:hvVtsirT"; char* optstring = "c:hvVtsirT";
struct option long_options[] = { struct option long_options[] = {
@ -281,6 +283,7 @@ int parse_args( int argc, char* argv[] )
{ "mono", no_argument, &clopt_mono, true }, { "mono", no_argument, &clopt_mono, true },
{ "gray", no_argument, &clopt_gray, true }, { "gray", no_argument, &clopt_gray, true },
{ "small", no_argument, &clopt_small, true }, { "small", no_argument, &clopt_small, true },
{ "tiny", no_argument, &clopt_tiny, true },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
@ -339,6 +342,8 @@ int parse_args( int argc, char* argv[] )
" --gray make the UI grayscale (default: " " --gray make the UI grayscale (default: "
"false)\n" "false)\n"
" --small make the text UI small (2×2 pixels per character) (default: " " --small make the text UI small (2×2 pixels per character) (default: "
"false)\n"
" --tiny make the text UI tiny (2×4 pixels per character) (default: "
"false)\n"; "false)\n";
while ( c != EOF ) { while ( c != EOF ) {
c = getopt_long( argc, argv, optstring, long_options, &option_index ); c = getopt_long( argc, argv, optstring, long_options, &option_index );
@ -505,6 +510,9 @@ int parse_args( int argc, char* argv[] )
lua_getglobal( config_lua_values, "small" ); lua_getglobal( config_lua_values, "small" );
small = lua_toboolean( config_lua_values, -1 ); small = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "tiny" );
tiny = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "x11_visual" ); lua_getglobal( config_lua_values, "x11_visual" );
x11_visual = ( char* )luaL_optstring( config_lua_values, -1, "default" ); x11_visual = ( char* )luaL_optstring( config_lua_values, -1, "default" );
@ -572,6 +580,8 @@ int parse_args( int argc, char* argv[] )
gray = clopt_gray; gray = clopt_gray;
if ( clopt_small != -1 ) if ( clopt_small != -1 )
small = clopt_small; small = clopt_small;
if ( clopt_tiny != -1 )
tiny = clopt_tiny;
/* After getting configs and params */ /* After getting configs and params */
/* normalize config_dir again in case it's been modified */ /* normalize config_dir again in case it's been modified */
@ -622,6 +632,7 @@ int parse_args( int argc, char* argv[] )
fprintf( stdout, "mono = %s\n", mono ? "true" : "false" ); fprintf( stdout, "mono = %s\n", mono ? "true" : "false" );
fprintf( stdout, "gray = %s\n", gray ? "true" : "false" ); fprintf( stdout, "gray = %s\n", gray ? "true" : "false" );
fprintf( stdout, "small = %s\n", small ? "true" : "false" ); fprintf( stdout, "small = %s\n", small ? "true" : "false" );
fprintf( stdout, "tiny = %s\n", tiny ? "true" : "false" );
fprintf( stdout, "\n" ); fprintf( stdout, "\n" );
fprintf( stdout, "x11_visual = \"%s\"\n", x11_visual ); fprintf( stdout, "x11_visual = \"%s\"\n", x11_visual );
fprintf( stdout, "netbook = %s\n", netbook ? "true" : "false" ); fprintf( stdout, "netbook = %s\n", netbook ? "true" : "false" );

View file

@ -24,6 +24,7 @@ extern bool gray;
/* tui */ /* tui */
extern bool small; extern bool small;
extern bool tiny;
/* sdl */ /* sdl */
extern bool hide_chrome; extern bool hide_chrome;

View file

@ -23,8 +23,8 @@
#define LCD_HEIGHT 64 #define LCD_HEIGHT 64
#define LCD_OFFSET_X 1 #define LCD_OFFSET_X 1
#define LCD_OFFSET_Y 1 #define LCD_OFFSET_Y 1
#define LCD_BOTTOM LCD_OFFSET_Y + ( small ? ( LCD_HEIGHT / 2 ) : LCD_HEIGHT ) #define LCD_BOTTOM LCD_OFFSET_Y + ( small ? ( LCD_HEIGHT / 2 ) : tiny ? ( LCD_HEIGHT / 4 ) : LCD_HEIGHT )
#define LCD_RIGHT LCD_OFFSET_X + ( small ? ( LCD_WIDTH / 2 ) + 1 : LCD_WIDTH ) #define LCD_RIGHT LCD_OFFSET_X + ( ( small || tiny ) ? ( LCD_WIDTH / 2 ) + 1 : LCD_WIDTH )
#define LCD_COLOR_BG 48 #define LCD_COLOR_BG 48
#define LCD_COLOR_FG 49 #define LCD_COLOR_FG 49
@ -56,14 +56,98 @@ static inline void ncurses_draw_annunciators( void )
mvaddwstr( 0, 4 + ( i * 4 ), ( ( annunciators_bits[ i ] & val ) == annunciators_bits[ i ] ) ? annunciators_icons[ i ] : L" " ); mvaddwstr( 0, 4 + ( i * 4 ), ( ( annunciators_bits[ i ] & val ) == annunciators_bits[ i ] ) ? annunciators_icons[ i ] : L" " );
} }
static inline wchar_t eight_bits_to_braille_char( bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7, bool b8 )
{
/*********/
/* b1 b4 */
/* b2 b5 */
/* b3 b6 */
/* b7 b8 */
/*********/
uint16_t chr = 0x2800;
if ( b1 )
chr |= 0b0000000000000001;
if ( b2 )
chr |= 0b0000000000000010;
if ( b3 )
chr |= 0b0000000000000100;
if ( b4 )
chr |= 0b0000000000001000;
if ( b5 )
chr |= 0b0000000000010000;
if ( b6 )
chr |= 0b0000000000100000;
if ( b7 )
chr |= 0b0000000001000000;
if ( b8 )
chr |= 0b0000000010000000;
return ( wchar_t )chr;
}
static inline void ncurses_draw_lcd_tiny( void )
{
bool b1, b2, b3, b4, b5, b6, b7, b8;
int nibble_top, nibble_middle_top, nibble_middle_bottom, nibble_bottom;
int step_x = 2;
int step_y = 4;
wchar_t line[ 66 ]; /* ( LCD_WIDTH / step_x ) + 1 */
if ( !mono && has_colors() )
attron( COLOR_PAIR( LCD_COLORS_PAIR ) );
for ( int y = 0; y < LCD_HEIGHT; y += step_y ) {
wcscpy( line, L"" );
for ( int nibble_x = 0; nibble_x < NIBBLES_PER_ROW - 1; ++nibble_x ) {
nibble_top = lcd_nibbles_buffer[ y ][ nibble_x ];
nibble_top &= 0x0f;
nibble_middle_top = lcd_nibbles_buffer[ y + 1 ][ nibble_x ];
nibble_middle_top &= 0x0f;
nibble_middle_bottom = lcd_nibbles_buffer[ y + 2 ][ nibble_x ];
nibble_middle_bottom &= 0x0f;
nibble_bottom = lcd_nibbles_buffer[ y + 3 ][ nibble_x ];
nibble_bottom &= 0x0f;
for ( int bit_x = 0; bit_x < NIBBLES_NB_BITS; bit_x += step_x ) {
b1 = 0 != ( nibble_top & ( 1 << ( bit_x & 3 ) ) );
b4 = 0 != ( nibble_top & ( 1 << ( ( bit_x + 1 ) & 3 ) ) );
b2 = 0 != ( nibble_middle_top & ( 1 << ( bit_x & 3 ) ) );
b5 = 0 != ( nibble_middle_top & ( 1 << ( ( bit_x + 1 ) & 3 ) ) );
b3 = 0 != ( nibble_middle_bottom & ( 1 << ( bit_x & 3 ) ) );
b6 = 0 != ( nibble_middle_bottom & ( 1 << ( ( bit_x + 1 ) & 3 ) ) );
b7 = 0 != ( nibble_bottom & ( 1 << ( bit_x & 3 ) ) );
b8 = 0 != ( nibble_bottom & ( 1 << ( ( bit_x + 1 ) & 3 ) ) );
wchar_t pixels = eight_bits_to_braille_char( b1, b2, b3, b4, b5, b6, b7, b8 );
wcsncat( line, &pixels, 1 );
}
}
mvaddwstr( LCD_OFFSET_Y + ( y / step_y ), LCD_OFFSET_X, line );
}
if ( !mono && has_colors() )
attroff( COLOR_PAIR( LCD_COLORS_PAIR ) );
wrefresh( stdscr );
}
static inline wchar_t bitsquare_to_small_char( bool top_left, bool top_right, bool bottom_left, bool bottom_right ) static inline wchar_t bitsquare_to_small_char( bool top_left, bool top_right, bool bottom_left, bool bottom_right )
{ {
if ( top_left ) { if ( top_left ) {
if ( top_right ) { if ( top_right ) {
if ( bottom_left ) if ( bottom_left )
return bottom_right ? L'' : L''; return bottom_right ? L'' : L''; /* 0x2588 0x2598 */
else else
return bottom_right ? L'' : L''; return bottom_right ? L'' : L''; /* 0x259C 0x2580 */
} else { } else {
if ( bottom_left ) if ( bottom_left )
return bottom_right ? L'' : L''; return bottom_right ? L'' : L'';
@ -486,6 +570,8 @@ void text_update_LCD( void )
if ( small ) if ( small )
ncurses_draw_lcd_small(); ncurses_draw_lcd_small();
else if ( tiny )
ncurses_draw_lcd_tiny();
else else
ncurses_draw_lcd(); ncurses_draw_lcd();
} }

BIN
tui-tiny-screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB