1
0
Fork 0
forked from Miroirs/x49gp

Compare commits

...

4 commits

Author SHA1 Message Date
Gwenhael Le Moine
a2f5b119bf
button->box isn't necessary 2024-11-10 11:17:23 +01:00
Gwenhael Le Moine
3b8474337d
build keyboard by rows and columns 2024-11-10 11:10:48 +01:00
Gwenhael Le Moine
3c38e3e46e
use annunciators' state directly as opacity 2024-11-10 11:10:20 +01:00
Gwenhael Le Moine
540f06d9fe
move code 2024-11-10 11:10:05 +01:00
2 changed files with 99 additions and 103 deletions

View file

@ -1424,30 +1424,6 @@ static gboolean react_to_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
return true; return true;
} }
static int redraw_lcd( GtkWidget* widget, cairo_t* cr, gpointer user_data )
{
x49gp_t* x49gp = user_data;
x49gp_ui_t* ui = x49gp->ui;
cairo_set_source_surface( cr, ui->lcd_surface, 0, 0 );
cairo_paint( cr );
return false;
}
static int draw_lcd( GtkWidget* widget, GdkEventConfigure* event, gpointer user_data )
{
x49gp_t* x49gp = user_data;
x49gp_ui_t* ui = x49gp->ui;
if ( NULL != ui->lcd_surface )
return false;
ui->lcd_surface = cairo_image_surface_create( CAIRO_FORMAT_RGB24, LCD_WIDTH, LCD_HEIGHT );
return false;
}
static gboolean react_to_window_click( GtkWidget* widget, GdkEventButton* event, gpointer user_data ) static gboolean react_to_window_click( GtkWidget* widget, GdkEventButton* event, gpointer user_data )
{ {
#ifdef DEBUG_X49GP_UI #ifdef DEBUG_X49GP_UI
@ -1486,6 +1462,30 @@ static gboolean react_to_window_click( GtkWidget* widget, GdkEventButton* event,
return false; return false;
} }
static int redraw_lcd( GtkWidget* widget, cairo_t* cr, gpointer user_data )
{
x49gp_t* x49gp = user_data;
x49gp_ui_t* ui = x49gp->ui;
cairo_set_source_surface( cr, ui->lcd_surface, 0, 0 );
cairo_paint( cr );
return false;
}
static int draw_lcd( GtkWidget* widget, GdkEventConfigure* event, gpointer user_data )
{
x49gp_t* x49gp = user_data;
x49gp_ui_t* ui = x49gp->ui;
if ( NULL != ui->lcd_surface )
return false;
ui->lcd_surface = cairo_image_surface_create( CAIRO_FORMAT_RGB24, LCD_WIDTH, LCD_HEIGHT );
return false;
}
static void do_quit( gpointer user_data, GtkWidget* widget, GdkEvent* event ) static void do_quit( gpointer user_data, GtkWidget* widget, GdkEvent* event )
{ {
x49gp_t* x49gp = user_data; x49gp_t* x49gp = user_data;
@ -1722,30 +1722,23 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
if ( ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL || ui->calculator == UI_CALCULATOR_HP50G_NEWRPL ) if ( ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL || ui->calculator == UI_CALCULATOR_HP50G_NEWRPL )
_ui_load__newrplify_ui_keys(); _ui_load__newrplify_ui_keys();
for ( int i = 0; i < NB_KEYS; i++ ) { int key_index = 0;
button = &ui->buttons[ i ]; for ( int row = 0; row < 10; row++ ) {
for ( int column = 0; column < ( ( row == 0 ) ? 6 : 5 ); column++ ) {
button = &ui->buttons[ key_index ];
button->x49gp = x49gp; button->x49gp = x49gp;
button->key = &ui_keys[ i ]; button->key = &ui_keys[ key_index ];
button->button = gtk_button_new(); button->button = gtk_button_new();
gtk_style_context_add_class( gtk_widget_get_style_context( button->button ), button->key->css_class );
gtk_widget_set_size_request( button->button, button->key->width, button->key->height ); gtk_widget_set_size_request( button->button, button->key->width, button->key->height );
gtk_widget_set_can_focus( button->button, false ); gtk_widget_set_can_focus( button->button, false );
gtk_style_context_add_class( gtk_widget_get_style_context( button->button ), button->key->css_class ); gtk_widget_add_events( button->button, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK );
button->box = gtk_event_box_new();
gtk_event_box_set_visible_window( GTK_EVENT_BOX( button->box ), true );
gtk_event_box_set_above_child( GTK_EVENT_BOX( button->box ), false );
gtk_container_add( GTK_CONTAINER( button->box ), button->button );
g_signal_connect( G_OBJECT( button->button ), "button-press-event", G_CALLBACK( react_to_button_press ), button ); g_signal_connect( G_OBJECT( button->button ), "button-press-event", G_CALLBACK( react_to_button_press ), button );
g_signal_connect( G_OBJECT( button->button ), "button-release-event", G_CALLBACK( react_to_button_release ), button ); g_signal_connect( G_OBJECT( button->button ), "button-release-event", G_CALLBACK( react_to_button_release ), button );
g_signal_connect( G_OBJECT( button->button ), "leave-notify-event", G_CALLBACK( react_to_button_leave ), button ); g_signal_connect( G_OBJECT( button->button ), "leave-notify-event", G_CALLBACK( react_to_button_leave ), button );
gtk_widget_add_events( button->button, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK ); gtk_fixed_put( GTK_FIXED( keyboard_container ), button->button, button->key->x, KEYBOARD_PADDING + button->key->y );
gtk_widget_set_size_request( button->box, button->key->width, button->key->height );
gtk_fixed_put( GTK_FIXED( keyboard_container ), button->box, button->key->x, KEYBOARD_PADDING + button->key->y );
if ( button->key->label ) { if ( button->key->label ) {
ui_label = gtk_label_new( NULL ); ui_label = gtk_label_new( NULL );
@ -1775,8 +1768,10 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
x2 = button->key->x + button->key->width - _tiny_text_width( button->key->right ); x2 = button->key->x + button->key->width - _tiny_text_width( button->key->right );
if ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) > button->key->width ) { if ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) > button->key->width ) {
x -= ( ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) ) - button->key->width ) / 2; x -=
x2 += ( ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) ) - button->key->width ) / 2; ( ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) ) - button->key->width ) / 2;
x2 +=
( ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) ) - button->key->width ) / 2;
} }
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_left, x, KEYBOARD_PADDING + y ); gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_left, x, KEYBOARD_PADDING + y );
@ -1806,8 +1801,10 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
y = button->key->y + button->key->height + 2; y = button->key->y + button->key->height + 2;
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_below, x, KEYBOARD_PADDING + y ); gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_below, x, KEYBOARD_PADDING + y );
} }
}
key_index++;
}
}
// Right-click menu // Right-click menu
ui->menu = gtk_menu_new(); ui->menu = gtk_menu_new();
@ -1894,12 +1891,12 @@ void gui_update_lcd( x49gp_t* x49gp )
s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd; s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd;
if ( lcd->lcdcon1 & 1 ) { if ( lcd->lcdcon1 & 1 ) {
gtk_widget_set_opacity( ui->ui_ann_left, x49gp_get_pixel_color( lcd, 131, 1 ) > 0 ? 1 : 0 ); gtk_widget_set_opacity( ui->ui_ann_left, x49gp_get_pixel_color( lcd, 131, 1 ) );
gtk_widget_set_opacity( ui->ui_ann_right, x49gp_get_pixel_color( lcd, 131, 2 ) > 0 ? 1 : 0 ); gtk_widget_set_opacity( ui->ui_ann_right, x49gp_get_pixel_color( lcd, 131, 2 ) );
gtk_widget_set_opacity( ui->ui_ann_alpha, x49gp_get_pixel_color( lcd, 131, 3 ) > 0 ? 1 : 0 ); gtk_widget_set_opacity( ui->ui_ann_alpha, x49gp_get_pixel_color( lcd, 131, 3 ) );
gtk_widget_set_opacity( ui->ui_ann_battery, x49gp_get_pixel_color( lcd, 131, 4 ) > 0 ? 1 : 0 ); gtk_widget_set_opacity( ui->ui_ann_battery, x49gp_get_pixel_color( lcd, 131, 4 ) );
gtk_widget_set_opacity( ui->ui_ann_busy, x49gp_get_pixel_color( lcd, 131, 5 ) > 0 ? 1 : 0 ); gtk_widget_set_opacity( ui->ui_ann_busy, x49gp_get_pixel_color( lcd, 131, 5 ) );
gtk_widget_set_opacity( ui->ui_ann_io, x49gp_get_pixel_color( lcd, 131, 0 ) > 0 ? 1 : 0 ); gtk_widget_set_opacity( ui->ui_ann_io, x49gp_get_pixel_color( lcd, 131, 0 ) );
for ( int y = 0; y < ( LCD_HEIGHT / LCD_PIXEL_SCALE ); y++ ) for ( int y = 0; y < ( LCD_HEIGHT / LCD_PIXEL_SCALE ); y++ )
for ( int x = 0; x < ( LCD_WIDTH / LCD_PIXEL_SCALE ); x++ ) for ( int x = 0; x < ( LCD_WIDTH / LCD_PIXEL_SCALE ); x++ )

View file

@ -58,7 +58,6 @@ typedef struct {
x49gp_t* x49gp; x49gp_t* x49gp;
const x49gp_ui_key_t* key; const x49gp_ui_key_t* key;
GtkWidget* button; GtkWidget* button;
GtkWidget* box;
gboolean down; gboolean down;
gboolean hold; gboolean hold;
} x49gp_ui_button_t; } x49gp_ui_button_t;