[libchamplain] demos/launcher-gtk: Add export to png buton



commit 8689ed647959defbfe11dec4b37736c5334a7547
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Thu Nov 12 11:58:14 2015 +0100

    demos/launcher-gtk: Add export to png buton
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757350

 demos/launcher-gtk.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/demos/launcher-gtk.c b/demos/launcher-gtk.c
index 36c7db5..12a06c0 100644
--- a/demos/launcher-gtk.c
+++ b/demos/launcher-gtk.c
@@ -51,6 +51,7 @@ toggle_layer (GtkToggleButton *widget,
     {
       champlain_path_layer_set_visible (path_layer, TRUE);
       champlain_path_layer_set_visible (path, TRUE);
+
       champlain_marker_layer_animate_in_all_markers (CHAMPLAIN_MARKER_LAYER (layer));
     }
   else
@@ -211,6 +212,51 @@ append_point (ChamplainPathLayer *layer, gdouble lon, gdouble lat)
 }
 
 static void
+export_to_png_cb (GdkPixbuf    *pixbuf,
+    GAsyncResult *res)
+{
+  gdk_pixbuf_save_to_stream_finish (res, NULL);
+}
+
+static void
+export_png (GtkButton     *button,
+    ChamplainView *view)
+{
+  cairo_surface_t *surface;
+  GdkPixbuf *pixbuf;
+  GFileOutputStream *os;
+  GFile *file;
+  gint width, height;
+
+  if (champlain_view_get_state (view) != CHAMPLAIN_STATE_DONE)
+    return;
+
+  surface = champlain_view_to_surface (view, TRUE);
+  if (!surface)
+    return;
+
+  width = cairo_image_surface_get_width (surface);
+  height = cairo_image_surface_get_height (surface);
+  pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
+  if (!pixbuf)
+    return;
+
+  file = g_file_new_for_path ("champlain-map.png");
+  os = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
+  if (!os)
+    {
+      g_object_unref (pixbuf);
+      return;
+    }
+
+  gdk_pixbuf_save_to_stream_async (pixbuf,
+                                   G_OUTPUT_STREAM (os), "png",
+                                   NULL,
+                                   (GAsyncReadyCallback) export_to_png_cb,
+                                   NULL);
+}
+
+static void
 add_clicked (GtkButton     *button,
              ChamplainView *view)
 {
@@ -382,6 +428,12 @@ main (int argc,
   g_signal_connect (button, "clicked", G_CALLBACK (add_clicked), view);
   gtk_container_add (GTK_CONTAINER (bbox), button);
 
+  button = gtk_button_new ();
+  image = gtk_image_new_from_icon_name ("camera-photo-symbolic", GTK_ICON_SIZE_BUTTON);
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  g_signal_connect (button, "clicked", G_CALLBACK (export_png), view);
+  gtk_container_add (GTK_CONTAINER (bbox), button);
+
   button = gtk_image_new ();
   gtk_widget_set_size_request (button, 22, -1);
   g_signal_connect (view, "notify::state", G_CALLBACK (view_state_changed),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]