1
0
Fork 0
forked from Miroirs/x49gp

rename and rearrange some ui code

This commit is contained in:
Gwenhael Le Moine 2024-10-29 15:27:54 +01:00
parent 3e3a7a5caa
commit fffd39029c
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
3 changed files with 100 additions and 92 deletions

View file

@ -318,11 +318,11 @@ void x49gp_lcd_update( x49gp_t* x49gp )
GdkGC* gc = gdk_gc_new( gtk_widget_get_window( ui->lcd_canvas ) );
for ( int y = 0; y < ( ui->lcd_height - ui->lcd_top_margin ) / LCD_PIXEL_SCALE; y++ ) {
for ( int y = 0; y < ( ui->lcd_height - ui->lcd_annunciators_height ) / LCD_PIXEL_SCALE; y++ ) {
for ( int x = 0; x < ui->lcd_width / LCD_PIXEL_SCALE; x++ ) {
color = x49gp_get_pixel_color( lcd, x, y );
gdk_gc_set_rgb_fg_color( gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
gdk_draw_rectangle( ui->lcd_pixmap, gc, true, LCD_PIXEL_SCALE * x, LCD_PIXEL_SCALE * y + ui->lcd_top_margin,
gdk_draw_rectangle( ui->lcd_pixmap, gc, true, LCD_PIXEL_SCALE * x, LCD_PIXEL_SCALE * y + ui->lcd_annunciators_height,
LCD_PIXEL_SCALE, LCD_PIXEL_SCALE );
}
}

114
src/ui.c
View file

@ -3223,13 +3223,47 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
{
x49gp_t* x49gp = module->x49gp;
x49gp_ui_t* ui = module->user_data;
x49gp_ui_button_t* button;
const x49gp_ui_key_t* key;
GtkWidget* screen_box;
GtkWidget *menu_mount_folder, *menu_mount_image, *menu_unmount;
GtkWidget *menu_debug, *menu_reset, *menu_quit;
GdkBitmap* shape;
/* create all buttons' shapes */
ui->shapes[ UI_SHAPE_BUTTON_TINY ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_tiny_bits, button_tiny_width, button_tiny_height );
ui->shapes[ UI_SHAPE_BUTTON_SMALL ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_small_bits, button_small_width, button_small_height );
ui->shapes[ UI_SHAPE_BUTTON_NORMAL ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_normal_bits, button_normal_width, button_normal_height );
ui->shapes[ UI_SHAPE_BUTTON_LARGE ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_large_bits, button_large_width, button_large_height );
ui->shapes[ UI_SHAPE_BUTTON_ROUND ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_round_bits, button_round_width, button_round_height );
/* create all colors */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_BLACK ], 0x00, 0x00, 0x00 ); /* #000000 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_WHITE ], 0xff, 0xff, 0xff ); /* #ffffff */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_YELLOW ], 0xfa, 0xe8, 0x2c ); /* #fae82c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_RED ], 0x8e, 0x25, 0x18 ); /* #8e2518 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GREEN ], 0x14, 0x4d, 0x49 ); /* #144d49 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_SILVER ], 0xe0, 0xe0, 0xe0 ); /* #e0e0e0 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_ORANGE ], 0xc0, 0x6e, 0x60 ); /* #c06e60 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_BLUE ], 0x40, 0x60, 0xa4 ); /* #4060a4 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_0 ], 0xab, 0xd2, 0xb4 ); /* #abd2b4 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_1 ], 0xa0, 0xc4, 0xa8 ); /* #a0c4a8 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_2 ], 0x94, 0xb6, 0x9c ); /* #94b69c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_3 ], 0x89, 0xa8, 0x90 ); /* #89a890 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_4 ], 0x7d, 0x9a, 0x84 ); /* #7d9a84 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_5 ], 0x72, 0x8c, 0x78 ); /* #728c78 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_6 ], 0x67, 0x7e, 0x6c ); /* #677e6c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_7 ], 0x5b, 0x70, 0x60 ); /* #5b7060 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_8 ], 0x50, 0x62, 0x54 ); /* #506254 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_9 ], 0x44, 0x54, 0x48 ); /* #445448 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_10 ], 0x39, 0x46, 0x3c ); /* #39463c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_11 ], 0x2e, 0x38, 0x30 ); /* #2e3830 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_12 ], 0x22, 0x2a, 0x24 ); /* #222a24 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_13 ], 0x17, 0x1c, 0x18 ); /* #171c18 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_14 ], 0x0b, 0x03, 0x0c ); /* #0b030c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_15 ], 0x00, 0x00, 0x00 ); /* #000000 */
/* set calculator type and name */
switch ( opt.model ) {
case MODEL_50G_NEWRPL:
ui->calculator = UI_CALCULATOR_HP50G_NEWRPL;
@ -3268,10 +3302,10 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
gdk_pixbuf_get_file_info( imagefile, &ui->width, &ui->height );
close( fd );
/* set coordinates of LCD and keyboard */
ui->lcd_width = 131 * LCD_PIXEL_SCALE;
ui->lcd_top_margin = 16;
ui->lcd_height = 80 * LCD_PIXEL_SCALE + ui->lcd_top_margin;
ui->lcd_annunciators_height = 16;
ui->lcd_height = ( 80 * LCD_PIXEL_SCALE ) + ui->lcd_annunciators_height;
ui->lcd_x_offset = ( ui->width - ui->lcd_width ) / 2;
ui->lcd_y_offset = 48; // 69;
@ -3290,6 +3324,7 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
// gtk_window_set_icon(GTK_WINDOW(ui->window), ui->bg_pixbuf);
GdkBitmap* shape;
gdk_pixbuf_render_pixmap_and_mask( ui->bg_pixbuf, NULL, &shape, 255 );
gtk_widget_set_size_request( ui->window, ui->width, ui->height );
@ -3299,17 +3334,6 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
gtk_widget_realize( ui->window );
ui->shapes[ UI_SHAPE_BUTTON_TINY ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_tiny_bits, button_tiny_width, button_tiny_height );
ui->shapes[ UI_SHAPE_BUTTON_SMALL ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_small_bits, button_small_width, button_small_height );
ui->shapes[ UI_SHAPE_BUTTON_NORMAL ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_normal_bits, button_normal_width, button_normal_height );
ui->shapes[ UI_SHAPE_BUTTON_LARGE ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_large_bits, button_large_width, button_large_height );
ui->shapes[ UI_SHAPE_BUTTON_ROUND ] =
gdk_bitmap_create_from_data( NULL, ( char* )button_round_bits, button_round_width, button_round_height );
ui->fixed = gtk_fixed_new();
gtk_container_add( GTK_CONTAINER( ui->window ), ui->fixed );
@ -3317,40 +3341,17 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
gtk_drawing_area_size( GTK_DRAWING_AREA( ui->background ), ui->width, ui->height );
x49gp_ui_place_at( x49gp, GTK_FIXED( ui->fixed ), ui->background, 0, 0, ui->width, ui->height );
x49gp_ui_color_init( &ui->colors[ UI_COLOR_BLACK ], 0x00, 0x00, 0x00 ); /* #000000 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_WHITE ], 0xff, 0xff, 0xff ); /* #ffffff */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_YELLOW ], 0xfa, 0xe8, 0x2c ); /* #fae82c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_RED ], 0x8e, 0x25, 0x18 ); /* #8e2518 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GREEN ], 0x14, 0x4d, 0x49 ); /* #144d49 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_SILVER ], 0xe0, 0xe0, 0xe0 ); /* #e0e0e0 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_ORANGE ], 0xc0, 0x6e, 0x60 ); /* #c06e60 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_BLUE ], 0x40, 0x60, 0xa4 ); /* #4060a4 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_0 ], 0xab, 0xd2, 0xb4 ); /* #abd2b4 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_1 ], 0xa0, 0xc4, 0xa8 ); /* #a0c4a8 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_2 ], 0x94, 0xb6, 0x9c ); /* #94b69c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_3 ], 0x89, 0xa8, 0x90 ); /* #89a890 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_4 ], 0x7d, 0x9a, 0x84 ); /* #7d9a84 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_5 ], 0x72, 0x8c, 0x78 ); /* #728c78 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_6 ], 0x67, 0x7e, 0x6c ); /* #677e6c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_7 ], 0x5b, 0x70, 0x60 ); /* #5b7060 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_8 ], 0x50, 0x62, 0x54 ); /* #506254 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_9 ], 0x44, 0x54, 0x48 ); /* #445448 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_10 ], 0x39, 0x46, 0x3c ); /* #39463c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_11 ], 0x2e, 0x38, 0x30 ); /* #2e3830 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_12 ], 0x22, 0x2a, 0x24 ); /* #222a24 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_13 ], 0x17, 0x1c, 0x18 ); /* #171c18 */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_14 ], 0x0b, 0x03, 0x0c ); /* #0b030c */
x49gp_ui_color_init( &ui->colors[ UI_COLOR_GRAYSCALE_15 ], 0x00, 0x00, 0x00 ); /* #000000 */
ui->lcd_canvas = gtk_drawing_area_new();
gtk_drawing_area_size( GTK_DRAWING_AREA( ui->lcd_canvas ), ui->lcd_width, ui->lcd_height );
screen_box = gtk_event_box_new();
GtkWidget* screen_box = gtk_event_box_new();
gtk_event_box_set_visible_window( GTK_EVENT_BOX( screen_box ), true );
gtk_event_box_set_above_child( GTK_EVENT_BOX( screen_box ), false );
gtk_container_add( GTK_CONTAINER( screen_box ), ui->lcd_canvas );
x49gp_ui_place_at( x49gp, GTK_FIXED( ui->fixed ), screen_box, ui->lcd_x_offset, ui->lcd_y_offset, ui->lcd_width, ui->lcd_height );
x49gp_ui_button_t* button;
const x49gp_ui_key_t* key;
for ( int i = 0; i < ui->nr_buttons; i++ ) {
switch ( ui->calculator ) {
case UI_CALCULATOR_HP49GP:
@ -3408,24 +3409,27 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
gtk_widget_add_events( button->button, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK );
}
// right-click menu
// {
ui->menu = gtk_menu_new();
menu_mount_folder = gtk_menu_item_new_with_label( "Mount SD folder ..." );
GtkWidget *menu_mount_folder = gtk_menu_item_new_with_label( "Mount SD folder ..." );
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), menu_mount_folder );
g_signal_connect( G_OBJECT( menu_mount_folder ), "activate", G_CALLBACK( x49gp_ui_mount_sd_folder ), x49gp );
menu_mount_image = gtk_menu_item_new_with_label( "Mount SD image ..." );
GtkWidget *menu_mount_image = gtk_menu_item_new_with_label( "Mount SD image ..." );
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), menu_mount_image );
g_signal_connect( G_OBJECT( menu_mount_image ), "activate", G_CALLBACK( x49gp_ui_mount_sd_image ), x49gp );
menu_unmount = gtk_menu_item_new_with_label( "Unmount SD" );
GtkWidget *menu_unmount = gtk_menu_item_new_with_label( "Unmount SD" );
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), menu_unmount );
g_signal_connect_swapped( G_OBJECT( menu_unmount ), "activate", G_CALLBACK( s3c2410_sdi_unmount ), x49gp );
ui->menu_unmount = menu_unmount;
if ( x49gp->debug_port != 0 ) {
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), gtk_separator_menu_item_new() );
menu_debug = gtk_menu_item_new_with_label( "Start debugger" );
GtkWidget *menu_debug = gtk_menu_item_new_with_label( "Start debugger" );
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), menu_debug );
g_signal_connect( G_OBJECT( menu_debug ), "activate", G_CALLBACK( x49gp_ui_debug ), x49gp );
ui->menu_debug = menu_debug;
@ -3433,14 +3437,17 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
ui->menu_debug = NULL;
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), gtk_separator_menu_item_new() );
menu_reset = gtk_menu_item_new_with_label( "Reset" );
GtkWidget *menu_reset = gtk_menu_item_new_with_label( "Reset" );
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), menu_reset );
g_signal_connect( G_OBJECT( menu_reset ), "activate", G_CALLBACK( x49gp_ui_calculator_reset ), x49gp );
menu_quit = gtk_menu_item_new_with_label( "Quit" );
GtkWidget *menu_quit = gtk_menu_item_new_with_label( "Quit" );
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), menu_quit );
g_signal_connect_swapped( G_OBJECT( menu_quit ), "activate", G_CALLBACK( x49gp_ui_quit ), x49gp );
gtk_widget_show_all( ui->menu );
// }
g_signal_connect( G_OBJECT( screen_box ), "button-press-event", G_CALLBACK( x49gp_ui_show_menu ), x49gp );
@ -3462,6 +3469,7 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
gtk_widget_add_events( ui->window, GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK );
gtk_widget_show_all( ui->window );
return 0;
}

View file

@ -137,7 +137,7 @@ struct __x49gp_ui_s__ {
gint lcd_y_offset;
gint lcd_width;
gint lcd_height;
gint lcd_top_margin;
gint lcd_annunciators_height;
};
int x49gp_ui_init( x49gp_t* x49gp );