Fully functional ncurses UI!!

This commit is contained in:
Gwenhael Le Moine 2023-09-23 17:16:43 +02:00
parent 8c546a6279
commit b908c50979
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -239,6 +239,7 @@ static inline void draw_row( long addr, int row )
if ( ( display.offset > 3 ) && ( row <= display.lines ) ) if ( ( display.offset > 3 ) && ( row <= display.lines ) )
line_length += 2; line_length += 2;
for ( int i = 0; i < line_length; i++ ) { for ( int i = 0; i < line_length; i++ ) {
v = read_nibble( addr + i ); v = read_nibble( addr + i );
if ( v != disp_buf[ row ][ i ] ) { if ( v != disp_buf[ row ][ i ] ) {
@ -248,14 +249,12 @@ static inline void draw_row( long addr, int row )
} }
} }
static void tui_button_pressed( int b ) static void tui_press_button( int b )
{ {
// Check not already pressed (may be important: avoids a useless do_kbd_int) // Check not already pressed (may be important: avoids a useless do_kbd_int)
if ( buttons[ b ].pressed == 1 ) if ( buttons[ b ].pressed == 1 )
return; return;
mvprintw( 70, 0, "pressed key: %i ( %s )", b, buttons[ b ].name );
buttons[ b ].pressed = 1; buttons[ b ].pressed = 1;
int code = buttons[ b ].code; int code = buttons[ b ].code;
@ -277,7 +276,7 @@ static void tui_button_pressed( int b )
} }
} }
static void tui_button_released( int b ) static void tui_release_button( int b )
{ {
// Check not already released (not critical) // Check not already released (not critical)
if ( buttons[ b ].pressed == 0 ) if ( buttons[ b ].pressed == 0 )
@ -296,11 +295,11 @@ static void tui_button_released( int b )
} }
} }
static void tui_button_release_all( void ) static void tui_release_all_buttons( void )
{ {
for ( int b = FIRST_BUTTON; b <= LAST_BUTTON; b++ ) for ( int b = FIRST_BUTTON; b <= LAST_BUTTON; b++ )
if ( buttons[ b ].pressed ) if ( buttons[ b ].pressed )
tui_button_released( b ); tui_release_button( b );
} }
/**********/ /**********/
@ -309,15 +308,14 @@ static void tui_button_release_all( void )
int text_get_event( void ) int text_get_event( void )
{ {
int hpkey = -1; int hpkey = -1;
uint32_t k;
/* check for input */ tui_release_all_buttons();
uint32_t k = getch();
/* check for inputs */
while ( ( k = getch() ) ) {
if ( k == ( uint32_t )ERR ) if ( k == ( uint32_t )ERR )
return -1; break;
/* return key to queue */
/* ungetch(ch); */
switch ( k ) { switch ( k ) {
case '0': case '0':
@ -492,21 +490,14 @@ int text_get_event( void )
exit_emulator(); exit_emulator();
exit( 0 ); exit( 0 );
break; break;
default:
return -1;
} }
if ( hpkey == -1 ) if ( !buttons[ hpkey ].pressed )
return -1; tui_press_button( hpkey );
/* tui_button_release_all(); */
if ( !buttons[ hpkey ].pressed ) {
tui_button_pressed( hpkey );
tui_button_released( hpkey );
} }
text_update_LCD();
return 1; return 1;
} }
@ -580,6 +571,8 @@ void text_update_LCD( void )
} }
} }
} }
refresh();
} }
void text_refresh_LCD( void ) {} void text_refresh_LCD( void ) {}
@ -657,7 +650,6 @@ void init_text_ui( int argc, char** argv )
curs_set( 0 ); curs_set( 0 );
nonl(); /* tell curses not to do NL->CR/NL on output */ nonl(); /* tell curses not to do NL->CR/NL on output */
cbreak(); /* take input chars one at a time, no wait for \n */ cbreak(); /* take input chars one at a time, no wait for \n */
/* (void) echo(); /\* echo input - in color *\/ */
noecho(); noecho();
if ( has_colors() ) { if ( has_colors() ) {
@ -692,9 +684,6 @@ void init_text_ui( int argc, char** argv )
mvprintw( 1, 1, "[ | | | | | ]" ); /* annunciators */ mvprintw( 1, 1, "[ | | | | | ]" ); /* annunciators */
/* DEBUG */
mvprintw( 0, 1, "screen: %i x %i", COLS, LINES );
/* nodelay( stdscr, FALSE ); */ /* nodelay( stdscr, FALSE ); */
/* echo(); */ /* echo(); */