forked from Miroirs/x49gp
gtk3 gui is finally visually good enough to drop gtk2
This commit is contained in:
parent
d90bb7a25e
commit
6c59edf49a
3 changed files with 73 additions and 230 deletions
2
Makefile
2
Makefile
|
@ -10,7 +10,7 @@ DEBUG_CFLAGS = -g # -pg
|
|||
OPTIM = 2
|
||||
|
||||
# GTK
|
||||
GTK_VERSION = "+-2.0"
|
||||
GTK_VERSION = "+-3.0"
|
||||
GTK_CFLAGS = $(shell pkg-config --cflags gtk$(GTK_VERSION)) -DGTK_DISABLE_SINGLE_INCLUDES -DGSEAL_ENABLE
|
||||
GTK_LDLIBS = $(shell pkg-config --libs gtk$(GTK_VERSION)) -lz -lm
|
||||
|
||||
|
|
297
src/x49gpng/ui.c
297
src/x49gpng/ui.c
|
@ -1023,16 +1023,25 @@ static x49gp_ui_key_t ui_keys[ NB_KEYS ] = {
|
|||
/* functions */
|
||||
/*************/
|
||||
|
||||
static PangoAttrList* ui_load__pango_attrs_common_new( void )
|
||||
static void _apply_css_to_widget( char* css, GtkWidget* widget )
|
||||
{
|
||||
PangoAttrList* pango_attributes = pango_attr_list_new();
|
||||
GtkCssProvider* style_provider = gtk_css_provider_new();
|
||||
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_family_new( opt.font ) );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_weight_new( PANGO_WEIGHT_BOLD ) );
|
||||
gtk_css_provider_load_from_data( style_provider, css, -1, NULL );
|
||||
|
||||
return pango_attributes;
|
||||
gtk_style_context_add_provider( gtk_widget_get_style_context( widget ), GTK_STYLE_PROVIDER( style_provider ),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1 );
|
||||
|
||||
g_object_unref( style_provider );
|
||||
}
|
||||
|
||||
static inline int _tiny_text_width( const char* text )
|
||||
{
|
||||
return strlen( text ) * 5;
|
||||
}
|
||||
|
||||
static int _tiny_text_height = 10;
|
||||
|
||||
static gboolean react_to_button_press( GtkWidget* widget, GdkEventButton* event, gpointer user_data )
|
||||
{
|
||||
x49gp_ui_button_t* button = user_data;
|
||||
|
@ -1154,11 +1163,7 @@ static gboolean do_show_context_menu( GtkWidget* widget, GdkEventButton* event,
|
|||
gtk_widget_set_sensitive( ui->menu_debug, !gdbserver_isactive() );
|
||||
|
||||
if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
gtk_menu_popup( GTK_MENU( ui->menu ), NULL, NULL, NULL, NULL, event->button, event->time );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
gtk_menu_popup_at_widget( GTK_MENU( ui->menu ), ui->lcd_canvas, GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL );
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1266,13 +1271,8 @@ static gboolean react_to_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
|
|||
/* We want to know the keyval as interpreted without modifiers. */
|
||||
/* However, there is one modifier we do care about: NumLock, */
|
||||
/* which normally is represented by MOD2. */
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
if ( !gdk_keymap_translate_keyboard_state( gdk_keymap_get_default(), event->hardware_keycode, event->state & GDK_MOD2_MASK,
|
||||
event->group, &keyval, NULL, NULL, NULL ) )
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
if ( !gdk_keymap_translate_keyboard_state( gdk_keymap_get_for_display( gdk_display_get_default() ), event->hardware_keycode,
|
||||
event->state & GDK_MOD2_MASK, event->group, &keyval, NULL, NULL, NULL ) )
|
||||
#endif
|
||||
return false;
|
||||
#ifdef DEBUG_X49GP_UI
|
||||
fprintf( stderr, "%s:%u: state %u, base keyval %04x\n", __FUNCTION__, __LINE__, event->state, keyval );
|
||||
|
@ -1522,11 +1522,7 @@ static gboolean react_to_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
|
|||
if ( ui->menu_debug )
|
||||
gtk_widget_set_sensitive( ui->menu_debug, !gdbserver_isactive() );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
gtk_menu_popup( GTK_MENU( ui->menu ), NULL, NULL, NULL, ui->lcd_canvas, 0, event->time );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
gtk_menu_popup_at_widget( GTK_MENU( ui->menu ), ui->lcd_canvas, GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL );
|
||||
#endif
|
||||
return false;
|
||||
|
||||
default:
|
||||
|
@ -1589,13 +1585,8 @@ static int draw_lcd( GtkWidget* widget, GdkEventConfigure* event, gpointer user_
|
|||
ui->lcd_surface = cairo_image_surface_create( CAIRO_FORMAT_RGB24, ui->lcd_width, ui->lcd_height );
|
||||
|
||||
cairo_t* cr = cairo_create( ui->lcd_surface );
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
GdkColor color = ui->colors[ UI_COLOR_GRAYSCALE_0 ];
|
||||
cairo_set_source_rgb( cr, color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0 );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
GdkRGBA color = ui->colors[ UI_COLOR_GRAYSCALE_0 ];
|
||||
cairo_set_source_rgb( cr, color.red, color.green, color.blue );
|
||||
#endif
|
||||
cairo_rectangle( cr, 0, 0, ui->lcd_width, ui->lcd_height );
|
||||
cairo_fill( cr );
|
||||
cairo_destroy( cr );
|
||||
|
@ -1660,14 +1651,6 @@ static int ui_exit( x49gp_module_t* module ) { return 0; }
|
|||
|
||||
static int ui_reset( x49gp_module_t* module, x49gp_reset_t reset ) { return 0; }
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
static void _ui_load__init_color( GdkColor* color, u8 red, u8 green, u8 blue )
|
||||
{
|
||||
color->red = ( red << 8 ) | red;
|
||||
color->green = ( green << 8 ) | green;
|
||||
color->blue = ( blue << 8 ) | blue;
|
||||
}
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
static void _ui_load__init_color( GdkRGBA* color, u8 red, u8 green, u8 blue )
|
||||
{
|
||||
color->red = red / 255.0;
|
||||
|
@ -1675,7 +1658,6 @@ static void _ui_load__init_color( GdkRGBA* color, u8 red, u8 green, u8 blue )
|
|||
color->blue = blue / 255.0;
|
||||
color->alpha = 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void _ui_load__newrplify_ui_keys()
|
||||
{
|
||||
|
@ -1733,52 +1715,17 @@ static inline void _ui_load__newrplify_ui_keys()
|
|||
ui_keys[ 50 ].left = NULL;
|
||||
}
|
||||
|
||||
static void ui_load__style_button( x49gp_ui_t* ui, x49gp_ui_button_t* button )
|
||||
{
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
GtkStyle* style = gtk_style_new();
|
||||
|
||||
for ( int i = 0; i < 5; i++ ) {
|
||||
style->fg[ i ] = ui->colors[ button->key->color ];
|
||||
style->bg[ i ] = ui->colors[ button->key->bg_color ];
|
||||
|
||||
style->text[ i ] = style->fg[ i ];
|
||||
style->base[ i ] = style->bg[ i ];
|
||||
}
|
||||
|
||||
gtk_widget_set_style( button->button, style );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
static const gchar button_style[] = "button {\n"
|
||||
"-GtkButton-color : %s;\n"
|
||||
"-GtkButton-background-color : %s;\n"
|
||||
"}";
|
||||
char* css;
|
||||
asprintf( &css, button_style, gdk_rgba_to_string( &( ui->colors[ button->key->color ] ) ),
|
||||
gdk_rgba_to_string( &( ui->colors[ button->key->bg_color ] ) ) );
|
||||
fprintf( stderr, "%s\n\n\n", css );
|
||||
GtkCssProvider* css_prov = gtk_css_provider_new();
|
||||
gtk_css_provider_load_from_data( css_prov, css, -1, NULL );
|
||||
|
||||
GtkStyleContext* ctx = gtk_widget_get_style_context( button->button );
|
||||
gtk_style_context_add_provider( ctx, GTK_STYLE_PROVIDER( css_prov ), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION );
|
||||
#endif
|
||||
}
|
||||
|
||||
static GtkWidget* _ui_load__create_annunciator_widget( x49gp_ui_t* ui, const char* label )
|
||||
{
|
||||
GtkWidget* ui_ann = gtk_label_new( NULL );
|
||||
|
||||
PangoAttrList* pango_attributes = ui_load__pango_attrs_common_new();
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_size_new( ( 12.0 / 1.8 ) * PANGO_SCALE ) );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_weight_new( PANGO_WEIGHT_BOLD ) );
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
GdkColor* fgcolor = &( ui->colors[ UI_COLOR_GRAYSCALE_0 ] );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
GdkRGBA* fgcolor = &( ui->colors[ UI_COLOR_GRAYSCALE_0 ] );
|
||||
#endif
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_foreground_new( fgcolor->red, fgcolor->green, fgcolor->blue ) );
|
||||
|
||||
gtk_label_set_attributes( GTK_LABEL( ui_ann ), pango_attributes );
|
||||
// add CSS style
|
||||
{
|
||||
gtk_style_context_add_class( gtk_widget_get_style_context( ui_ann ), "x49gpng-annunciator" );
|
||||
char* css;
|
||||
if ( asprintf( &css, ".x49gpng-annunciator { font-size: 12px; font-weight: bold; color: %s; }\n",
|
||||
gdk_rgba_to_string( &( ui->colors[ UI_COLOR_GRAYSCALE_0 ] ) ) ) >= 0 )
|
||||
_apply_css_to_widget( css, ui_ann );
|
||||
}
|
||||
|
||||
gtk_label_set_use_markup( GTK_LABEL( ui_ann ), true );
|
||||
gtk_label_set_markup( GTK_LABEL( ui_ann ), label );
|
||||
|
@ -1786,18 +1733,6 @@ static GtkWidget* _ui_load__create_annunciator_widget( x49gp_ui_t* ui, const cha
|
|||
return ui_ann;
|
||||
}
|
||||
|
||||
static void _ui_load__apply_css_to_widget( char* css, GtkWidget* widget )
|
||||
{
|
||||
GtkCssProvider* style_provider = gtk_css_provider_new();
|
||||
|
||||
gtk_css_provider_load_from_data( style_provider, css, -1, NULL );
|
||||
|
||||
gtk_style_context_add_provider( gtk_widget_get_style_context( widget ), GTK_STYLE_PROVIDER( style_provider ),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER + 1 );
|
||||
|
||||
g_object_unref( style_provider );
|
||||
}
|
||||
|
||||
static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
||||
{
|
||||
x49gp_t* x49gp = module->x49gp;
|
||||
|
@ -1890,14 +1825,18 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
gtk_window_set_decorated( GTK_WINDOW( ui->window ), true );
|
||||
gtk_window_set_resizable( GTK_WINDOW( ui->window ), true );
|
||||
gtk_window_set_title( GTK_WINDOW( ui->window ), ui->name );
|
||||
gtk_widget_set_name( ui->window, "x49gpng-main-window" );
|
||||
gtk_widget_realize( ui->window );
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
int faceplate_color = ( ui->calculator == UI_CALCULATOR_HP49GP || ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL )
|
||||
? UI_COLOR_FACEPLATE_49GP
|
||||
: UI_COLOR_FACEPLATE_50G;
|
||||
gtk_widget_modify_bg( ui->window, GTK_STATE_NORMAL, &( ui->colors[ faceplate_color ] ) );
|
||||
#endif
|
||||
// add CSS style
|
||||
{
|
||||
gtk_style_context_add_class( gtk_widget_get_style_context( ui->window ), "x49gpng-main-window" );
|
||||
char* css;
|
||||
if ( asprintf( &css, ".x49gpng-main-window { background-color: %s; }\n",
|
||||
gdk_rgba_to_string( &( ui->colors[ faceplate_color ] ) ) ) >= 0 )
|
||||
_apply_css_to_widget( css, ui->window );
|
||||
}
|
||||
gtk_container_add( GTK_CONTAINER( ui->window ), fixed_widgets_container );
|
||||
|
||||
g_signal_connect( G_OBJECT( ui->window ), "focus-out-event", G_CALLBACK( react_to_focus_lost ), x49gp );
|
||||
|
@ -1911,11 +1850,7 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
ui->lcd_canvas = gtk_drawing_area_new();
|
||||
gtk_widget_set_name( ui->lcd_canvas, "lcd" );
|
||||
gtk_widget_set_size_request( ui->lcd_canvas, ui->lcd_width, ui->lcd_height );
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
g_signal_connect( G_OBJECT( ui->lcd_canvas ), "expose-event", G_CALLBACK( redraw_lcd ), x49gp );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
g_signal_connect( G_OBJECT( ui->lcd_canvas ), "draw", G_CALLBACK( redraw_lcd ), x49gp );
|
||||
#endif
|
||||
g_signal_connect( G_OBJECT( ui->lcd_canvas ), "configure-event", G_CALLBACK( draw_lcd ), x49gp );
|
||||
|
||||
gtk_event_box_set_visible_window( GTK_EVENT_BOX( lcd_canvas_container ), true );
|
||||
|
@ -1934,9 +1869,6 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
|
||||
GtkWidget* fixed_annunciators_container = gtk_fixed_new();
|
||||
gtk_widget_set_name( fixed_annunciators_container, "annunciators-container" );
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
gtk_widget_modify_bg( fixed_annunciators_container, GTK_STATE_NORMAL, &( ui->colors[ UI_COLOR_GRAYSCALE_0 ] ) );
|
||||
#endif
|
||||
gtk_widget_set_size_request( fixed_annunciators_container, ui->lcd_width, annunciator_height );
|
||||
gtk_fixed_put( GTK_FIXED( fixed_widgets_container ), fixed_annunciators_container, ui->annunciators_x_offset,
|
||||
ui->annunciators_y_offset );
|
||||
|
@ -1964,10 +1896,6 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
{
|
||||
double tiny_font_size = 8.0;
|
||||
x49gp_ui_button_t* button;
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
PangoAttrList* pango_attributes;
|
||||
GdkColor* fgcolor;
|
||||
#endif
|
||||
GtkWidget* ui_label;
|
||||
GtkWidget* ui_left;
|
||||
GtkWidget* ui_right;
|
||||
|
@ -1977,10 +1905,6 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
int left_color;
|
||||
int right_color;
|
||||
int below_color;
|
||||
GtkRequisition widget_size, widget2_size;
|
||||
#if GTK_MAJOR_VERSION == 3
|
||||
GtkRequisition widget_minimum_size, widget2_minimum_size;
|
||||
#endif
|
||||
int x, y, x2, y2;
|
||||
|
||||
switch ( ui->calculator ) {
|
||||
|
@ -2016,28 +1940,32 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
gtk_widget_set_size_request( button->button, button->key->width, button->key->height );
|
||||
gtk_widget_set_can_focus( button->button, false );
|
||||
|
||||
ui_load__style_button( ui, button );
|
||||
{
|
||||
gtk_style_context_add_class( gtk_widget_get_style_context( button->button ), "x49gpng-button" );
|
||||
char* css;
|
||||
if ( asprintf( &css,
|
||||
".x49gpng-button { all: unset; "
|
||||
"padding: 0px; "
|
||||
"border-width: 0px; "
|
||||
"color : %s; "
|
||||
"background-image: none; "
|
||||
"background-color : %s; }",
|
||||
gdk_rgba_to_string( &( ui->colors[ button->key->color ] ) ),
|
||||
gdk_rgba_to_string( &( ui->colors[ button->key->bg_color ] ) ) ) >= 0 )
|
||||
_apply_css_to_widget( css, button->button );
|
||||
}
|
||||
|
||||
if ( button->key->label ) {
|
||||
ui_label = gtk_label_new( NULL );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
pango_attributes = ui_load__pango_attrs_common_new();
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_size_new( ( button->key->font_size / 1.8 ) * PANGO_SCALE ) );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_weight_new( PANGO_WEIGHT_BOLD ) );
|
||||
fgcolor = &( ui->colors[ button->key->color ] );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_foreground_new( fgcolor->red, fgcolor->green, fgcolor->blue ) );
|
||||
|
||||
gtk_label_set_attributes( GTK_LABEL( ui_label ), pango_attributes );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
// add CSS style
|
||||
{
|
||||
gtk_style_context_add_class( gtk_widget_get_style_context( ui_label ), "x49gpng-button-label" );
|
||||
char* css;
|
||||
if ( asprintf( &css, "GtkLabel { font-size: %f; font-weight: bold; color: %s; }\n", button->key->font_size,
|
||||
gdk_rgba_to_string( &( ui->colors[ button->key->color ] ) ) ) >= 0 )
|
||||
_ui_load__apply_css_to_widget( css, ui_label );
|
||||
if ( asprintf( &css, ".x49gpng-button-label { font-size: %fpx; font-weight: bold; color: %s; }\n",
|
||||
button->key->font_size, gdk_rgba_to_string( &( ui->colors[ button->key->color ] ) ) ) >= 0 )
|
||||
_apply_css_to_widget( css, ui_label );
|
||||
}
|
||||
#endif
|
||||
|
||||
gtk_label_set_use_markup( GTK_LABEL( ui_label ), true );
|
||||
gtk_label_set_markup( GTK_LABEL( ui_label ), button->key->label );
|
||||
|
@ -2047,23 +1975,14 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
if ( button->key->left ) {
|
||||
ui_left = gtk_label_new( NULL );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
pango_attributes = ui_load__pango_attrs_common_new();
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_size_new( ( tiny_font_size / 1.8 ) * PANGO_SCALE ) );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_weight_new( PANGO_WEIGHT_BOLD ) );
|
||||
fgcolor = &( ui->colors[ left_color ] );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_foreground_new( fgcolor->red, fgcolor->green, fgcolor->blue ) );
|
||||
|
||||
gtk_label_set_attributes( GTK_LABEL( ui_left ), pango_attributes );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
// add CSS style
|
||||
{
|
||||
gtk_style_context_add_class( gtk_widget_get_style_context( ui_left ), "x49gpng-button-label-left" );
|
||||
char* css;
|
||||
if ( asprintf( &css, "GtkLabel { font-size: %f; font-weight: bold; color: %s; }\n", tiny_font_size,
|
||||
if ( asprintf( &css, ".x49gpng-button-label-left { font-size: %fpx; font-weight: bold; color: %s; }\n", tiny_font_size,
|
||||
gdk_rgba_to_string( &( ui->colors[ left_color ] ) ) ) >= 0 )
|
||||
_ui_load__apply_css_to_widget( css, ui_left );
|
||||
_apply_css_to_widget( css, ui_left );
|
||||
}
|
||||
#endif
|
||||
|
||||
gtk_label_set_use_markup( GTK_LABEL( ui_left ), true );
|
||||
gtk_label_set_markup( GTK_LABEL( ui_left ), button->key->left );
|
||||
|
@ -2071,127 +1990,73 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
if ( button->key->right ) {
|
||||
ui_right = gtk_label_new( NULL );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
pango_attributes = ui_load__pango_attrs_common_new();
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_size_new( ( tiny_font_size / 1.8 ) * PANGO_SCALE ) );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_weight_new( PANGO_WEIGHT_BOLD ) );
|
||||
fgcolor = &( ui->colors[ right_color ] );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_foreground_new( fgcolor->red, fgcolor->green, fgcolor->blue ) );
|
||||
|
||||
gtk_label_set_attributes( GTK_LABEL( ui_right ), pango_attributes );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
// add CSS style
|
||||
{
|
||||
gtk_style_context_add_class( gtk_widget_get_style_context( ui_right ), "x49gpng-button-label-right" );
|
||||
char* css;
|
||||
if ( asprintf( &css, "GtkLabel { font-size: %f; font-weight: bold; color: %s; }\n", tiny_font_size,
|
||||
gdk_rgba_to_string( &( ui->colors[ right_color ] ) ) ) >= 0 )
|
||||
_ui_load__apply_css_to_widget( css, ui_right );
|
||||
if ( asprintf( &css, ".x49gpng-button-label-right { font-size: %fpx; font-weight: bold; color: %s; }\n",
|
||||
tiny_font_size, gdk_rgba_to_string( &( ui->colors[ right_color ] ) ) ) >= 0 )
|
||||
_apply_css_to_widget( css, ui_right );
|
||||
}
|
||||
#endif
|
||||
|
||||
gtk_label_set_use_markup( GTK_LABEL( ui_right ), true );
|
||||
gtk_label_set_markup( GTK_LABEL( ui_right ), button->key->right );
|
||||
}
|
||||
if ( button->key->right ) {
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
gtk_widget_size_request( ui_left, &widget_size );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
gtk_widget_get_preferred_size( ui_left, &widget_minimum_size, &widget_size );
|
||||
#endif
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
gtk_widget_size_request( ui_right, &widget2_size );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
gtk_widget_get_preferred_size( ui_right, &widget2_minimum_size, &widget2_size );
|
||||
#endif
|
||||
|
||||
x = ui->kb_x_offset + button->key->x;
|
||||
y = ui->kb_y_offset + button->key->y - widget_size.height - 2;
|
||||
y = ui->kb_y_offset + button->key->y - _tiny_text_height - 2;
|
||||
|
||||
x2 = ui->kb_x_offset + button->key->x + button->key->width - widget2_size.width;
|
||||
y2 = ui->kb_y_offset + button->key->y - widget2_size.height - 2;
|
||||
x2 = ui->kb_x_offset + button->key->x + button->key->width - _tiny_text_width( button->key->right );
|
||||
y2 = ui->kb_y_offset + button->key->y - _tiny_text_height - 2;
|
||||
|
||||
if ( widget_size.width + widget2_size.width > button->key->width ) {
|
||||
x -= ( ( widget_size.width + widget2_size.width ) - button->key->width ) / 2;
|
||||
x2 += ( ( widget_size.width + widget2_size.width ) - button->key->width ) / 2;
|
||||
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( fixed_widgets_container ), ui_left, x, y );
|
||||
gtk_fixed_put( GTK_FIXED( fixed_widgets_container ), ui_right, x2, y2 );
|
||||
} else {
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
gtk_widget_size_request( ui_left, &widget_size );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
gtk_widget_get_preferred_size( ui_left, &widget_minimum_size, &widget_size );
|
||||
#endif
|
||||
x = ui->kb_x_offset + button->key->x + ( ( button->key->width - widget_size.width ) / 2 );
|
||||
y = ui->kb_y_offset + button->key->y - widget_size.height - 2;
|
||||
x = ui->kb_x_offset + button->key->x + ( ( button->key->width - _tiny_text_width( button->key->left ) ) / 2 );
|
||||
y = ui->kb_y_offset + button->key->y - _tiny_text_height - 2;
|
||||
gtk_fixed_put( GTK_FIXED( fixed_widgets_container ), ui_left, x, y );
|
||||
}
|
||||
}
|
||||
if ( button->key->letter ) {
|
||||
ui_letter = gtk_label_new( NULL );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
pango_attributes = ui_load__pango_attrs_common_new();
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_size_new( ( button->key->letter_size / 1.8 ) * PANGO_SCALE ) );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_weight_new( PANGO_WEIGHT_BOLD ) );
|
||||
fgcolor = &( ui->colors[ UI_COLOR_YELLOW ] );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_foreground_new( fgcolor->red, fgcolor->green, fgcolor->blue ) );
|
||||
|
||||
gtk_label_set_attributes( GTK_LABEL( ui_letter ), pango_attributes );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
// add CSS style
|
||||
{
|
||||
gtk_style_context_add_class( gtk_widget_get_style_context( ui_letter ), "x49gpng-button-label-letter" );
|
||||
char* css;
|
||||
if ( asprintf( &css, "GtkLabel { font-size: %f; font-weight: bold; color: %s; }\n", tiny_font_size,
|
||||
gdk_rgba_to_string( &( ui->colors[ UI_COLOR_YELLOW ] ) ) ) >= 0 )
|
||||
_ui_load__apply_css_to_widget( css, ui_letter );
|
||||
if ( asprintf( &css, ".x49gpng-button-label-letter { font-size: %fpx; font-weight: bold; color: %s; }\n",
|
||||
tiny_font_size, gdk_rgba_to_string( &( ui->colors[ UI_COLOR_YELLOW ] ) ) ) >= 0 )
|
||||
_apply_css_to_widget( css, ui_letter );
|
||||
}
|
||||
#endif
|
||||
|
||||
gtk_label_set_use_markup( GTK_LABEL( ui_letter ), true );
|
||||
gtk_label_set_markup( GTK_LABEL( ui_letter ), button->key->letter );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
gtk_widget_size_request( ui_letter, &widget_size );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
gtk_widget_get_preferred_size( ui_letter, &widget_minimum_size, &widget_size );
|
||||
#endif
|
||||
|
||||
x = ui->kb_x_offset + button->key->x + button->key->width;
|
||||
y = ui->kb_y_offset + button->key->y + button->key->height - ( widget_size.height / 2 );
|
||||
y = ui->kb_y_offset + button->key->y + button->key->height - ( _tiny_text_height / 2 );
|
||||
gtk_fixed_put( GTK_FIXED( fixed_widgets_container ), ui_letter, x, y );
|
||||
}
|
||||
if ( button->key->below ) {
|
||||
ui_below = gtk_label_new( NULL );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
pango_attributes = ui_load__pango_attrs_common_new();
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_size_new( ( tiny_font_size / 1.8 ) * PANGO_SCALE ) );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_weight_new( PANGO_WEIGHT_BOLD ) );
|
||||
fgcolor = &( ui->colors[ below_color ] );
|
||||
pango_attr_list_insert( pango_attributes, pango_attr_foreground_new( fgcolor->red, fgcolor->green, fgcolor->blue ) );
|
||||
|
||||
gtk_label_set_attributes( GTK_LABEL( ui_below ), pango_attributes );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
// add CSS style
|
||||
{
|
||||
gtk_style_context_add_class( gtk_widget_get_style_context( ui_below ), "x49gpng-button-label-below" );
|
||||
char* css;
|
||||
if ( asprintf( &css, "GtkLabel { font-size: %f; font-weight: bold; color: %s; }\n", tiny_font_size,
|
||||
if ( asprintf( &css, ".x49gpng-button-label-below { font-size: %fpx; font-weight: bold; color: %s; }\n", tiny_font_size,
|
||||
gdk_rgba_to_string( &( ui->colors[ below_color ] ) ) ) >= 0 )
|
||||
_ui_load__apply_css_to_widget( css, ui_below );
|
||||
_apply_css_to_widget( css, ui_below );
|
||||
}
|
||||
#endif
|
||||
|
||||
gtk_label_set_use_markup( GTK_LABEL( ui_below ), true );
|
||||
gtk_label_set_markup( GTK_LABEL( ui_below ), button->key->below );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
gtk_widget_size_request( ui_below, &widget_size );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
gtk_widget_get_preferred_size( ui_below, &widget_minimum_size, &widget_size );
|
||||
#endif
|
||||
x = ui->kb_x_offset + button->key->x + ( ( button->key->width - widget_size.width ) / 2 );
|
||||
x = ui->kb_x_offset + button->key->x + ( ( button->key->width - _tiny_text_width( button->key->below ) ) / 2 );
|
||||
y = ui->kb_y_offset + button->key->y + button->key->height + 2;
|
||||
gtk_fixed_put( GTK_FIXED( fixed_widgets_container ), ui_below, x, y );
|
||||
}
|
||||
|
@ -2253,20 +2118,6 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
|
|||
gtk_widget_show_all( ui->menu );
|
||||
}
|
||||
|
||||
#if GTK_MAJOR_VERSION == 3
|
||||
// add CSS style
|
||||
{
|
||||
char* css;
|
||||
int faceplate_color = ( ui->calculator == UI_CALCULATOR_HP49GP || ui->calculator == UI_CALCULATOR_HP49GP_NEWRPL )
|
||||
? UI_COLOR_FACEPLATE_49GP
|
||||
: UI_COLOR_FACEPLATE_50G;
|
||||
|
||||
if ( asprintf( &css, "#x49gpng-main-window { background-color: %s; }\n",
|
||||
gdk_rgba_to_string( &( ui->colors[ faceplate_color ] ) ) ) >= 0 )
|
||||
_ui_load__apply_css_to_widget( css, ui->window );
|
||||
}
|
||||
#endif
|
||||
|
||||
// finally show the window
|
||||
gtk_widget_show_all( ui->window );
|
||||
|
||||
|
@ -2283,11 +2134,7 @@ static void _draw_pixel( cairo_surface_t* target, int x, int y, int w, int h, Gd
|
|||
{
|
||||
cairo_t* cr = cairo_create( target );
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
cairo_set_source_rgb( cr, color->red / 65535.0, color->green / 65535.0, color->blue / 65535.0 );
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
cairo_set_source_rgb( cr, color->red, color->green, color->blue );
|
||||
#endif
|
||||
cairo_rectangle( cr, x, y, w, h );
|
||||
cairo_fill( cr );
|
||||
|
||||
|
|
|
@ -83,11 +83,7 @@ struct __x49gp_ui_s__ {
|
|||
GtkWidget* menu_unmount;
|
||||
GtkWidget* menu_debug;
|
||||
|
||||
#if GTK_MAJOR_VERSION == 2
|
||||
GdkColor colors[ UI_COLOR_MAX ];
|
||||
#elif GTK_MAJOR_VERSION == 3
|
||||
GdkRGBA colors[ UI_COLOR_MAX ];
|
||||
#endif
|
||||
|
||||
x49gp_ui_calculator_t calculator;
|
||||
|
||||
|
|
Loading…
Reference in a new issue