[Xfce4-commits] ristretto:ristretto-0.0 Add a preload state to the pictureviewer, where it will render the thumbnail instead of the original image.

2011-10-23 Thread Stephan Arts
Updating branch refs/heads/ristretto-0.0
 to d4e2a5d7d9d203d5477a3dad227c1d7849b80df4 (commit)
   from 7d29665d25fe6356853220c6a2e3506fe02d9635 (commit)

commit d4e2a5d7d9d203d5477a3dad227c1d7849b80df4
Author: Stephan Arts stephan@thor.(none)
Date:   Sat Feb 21 01:08:31 2009 +0100

Add a preload state to the pictureviewer, where it will render the 
thumbnail instead of the original image.

 src/picture_viewer.c |  232 ++
 1 files changed, 44 insertions(+), 188 deletions(-)

diff --git a/src/picture_viewer.c b/src/picture_viewer.c
index c88bbc6..6a75a07 100644
--- a/src/picture_viewer.c
+++ b/src/picture_viewer.c
@@ -56,6 +56,8 @@ struct _RsttoPictureViewerPriv
 void (*cb_value_changed)(GtkAdjustment *, RsttoPictureViewer 
*);
 GdkColor *bg_color;
 
+gdouble  scale;
+
 struct
 {
 gdouble x;
@@ -674,207 +676,61 @@ rstto_picture_viewer_refresh(RsttoPictureViewer *viewer)
 {
 GtkWidget *widget = GTK_WIDGET(viewer);
 GdkPixbuf *src_pixbuf = NULL;
+GdkPixbuf *thumb_pixbuf = NULL;
 gboolean *fit_to_screen = NULL;
 gdouble *scale = NULL;
-gboolean changed = TRUE;
+gint width = 0, height = 0;
 
-if (viewer-priv-image)
+if (viewer-priv-state == RSTTO_PICTURE_VIEWER_STATE_PREVIEW)
 {
-fit_to_screen = g_object_get_data (G_OBJECT (viewer-priv-image), 
viewer-fit-to-screen);
-scale = g_object_get_data (G_OBJECT (viewer-priv-image), 
viewer-scale);
+if (viewer-priv-image != NULL);
+{   
+src_pixbuf = rstto_image_get_pixbuf (viewer-priv-image);
+thumb_pixbuf = rstto_image_get_thumbnail (viewer-priv-image);
 
-src_pixbuf = rstto_image_get_pixbuf (viewer-priv-image);
-
-if (viewer-priv-state == RSTTO_PICTURE_VIEWER_STATE_PREVIEW)
-{
-src_pixbuf = rstto_image_get_thumbnail (viewer-priv-image);
-}
-if (src_pixbuf != NULL)
-{
-g_object_ref (src_pixbuf);
-}
-else
-{
-if(viewer-priv-dst_pixbuf)
+if (src_pixbuf)
 {
-g_object_unref(viewer-priv-dst_pixbuf);
-viewer-priv-dst_pixbuf = NULL;
+width = gdk_pixbuf_get_width (src_pixbuf);
+height = gdk_pixbuf_get_height (src_pixbuf);
+
+/* Check if the image fits inside the viewer,
+ * if not, scale it down to fit
+ */
+if ((GTK_WIDGET (viewer)-allocation.width  width) ||
+(GTK_WIDGET (viewer)-allocation.height  height))
+{
+/* The image does not fit the picture-viewer, and 
+ * we decided to scale it down to fit. Now we need to check
+ * which side we need to use as a reference.
+ *
+ * We use the one that produces a larger scale difference
+ * to the viewer.
+ */
+if ((GTK_WIDGET (viewer)-allocation.width / width) 
+(GTK_WIDGET (viewer)-allocation.height / height))
+{
+viewer-priv-scale = GTK_WIDGET 
(viewer)-allocation.width / width;
+}
+else
+{
+viewer-priv-scale = GTK_WIDGET 
(viewer)-allocation.height / height;
+}
+}
+else
+{
+/* The image is smaller then the picture-viewer,
+ * As a result, view it at it's original size.
+ */
+viewer-priv-scale = 1.0;
+}
 }
-return changed;
 }
 }
 else
 {
-if(viewer-priv-dst_pixbuf)
-{
-g_object_unref(viewer-priv-dst_pixbuf);
-viewer-priv-dst_pixbuf = NULL;
-}
-return changed;
-}
-
-
-if (scale == NULL)
-scale = g_new0 (gdouble, 1);
-if (fit_to_screen == NULL)
-fit_to_screen = g_new0 (gboolean , 1);
-
-
-gboolean vadjustment_changed = FALSE;
-gboolean hadjustment_changed = FALSE;
-
-gdouble width = (gdouble)gdk_pixbuf_get_width(src_pixbuf);
-gdouble height = (gdouble)gdk_pixbuf_get_height(src_pixbuf);
-
-if (*scale == 0)
-{
-if ((widget-allocation.width  width)  (widget-allocation.height  
height))
-{
-*scale = 1.0;
-*fit_to_screen = FALSE;
 
-g_object_set_data (G_OBJECT (viewer-priv-image), viewer-scale, 
scale);
-g_object_set_data (G_OBJECT (viewer-priv-image), 
viewer-fit-to-screen, fit_to_screen);
-}
-else
-{
-*fit_to_screen = TRUE;
-g_object_set_data (G_OBJECT (viewer-priv-image), 
viewer-fit-to-screen, 

[Xfce4-commits] ristretto:ristretto-0.0 Add a preload state to the pictureviewer, where it will render the thumbnail instead of the original image.

2011-10-23 Thread Stephan Arts
Updating branch refs/heads/ristretto-0.0
 to d4e2a5d7d9d203d5477a3dad227c1d7849b80df4 (commit)
   from 7d29665d25fe6356853220c6a2e3506fe02d9635 (commit)

commit d4e2a5d7d9d203d5477a3dad227c1d7849b80df4
Author: Stephan Arts stephan@thor.(none)
Date:   Sat Feb 21 01:08:31 2009 +0100

Add a preload state to the pictureviewer, where it will render the 
thumbnail instead of the original image.

 src/picture_viewer.c |  232 ++
 1 files changed, 44 insertions(+), 188 deletions(-)

diff --git a/src/picture_viewer.c b/src/picture_viewer.c
index c88bbc6..6a75a07 100644
--- a/src/picture_viewer.c
+++ b/src/picture_viewer.c
@@ -56,6 +56,8 @@ struct _RsttoPictureViewerPriv
 void (*cb_value_changed)(GtkAdjustment *, RsttoPictureViewer 
*);
 GdkColor *bg_color;
 
+gdouble  scale;
+
 struct
 {
 gdouble x;
@@ -674,207 +676,61 @@ rstto_picture_viewer_refresh(RsttoPictureViewer *viewer)
 {
 GtkWidget *widget = GTK_WIDGET(viewer);
 GdkPixbuf *src_pixbuf = NULL;
+GdkPixbuf *thumb_pixbuf = NULL;
 gboolean *fit_to_screen = NULL;
 gdouble *scale = NULL;
-gboolean changed = TRUE;
+gint width = 0, height = 0;
 
-if (viewer-priv-image)
+if (viewer-priv-state == RSTTO_PICTURE_VIEWER_STATE_PREVIEW)
 {
-fit_to_screen = g_object_get_data (G_OBJECT (viewer-priv-image), 
viewer-fit-to-screen);
-scale = g_object_get_data (G_OBJECT (viewer-priv-image), 
viewer-scale);
+if (viewer-priv-image != NULL);
+{   
+src_pixbuf = rstto_image_get_pixbuf (viewer-priv-image);
+thumb_pixbuf = rstto_image_get_thumbnail (viewer-priv-image);
 
-src_pixbuf = rstto_image_get_pixbuf (viewer-priv-image);
-
-if (viewer-priv-state == RSTTO_PICTURE_VIEWER_STATE_PREVIEW)
-{
-src_pixbuf = rstto_image_get_thumbnail (viewer-priv-image);
-}
-if (src_pixbuf != NULL)
-{
-g_object_ref (src_pixbuf);
-}
-else
-{
-if(viewer-priv-dst_pixbuf)
+if (src_pixbuf)
 {
-g_object_unref(viewer-priv-dst_pixbuf);
-viewer-priv-dst_pixbuf = NULL;
+width = gdk_pixbuf_get_width (src_pixbuf);
+height = gdk_pixbuf_get_height (src_pixbuf);
+
+/* Check if the image fits inside the viewer,
+ * if not, scale it down to fit
+ */
+if ((GTK_WIDGET (viewer)-allocation.width  width) ||
+(GTK_WIDGET (viewer)-allocation.height  height))
+{
+/* The image does not fit the picture-viewer, and 
+ * we decided to scale it down to fit. Now we need to check
+ * which side we need to use as a reference.
+ *
+ * We use the one that produces a larger scale difference
+ * to the viewer.
+ */
+if ((GTK_WIDGET (viewer)-allocation.width / width) 
+(GTK_WIDGET (viewer)-allocation.height / height))
+{
+viewer-priv-scale = GTK_WIDGET 
(viewer)-allocation.width / width;
+}
+else
+{
+viewer-priv-scale = GTK_WIDGET 
(viewer)-allocation.height / height;
+}
+}
+else
+{
+/* The image is smaller then the picture-viewer,
+ * As a result, view it at it's original size.
+ */
+viewer-priv-scale = 1.0;
+}
 }
-return changed;
 }
 }
 else
 {
-if(viewer-priv-dst_pixbuf)
-{
-g_object_unref(viewer-priv-dst_pixbuf);
-viewer-priv-dst_pixbuf = NULL;
-}
-return changed;
-}
-
-
-if (scale == NULL)
-scale = g_new0 (gdouble, 1);
-if (fit_to_screen == NULL)
-fit_to_screen = g_new0 (gboolean , 1);
-
-
-gboolean vadjustment_changed = FALSE;
-gboolean hadjustment_changed = FALSE;
-
-gdouble width = (gdouble)gdk_pixbuf_get_width(src_pixbuf);
-gdouble height = (gdouble)gdk_pixbuf_get_height(src_pixbuf);
-
-if (*scale == 0)
-{
-if ((widget-allocation.width  width)  (widget-allocation.height  
height))
-{
-*scale = 1.0;
-*fit_to_screen = FALSE;
 
-g_object_set_data (G_OBJECT (viewer-priv-image), viewer-scale, 
scale);
-g_object_set_data (G_OBJECT (viewer-priv-image), 
viewer-fit-to-screen, fit_to_screen);
-}
-else
-{
-*fit_to_screen = TRUE;
-g_object_set_data (G_OBJECT (viewer-priv-image), 
viewer-fit-to-screen,