static void print_item (int left_edge, int width, int index, int colour) { char key[] = "\x0A "; key[1] = 'A' + index; left_edge = ( left_edge + 1 ) * 8 + 1; left_edge = widget_printstring( left_edge, index * 8 + 24, colour, key ); left_edge = widget_printstring( left_edge + 1, index * 8 + 24, colour, ": " ); widget_printstring( left_edge + 1, index * 8 + 24, colour, options[index] ); }
int widget_menu_draw( void *data ) { widget_menu_entry *ptr; size_t menu_entries, width, height = 0; int menu_left_edge_x; char buffer[128]; highlight_line = 0; menu = (widget_menu_entry*)data; /* How many menu items do we have? */ for( ptr = &menu[1]; ptr->text; ptr++ ) height += ptr->text[0] ? 2 : 1; menu_entries = ptr - &menu[1]; count = menu_entries; width = widget_calculate_menu_width(menu); menu_left_edge_x = DISPLAY_WIDTH_COLS/2-width/2; widget_dialog_with_border( menu_left_edge_x, 2, width, 2 + height / 2 ); snprintf( buffer, sizeof( buffer ), "%s", menu->text ); widget_printstring( menu_left_edge_x*8+2, 16, WIDGET_COLOUR_TITLE, buffer ); print_items(); return 0; }
int widget_roms_draw( void *data ) { int i; char buffer[32]; char key[] = "\x0A "; if( data ) info = data; /* Get a copy of the current settings */ if( !info->initialised ) { widget_settings = malloc( sizeof( settings_info ) ); if( !widget_settings ) { ui_error( UI_ERROR_ERROR, "out of memory at %s:%d", __FILE__, __LINE__ ); return 1; } memset( widget_settings, 0, sizeof( settings_info ) ); settings_copy( widget_settings, &settings_current ); info->initialised = 1; } first_rom = info->start; rom_count = info->count; is_peripheral = info->is_peripheral; /* Blank the main display area */ widget_dialog_with_border( 1, 2, 30, rom_count + 2 ); widget_printstring( 10, 16, WIDGET_COLOUR_TITLE, info->title ); widget_display_lines( 2, rom_count + 2 ); for( i=0; i < info->count; i++ ) { snprintf( buffer, sizeof( buffer ), "ROM %d:", i ); key[1] = 'A' + i; widget_printstring_right( 24, i*8+24, WIDGET_COLOUR_FOREGROUND, key ); widget_printstring( 28, i*8+24, WIDGET_COLOUR_FOREGROUND, buffer ); print_rom( i ); } return 0; }
void print_items( void ) { int i; char buffer[128]; size_t height = 24; int width = widget_calculate_menu_width(menu); int menu_left_edge_x = (DISPLAY_WIDTH_COLS/2-width/2)*8+1; for( i = 0; i < count; i++ ) { int colour; if( !menu[i+1].text[0] ) { height += 4; continue; } snprintf( buffer, sizeof (buffer), menu[i+1].text ); colour = menu[i+1].inactive ? WIDGET_COLOUR_DISABLED : WIDGET_COLOUR_FOREGROUND; if( i == highlight_line ) { widget_rectangle( menu_left_edge_x, height, width*8-2, 1*8, WIDGET_COLOUR_HIGHLIGHT ); } else { widget_rectangle( menu_left_edge_x, height, width*8-2, 1*8, WIDGET_COLOUR_BACKGROUND ); } widget_printstring( menu_left_edge_x+8, height, colour, buffer ); if( menu[i+1].submenu ) { widget_draw_submenu_arrow(DISPLAY_BORDER_ASPECT_WIDTH+menu_left_edge_x+ width*8-9, i*8+49, colour); } if( menu[i+1].detail ) { size_t detail_width = widget_stringwidth( menu[i+1].detail() ); int x = menu_left_edge_x + (width-1)*8 - detail_width - 2; widget_printstring( x, height, WIDGET_COLOUR_DISABLED, menu[i+1].detail() ); } height += 8; } widget_display_lines( 2, count + 2 ); }
static int internal_query_draw( widget_query_entry *query, int save, const char *message ) { widget_query_entry *ptr; size_t height = 0; int menu_width; int menu_left_edge_x; int i; if( split_message( message, &message_lines, &num_message_lines, 28 ) ) { return 1; } menu_width = widget_calculate_query_width( title, query, message_lines, num_message_lines ); height = num_message_lines; /* How many options do we have? */ for( ptr = query; ptr->text; ptr++ ) height ++; menu_left_edge_x = DISPLAY_WIDTH_COLS/2-menu_width/2; /* Draw the dialog box */ widget_dialog_with_border( menu_left_edge_x, 2, menu_width, 2 + height ); widget_printstring( menu_left_edge_x*8+2, 16, WIDGET_COLOUR_TITLE, title ); for( i=0; i<num_message_lines; i++ ) { widget_printstring( menu_left_edge_x*8+8, i*8+24, WIDGET_COLOUR_FOREGROUND, message_lines[i] ); } for( ptr = query; ptr->text; ptr++ ) { widget_query_line_draw( menu_left_edge_x, menu_width, ptr, ptr->text ); } widget_display_lines( 2, 2 + height ); return 0; }
int widget_text_draw( void *data ) { widget_text_t* text_data = data; if( data ) { title = text_data->title; allow = text_data->allow; snprintf( text, sizeof( text ), "%s", text_data->text ); } widget_dialog_with_border( 1, 2, 30, 3 ); widget_printstring( 10, 16, WIDGET_COLOUR_TITLE, title ); widget_printstring_right( 12, 28, 5, "[" ); widget_printstring( 244, 28, 5, "]" ); widget_display_lines( 2, 3 ); return widget_text_draw_text(); }
static void widget_query_line_draw( int left_edge, int width, struct widget_query_entry *menu, const char *label ) { int colour = WIDGET_COLOUR_BACKGROUND; int y = (menu->index + num_message_lines) * 8 + 24; if( menu->index == highlight_line ) colour = WIDGET_COLOUR_HIGHLIGHT; widget_rectangle( left_edge*8+1, y, width*8-2, 1*8, colour ); widget_printstring( left_edge*8+8, y, WIDGET_COLOUR_FOREGROUND, menu->text ); widget_display_rasters( y, 8 ); }
int widget_error_draw( void *data ) { char **lines; size_t count; size_t i; error_info = (widget_error_t*)data; if( split_message( error_info->message, &lines, &count, 28 ) ) return 1; widget_dialog_with_border( 1, 2, 30, count+2 ); switch( error_info->severity ) { case UI_ERROR_INFO: widget_printstring( 10, 16, WIDGET_COLOUR_TITLE, "Info" ); break; case UI_ERROR_WARNING: widget_printstring( 10, 16, WIDGET_COLOUR_TITLE, "Warning" ); break; case UI_ERROR_ERROR: widget_printstring( 10, 16, WIDGET_COLOUR_TITLE, "Error" ); break; default: widget_printstring( 10, 16, WIDGET_COLOUR_TITLE, "(Unknown message)" ); break; } for( i=0; i<count; i++ ) { widget_printstring( 17, i*8+24, WIDGET_COLOUR_FOREGROUND, lines[i] ); free( lines[i] ); } free( lines ); widget_display_lines( 2, count + 3 ); return 0; }
static void print_rom( int which ) { const char *setting; setting = *( settings_get_rom_setting( widget_settings, which + first_rom, is_peripheral ) ); while( widget_stringwidth( setting ) >= 232 - 68 ) ++setting; widget_rectangle( 68, which * 8 + 24, 232 - 68, 8, WIDGET_COLOUR_BACKGROUND ); widget_printstring (68, which * 8 + 24, WIDGET_COLOUR_FOREGROUND, setting ); widget_display_rasters( which * 8 + 24, 8 ); }
int widget_select_draw( void *data ) { int i; size_t width; int menu_left_edge_x; if( data ) { widget_select_t *ptr = data; title = ptr->title; options = ptr->options; count = ptr->count; result = &( ptr->result ); finish_all = ptr->finish_all; highlight_line = ptr->current; } width = widget_calculate_select_width( title ); menu_left_edge_x = DISPLAY_WIDTH_COLS/2-width/2; /* Blank the main display area */ widget_dialog_with_border( menu_left_edge_x, 2, width, count + 2 ); widget_printstring( menu_left_edge_x*8+2, 16, WIDGET_COLOUR_TITLE, title ); for( i = 0; i < count; i++ ) { if( i == highlight_line ) { widget_rectangle( menu_left_edge_x*8+1, i*8+24, width*8-2, 1*8, WIDGET_COLOUR_HIGHLIGHT ); } print_item( menu_left_edge_x, width, i, WIDGET_COLOUR_FOREGROUND ); } widget_display_lines( 2, count + 2 ); return 0; }
static int widget_text_draw_text( void ) { int width; const char *tptr; widget_rectangle( 12, 28, 232, 8, WIDGET_COLOUR_BACKGROUND ); tptr = text - 1; do { width = widget_stringwidth (++tptr); } while (width > 28 * 8 - 4); if( tptr != text ) widget_rectangle( 14, 29, 1, 6, 5 ); widget_printstring( 16, 28, WIDGET_COLOUR_FOREGROUND, tptr ); widget_rectangle( 17 + width, 35, 4, 1, 5 ); widget_display_rasters( 28, 8 ); return 0; }