From ae21398a5a904864ade1f1e1fa56c49d0f77391e Mon Sep 17 00:00:00 2001 From: Andreas Frisch Date: Tue, 10 May 2016 16:39:41 +0200 Subject: [PATCH] load ui template at runtime, configurable in ini file, load print offsets from ini --- default.ini | 4 ++++ photobooth.c | 15 ++++++++++++--- photobooth.h | 2 ++ photoboothwin.c | 33 ++++++++++++++++++++++++++------- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/default.ini b/default.ini index 239c6e1..3af50c6 100644 --- a/default.ini +++ b/default.ini @@ -1,6 +1,8 @@ [general] countdown = 5 countdown_audio_file = beep.m4a +template = photobooth.ui +stylesheet = photobooth.css overlay_image = overlay_print_rainbows.png [printer] @@ -9,6 +11,8 @@ dpi = 346 width = 2076 height = 1384 icc_profile = CP955_F.icc +offset_x = 12.0 +offset_y = 16.0 [camera] preview_width = 640 diff --git a/photobooth.c b/photobooth.c index fb7b793..99bcb15 100644 --- a/photobooth.c +++ b/photobooth.c @@ -51,6 +51,7 @@ struct _PhotoBoothPrivate gchar *printer_backend; gint print_dpi, print_width, print_height; + gdouble print_x_offset, print_y_offset; gchar *print_icc_profile; gint prints_remaining; GstBuffer *print_buffer; @@ -195,12 +196,15 @@ static void photo_booth_init (PhotoBooth *pb) priv->print_dpi = PRINT_DPI; priv->print_width = PRINT_WIDTH; priv->print_height = PRINT_HEIGHT; + priv->print_x_offset = priv->print_y_offset = 0; priv->print_buffer = NULL; priv->print_icc_profile = NULL; priv->cam_icc_profile = NULL; priv->printer_backend = NULL; priv->printer_settings = NULL; priv->overlay_image = NULL; + G_stylesheet_filename = NULL; + G_template_filename = NULL; G_strings_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); g_mutex_init (&priv->processing_mutex); @@ -270,6 +274,8 @@ static void photo_booth_dispose (GObject *object) g_hash_table_destroy (G_strings_table); g_mutex_clear (&priv->processing_mutex); G_OBJECT_CLASS (photo_booth_parent_class)->dispose (object); + g_free (G_stylesheet_filename); + g_free (G_template_filename); } void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename) @@ -308,6 +314,8 @@ void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename) } if (g_key_file_has_group (gkf, "general")) { + G_template_filename = g_key_file_get_string (gkf, "general", "template", NULL); + G_stylesheet_filename = g_key_file_get_string (gkf, "general", "stylesheet", NULL); priv->countdown = g_key_file_get_integer (gkf, "general", "countdown", NULL); gchar *audiofile = g_key_file_get_string (gkf, "general", "countdown_audio_file", NULL); if (audiofile) @@ -325,7 +333,6 @@ void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename) g_free (audioabsfilename); } priv->overlay_image = g_key_file_get_string (gkf, "general", "overlay_image", NULL); - GST_INFO ( "overlay_image: %s", priv->overlay_image); } if (g_key_file_has_group (gkf, "printer")) { @@ -334,6 +341,8 @@ void photo_booth_load_settings (PhotoBooth *pb, const gchar *filename) priv->print_width = g_key_file_get_integer (gkf, "printer", "width", NULL); priv->print_height = g_key_file_get_integer (gkf, "printer", "height", NULL); priv->print_icc_profile = g_key_file_get_string (gkf, "printer", "icc_profile", NULL); + priv->print_x_offset = g_key_file_get_double (gkf, "printer", "offset_x", NULL); + priv->print_y_offset = g_key_file_get_double (gkf, "printer", "offset_y", NULL); } if (g_key_file_has_group (gkf, "camera")) { @@ -1467,7 +1476,7 @@ static void photo_booth_draw_page (GtkPrintOperation *operation, GtkPrintContext GST_ERROR_OBJECT (context, "can't draw because we have no photo buffer!"); return; } - GST_DEBUG_OBJECT (context, "draw_page no. %i . %" GST_PTR_FORMAT "", page_nr, priv->print_buffer); + GST_INFO_OBJECT (context, "draw_page no. %i . %" GST_PTR_FORMAT " size %dx%x, %i dpi, offsets (%.2f, %.2f)", page_nr, priv->print_buffer, priv->print_width, priv->print_height, priv->print_dpi, priv->print_x_offset, priv->print_y_offset); gst_buffer_map(priv->print_buffer, &map, GST_MAP_READ); guint8 *h = map.data; @@ -1481,7 +1490,7 @@ static void photo_booth_draw_page (GtkPrintOperation *operation, GtkPrintContext float scale = (float) PT_PER_IN / (float) priv->print_dpi; cairo_scale(cr, scale, scale); - cairo_set_source_surface(cr, cairosurface, 16.0, 16.0); // FIXME offsets? + cairo_set_source_surface(cr, cairosurface, priv->print_x_offset, priv->print_y_offset); cairo_paint(cr); cairo_set_matrix(cr, &m); diff --git a/photobooth.h b/photobooth.h index 112a194..12ef176 100644 --- a/photobooth.h +++ b/photobooth.h @@ -82,6 +82,8 @@ typedef enum PB_STATE_PRINTING } PhotoboothState; +gchar *G_template_filename; +gchar *G_stylesheet_filename; GHashTable *G_strings_table; #define _(key) (g_hash_table_contains (G_strings_table, key) ? g_hash_table_lookup (G_strings_table, key) : key) diff --git a/photoboothwin.c b/photoboothwin.c index bf1e98b..552c8c7 100644 --- a/photoboothwin.c +++ b/photoboothwin.c @@ -15,6 +15,7 @@ #include #include +#include #include "photobooth.h" #include "photoboothwin.h" @@ -39,7 +40,21 @@ gboolean _pbw_clock_tick (GtkLabel *status_clock); static void photo_booth_window_class_init (PhotoBoothWindowClass *klass) { GST_DEBUG_CATEGORY_INIT (photo_booth_windows_debug, "photoboothwin", GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLUE, "PhotoBoothWindow"); - gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/schaffenburg/photobooth/photobooth.ui"); + GError *error = NULL; + if (G_template_filename) + { + GST_DEBUG ("open template from file '%s'", G_template_filename); + GMappedFile *templatef = g_mapped_file_new (G_template_filename, FALSE, &error); + gtk_widget_class_set_template (GTK_WIDGET_CLASS (klass), g_mapped_file_get_bytes (templatef)); + g_mapped_file_unref (templatef); + } + if (error) + { + GST_INFO ( "can't use template from file '%s': %s. Falling back to default resource!", G_template_filename, error->message); + g_error_free (error); + gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/schaffenburg/photobooth/photobooth.ui"); + } + GST_DEBUG ("done!"); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, overlay); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, spinner); gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), PhotoBoothWindow, countdown_label); @@ -56,13 +71,17 @@ static void photo_booth_window_init (PhotoBoothWindow *win) priv = photo_booth_window_get_instance_private (win); GdkScreen *screen = gdk_screen_get_default (); gtk_window_fullscreen_on_monitor (GTK_WINDOW (win), screen, 0); - GFile *cssfile = g_file_new_for_path ("photobooth.css"); - if (cssfile) + if (G_stylesheet_filename) { - GtkCssProvider *cssprovider = gtk_css_provider_new (); - gtk_css_provider_load_from_file (cssprovider, cssfile, NULL); - gtk_style_context_add_provider_for_screen (screen, (GtkStyleProvider *)cssprovider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - g_object_unref (cssfile); + GFile *cssfile = g_file_new_for_path (G_stylesheet_filename); + if (cssfile) + { + GST_DEBUG ("open stylesheet from file '%s'", G_stylesheet_filename); + GtkCssProvider *cssprovider = gtk_css_provider_new (); + gtk_css_provider_load_from_file (cssprovider, cssfile, NULL); + gtk_style_context_add_provider_for_screen (screen, (GtkStyleProvider *)cssprovider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref (cssfile); + } } g_timeout_add (1000, (GSourceFunc) _pbw_clock_tick, win->status_clock); }