[gnome-panel/wip/3.0-freeze-break] panel: Replace fit/stretch settings keys for background with image-style



commit 92d22e2dd0b544a3747e798d06d27daf349258b0
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Mar 25 11:54:32 2011 +0100

    panel: Replace fit/stretch settings keys for background with image-style
    
    The two options were incompatibly, so it's really an enum.

 data/org.gnome.gnome-panel.toplevel.gschema.xml |   15 +--
 gnome-panel/panel-background.c                  |  105 +++++++++--------------
 gnome-panel/panel-background.h                  |    3 +-
 gnome-panel/panel-enums-gsettings.h             |    6 ++
 gnome-panel/panel-schemas.h                     |    3 +-
 5 files changed, 54 insertions(+), 78 deletions(-)
---
diff --git a/data/org.gnome.gnome-panel.toplevel.gschema.xml b/data/org.gnome.gnome-panel.toplevel.gschema.xml
index a97f445..7f5e4ae 100644
--- a/data/org.gnome.gnome-panel.toplevel.gschema.xml
+++ b/data/org.gnome.gnome-panel.toplevel.gschema.xml
@@ -113,20 +113,15 @@
       <summary>Background image</summary>
       <description>Specifies the file to be used for the background image. If the image contains an alpha channel it will be composited onto the desktop background image.</description>
     </key>
-    <key name="fit" type="b">
-      <default>false</default>
-      <summary>Fit image to panel</summary>
-      <description>If true, the image will be scaled (retaining the aspect ratio of the image) to the panel height (if horizontal).</description>
-    </key>
-    <key name="stretch" type="b">
-      <default>false</default>
-      <summary>Stretch image to panel</summary>
-      <description>If true, the image will be scaled to the panel dimensions. The aspect ratio of the image will not be maintained.</description>
-    </key>
     <key name="image-rotate" type="b">
       <default>false</default>
       <summary>Rotate image on vertical panels</summary>
       <description>If true, the background image will be rotated when the panel is oriented vertically.</description>
     </key>
+    <key name="image-style" enum="org.gnome.gnome-panel.PanelBackgroundImageStyle">
+      <default>'none'</default>
+      <summary>Image options</summary>
+      <description>Determines how the image set by image-uri is rendered. Possible values are "none", "stretch", "fit". With "stretch", the image will be scaled to the panel dimensions and the aspect ratio of the image will not be maintained. With "fit", the image will be scaled (retaining the aspect ratio of the image) to the panel height (if horizontal).</description>
+    </key>
   </schema>
 </schemalist>
diff --git a/gnome-panel/panel-background.c b/gnome-panel/panel-background.c
index 09f0697..afe879c 100644
--- a/gnome-panel/panel-background.c
+++ b/gnome-panel/panel-background.c
@@ -334,7 +334,26 @@ get_scaled_and_rotated_pixbuf (PanelBackground *background)
 	width  = orig_width;
 	height = orig_height;
 
-	if (background->fit_image) {
+	switch (background->style_image) {
+	case PANEL_BACKGROUND_IMAGE_STYLE_NONE:
+		if (background->orientation == GTK_ORIENTATION_VERTICAL &&
+			   background->rotate_image) {
+			int tmp = width;
+			width = height;
+			height = tmp;
+		}
+		break;
+	case PANEL_BACKGROUND_IMAGE_STYLE_STRETCH:
+		if (background->orientation == GTK_ORIENTATION_VERTICAL &&
+		    background->rotate_image) {
+			width  = panel_height;
+			height = panel_width;
+		} else {
+			width  = panel_width;
+			height = panel_height;
+		}
+		break;
+	case PANEL_BACKGROUND_IMAGE_STYLE_FIT:
 		switch (background->orientation) {
 		case GTK_ORIENTATION_HORIZONTAL:
 			width  = orig_width * panel_height / orig_height;
@@ -353,20 +372,10 @@ get_scaled_and_rotated_pixbuf (PanelBackground *background)
 			g_assert_not_reached ();
 			break;
 		}
-	} else if (background->stretch_image) {
-		if (background->orientation == GTK_ORIENTATION_VERTICAL &&
-		    background->rotate_image) {
-			width  = panel_height;
-			height = panel_width;
-		} else {
-			width  = panel_width;
-			height = panel_height;
-		}
-	} else if (background->orientation == GTK_ORIENTATION_VERTICAL &&
-		   background->rotate_image) {
-		int tmp = width;
-		width = height;
-		height = tmp;
+		break;
+	default:
+		g_assert_not_reached ();
+		break;
 	}
 
 	if (width == orig_width &&
@@ -605,44 +614,21 @@ panel_background_set_image_uri (PanelBackground *background,
 }
 
 static void
-panel_background_set_fit_no_update (PanelBackground *background,
-				    gboolean         fit_image)
-{
-	background->fit_image = fit_image != FALSE;
-}
-
-static void
-panel_background_set_fit (PanelBackground *background,
-			  gboolean         fit_image)
-{
-	fit_image = fit_image != FALSE;
-
-	if (background->fit_image == fit_image)
-		return;
-
-	free_transformed_resources (background);
-	panel_background_set_fit_no_update (background, fit_image);
-	panel_background_transform (background);
-}
-
-static void
-panel_background_set_stretch_no_update (PanelBackground *background,
-				        gboolean         stretch_image)
+panel_background_set_image_style_no_update (PanelBackground           *background,
+					    PanelBackgroundImageStyle  style)
 {
-	background->stretch_image = stretch_image != FALSE;
+	background->style_image = style;
 }
 
 static void
-panel_background_set_stretch (PanelBackground *background,
-			      gboolean         stretch_image)
+panel_background_set_image_style (PanelBackground           *background,
+				  PanelBackgroundImageStyle  style)
 {
-	stretch_image = stretch_image != FALSE;
-
-	if (background->stretch_image == stretch_image)
+	if (background->style_image == style)
 		return;
 
 	free_transformed_resources (background);
-	panel_background_set_stretch_no_update (background, stretch_image);
+	panel_background_set_image_style_no_update (background, style);
 	panel_background_transform (background);
 }
 
@@ -689,12 +675,10 @@ panel_background_settings_changed (GSettings       *settings,
 		value_str = g_settings_get_string (settings, key);
 		panel_background_set_image_uri (background, value_str);
 		g_free (value_str);
-	} else if (g_strcmp0 (key, PANEL_BACKGROUND_FIT_KEY) == 0) {
-		value_boolean = g_settings_get_boolean (settings, key);
-		panel_background_set_fit (background, value_boolean);
-	} else if (g_strcmp0 (key, PANEL_BACKGROUND_STRETCH_KEY) == 0) {
-		value_boolean = g_settings_get_boolean (settings, key);
-		panel_background_set_stretch (background, value_boolean);
+	} else if (g_strcmp0 (key, PANEL_BACKGROUND_IMAGE_STYLE_KEY) == 0) {
+		PanelBackgroundImageStyle style;
+		style = g_settings_get_enum (settings, key);
+		panel_background_set_image_style (background, style);
 	} else if (g_strcmp0 (key, PANEL_BACKGROUND_IMAGE_ROTATE_KEY) == 0) {
 		value_boolean = g_settings_get_boolean (settings, key);
 		panel_background_set_rotate (background, value_boolean);
@@ -711,8 +695,7 @@ panel_background_settings_init (PanelBackground *background,
 	char                *color_str;
 	GdkRGBA              color;
 	char                *image;
-	gboolean             fit_image;
-	gboolean             stretch_image;
+	PanelBackgroundImageStyle style_image;
 	gboolean             rotate_image;
 
 	g_assert (background->settings == NULL);
@@ -734,13 +717,9 @@ panel_background_settings_init (PanelBackground *background,
 	panel_background_set_image_uri_no_update (background, image);
 	g_free (image);
 
-	fit_image = g_settings_get_boolean (background->settings,
-					    PANEL_BACKGROUND_FIT_KEY);
-	panel_background_set_fit_no_update (background, fit_image);
-
-	stretch_image = g_settings_get_boolean (background->settings,
-						PANEL_BACKGROUND_STRETCH_KEY);
-	panel_background_set_stretch_no_update (background, stretch_image);
+	style_image = g_settings_get_enum (background->settings,
+					   PANEL_BACKGROUND_IMAGE_STYLE_KEY);
+	panel_background_set_image_style_no_update (background, style_image);
 
 	rotate_image = g_settings_get_boolean (background->settings,
 					       PANEL_BACKGROUND_IMAGE_ROTATE_KEY);
@@ -823,8 +802,7 @@ panel_background_change_region (PanelBackground *background,
 			need_to_retransform = TRUE;
 		} else if ((background->region.width != width ||
 			    background->region.height != height) &&
-			   (background->fit_image ||
-			    background->stretch_image)) {
+			   (background->style_image != PANEL_BACKGROUND_IMAGE_STYLE_NONE)) {
 			/* or if the size changes and we are 
 			   stretching or fitting the image */
 			need_to_retransform = TRUE;
@@ -901,8 +879,7 @@ panel_background_init (PanelBackground              *background,
 	background->default_color.blue  = 0.;
 	background->default_color.alpha = 1.;
 
-	background->fit_image     = FALSE;
-	background->stretch_image = FALSE;
+	background->style_image   = PANEL_BACKGROUND_IMAGE_STYLE_NONE;
 	background->rotate_image  = FALSE;
 
 	background->has_alpha = FALSE;
diff --git a/gnome-panel/panel-background.h b/gnome-panel/panel-background.h
index eb9a93a..89e7b33 100644
--- a/gnome-panel/panel-background.h
+++ b/gnome-panel/panel-background.h
@@ -64,8 +64,7 @@ struct _PanelBackground {
 	cairo_pattern_t        *default_pattern;
 	GdkRGBA                 default_color;
 
-        guint                   fit_image : 1;
-        guint                   stretch_image : 1;
+        PanelBackgroundImageStyle style_image;
         guint                   rotate_image : 1;
 
 	guint                   has_alpha : 1;
diff --git a/gnome-panel/panel-enums-gsettings.h b/gnome-panel/panel-enums-gsettings.h
index a559657..4f2f8a0 100644
--- a/gnome-panel/panel-enums-gsettings.h
+++ b/gnome-panel/panel-enums-gsettings.h
@@ -50,6 +50,12 @@ typedef enum {
 	PANEL_BACK_IMAGE = 2
 } PanelBackgroundType;
 
+typedef enum {
+	PANEL_BACKGROUND_IMAGE_STYLE_NONE    = 0,
+	PANEL_BACKGROUND_IMAGE_STYLE_STRETCH = 1,
+	PANEL_BACKGROUND_IMAGE_STYLE_FIT     = 2
+} PanelBackgroundImageStyle;
+
 G_END_DECLS
 
 #endif /* __PANEL_ENUMS_GSETTINGS_H__ */
diff --git a/gnome-panel/panel-schemas.h b/gnome-panel/panel-schemas.h
index d40000e..ae89c20 100644
--- a/gnome-panel/panel-schemas.h
+++ b/gnome-panel/panel-schemas.h
@@ -56,8 +56,7 @@
 #define PANEL_BACKGROUND_TYPE_KEY         "type"
 #define PANEL_BACKGROUND_COLOR_KEY        "color"
 #define PANEL_BACKGROUND_IMAGE_URI_KEY    "image-uri"
-#define PANEL_BACKGROUND_FIT_KEY          "fit"
-#define PANEL_BACKGROUND_STRETCH_KEY      "stretch"
+#define PANEL_BACKGROUND_IMAGE_STYLE_KEY  "image-style"
 #define PANEL_BACKGROUND_IMAGE_ROTATE_KEY "image-rotate"
 #define PANEL_BACKGROUND_COLOR_DEFAULT    "rgba(255,255,255,.2)"
 



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