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;
}
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 )
{
#ifdef DEBUG_X49GP_UI
@ -1486,6 +1462,30 @@ static gboolean react_to_window_click( GtkWidget* widget, GdkEventButton* event,
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 )
{
x49gp_t* x49gp = user_data;
@ -1722,92 +1722,89 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
if ( ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL || ui->calculator == UI_CALCULATOR_HP50G_NEWRPL )
_ui_load__newrplify_ui_keys();
for ( int i = 0; i < NB_KEYS; i++ ) {
button = &ui->buttons[ i ];
int key_index = 0;
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->key = &ui_keys[ key_index ];
button->x49gp = x49gp;
button->key = &ui_keys[ i ];
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_can_focus( button->button, false );
gtk_widget_add_events( button->button, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK );
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 ), "leave-notify-event", G_CALLBACK( react_to_button_leave ), button );
button->button = gtk_button_new();
gtk_widget_set_size_request( button->button, button->key->width, button->key->height );
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_fixed_put( GTK_FIXED( keyboard_container ), button->button, button->key->x, KEYBOARD_PADDING + button->key->y );
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 );
if ( button->key->label ) {
ui_label = gtk_label_new( NULL );
gtk_style_context_add_class( gtk_widget_get_style_context( ui_label ), "label-key" );
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 ), "leave-notify-event", G_CALLBACK( react_to_button_leave ), button );
gtk_label_set_use_markup( GTK_LABEL( ui_label ), true );
gtk_label_set_markup( GTK_LABEL( ui_label ), button->key->label );
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_fixed_put( GTK_FIXED( keyboard_container ), button->box, button->key->x, KEYBOARD_PADDING + button->key->y );
if ( button->key->label ) {
ui_label = gtk_label_new( NULL );
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_markup( GTK_LABEL( ui_label ), button->key->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 );
gtk_container_add( GTK_CONTAINER( button->button ), ui_label );
}
y = y2 = button->key->y - ( TINY_TEXT_HEIGHT + 2 );
if ( button->key->right ) {
x = button->key->x;
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 );
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 ) {
x -= ( ( _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;
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->right ) {
x = button->key->x;
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 );
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 ) {
x -=
( ( _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 ) {
ui_letter = gtk_label_new( NULL );
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_markup( GTK_LABEL( ui_letter ), button->key->letter );
if ( button->key->letter ) {
ui_letter = gtk_label_new( NULL );
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_markup( GTK_LABEL( ui_letter ), button->key->letter );
x = button->key->x + button->key->width + ( TINY_TEXT_WIDTH / 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 );
}
if ( button->key->below ) {
ui_below = gtk_label_new( NULL );
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_markup( GTK_LABEL( ui_below ), button->key->below );
x = button->key->x + button->key->width + ( TINY_TEXT_WIDTH / 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 );
}
if ( button->key->below ) {
ui_below = gtk_label_new( NULL );
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_markup( GTK_LABEL( ui_below ), button->key->below );
x = button->key->x + ( ( button->key->width - _tiny_text_width( button->key->below ) ) / 2 );
y = button->key->y + button->key->height + 2;
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_below, x, KEYBOARD_PADDING + y );
x = button->key->x + ( ( button->key->width - _tiny_text_width( button->key->below ) ) / 2 );
y = button->key->y + button->key->height + 2;
gtk_fixed_put( GTK_FIXED( keyboard_container ), ui_below, x, KEYBOARD_PADDING + y );
}
key_index++;
}
}
// Right-click menu
ui->menu = gtk_menu_new();
@ -1894,12 +1891,12 @@ void gui_update_lcd( x49gp_t* x49gp )
s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd;
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_right, x49gp_get_pixel_color( lcd, 131, 2 ) > 0 ? 1 : 0 );
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_battery, x49gp_get_pixel_color( lcd, 131, 4 ) > 0 ? 1 : 0 );
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_io, x49gp_get_pixel_color( lcd, 131, 0 ) > 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 ) );
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 ) );
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 ) );
for ( int y = 0; y < ( LCD_HEIGHT / LCD_PIXEL_SCALE ); y++ )
for ( int x = 0; x < ( LCD_WIDTH / LCD_PIXEL_SCALE ); x++ )

View file

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