[ui_text] Wow, --tui --tiny was much easier then I feared!
This commit is contained in:
parent
b6ddb9b8ea
commit
8be22aecec
6 changed files with 108 additions and 4 deletions
|
@ -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")
|
||||
|
||||
### `--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)
|
||||
|
||||
![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
2
dist/x48ng.man.1
vendored
|
@ -112,6 +112,8 @@ where options include (depending on compiled front-ends):
|
|||
\-\-gray make the UI grayscale (default: false)
|
||||
.br
|
||||
\-\-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
|
||||
.I x48ng
|
||||
|
|
|
@ -42,6 +42,7 @@ bool gray = false;
|
|||
|
||||
/* tui */
|
||||
bool small = false;
|
||||
bool tiny = false;
|
||||
|
||||
/* sdl */
|
||||
bool hide_chrome = false;
|
||||
|
@ -238,6 +239,7 @@ int parse_args( int argc, char* argv[] )
|
|||
int clopt_mono = -1;
|
||||
int clopt_gray = -1;
|
||||
int clopt_small = -1;
|
||||
int clopt_tiny = -1;
|
||||
|
||||
char* optstring = "c:hvVtsirT";
|
||||
struct option long_options[] = {
|
||||
|
@ -281,6 +283,7 @@ int parse_args( int argc, char* argv[] )
|
|||
{ "mono", no_argument, &clopt_mono, true },
|
||||
{ "gray", no_argument, &clopt_gray, true },
|
||||
{ "small", no_argument, &clopt_small, true },
|
||||
{ "tiny", no_argument, &clopt_tiny, true },
|
||||
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
@ -339,6 +342,8 @@ int parse_args( int argc, char* argv[] )
|
|||
" --gray make the UI grayscale (default: "
|
||||
"false)\n"
|
||||
" --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";
|
||||
while ( c != EOF ) {
|
||||
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" );
|
||||
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" );
|
||||
x11_visual = ( char* )luaL_optstring( config_lua_values, -1, "default" );
|
||||
|
||||
|
@ -572,6 +580,8 @@ int parse_args( int argc, char* argv[] )
|
|||
gray = clopt_gray;
|
||||
if ( clopt_small != -1 )
|
||||
small = clopt_small;
|
||||
if ( clopt_tiny != -1 )
|
||||
tiny = clopt_tiny;
|
||||
|
||||
/* After getting configs and params */
|
||||
/* 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, "gray = %s\n", gray ? "true" : "false" );
|
||||
fprintf( stdout, "small = %s\n", small ? "true" : "false" );
|
||||
fprintf( stdout, "tiny = %s\n", tiny ? "true" : "false" );
|
||||
fprintf( stdout, "\n" );
|
||||
fprintf( stdout, "x11_visual = \"%s\"\n", x11_visual );
|
||||
fprintf( stdout, "netbook = %s\n", netbook ? "true" : "false" );
|
||||
|
|
|
@ -24,6 +24,7 @@ extern bool gray;
|
|||
|
||||
/* tui */
|
||||
extern bool small;
|
||||
extern bool tiny;
|
||||
|
||||
/* sdl */
|
||||
extern bool hide_chrome;
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#define LCD_HEIGHT 64
|
||||
#define LCD_OFFSET_X 1
|
||||
#define LCD_OFFSET_Y 1
|
||||
#define LCD_BOTTOM LCD_OFFSET_Y + ( small ? ( LCD_HEIGHT / 2 ) : LCD_HEIGHT )
|
||||
#define LCD_RIGHT LCD_OFFSET_X + ( small ? ( LCD_WIDTH / 2 ) + 1 : LCD_WIDTH )
|
||||
#define LCD_BOTTOM LCD_OFFSET_Y + ( small ? ( LCD_HEIGHT / 2 ) : tiny ? ( LCD_HEIGHT / 4 ) : LCD_HEIGHT )
|
||||
#define LCD_RIGHT LCD_OFFSET_X + ( ( small || tiny ) ? ( LCD_WIDTH / 2 ) + 1 : LCD_WIDTH )
|
||||
|
||||
#define LCD_COLOR_BG 48
|
||||
#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" " );
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
if ( top_left ) {
|
||||
if ( top_right ) {
|
||||
if ( bottom_left )
|
||||
return bottom_right ? L'█' : L'▛';
|
||||
return bottom_right ? L'█' : L'▛'; /* 0x2588 0x2598 */
|
||||
else
|
||||
return bottom_right ? L'▜' : L'▀';
|
||||
return bottom_right ? L'▜' : L'▀'; /* 0x259C 0x2580 */
|
||||
} else {
|
||||
if ( bottom_left )
|
||||
return bottom_right ? L'▙' : L'▌';
|
||||
|
@ -486,6 +570,8 @@ void text_update_LCD( void )
|
|||
|
||||
if ( small )
|
||||
ncurses_draw_lcd_small();
|
||||
else if ( tiny )
|
||||
ncurses_draw_lcd_tiny();
|
||||
else
|
||||
ncurses_draw_lcd();
|
||||
}
|
||||
|
|
BIN
tui-tiny-screenshot.png
Normal file
BIN
tui-tiny-screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
Loading…
Reference in a new issue