aboutsummaryrefslogtreecommitdiff
path: root/src/displaywindow.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-03-01 10:55:21 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:16 +0100
commit6341b8ee8d9be0b6fed14cf418161706e4caa5c5 (patch)
treeee4a45341508c41da13e59d0c40b8cfc78e69a99 /src/displaywindow.c
parentfbd247a5c5f098688e98e77af95505422db62ef1 (diff)
Fix hdfsee's PNG saving
Diffstat (limited to 'src/displaywindow.c')
-rw-r--r--src/displaywindow.c52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c
index 3329649e..0045c191 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -161,19 +161,17 @@ static void show_ring(cairo_t *cr, DisplayWindow *dw,
}
-static gboolean displaywindow_expose(GtkWidget *da, GdkEventExpose *event,
- DisplayWindow *dw)
+static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw)
{
cairo_t *cr;
int i;
cairo_matrix_t basic_m;
cairo_matrix_t m;
- cr = gdk_cairo_create(da->window);
+ cr = cairo_create(surf);
/* Blank white background */
- cairo_rectangle(cr, 0.0, 0.0, da->allocation.width,
- da->allocation.height);
+ cairo_rectangle(cr, 0.0, 0.0, dw->width, dw->height);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_fill(cr);
@@ -246,13 +244,13 @@ static gboolean displaywindow_expose(GtkWidget *da, GdkEventExpose *event,
if ( dw->image->features == NULL ) {
cairo_destroy(cr);
- return FALSE;
+ return 0;
}
/* Ensure a clean Cairo context, since the rings often cause
* matrix trouble */
cairo_destroy(cr);
- cr = gdk_cairo_create(da->window);
+ cr = cairo_create(surf);
cairo_set_matrix(cr, &basic_m);
for ( i=0; i<image_feature_count(dw->image->features); i++ ) {
@@ -301,10 +299,47 @@ static gboolean displaywindow_expose(GtkWidget *da, GdkEventExpose *event,
cairo_destroy(cr);
+ return 0;
+}
+
+
+static gboolean displaywindow_expose(GtkWidget *da, GdkEventExpose *event,
+ DisplayWindow *dw)
+{
+ cairo_t *cr;
+ cairo_surface_t *surf;
+
+ cr = gdk_cairo_create(da->window);
+ surf = cairo_get_target(cr);
+ draw_stuff(surf, dw);
+ cairo_destroy(cr);
+
return FALSE;
}
+static int write_png(const char *filename, DisplayWindow *dw)
+{
+ cairo_status_t r;
+ cairo_t *cr;
+ cairo_surface_t *surf;
+
+ surf = gdk_window_create_similar_surface(dw->drawingarea->window,
+ CAIRO_CONTENT_COLOR,
+ dw->width, dw->height);
+
+ draw_stuff(surf, dw);
+
+ r = cairo_surface_write_to_png(surf, filename);
+ if ( r != CAIRO_STATUS_SUCCESS ) return 1;
+
+ cairo_destroy(cr);
+ cairo_surface_destroy(surf);
+
+ return 0;
+}
+
+
static gint displaywindow_close(GtkWidget *widget, DisplayWindow *dw)
{
gtk_widget_destroy(dw->window);
@@ -817,8 +852,7 @@ static gint displaywindow_save_response(GtkWidget *d, gint response,
type = gtk_combo_box_get_active(GTK_COMBO_BOX(cd->cb));
if ( type == 0 ) {
- /* FIXME: Use Cairo or something */
- r = render_png(dw->pixbufs[0], file);
+ r = write_png(file, dw);
} else if ( type == 1 ) {
r = render_tiff_fp(dw->image, file);
} else if ( type == 2 ) {