1
0
Fork 0
forked from Miroirs/x49gp

Compare commits

...

3 commits

Author SHA1 Message Date
Gwenhael Le Moine
9c6da9257a
fiddling to try to understand ui.c 2024-10-30 15:41:37 +01:00
Gwenhael Le Moine
8a47fd4ff8
tweaks 2024-10-30 14:44:17 +01:00
Gwenhael Le Moine
97a3df3e18
make font a parametrable option 2024-10-30 14:37:38 +01:00
5 changed files with 106 additions and 114 deletions

View file

@ -168,6 +168,9 @@ $(QEMU_DIR)/config-host.h:
$(QEMU_OBJS): dummy $(QEMU_OBJS): dummy
+$(MAKE) -C $(QEMU_DIR) -f Makefile-small +$(MAKE) -C $(QEMU_DIR) -f Makefile-small
clean-qemu:
$(MAKE) -C $(QEMU_DIR) -f Makefile-small clean
# Depend # Depend
MAKEDEPEND = $(CC) -MM MAKEDEPEND = $(CC) -MM
@ -180,17 +183,13 @@ depend: depend-libs
$(MAKEDEPEND) $(X49GP_CFLAGS) $(SRCS) >.depend $(MAKEDEPEND) $(X49GP_CFLAGS) $(SRCS) >.depend
# Cleaning # Cleaning
clean-qemu: clean:
$(MAKE) -C $(QEMU_DIR) -f Makefile-small clean
clean: clean-qemu
rm -f ./src/x49gpng/*.o core *~ .depend rm -f ./src/x49gpng/*.o core *~ .depend
distclean: clean distclean: clean clean-qemu
$(MAKE) -C $(QEMU_DIR) -f Makefile-small distclean
rm -f dist/$(TARGET) dist/$(TARGET).desktop dist/$(TARGET).man rm -f dist/$(TARGET) dist/$(TARGET).desktop dist/$(TARGET).man
mrproper: clean-qemu distclean mrproper: distclean
make -C dist/firmware/ mrproper make -C dist/firmware/ mrproper
# auto-format code # auto-format code

View file

@ -29,7 +29,13 @@ void config_init( char* progname, int argc, char* argv[] )
opt.model = MODEL_50G; opt.model = MODEL_50G;
opt.name = NULL; opt.name = NULL;
const char* optstring = "hrc:D:df:Fn:"; #if defined( __linux__ )
opt.font = "urw gothic l";
#else
opt.font = "Century Gothic";
#endif
const char* optstring = "hrc:D:df:Fn:t:";
struct option long_options[] = { struct option long_options[] = {
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
@ -47,6 +53,8 @@ void config_init( char* progname, int argc, char* argv[] )
{"49gp-newrpl", no_argument, NULL, 497}, {"49gp-newrpl", no_argument, NULL, 497},
{"name", required_argument, NULL, 'n'}, {"name", required_argument, NULL, 'n'},
{"font", required_argument, NULL, 't'},
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
@ -66,6 +74,7 @@ void config_init( char* progname, int argc, char* argv[] )
" --49gp show HP 49g+ faceplate\n" " --49gp show HP 49g+ faceplate\n"
" --49gp-newrpl show HP 49g+ faceplate with newRPL labels\n" " --49gp-newrpl show HP 49g+ faceplate with newRPL labels\n"
" -n --name[=<name>] set alternate UI name\n" " -n --name[=<name>] set alternate UI name\n"
" -t --font[=<fontname>] set alternate UI font\n"
" -D --enable-debug[=<port>] enable the debugger interface\n" " -D --enable-debug[=<port>] enable the debugger interface\n"
" (default port: %u)\n" " (default port: %u)\n"
" -d --debug use along -D to also start the debugger immediately\n" " -d --debug use along -D to also start the debugger immediately\n"
@ -117,6 +126,9 @@ void config_init( char* progname, int argc, char* argv[] )
case 'n': case 'n':
opt.name = strdup( optarg ); opt.name = strdup( optarg );
break; break;
case 't':
opt.font = strdup( optarg );
break;
default: default:
break; break;
} }

View file

@ -24,6 +24,8 @@ struct options {
x49gpng_model_t model; x49gpng_model_t model;
char* name; char* name;
char* font;
}; };
extern struct options opt; extern struct options opt;

View file

@ -337,7 +337,7 @@ void x49gp_lcd_update( x49gp_t* x49gp )
for ( int x = 0; x < ( ui->lcd_width / LCD_PIXEL_SCALE ); x++ ) for ( int x = 0; x < ( ui->lcd_width / LCD_PIXEL_SCALE ); x++ )
x49gp_draw_rectangle( ui->lcd_pixmap, LCD_PIXEL_SCALE * x, LCD_PIXEL_SCALE * y + ui->lcd_annunciators_height, x49gp_draw_rectangle( ui->lcd_pixmap, LCD_PIXEL_SCALE * x, LCD_PIXEL_SCALE * y + ui->lcd_annunciators_height,
LCD_PIXEL_SCALE, LCD_PIXEL_SCALE, LCD_PIXEL_SCALE, LCD_PIXEL_SCALE,
&(ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, x, y ) ]) ); &( ui->colors[ UI_COLOR_GRAYSCALE_0 + x49gp_get_pixel_color( lcd, x, y ) ] ) );
} }
GdkRectangle rect; GdkRectangle rect;

View file

@ -29,13 +29,7 @@
#include "gdbstub.h" #include "gdbstub.h"
#define DEBUG_LAYOUT false #define DEBUG_LAYOUT true
#if defined( __linux__ )
# define X49GP_UI_NORMAL_FONT "urw gothic l"
#else
# define X49GP_UI_NORMAL_FONT "Century Gothic"
#endif
static const x49gp_ui_key_t x49gp_ui_keys[] = { static const x49gp_ui_key_t x49gp_ui_keys[] = {
{"F1", "A", "Y=", NULL, NULL, UI_COLOR_BLACK, 12.0, CAIRO_FONT_WEIGHT_BOLD, UI_SHAPE_BUTTON_TINY, 12.0, UI_LAYOUT_LEFT, 0, 0, {"F1", "A", "Y=", NULL, NULL, UI_COLOR_BLACK, 12.0, CAIRO_FONT_WEIGHT_BOLD, UI_SHAPE_BUTTON_TINY, 12.0, UI_LAYOUT_LEFT, 0, 0,
@ -1599,6 +1593,7 @@ static int x49gp_ui_button_pixmaps_init( x49gp_t* x49gp, x49gp_ui_button_t* butt
GdkPixbuf *src, *dst; GdkPixbuf *src, *dst;
cairo_t* cr; cairo_t* cr;
GtkStyle* style = gtk_style_new(); GtkStyle* style = gtk_style_new();
x49gp_ui_style_init( style, button->button, &ui->colors[ button->key->color ], &ui->colors[ UI_COLOR_BLACK ] ); x49gp_ui_style_init( style, button->button, &ui->colors[ button->key->color ], &ui->colors[ UI_COLOR_BLACK ] );
for ( int i = 0; i < 5; i++ ) { for ( int i = 0; i < 5; i++ ) {
@ -2292,30 +2287,6 @@ void x49gp_ui_show_error( x49gp_t* x49gp, const char* text )
gtk_widget_destroy( dialog ); gtk_widget_destroy( dialog );
} }
static void x49gp_ui_choose_file( x49gp_t* x49gp, const char* prompt, GtkFileChooserAction action, char** filename )
{
GtkWidget* dialog;
x49gp_ui_t* ui = x49gp->ui;
dialog = gtk_file_chooser_dialog_new( prompt, GTK_WINDOW( ui->window ), action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
GTK_RESPONSE_ACCEPT, NULL );
gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( dialog ), true );
gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( dialog ), false );
if ( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_ACCEPT )
*filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ) );
else
*filename = NULL;
gtk_widget_destroy( dialog );
}
void x49gp_ui_open_firmware( x49gp_t* x49gp, char** filename )
{
x49gp_ui_choose_file( x49gp, "Choose firmware ...", GTK_FILE_CHOOSER_ACTION_OPEN, filename );
}
static gboolean x49gp_ui_button_press( GtkWidget* widget, GdkEventButton* event, gpointer user_data ) static gboolean x49gp_ui_button_press( GtkWidget* widget, GdkEventButton* event, gpointer user_data )
{ {
x49gp_ui_button_t* button = user_data; x49gp_ui_button_t* button = user_data;
@ -2364,8 +2335,8 @@ static gboolean x49gp_ui_button_press( GtkWidget* widget, GdkEventButton* event,
static void x49gp_release_single_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cause ) static void x49gp_release_single_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cause )
{ {
x49gp_t* x49gp = button->x49gp; x49gp_t* x49gp = button->x49gp;
const x49gp_ui_key_t* key; const x49gp_ui_key_t* key = button->key;
GtkButton* gtkbutton; GtkButton* gtkbutton = GTK_BUTTON( button->button );
/* #ifdef DEBUG_X49GP_UI */ /* #ifdef DEBUG_X49GP_UI */
/* printf( "%s: button %u: col %u, row %u, eint %u\n", __FUNCTION__, event->button, button->key->column, button->key->row, */ /* printf( "%s: button %u: col %u, row %u, eint %u\n", __FUNCTION__, event->button, button->key->column, button->key->row, */
@ -2375,14 +2346,10 @@ static void x49gp_release_single_button( x49gp_ui_button_t* button, x49gp_ui_but
button->down = false; button->down = false;
button->hold = false; button->hold = false;
gtkbutton = GTK_BUTTON( button->button );
/* if ( button != cause ) */ /* if ( button != cause ) */
/* gtkbutton->in_button = false; */ /* gtkbutton->in_button = false; */
gtk_button_released( gtkbutton ); gtk_button_released( gtkbutton );
key = button->key;
if ( key->rowbit ) if ( key->rowbit )
s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, 0 ); s3c2410_io_port_g_update( x49gp, key->column, key->row, key->columnbit, key->rowbit, 0 );
else else
@ -2487,6 +2454,30 @@ static void x49gp_ui_popup_at_widget( GtkMenu* menu, gint* x, gint* y, gboolean*
*y += widget_allocation.y; *y += widget_allocation.y;
} }
static void x49gp_ui_choose_file( x49gp_t* x49gp, const char* prompt, GtkFileChooserAction action, char** filename )
{
GtkWidget* dialog;
x49gp_ui_t* ui = x49gp->ui;
dialog = gtk_file_chooser_dialog_new( prompt, GTK_WINDOW( ui->window ), action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
GTK_RESPONSE_ACCEPT, NULL );
gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( dialog ), true );
gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( dialog ), false );
if ( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_ACCEPT )
*filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ) );
else
*filename = NULL;
gtk_widget_destroy( dialog );
}
void x49gp_ui_open_firmware( x49gp_t* x49gp, char** filename )
{
x49gp_ui_choose_file( x49gp, "Choose firmware ...", GTK_FILE_CHOOSER_ACTION_OPEN, filename );
}
static void x49gp_ui_mount_sd_folder( GtkMenuItem* menuitem, gpointer user_data ) static void x49gp_ui_mount_sd_folder( GtkMenuItem* menuitem, gpointer user_data )
{ {
x49gp_t* x49gp = user_data; x49gp_t* x49gp = user_data;
@ -2895,8 +2886,8 @@ static void x49gp_button_realize( GtkWidget* widget, gpointer user_data )
#endif #endif
if ( key->letter ) { if ( key->letter ) {
x49gp_ui_text_size( cr, X49GP_UI_NORMAL_FONT, key->letter_size, &xoff, &yoff, &width, &height, &ascent, &descent, 1, x49gp_ui_text_size( cr, opt.font, key->letter_size, &xoff, &yoff, &width, &height, &ascent, &descent, 1, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_SLANT_NORMAL, key->font_weight, key->letter ); key->font_weight, key->letter );
switch ( key->layout ) { switch ( key->layout ) {
case UI_LAYOUT_LEFT: case UI_LAYOUT_LEFT:
@ -2916,18 +2907,18 @@ static void x49gp_button_realize( GtkWidget* widget, gpointer user_data )
break; break;
} }
x49gp_ui_draw_text( cr, &ui->colors[ UI_COLOR_YELLOW ], X49GP_UI_NORMAL_FONT, key->letter_size, 0.0, x + xoffset, y + yoffset, 1, x49gp_ui_draw_text( cr, &ui->colors[ UI_COLOR_YELLOW ], opt.font, key->letter_size, 0.0, x + xoffset, y + yoffset, 1,
CAIRO_FONT_SLANT_NORMAL, key->font_weight, key->letter ); CAIRO_FONT_SLANT_NORMAL, key->font_weight, key->letter );
} }
x49gp_ui_text_size( cr, X49GP_UI_NORMAL_FONT, key->font_size, &xoff, &yoff, &width, &height, &ascent, &descent, 1, x49gp_ui_text_size( cr, opt.font, key->font_size, &xoff, &yoff, &width, &height, &ascent, &descent, 1, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_SLANT_NORMAL, key->font_weight, key->label ); key->font_weight, key->label );
x = ( int )floor( ( w - 1.0 - width ) / 2.0 - xoff + 0.5 ); x = ( int )floor( ( w - 1.0 - width ) / 2.0 - xoff + 0.5 );
y = ( int )floor( ( h - 1.0 + ascent ) / 2.0 + 0.5 ); y = ( int )floor( ( h - 1.0 + ascent ) / 2.0 + 0.5 );
x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->text[ 0 ], X49GP_UI_NORMAL_FONT, key->font_size, 0.0, x + xoffset, y + yoffset, x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->text[ 0 ], opt.font, key->font_size, 0.0, x + xoffset, y + yoffset, 1,
1, CAIRO_FONT_SLANT_NORMAL, key->font_weight, key->label ); CAIRO_FONT_SLANT_NORMAL, key->font_weight, key->label );
cairo_destroy( cr ); cairo_destroy( cr );
} }
@ -3016,8 +3007,8 @@ static int x49gp_lcd_configure_event( GtkWidget* widget, GdkEventConfigure* even
cairo_set_line_cap( cr, CAIRO_LINE_CAP_BUTT ); cairo_set_line_cap( cr, CAIRO_LINE_CAP_BUTT );
cairo_set_line_join( cr, CAIRO_LINE_JOIN_MITER ); cairo_set_line_join( cr, CAIRO_LINE_JOIN_MITER );
x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->black, X49GP_UI_NORMAL_FONT, 100.0, 1.0, ui->lcd_x_offset + 10, x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->black, opt.font, 100.0, 1.0, ui->lcd_x_offset + 10, ui->lcd_y_offset + 160,
ui->lcd_y_offset + 160, 1, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD, "\\arrowleftdblfull" ); 1, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD, "\\arrowleftdblfull" );
cairo_destroy( cr ); cairo_destroy( cr );
} }
@ -3060,11 +3051,11 @@ static int x49gp_window_configure_event( GtkWidget* widget, GdkEventConfigure* e
switch ( ui->calculator ) { switch ( ui->calculator ) {
case UI_CALCULATOR_HP49GP: case UI_CALCULATOR_HP49GP:
case UI_CALCULATOR_HP49GP_NEWRPL: case UI_CALCULATOR_HP49GP_NEWRPL:
x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->black, X49GP_UI_NORMAL_FONT, 15.0, 0.0, 14 /* 38 */, 20 /* 42 */, 2, x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->black, opt.font, 15.0, 0.0, 14 /* 38 */, 20 /* 42 */, 2,
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD, "hp", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD, "hp", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL,
" 49g+" ); " 49g+" );
x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->black, X49GP_UI_NORMAL_FONT, 13.0, 0.0, 14 /* 38 */, 34 /* 56 */, 1, x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->black, opt.font, 13.0, 0.0, 14 /* 38 */, 34 /* 56 */, 1,
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "graphing calculator" ); CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "graphing calculator" );
x49gp_ui_draw_symbol( cr, &gtk_widget_get_style( widget )->black, 10.0, 0.0, true, 114 /* 138 */, 8 /* 25 */, x49gp_ui_draw_symbol( cr, &gtk_widget_get_style( widget )->black, 10.0, 0.0, true, 114 /* 138 */, 8 /* 25 */,
@ -3081,11 +3072,11 @@ static int x49gp_window_configure_event( GtkWidget* widget, GdkEventConfigure* e
case UI_CALCULATOR_HP50G: case UI_CALCULATOR_HP50G:
case UI_CALCULATOR_HP50G_NEWRPL: case UI_CALCULATOR_HP50G_NEWRPL:
x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->white, X49GP_UI_NORMAL_FONT, 15.0, 0.0, 14 /* 38 */, 20 /* 42 */, 2, x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->white, opt.font, 15.0, 0.0, 14 /* 38 */, 20 /* 42 */, 2,
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "HP", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "HP", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL,
" 50g" ); " 50g" );
x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->white, X49GP_UI_NORMAL_FONT, 13.0, 0.0, 14 /* 38 */, 34 /* 56 */, 1, x49gp_ui_draw_text( cr, &gtk_widget_get_style( widget )->white, opt.font, 13.0, 0.0, 14 /* 38 */, 34 /* 56 */, 1,
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "Graphing Calculator" ); CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "Graphing Calculator" );
x49gp_ui_draw_symbol( cr, &gtk_widget_get_style( widget )->white, 10.0, 0.0, true, 134 /* 168 */, 8 /* 25 */, x49gp_ui_draw_symbol( cr, &gtk_widget_get_style( widget )->white, 10.0, 0.0, true, 134 /* 168 */, 8 /* 25 */,
@ -3290,13 +3281,12 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
int fd = x49gp_module_open_rodata( module, int fd = x49gp_module_open_rodata( module,
ui->calculator == UI_CALCULATOR_HP49GP || ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL ui->calculator == UI_CALCULATOR_HP49GP || ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL
? "hp49g+-cropped.png" ? "hp49g+-cropped.png"
: "hp50g-cropped.png", : "blank.png" /* "hp50g-cropped.png" */,
&imagefile ); &imagefile );
if ( fd < 0 ) if ( fd < 0 )
return fd; return fd;
ui->bg_pixbuf = gdk_pixbuf_new_from_file( imagefile, &gerror ); ui->bg_pixbuf = gdk_pixbuf_new_from_file( imagefile, &gerror );
/* ui->bg_pixbuf = gdk_pixbuf_new_from_file_at_scale( imagefile, 302, 727, true, &gerror ); */
/* set ui->width and ui->height based on imagefile dimensions */ /* set ui->width and ui->height based on imagefile dimensions */
gdk_pixbuf_get_file_info( imagefile, &ui->width, &ui->height ); gdk_pixbuf_get_file_info( imagefile, &ui->width, &ui->height );
@ -3324,14 +3314,6 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
// gtk_window_set_icon(GTK_WINDOW(ui->window), ui->bg_pixbuf); // 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 );
gtk_widget_shape_combine_mask( ui->window, shape, 0, 0 );
g_object_unref( shape );
gtk_widget_realize( ui->window ); gtk_widget_realize( ui->window );
ui->fixed = gtk_fixed_new(); ui->fixed = gtk_fixed_new();
@ -3350,65 +3332,66 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
gtk_container_add( GTK_CONTAINER( screen_box ), ui->lcd_canvas ); 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_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; x49gp_ui_button_t* button;
for ( int i = 0; i < ui->nr_buttons; i++ ) { const x49gp_ui_key_t* keys;
switch ( ui->calculator ) { switch ( ui->calculator ) {
case UI_CALCULATOR_HP49GP: case UI_CALCULATOR_HP49GP:
key = &x49gp_ui_keys[ i ]; keys = x49gp_ui_keys;
break; break;
case UI_CALCULATOR_HP49GP_NEWRPL: case UI_CALCULATOR_HP49GP_NEWRPL:
key = &x49gp_newrpl_ui_keys[ i ]; keys = x49gp_newrpl_ui_keys;
break; break;
default: default:
ui->calculator = UI_CALCULATOR_HP50G; ui->calculator = UI_CALCULATOR_HP50G;
/* fall through */ /* fall through */
case UI_CALCULATOR_HP50G: case UI_CALCULATOR_HP50G:
key = &x50g_ui_keys[ i ]; keys = x50g_ui_keys;
break; break;
case UI_CALCULATOR_HP50G_NEWRPL: case UI_CALCULATOR_HP50G_NEWRPL:
key = &x50g_newrpl_ui_keys[ i ]; keys = x50g_newrpl_ui_keys;
break; break;
} }
button = &ui->buttons[ i ];
button->x49gp = x49gp; for ( int i = 0; i < ui->nr_buttons; i++ ) {
button->key = key; button = &ui->buttons[ i ];
button->button = gtk_button_new(); button->x49gp = x49gp;
gtk_widget_set_size_request( button->button, key->width, key->height ); button->key = &keys[ i ];
gtk_widget_set( button->button, "can-focus", false, NULL );
x49gp_ui_button_pixmaps_init( x49gp, button, key->color ); button->button = gtk_button_new();
gtk_widget_set_size_request( button->button, keys[ i ].width, keys[ i ].height );
gtk_widget_set( button->button, "can-focus", false, NULL );
if ( key->label ) { x49gp_ui_button_pixmaps_init( x49gp, button, keys[ i ].color );
button->label = gtk_label_new( "" );
gtk_widget_set_style( button->label, gtk_widget_get_style( button->button ) );
gtk_container_add( GTK_CONTAINER( button->button ), button->label );
g_signal_connect( G_OBJECT( button->label ), "expose-event", G_CALLBACK( x49gp_button_expose_event ), button ); if ( keys[ i ].label ) {
button->label = gtk_label_new( "" );
gtk_widget_set_style( button->label, gtk_widget_get_style( button->button ) );
gtk_container_add( GTK_CONTAINER( button->button ), button->label );
g_signal_connect_after( G_OBJECT( button->label ), "realize", G_CALLBACK( x49gp_button_realize ), button ); g_signal_connect( G_OBJECT( button->label ), "expose-event", G_CALLBACK( x49gp_button_expose_event ), button );
g_signal_connect_after( G_OBJECT( button->label ), "realize", G_CALLBACK( x49gp_button_realize ), button );
}
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_widget_shape_combine_mask( button->box, ui->shapes[ keys[ i ].shape ], 0, 0 );
gtk_container_add( GTK_CONTAINER( button->box ), button->button );
x49gp_ui_place_at( x49gp, GTK_FIXED( ui->fixed ), button->box, ui->kb_x_offset + keys[ i ].x, ui->kb_y_offset + keys[ i ].y,
keys[ i ].width, keys[ i ].height );
g_signal_connect( G_OBJECT( button->button ), "button-press-event", G_CALLBACK( x49gp_ui_button_press ), button );
g_signal_connect( G_OBJECT( button->button ), "button-release-event", G_CALLBACK( x49gp_ui_button_release ), button );
g_signal_connect( G_OBJECT( button->button ), "leave-notify-event", G_CALLBACK( x49gp_ui_button_leave ), button );
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_widget_shape_combine_mask( button->box, ui->shapes[ key->shape ], 0, 0 );
gtk_container_add( GTK_CONTAINER( button->box ), button->button );
x49gp_ui_place_at( x49gp, GTK_FIXED( ui->fixed ), button->box, ui->kb_x_offset + key->x, ui->kb_y_offset + key->y, key->width,
key->height );
g_signal_connect( G_OBJECT( button->button ), "button-press-event", G_CALLBACK( x49gp_ui_button_press ), button );
g_signal_connect( G_OBJECT( button->button ), "button-release-event", G_CALLBACK( x49gp_ui_button_release ), button );
g_signal_connect( G_OBJECT( button->button ), "leave-notify-event", G_CALLBACK( x49gp_ui_button_leave ), button );
gtk_widget_add_events( button->button, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK );
} }
// right-click menu // right-click menu
// { // {
ui->menu = gtk_menu_new(); ui->menu = gtk_menu_new();
@ -3450,21 +3433,17 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
// } // }
g_signal_connect( G_OBJECT( screen_box ), "button-press-event", G_CALLBACK( x49gp_ui_show_menu ), x49gp ); g_signal_connect( G_OBJECT( screen_box ), "button-press-event", G_CALLBACK( x49gp_ui_show_menu ), x49gp );
g_signal_connect( G_OBJECT( ui->background ), "configure-event", G_CALLBACK( x49gp_window_configure_event ), x49gp ); g_signal_connect( G_OBJECT( ui->background ), "configure-event", G_CALLBACK( x49gp_window_configure_event ), x49gp );
g_signal_connect( G_OBJECT( ui->lcd_canvas ), "expose-event", G_CALLBACK( x49gp_lcd_expose_event ), x49gp ); g_signal_connect( G_OBJECT( ui->lcd_canvas ), "expose-event", G_CALLBACK( x49gp_lcd_expose_event ), x49gp );
g_signal_connect( G_OBJECT( ui->lcd_canvas ), "configure-event", G_CALLBACK( x49gp_lcd_configure_event ), x49gp ); g_signal_connect( G_OBJECT( ui->lcd_canvas ), "configure-event", G_CALLBACK( x49gp_lcd_configure_event ), x49gp );
g_signal_connect_swapped( G_OBJECT( ui->window ), "delete-event", G_CALLBACK( x49gp_ui_quit ), x49gp );
g_signal_connect_swapped( G_OBJECT( ui->window ), "destroy", G_CALLBACK( x49gp_ui_quit ), x49gp );
g_signal_connect( G_OBJECT( ui->window ), "focus-out-event", G_CALLBACK( x49gp_ui_focus_lost ), x49gp ); g_signal_connect( G_OBJECT( ui->window ), "focus-out-event", G_CALLBACK( x49gp_ui_focus_lost ), x49gp );
g_signal_connect( G_OBJECT( ui->window ), "key-press-event", G_CALLBACK( x49gp_ui_key_event ), x49gp ); g_signal_connect( G_OBJECT( ui->window ), "key-press-event", G_CALLBACK( x49gp_ui_key_event ), x49gp );
g_signal_connect( G_OBJECT( ui->window ), "key-release-event", G_CALLBACK( x49gp_ui_key_event ), x49gp ); g_signal_connect( G_OBJECT( ui->window ), "key-release-event", G_CALLBACK( x49gp_ui_key_event ), x49gp );
g_signal_connect( G_OBJECT( ui->window ), "button-press-event", G_CALLBACK( x49gp_window_button_press ), x49gp ); g_signal_connect( G_OBJECT( ui->window ), "button-press-event", G_CALLBACK( x49gp_window_button_press ), x49gp );
g_signal_connect_swapped( G_OBJECT( ui->window ), "delete-event", G_CALLBACK( x49gp_ui_quit ), x49gp );
g_signal_connect_swapped( G_OBJECT( ui->window ), "destroy", G_CALLBACK( x49gp_ui_quit ), x49gp );
gtk_widget_add_events( ui->window, GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK ); gtk_widget_add_events( ui->window, GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK );