[Xfce4-commits] <ristretto:master> Center image

Stephan Arts noreply at xfce.org
Fri Oct 21 17:38:03 CEST 2011


Updating branch refs/heads/master
         to 561eb6fcc5bff17432bba70509462cea64836ca3 (commit)
       from 2ae7a2bbe7f526b26e2ea3db3c7aa44528ae3ae1 (commit)

commit 561eb6fcc5bff17432bba70509462cea64836ca3
Author: Stephan Arts <stephan at xfce.org>
Date:   Fri Oct 21 07:39:21 2011 +0200

    Center image

 src/image_viewer.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/image_viewer.c b/src/image_viewer.c
index 8719d8f..7a195a0 100644
--- a/src/image_viewer.c
+++ b/src/image_viewer.c
@@ -795,6 +795,9 @@ static void
 rstto_image_viewer_paint (GtkWidget *widget, cairo_t *ctx)
 {
     RsttoImageViewer *viewer = RSTTO_IMAGE_VIEWER (widget);
+    gdouble x_offset = 0.0;
+    gdouble y_offset = 0.0;
+    
 
     if(GTK_WIDGET_REALIZED(widget))
     {          
@@ -837,10 +840,30 @@ rstto_image_viewer_paint (GtkWidget *widget, cairo_t *ctx)
                                 ctx,
                                 0.0 - gtk_adjustment_get_value (viewer->hadjustment),
                                 0.0 - gtk_adjustment_get_value (viewer->vadjustment));
+                        x_offset = ((gdouble)widget->allocation.width - (
+                                    (gdouble)viewer->priv->image_width * 
+                                        viewer->priv->scale) ) / 2.0;
+                        y_offset = ((gdouble)widget->allocation.height - (
+                                    (gdouble)viewer->priv->image_height * 
+                                        viewer->priv->scale) ) / 2.0;
                         break;
 
                 }
 
+                if (x_offset < 0.)
+                {
+                    x_offset = 0.0;
+                }
+                if (y_offset < 0.)
+                {
+                    y_offset = 0.0;
+                }
+
+                cairo_translate (
+                        ctx,
+                        x_offset,
+                        y_offset);
+
                 /* TODO: center image on widget when zoomed out */
                 cairo_scale (
                         ctx,


More information about the Xfce4-commits mailing list