This attached patch for eel is from bug 320830 [1] required as a dependency to implement a new background mode for control center in bug 105231 [2]. It was requested to be posted on the Nautilus list for any comments. It adds an EEL_BACKGROUND_ZOOM background placement enum and the two functions eel_gdk_scale_to_min_factor() and eel_gdk_pixbuf_scale_to_min(). The functions are the opposite of the existing eel_gdk_scale_to_fit_factor and eel_gdk_pixbuf_scale_to_fit functions. Instead of scaling to fit within a box, these are used scale to fit outwith a box. Two possible issues, the first of which is the function label "min" which may not be ideal so perhaps "outfit" instead? The name of the enum EEL_BACKGROUND_ZOOM was based on the submitted name "Zoom" of the new background mode but the name has not been decided upon yet AFAIK. See bug 105321 [2] for naming discussions with "Cropped" being about the next best and other suggestions welcome. However as it's internal only and the existing EEL_BACKGROUND_STRETCHED doesn't exactly match its current label "Fill Screen" either, it's not too critical but would be nice to match. [1] http://bugzilla.gnome.org/show_bug.cgi?id=320830 [2] http://bugzilla.gnome.org/show_bug.cgi?id=105231 -- Alan. "One must never be purposelessnessnesslessness."
diff -ur eel.orig/eel/eel-background.c eel/eel/eel-background.c
--- eel.orig/eel/eel-background.c 2005-10-27 16:03:37.000000000 +0100
+++ eel/eel/eel-background.c 2005-11-22 00:17:03.000000000 +0000
@@ -551,6 +551,7 @@
switch (background->details->image_placement) {
case EEL_BACKGROUND_TILED:
case EEL_BACKGROUND_SCALED:
+ case EEL_BACKGROUND_ZOOM:
return TRUE;
default:
g_assert_not_reached ();
@@ -676,6 +677,24 @@
}
}
break;
+ case EEL_BACKGROUND_ZOOM:
+ eel_gdk_scale_to_min_factor (background->details->image_width_unscaled,
+ background->details->image_height_unscaled,
+ dest_width, dest_height,
+ &fit_width, &fit_height);
+
+ if (image_width != fit_width || image_height != fit_height) {
+ if (cur_scaled) {
+ reload_image = TRUE;
+ } else {
+ scaled_pixbuf = eel_gdk_pixbuf_scale_to_min (background->details->image, dest_width, dest_height);
+ g_object_unref (background->details->image);
+ background->details->image = scaled_pixbuf;
+ image_width = gdk_pixbuf_get_width (scaled_pixbuf);
+ image_height = gdk_pixbuf_get_height (scaled_pixbuf);
+ }
+ }
+ break;
}
if (reload_image) {
@@ -757,6 +776,7 @@
case EEL_BACKGROUND_CENTERED:
case EEL_BACKGROUND_SCALED:
case EEL_BACKGROUND_SCALED_ASPECT:
+ case EEL_BACKGROUND_ZOOM:
*pixmap_width = entire_width;
*pixmap_height = entire_height;
}
@@ -1354,6 +1374,7 @@
case EEL_BACKGROUND_CENTERED:
case EEL_BACKGROUND_SCALED:
case EEL_BACKGROUND_SCALED_ASPECT:
+ case EEL_BACKGROUND_ZOOM:
/* Since the image has already been scaled, all these cases
* can be treated identically.
*/
diff -ur eel.orig/eel/eel-background.h eel/eel/eel-background.h
--- eel.orig/eel/eel-background.h 2005-03-16 08:29:16.000000000 +0000
+++ eel/eel/eel-background.h 2005-11-22 00:17:03.000000000 +0000
@@ -63,7 +63,8 @@
EEL_BACKGROUND_TILED = 0, /* zero makes this the default placement */
EEL_BACKGROUND_CENTERED,
EEL_BACKGROUND_SCALED,
- EEL_BACKGROUND_SCALED_ASPECT
+ EEL_BACKGROUND_SCALED_ASPECT,
+ EEL_BACKGROUND_ZOOM
} EelBackgroundImagePlacement;
GtkType eel_background_get_type (void);
diff -ur eel.orig/eel/eel-gdk-pixbuf-extensions.c eel/eel/eel-gdk-pixbuf-extensions.c
--- eel.orig/eel/eel-gdk-pixbuf-extensions.c 2005-10-27 16:03:37.000000000 +0100
+++ eel/eel/eel-gdk-pixbuf-extensions.c 2005-11-22 00:17:03.000000000 +0000
@@ -404,6 +404,37 @@
}
}
+double
+eel_gdk_scale_to_min_factor (int width, int height,
+ int min_width, int min_height,
+ int *scaled_width, int *scaled_height)
+{
+ double scale_factor;
+
+ scale_factor = MAX (min_width / (double) width, min_height / (double) height);
+
+ *scaled_width = floor (width * scale_factor + .5);
+ *scaled_height = floor (height * scale_factor + .5);
+
+ return scale_factor;
+}
+
+/* Returns a scaled copy of pixbuf, preserving aspect ratio. The copy will
+ * be scaled as small as possible without going under the specified width and height.
+ */
+GdkPixbuf *
+eel_gdk_pixbuf_scale_to_min (GdkPixbuf *pixbuf, int min_width, int min_height)
+{
+ int scaled_width;
+ int scaled_height;
+
+ eel_gdk_scale_to_min_factor (gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf),
+ min_width, min_height,
+ &scaled_width, &scaled_height);
+
+ return gdk_pixbuf_scale_simple (pixbuf, scaled_width, scaled_height, GDK_INTERP_BILINEAR);
+}
+
/**
* eel_gdk_pixbuf_is_valid:
* @pixbuf: A GdkPixbuf
diff -ur eel.orig/eel/eel-gdk-pixbuf-extensions.h eel/eel/eel-gdk-pixbuf-extensions.h
--- eel.orig/eel/eel-gdk-pixbuf-extensions.h 2002-07-10 09:20:11.000000000 +0100
+++ eel/eel/eel-gdk-pixbuf-extensions.h 2005-11-22 00:17:03.000000000 +0000
@@ -71,6 +71,15 @@
int max_height,
int *scaled_width,
int *scaled_height);
+GdkPixbuf * eel_gdk_pixbuf_scale_to_min (GdkPixbuf *pixbuf,
+ int min_width,
+ int min_height);
+double eel_gdk_scale_to_min_factor (int width,
+ int height,
+ int min_width,
+ int min_height,
+ int *scaled_width,
+ int *scaled_height);
/* return average color values for each component (argb) */
guint32 eel_gdk_pixbuf_average_value (GdkPixbuf *pixbuf);
Attachment:
signature.asc
Description: This is a digitally signed message part