[vte/vte-next: 43/47] Make background tint colour use GdkRGBA



commit d83e86f788bc8a515d1a8729f62ca3cd4ad631f1
Author: Christian Persch <chpe gnome org>
Date:   Tue May 3 00:11:04 2011 +0200

    Make background tint colour use GdkRGBA
    
    Remove vte_terminal_set_background_tint_color and vte_terminal_set_opacity.
    The opacity is now taken from the alpha component of the tint GdkRGBA.

 doc/reference/vte-sections.txt |    2 -
 src/vte-private.h              |    3 +-
 src/vte.c                      |  135 ++++++++--------------------------------
 src/vteapp.c                   |   10 ++--
 src/vtebg.c                    |   30 ++++-----
 src/vtebg.h                    |    2 +-
 src/vtedraw.c                  |   15 ++---
 src/vtedraw.h                  |    7 +--
 8 files changed, 53 insertions(+), 151 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index a7e6972..c23e98f 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -43,12 +43,10 @@ vte_terminal_set_color_highlight_rgba
 vte_terminal_set_colors
 vte_terminal_set_colors_rgba
 vte_terminal_set_default_colors
-vte_terminal_set_opacity
 vte_terminal_set_background_image
 vte_terminal_set_background_image_file
 vte_terminal_set_background_saturation
 vte_terminal_set_background_transparent
-vte_terminal_set_background_tint_color
 vte_terminal_set_background_tint_color_rgba
 vte_terminal_set_scroll_background
 vte_terminal_set_cursor_shape
diff --git a/src/vte-private.h b/src/vte-private.h
index e57c909..5076f83 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -369,9 +369,8 @@ struct _VteTerminalPrivate {
 	gboolean bg_transparent;
 	GdkPixbuf *bg_pixbuf;
 	char *bg_file;
-	PangoColor bg_tint_color;
+        GdkRGBA bg_tint_color;
 	guint16 bg_saturation;	/* out of VTE_SATURATION_MAX */
-	guint16 bg_opacity;
 
 	/* Key modifiers. */
 	GdkModifierType modifiers;
diff --git a/src/vte.c b/src/vte.c
index 2600517..e650a85 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -144,7 +144,6 @@ enum {
         PROP_AUDIBLE_BELL,
         PROP_BACKGROUND_IMAGE_FILE,
         PROP_BACKGROUND_IMAGE_PIXBUF,
-        PROP_BACKGROUND_OPACITY,
         PROP_BACKGROUND_SATURATION,
         PROP_BACKGROUND_TINT_COLOR,
         PROP_BACKGROUND_TRANSPARENT,
@@ -2737,31 +2736,6 @@ vte_terminal_set_colors_rgba(VteTerminal *terminal,
 }
 
 /**
- * vte_terminal_set_opacity:
- * @terminal: a #VteTerminal
- * @opacity: the new opacity
- *
- * Sets the opacity of the terminal background, were 0 means completely
- * transparent and 65535 means completely opaque.
- */
-void
-vte_terminal_set_opacity(VteTerminal *terminal, guint16 opacity)
-{
-        VteTerminalPrivate *pvt;
-
-	g_return_if_fail(VTE_IS_TERMINAL(terminal));
-
-        pvt = terminal->pvt;
-
-        if (opacity == pvt->bg_opacity)
-                return;
-
-	pvt->bg_opacity = opacity;
-
-        g_object_notify(G_OBJECT(terminal), "background-opacity");
-}
-
-/**
  * vte_terminal_set_default_colors:
  * @terminal: a #VteTerminal
  *
@@ -7831,11 +7805,11 @@ vte_terminal_init(VteTerminal *terminal)
 	gtk_widget_ensure_style(&terminal->widget);
 
 	/* Set up background information. */
-	pvt->bg_tint_color.red = 0;
-	pvt->bg_tint_color.green = 0;
-	pvt->bg_tint_color.blue = 0;
+	pvt->bg_tint_color.red = 0.;
+	pvt->bg_tint_color.green = 0.;
+	pvt->bg_tint_color.blue = 0.;
+        pvt->bg_tint_color.alpha = 1.;
 	pvt->bg_saturation = 0.4 * VTE_SATURATION_MAX;
-	pvt->bg_opacity = 0xffff;
 	pvt->selection_block_mode = FALSE;
 	pvt->has_fonts = FALSE;
 	pvt->root_pixmap_changed_tag = 0;
@@ -10801,9 +10775,6 @@ vte_terminal_get_property (GObject *object,
                 case PROP_BACKGROUND_IMAGE_PIXBUF:
                         g_value_set_object (value, pvt->bg_pixbuf);
                         break;
-                case PROP_BACKGROUND_OPACITY:
-                        g_value_set_double (value, (double) pvt->bg_opacity / (double) G_MAXUINT16);
-                        break;
                 case PROP_BACKGROUND_SATURATION:
                         g_value_set_double (value, (double) pvt->bg_saturation / (double) VTE_SATURATION_MAX);
                         break;
@@ -10908,14 +10879,11 @@ vte_terminal_set_property (GObject *object,
                 case PROP_BACKGROUND_IMAGE_PIXBUF:
                         vte_terminal_set_background_image (terminal, g_value_get_object (value));
                         break;
-                case PROP_BACKGROUND_OPACITY:
-                        vte_terminal_set_opacity (terminal, g_value_get_double (value) * (double) G_MAXUINT16);
-                        break;
                 case PROP_BACKGROUND_SATURATION:
                         vte_terminal_set_background_saturation (terminal, g_value_get_double (value));
                         break;
                 case PROP_BACKGROUND_TINT_COLOR:
-                        vte_terminal_set_background_tint_color (terminal, g_value_get_boxed (value));
+                        vte_terminal_set_background_tint_color_rgba (terminal, g_value_get_boxed (value));
                         break;
                 case PROP_BACKGROUND_TRANSPARENT:
                         vte_terminal_set_background_transparent (terminal, g_value_get_boolean (value));
@@ -11640,22 +11608,6 @@ vte_terminal_class_init(VteTerminalClass *klass)
                                       G_PARAM_READWRITE | STATIC_PARAMS));
 
         /**
-         * VteTerminal:background-opacity:
-         *
-         * Sets the opacity of the terminal background, were 0.0 means completely
-         * transparent and 1.0 means completely opaque.
-         *
-         * Since: 0.20
-         */
-        g_object_class_install_property
-                (gobject_class,
-                 PROP_BACKGROUND_OPACITY,
-                 g_param_spec_double ("background-opacity", NULL, NULL,
-                                      0.0, 1.0,
-                                      1.0,
-                                      G_PARAM_READWRITE | STATIC_PARAMS));
-     
-        /**
          * VteTerminal:background-saturation:
          *
          * If a background image has been set using #VteTerminal:background-image-file: or
@@ -11693,7 +11645,7 @@ vte_terminal_class_init(VteTerminalClass *klass)
                 (gobject_class,
                  PROP_BACKGROUND_TINT_COLOR,
                  g_param_spec_boxed ("background-tint-color", NULL, NULL,
-                                     GDK_TYPE_COLOR,
+                                     GDK_TYPE_RGBA,
                                      G_PARAM_READWRITE | STATIC_PARAMS));
      
         /**
@@ -12340,6 +12292,7 @@ vte_terminal_background_update(VteTerminal *terminal)
 	double saturation;
 	const PangoColor *entry;
 	GdkColor color;
+        GdkRGBA rgba;
 
 	/* If we're not realized yet, don't worry about it, because we get
 	 * called when we realize. */
@@ -12355,9 +12308,9 @@ vte_terminal_background_update(VteTerminal *terminal)
 
 	entry = &terminal->pvt->palette[VTE_DEF_BG];
 	_vte_debug_print(VTE_DEBUG_BG,
-			 "Setting background color to (%d, %d, %d, %d).\n",
+			 "Setting background color to (%d, %d, %d, %.3f).\n",
 			 entry->red, entry->green, entry->blue,
-			 terminal->pvt->bg_opacity);
+			 terminal->pvt->bg_tint_color.alpha);
 
 	/* Set the terminal widget background color since otherwise we
 	 * won't draw it for VTE_BG_SOURCE_NONE. */
@@ -12366,11 +12319,11 @@ vte_terminal_background_update(VteTerminal *terminal)
 	color.blue = entry->blue;
 	gtk_widget_modify_bg (&terminal->widget, GTK_STATE_NORMAL, &color);
 
-	_vte_draw_set_background_solid (terminal->pvt->draw, 
-					entry->red / 65535.,
-					entry->green / 65535.,
-					entry->blue / 65535.,
-					terminal->pvt->bg_opacity / 65535.);
+        rgba.red = entry->red / 65535.;
+        rgba.green = entry->green / 65535.;
+        rgba.blue = entry->blue / 65535.;
+        rgba.alpha = terminal->pvt->bg_tint_color.alpha;
+        _vte_draw_set_background_solid (terminal->pvt->draw, &rgba);
 
 	/* If we're transparent, and either have no root image or are being
 	 * told to update it, get a new copy of the root window. */
@@ -12480,9 +12433,9 @@ vte_terminal_set_background_saturation(VteTerminal *terminal, double saturation)
 }
 
 /**
- * vte_terminal_set_background_tint_color:
+ * vte_terminal_set_background_tint_color_rgba:
  * @terminal: a #VteTerminal
- * @color: a color which the terminal background should be tinted to if its
+ * @color: (allow-none): a color which the terminal background should be tinted to if its
  *   saturation is not 1.0.
  *
  * If a background image has been set using
@@ -12495,34 +12448,26 @@ vte_terminal_set_background_saturation(VteTerminal *terminal, double saturation)
  * the root window) and modify its pixel values.  The initial tint color
  * is black.
  *
- * Since: 0.11
+ * Since: 0.30
  */
 void
-vte_terminal_set_background_tint_color(VteTerminal *terminal,
-				       const GdkColor *color)
+vte_terminal_set_background_tint_color_rgba(VteTerminal *terminal,
+                                            const GdkRGBA *rgba)
 {
         VteTerminalPrivate *pvt;
-	PangoColor *tint;
 
-	g_return_if_fail(VTE_IS_TERMINAL(terminal));
-	g_return_if_fail(color != NULL);
+        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+        g_return_if_fail(rgba != NULL);
 
         pvt = terminal->pvt;
 
-	_vte_debug_print(VTE_DEBUG_MISC,
-			"Setting background tint to %d,%d,%d.\n",
-			terminal->pvt->bg_tint_color.red >> 8,
-			terminal->pvt->bg_tint_color.green >> 8,
-			terminal->pvt->bg_tint_color.blue >> 8);
-        tint = &pvt->bg_tint_color;
-	if (color->red == tint->red &&
-            color->green == tint->green &&
-            color->blue == tint->blue)
+        _vte_debug_print(VTE_DEBUG_MISC,
+                        "Setting background tint to %.3f,%.3f,%.3f,%.3f\n",
+                        rgba->red, rgba->green, rgba->blue, rgba->alpha);
+        if (gdk_rgba_equal(&pvt->bg_tint_color, rgba))
                 return;
 
-	tint->red = color->red;
-	tint->green = color->green;
-	tint->blue = color->blue;
+        pvt->bg_tint_color = *rgba;
 
         g_object_notify(G_OBJECT (terminal), "background-tint-color");
 
@@ -12530,34 +12475,6 @@ vte_terminal_set_background_tint_color(VteTerminal *terminal,
 }
 
 /**
- * vte_terminal_set_background_tint_color_rgba:
- * @terminal: a #VteTerminal
- * @color: (allow-none): a color which the terminal background should be tinted to if its
- *   saturation is not 1.0.
- *
- * If a background image has been set using
- * vte_terminal_set_background_image(),
- * vte_terminal_set_background_image_file(), or
- * vte_terminal_set_background_transparent(), and the value set by
- * vte_terminal_set_background_saturation() is less than one, the terminal
- * will adjust the color of the image before drawing the image.  To do so,
- * the terminal will create a copy of the background image (or snapshot of
- * the root window) and modify its pixel values.  The initial tint color
- * is black.
- *
- * Since: 0.30
- */
-void
-vte_terminal_set_background_tint_color_rgba(VteTerminal *terminal,
-                                            const GdkRGBA *rgba)
-{
-        GdkColor color;
-
-        gdk_color_from_rgba(&color, rgba);
-        vte_terminal_set_background_tint_color(terminal, &color);
-}
-
-/**
  * vte_terminal_set_background_transparent:
  * @terminal: a #VteTerminal
  * @transparent: whether the terminal should fake transparency
diff --git a/src/vteapp.c b/src/vteapp.c
index b85b721..277b009 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -567,7 +567,8 @@ main(int argc, char **argv)
 	char *cursor_blink_mode_string = NULL;
 	char *cursor_shape_string = NULL;
 	char *scrollbar_policy_string = NULL;
-	GdkColor fore, back, tint, highlight, cursor;
+	GdkColor fore, back, highlight, cursor;
+        GdkRGBA tint;
 	const GOptionEntry options[]={
 		{
 			"background", 'B', 0,
@@ -771,8 +772,8 @@ main(int argc, char **argv)
 	highlight.red = highlight.green = highlight.blue = 0xc000;
 	cursor.red = 0xffff;
 	cursor.green = cursor.blue = 0x8000;
-	tint.red = tint.green = tint.blue = 0;
-	tint = back;
+	tint.red = tint.green = tint.blue = 0.;
+        tint.alpha = .875;
 
 	gdk_window_set_debug_updates(debug);
 
@@ -890,9 +891,8 @@ main(int argc, char **argv)
 		vte_terminal_set_background_transparent(terminal,
 							TRUE);
 	}
-	vte_terminal_set_background_tint_color(terminal, &tint);
+	vte_terminal_set_background_tint_color_rgba(terminal, &tint);
 	vte_terminal_set_colors(terminal, &fore, &back, NULL, 0);
-	vte_terminal_set_opacity(terminal, 0xdddd);
 	if (highlight_set) {
 		vte_terminal_set_color_highlight(terminal,
 						 &highlight);
diff --git a/src/vtebg.c b/src/vtebg.c
index c2a42ff..0670285 100644
--- a/src/vtebg.c
+++ b/src/vtebg.c
@@ -52,7 +52,7 @@ typedef struct {
 	GdkPixbuf *source_pixbuf;
 	char *source_file;
 
-	PangoColor tint_color;
+	GdkRGBA tint_color;
 	double saturation;
 	cairo_surface_t *surface;
 } VteBgCacheItem;
@@ -255,14 +255,6 @@ vte_bg_get_for_screen(GdkScreen *screen)
 	return bg;
 }
 
-static gboolean
-vte_bg_colors_equal(const PangoColor *a, const PangoColor *b)
-{
-	return  (a->red >> 8) == (b->red >> 8) &&
-		(a->green >> 8) == (b->green >> 8) &&
-		(a->blue >> 8) == (b->blue >> 8);
-}
-
 static void
 vte_bg_cache_item_free(VteBgCacheItem *item)
 {
@@ -346,7 +338,7 @@ vte_bg_cache_add(VteBg *bg, VteBgCacheItem *item)
  * @source_type: a #VteBgSourceType
  * @source_pixbuf: a #GdkPixbuf, or %NULL
  * @source_file: path of an image file, or %NULL
- * @tint: a #PangoColor to use as tint color
+ * @tint: a #GdkRGBA to use as tint color
  * @saturation: the saturation as a value between 0.0 and 1.0
  *
  * Returns: a reference to a #cairo_surface_t, or %NULL on if
@@ -357,7 +349,7 @@ vte_bg_cache_search(VteBg *bg,
 		    VteBgSourceType source_type,
 		    const GdkPixbuf *source_pixbuf,
 		    const char *source_file,
-		    const PangoColor *tint,
+		    const GdkRGBA *tint,
 		    double saturation)
 {
 	GList *i;
@@ -365,7 +357,7 @@ vte_bg_cache_search(VteBg *bg,
 	vte_bg_cache_prune(bg);
 	for (i = bg->pvt->cache; i != NULL; i = g_list_next(i)) {
 		VteBgCacheItem *item = i->data;
-		if (vte_bg_colors_equal(&item->tint_color, tint) &&
+		if (gdk_rgba_equal (&item->tint_color, tint) &&
 		    (saturation == item->saturation) &&
 		    (source_type == item->source_type)) {
 			switch (source_type) {
@@ -409,7 +401,7 @@ vte_bg_get_surface(VteBg *bg,
 		   VteBgSourceType source_type,
 		   GdkPixbuf *source_pixbuf,
 		   const char *source_file,
-		   const PangoColor *tint,
+		   const GdkRGBA *tint,
 		   double saturation,
 		   cairo_surface_t *other)
 {
@@ -419,6 +411,7 @@ vte_bg_get_surface(VteBg *bg,
 	cairo_surface_t *cached;
 	cairo_t *cr;
 	int width, height;
+        double alpha;
 
         g_return_val_if_fail(VTE_IS_BG(bg), NULL);
         pvt = bg->pvt;
@@ -502,12 +495,13 @@ vte_bg_get_surface(VteBg *bg,
 #endif
 	cairo_paint (cr);
 
-	if (saturation < 1.0) {
+        alpha = (1. - saturation) * tint->alpha;
+	if (alpha > 0.) {
 		cairo_set_source_rgba (cr, 
-				       tint->red / 65535.,
-				       tint->green / 65535.,
-				       tint->blue / 65535.,
-				       1 - saturation);
+				       tint->red,
+				       tint->green,
+				       tint->blue,
+				       alpha);
 		cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 		cairo_paint (cr);
 	}
diff --git a/src/vtebg.h b/src/vtebg.h
index f2cf77b..700f892 100644
--- a/src/vtebg.h
+++ b/src/vtebg.h
@@ -61,7 +61,7 @@ vte_bg_get_surface(VteBg *bg,
 		   VteBgSourceType source_type,
 		   GdkPixbuf *source_pixbuf,
 		   const char *source_file,
-		   const PangoColor *tint,
+		   const GdkRGBA *tint,
 		   double saturation,
 		   cairo_surface_t *other);
 
diff --git a/src/vtedraw.c b/src/vtedraw.c
index 4f6d9ed..df19ec7 100644
--- a/src/vtedraw.c
+++ b/src/vtedraw.c
@@ -803,18 +803,15 @@ _vte_draw_end (struct _vte_draw *draw)
 
 void
 _vte_draw_set_background_solid(struct _vte_draw *draw,
-			       double red,
-			       double green,
-			       double blue,
-			       double opacity)
+                               const GdkRGBA *color)
 {
 	if (draw->bg_pattern)
 		cairo_pattern_destroy (draw->bg_pattern);
 
-	draw->bg_pattern = cairo_pattern_create_rgba (red,
-						      green,
-						      blue,
-						      opacity);
+	draw->bg_pattern = cairo_pattern_create_rgba (color->red,
+						      color->green,
+						      color->blue,
+						      color->alpha);
 }
 
 void
@@ -822,7 +819,7 @@ _vte_draw_set_background_image (struct _vte_draw *draw,
 			        VteBgSourceType type,
 			        GdkPixbuf *pixbuf,
 			        const char *filename,
-			        const PangoColor *color,
+			        const GdkRGBA *color,
 			        double saturation)
 {
 	cairo_surface_t *surface;
diff --git a/src/vtedraw.h b/src/vtedraw.h
index a183322..a25e8f1 100644
--- a/src/vtedraw.h
+++ b/src/vtedraw.h
@@ -69,15 +69,12 @@ void _vte_draw_start(struct _vte_draw *draw);
 void _vte_draw_end(struct _vte_draw *draw);
 
 void _vte_draw_set_background_solid(struct _vte_draw *draw,
-				    double red,
-				    double green,
-				    double blue,
-				    double opacity);
+                                    const GdkRGBA *color);
 void _vte_draw_set_background_image(struct _vte_draw *draw,
 				    VteBgSourceType type,
 				    GdkPixbuf *pixbuf,
 				    const char *file,
-				    const PangoColor *color,
+				    const GdkRGBA *color,
 				    double saturation);
 void _vte_draw_set_background_scroll(struct _vte_draw *draw,
 				     gint x, gint y);



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