1
0
Fork 0
forked from Miroirs/x49gp

build keyboard by rows and columns

This commit is contained in:
Gwenhael Le Moine 2024-11-10 11:10:48 +01:00
parent 3c38e3e46e
commit 3b8474337d
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -1722,92 +1722,98 @@ 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_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_style_context_add_class( gtk_widget_get_style_context( button->button ), button->key->css_class );
button->box = gtk_event_box_new(); button->box = gtk_event_box_new();
gtk_event_box_set_visible_window( GTK_EVENT_BOX( button->box ), true ); 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_event_box_set_above_child( GTK_EVENT_BOX( button->box ), false );
gtk_container_add( GTK_CONTAINER( button->box ), button->button ); 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_widget_add_events( button->button, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK );
gtk_widget_set_size_request( button->box, button->key->width, button->key->height ); 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 ); 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 );
gtk_style_context_add_class( gtk_widget_get_style_context( ui_label ), "label-key" ); gtk_style_context_add_class( gtk_widget_get_style_context( ui_label ), "label-key" );
gtk_label_set_use_markup( GTK_LABEL( ui_label ), true ); gtk_label_set_use_markup( GTK_LABEL( ui_label ), true );
gtk_label_set_markup( GTK_LABEL( ui_label ), button->key->label ); gtk_label_set_markup( GTK_LABEL( ui_label ), button->key->label );
gtk_container_add( GTK_CONTAINER( button->button ), ui_label ); gtk_container_add( GTK_CONTAINER( button->button ), ui_label );
}
if ( button->key->left ) {
ui_left = gtk_label_new( NULL );
gtk_style_context_add_class( gtk_widget_get_style_context( ui_left ), "label-left" );
gtk_label_set_use_markup( GTK_LABEL( ui_left ), true );
gtk_label_set_markup( GTK_LABEL( ui_left ), button->key->left );
if ( button->key->right ) {
ui_right = gtk_label_new( NULL );
gtk_style_context_add_class( gtk_widget_get_style_context( ui_right ), "label-right" );
gtk_label_set_use_markup( GTK_LABEL( ui_right ), true );
gtk_label_set_markup( GTK_LABEL( ui_right ), button->key->right );
} }
y = y2 = button->key->y - ( TINY_TEXT_HEIGHT + 2 ); if ( button->key->left ) {
if ( button->key->right ) { ui_left = gtk_label_new( NULL );
x = button->key->x; gtk_style_context_add_class( gtk_widget_get_style_context( ui_left ), "label-left" );
gtk_label_set_use_markup( GTK_LABEL( ui_left ), true );
gtk_label_set_markup( GTK_LABEL( ui_left ), button->key->left );
x2 = button->key->x + button->key->width - _tiny_text_width( button->key->right ); if ( button->key->right ) {
ui_right = gtk_label_new( NULL );
if ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) > button->key->width ) { gtk_style_context_add_class( gtk_widget_get_style_context( ui_right ), "label-right" );
x -= ( ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) ) - button->key->width ) / 2; gtk_label_set_use_markup( GTK_LABEL( ui_right ), true );
x2 += ( ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) ) - button->key->width ) / 2; gtk_label_set_markup( GTK_LABEL( ui_right ), button->key->right );
} }
y = y2 = button->key->y - ( TINY_TEXT_HEIGHT + 2 );
if ( button->key->right ) {
x = button->key->x;
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_left, x, KEYBOARD_PADDING + y ); x2 = button->key->x + button->key->width - _tiny_text_width( button->key->right );
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_right, x2, KEYBOARD_PADDING + y2 );
} else { if ( _tiny_text_width( button->key->right ) + _tiny_text_width( button->key->left ) > button->key->width ) {
x = button->key->x + ( ( button->key->width - _tiny_text_width( button->key->left ) ) / 2 ); x -=
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_left, x, KEYBOARD_PADDING + y ); ( ( _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_right, x2, KEYBOARD_PADDING + y2 );
} else {
x = button->key->x + ( ( button->key->width - _tiny_text_width( button->key->left ) ) / 2 );
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_left, x, KEYBOARD_PADDING + y );
}
} }
} if ( button->key->letter ) {
if ( button->key->letter ) { ui_letter = gtk_label_new( NULL );
ui_letter = gtk_label_new( NULL ); gtk_style_context_add_class( gtk_widget_get_style_context( ui_letter ), "label-letter" );
gtk_style_context_add_class( gtk_widget_get_style_context( ui_letter ), "label-letter" ); gtk_label_set_use_markup( GTK_LABEL( ui_letter ), true );
gtk_label_set_use_markup( GTK_LABEL( ui_letter ), true ); gtk_label_set_markup( GTK_LABEL( ui_letter ), button->key->letter );
gtk_label_set_markup( GTK_LABEL( ui_letter ), button->key->letter );
x = button->key->x + button->key->width + ( TINY_TEXT_WIDTH / 2 ); x = button->key->x + button->key->width + ( TINY_TEXT_WIDTH / 2 );
y = button->key->y + button->key->height - ( TINY_TEXT_HEIGHT / 2 ); y = button->key->y + button->key->height - ( TINY_TEXT_HEIGHT / 2 );
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_letter, x, KEYBOARD_PADDING + y ); gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_letter, x, KEYBOARD_PADDING + y );
} }
if ( button->key->below ) { if ( button->key->below ) {
ui_below = gtk_label_new( NULL ); ui_below = gtk_label_new( NULL );
gtk_style_context_add_class( gtk_widget_get_style_context( ui_below ), "label-below" ); gtk_style_context_add_class( gtk_widget_get_style_context( ui_below ), "label-below" );
gtk_label_set_use_markup( GTK_LABEL( ui_below ), true ); gtk_label_set_use_markup( GTK_LABEL( ui_below ), true );
gtk_label_set_markup( GTK_LABEL( ui_below ), button->key->below ); gtk_label_set_markup( GTK_LABEL( ui_below ), button->key->below );
x = button->key->x + ( ( button->key->width - _tiny_text_width( button->key->below ) ) / 2 ); x = button->key->x + ( ( button->key->width - _tiny_text_width( button->key->below ) ) / 2 );
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();