summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2017-11-03 14:50:45 +1300
committerRobert Ancell <robert.ancell@canonical.com>2018-01-31 09:19:47 +1300
commit2fb4509d184c4bb502ce01c818abc7cd10cd5d77 (patch)
treeb35e00924328367ba2492cbc19ab45438b32beeb
parent3d0d7575218f8e03f75e80c50f1f0ad34d6b9d3b (diff)
downloadgnome-desktop-2fb4509d184c4bb502ce01c818abc7cd10cd5d77.tar.gz
gnome-bg: Add new GdkRGBA methods to replace obsolete GdkColor methods
This is an API/ABI break. The only expected consumer of this feature is gnome-control-center. https://bugzilla.gnome.org/show_bug.cgi?id=789840
-rw-r--r--configure.ac2
-rw-r--r--docs/reference/gnome-desktop3/gnome-desktop3-sections.txt4
-rw-r--r--libgnome-desktop/gnome-bg.c102
-rw-r--r--libgnome-desktop/gnome-bg.h12
4 files changed, 56 insertions, 64 deletions
diff --git a/configure.ac b/configure.ac
index 43a09551..4eee27fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,7 @@ AC_CONFIG_MACRO_DIR([m4])
# change to C+1:0:0
# - If the interface is the same as the previous version, change to C:R+1:A
-LT_VERSION=14:1:2
+LT_VERSION=15:0:0
AC_SUBST(LT_VERSION)
LT_PREREQ([2.2.6])
diff --git a/docs/reference/gnome-desktop3/gnome-desktop3-sections.txt b/docs/reference/gnome-desktop3/gnome-desktop3-sections.txt
index 9904103f..182fa60a 100644
--- a/docs/reference/gnome-desktop3/gnome-desktop3-sections.txt
+++ b/docs/reference/gnome-desktop3/gnome-desktop3-sections.txt
@@ -5,9 +5,9 @@ gnome_bg_load_from_preferences
gnome_bg_save_to_preferences
gnome_bg_set_filename
gnome_bg_set_placement
-gnome_bg_set_color
+gnome_bg_set_rgba
gnome_bg_get_placement
-gnome_bg_get_color
+gnome_bg_get_rgba
gnome_bg_get_filename
gnome_bg_draw
gnome_bg_create_surface
diff --git a/libgnome-desktop/gnome-bg.c b/libgnome-desktop/gnome-bg.c
index 82b2785a..2b6ecd3e 100644
--- a/libgnome-desktop/gnome-bg.c
+++ b/libgnome-desktop/gnome-bg.c
@@ -76,8 +76,8 @@ struct _GnomeBG
char * filename;
GDesktopBackgroundStyle placement;
GDesktopBackgroundShading color_type;
- GdkColor primary;
- GdkColor secondary;
+ GdkRGBA primary;
+ GdkRGBA secondary;
GFileMonitor * file_monitor;
@@ -126,8 +126,8 @@ static GdkPixbuf *pixbuf_scale_to_min (GdkPixbuf *src,
int min_height);
static void pixbuf_draw_gradient (GdkPixbuf *pixbuf,
gboolean horizontal,
- GdkColor *c1,
- GdkColor *c2,
+ GdkRGBA *c1,
+ GdkRGBA *c2,
GdkRectangle *rect);
static void pixbuf_tile (GdkPixbuf *src,
GdkPixbuf *dest);
@@ -170,24 +170,24 @@ static GnomeBGSlideShow *read_slideshow_file (const char *filename,
static void
color_from_string (const char *string,
- GdkColor *colorp)
+ GdkRGBA *colorp)
{
/* If all else fails use black */
- gdk_color_parse ("black", colorp);
+ gdk_rgba_parse (colorp, "black");
if (!string)
return;
- gdk_color_parse (string, colorp);
+ gdk_rgba_parse (colorp, string);
}
static char *
-color_to_string (const GdkColor *color)
+color_to_string (const GdkRGBA *color)
{
return g_strdup_printf ("#%02x%02x%02x",
- color->red >> 8,
- color->green >> 8,
- color->blue >> 8);
+ (int) (0.5 + color->red * 255),
+ (int) (0.5 + color->green * 255),
+ (int) (0.5 + color->blue * 255));
}
static gboolean
@@ -298,7 +298,7 @@ gnome_bg_load_from_preferences (GnomeBG *bg,
char *tmp;
char *filename;
GDesktopBackgroundShading ctype;
- GdkColor c1, c2;
+ GdkRGBA c1, c2;
GDesktopBackgroundStyle placement;
g_return_if_fail (GNOME_IS_BG (bg));
@@ -322,7 +322,7 @@ gnome_bg_load_from_preferences (GnomeBG *bg,
/* Placement */
placement = g_settings_get_enum (settings, BG_KEY_PICTURE_PLACEMENT);
- gnome_bg_set_color (bg, ctype, &c1, &c2);
+ gnome_bg_set_rgba (bg, ctype, &c1, &c2);
gnome_bg_set_placement (bg, placement);
gnome_bg_set_filename (bg, filename);
@@ -443,17 +443,17 @@ gnome_bg_new (void)
}
void
-gnome_bg_set_color (GnomeBG *bg,
- GDesktopBackgroundShading type,
- GdkColor *primary,
- GdkColor *secondary)
+gnome_bg_set_rgba (GnomeBG *bg,
+ GDesktopBackgroundShading type,
+ GdkRGBA *primary,
+ GdkRGBA *secondary)
{
g_return_if_fail (bg != NULL);
g_return_if_fail (primary != NULL);
if (bg->color_type != type ||
- !gdk_color_equal (&bg->primary, primary) ||
- (secondary && !gdk_color_equal (&bg->secondary, secondary))) {
+ !gdk_rgba_equal (&bg->primary, primary) ||
+ (secondary && !gdk_rgba_equal (&bg->secondary, secondary))) {
bg->color_type = type;
bg->primary = *primary;
@@ -487,10 +487,10 @@ gnome_bg_get_placement (GnomeBG *bg)
}
void
-gnome_bg_get_color (GnomeBG *bg,
- GDesktopBackgroundShading *type,
- GdkColor *primary,
- GdkColor *secondary)
+gnome_bg_get_rgba (GnomeBG *bg,
+ GDesktopBackgroundShading *type,
+ GdkRGBA *primary,
+ GdkRGBA *secondary)
{
g_return_if_fail (bg != NULL);
@@ -708,9 +708,9 @@ draw_color_area (GnomeBG *bg,
switch (bg->color_type) {
case G_DESKTOP_BACKGROUND_SHADING_SOLID:
/* not really a big deal to ignore the area of interest */
- pixel = ((bg->primary.red >> 8) << 24) |
- ((bg->primary.green >> 8) << 16) |
- ((bg->primary.blue >> 8) << 8) |
+ pixel = ((int) (0.5 + bg->primary.red * 255) << 24) |
+ ((int) (0.5 + bg->primary.green * 255) << 16) |
+ ((int) (0.5 + bg->primary.blue * 255) << 8) |
(0xff);
gdk_pixbuf_fill (dest, pixel);
@@ -1080,11 +1080,8 @@ gnome_bg_create_surface (GnomeBG *bg,
cr = cairo_create (surface);
if (!bg->filename && bg->color_type == G_DESKTOP_BACKGROUND_SHADING_SOLID) {
- gdk_cairo_set_source_color (cr, &(bg->primary));
- average.red = bg->primary.red / 65535.0;
- average.green = bg->primary.green / 65535.0;
- average.blue = bg->primary.blue / 65535.0;
- average.alpha = 1.0;
+ gdk_cairo_set_source_rgba (cr, &(bg->primary));
+ average = bg->primary;
}
else {
GdkPixbuf *pixbuf;
@@ -1117,8 +1114,8 @@ gnome_bg_is_dark (GnomeBG *bg,
int width,
int height)
{
- GdkColor color;
- int intensity;
+ GdkRGBA color;
+ gdouble intensity;
GdkPixbuf *pixbuf;
g_return_val_if_fail (bg != NULL, FALSE);
@@ -1132,24 +1129,19 @@ gnome_bg_is_dark (GnomeBG *bg,
}
pixbuf = get_pixbuf_for_size (bg, -1, width, height);
if (pixbuf) {
- GdkRGBA argb;
- guchar a, r, g, b;
-
- pixbuf_average_value (pixbuf, &argb);
- a = argb.alpha * 0xff;
- r = argb.red * 0xff;
- g = argb.green * 0xff;
- b = argb.blue * 0xff;
+ GdkRGBA average;
+
+ pixbuf_average_value (pixbuf, &average);
- color.red = (color.red * (0xFF - a) + r * 0x101 * a) / 0xFF;
- color.green = (color.green * (0xFF - a) + g * 0x101 * a) / 0xFF;
- color.blue = (color.blue * (0xFF - a) + b * 0x101 * a) / 0xFF;
+ color.red = color.red * (1.0 - average.alpha) + average.red * average.alpha;
+ color.green = color.green * (1.0 - average.alpha) + average.green * average.alpha;
+ color.blue = color.blue * (1.0 - average.alpha) + average.blue * average.alpha;
g_object_unref (pixbuf);
}
- intensity = (color.red * 77 +
- color.green * 150 +
- color.blue * 28) >> 16;
+ intensity = color.red * 77 +
+ color.green * 150 +
+ color.blue * 28;
return intensity < 160; /* biased slightly to be dark */
}
@@ -2384,9 +2376,9 @@ pixbuf_scale_to_min (GdkPixbuf *src, int min_width, int min_height)
}
static guchar *
-create_gradient (const GdkColor *primary,
- const GdkColor *secondary,
- int n_pixels)
+create_gradient (const GdkRGBA *primary,
+ const GdkRGBA *secondary,
+ int n_pixels)
{
guchar *result = g_malloc (n_pixels * 3);
int i;
@@ -2394,9 +2386,9 @@ create_gradient (const GdkColor *primary,
for (i = 0; i < n_pixels; ++i) {
double ratio = (i + 0.5) / n_pixels;
- result[3 * i + 0] = ((guint16) (primary->red * (1 - ratio) + secondary->red * ratio)) >> 8;
- result[3 * i + 1] = ((guint16) (primary->green * (1 - ratio) + secondary->green * ratio)) >> 8;
- result[3 * i + 2] = ((guint16) (primary->blue * (1 - ratio) + secondary->blue * ratio)) >> 8;
+ result[3 * i + 0] = (int) (0.5 + (primary->red * (1 - ratio) + secondary->red * ratio) * 255);
+ result[3 * i + 1] = (int) (0.5 + (primary->green * (1 - ratio) + secondary->green * ratio) * 255);
+ result[3 * i + 2] = (int) (0.5 + (primary->blue * (1 - ratio) + secondary->blue * ratio) * 255);
}
return result;
@@ -2405,8 +2397,8 @@ create_gradient (const GdkColor *primary,
static void
pixbuf_draw_gradient (GdkPixbuf *pixbuf,
gboolean horizontal,
- GdkColor *primary,
- GdkColor *secondary,
+ GdkRGBA *primary,
+ GdkRGBA *secondary,
GdkRectangle *rect)
{
int width;
diff --git a/libgnome-desktop/gnome-bg.h b/libgnome-desktop/gnome-bg.h
index 3ec97a7c..f19173d8 100644
--- a/libgnome-desktop/gnome-bg.h
+++ b/libgnome-desktop/gnome-bg.h
@@ -61,17 +61,17 @@ void gnome_bg_set_filename (GnomeBG *bg,
const char *filename);
void gnome_bg_set_placement (GnomeBG *bg,
GDesktopBackgroundStyle placement);
-void gnome_bg_set_color (GnomeBG *bg,
+void gnome_bg_set_rgba (GnomeBG *bg,
GDesktopBackgroundShading type,
- GdkColor *primary,
- GdkColor *secondary);
+ GdkRGBA *primary,
+ GdkRGBA *secondary);
/* Getters */
GDesktopBackgroundStyle gnome_bg_get_placement (GnomeBG *bg);
-void gnome_bg_get_color (GnomeBG *bg,
+void gnome_bg_get_rgba (GnomeBG *bg,
GDesktopBackgroundShading *type,
- GdkColor *primary,
- GdkColor *secondary);
+ GdkRGBA *primary,
+ GdkRGBA *secondary);
const gchar * gnome_bg_get_filename (GnomeBG *bg);
/* Drawing and thumbnailing */