[vte] widget: Make background tint colour use GdkRGBA



commit 1ec6c43d1aa89620e040f5a8eebe25b6772a35e6
Author: Christian Persch <chpe gnome org>
Date:   Mon May 2 23:21:01 2011 +0200

    widget: 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.
    
    Conflicts:
        doc/reference/vte-sections.txt
        src/vte.c
        src/vte.h
        src/vteapp.c

 doc/reference/vte-sections.txt |    2 -
 src/vte-private.h              |    3 +-
 src/vte.c                      |  111 ++++++++--------------------------------
 src/vte.h                      |    3 +
 src/vteapp.c                   |   10 ++--
 src/vtebg.c                    |   30 ++++-------
 src/vtebg.h                    |    2 +-
 src/vtedraw.c                  |   15 ++---
 src/vtedraw.h                  |    7 +--
 9 files changed, 52 insertions(+), 131 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 864d89e..fd98da7 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -126,12 +126,10 @@ vte_terminal_get_current_file_uri
 
 <SUBSECTION Deprecated>
 vte_terminal_im_append_menuitems
-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_scroll_background
 
 <SUBSECTION Private>
diff --git a/src/vte-private.h b/src/vte-private.h
index af68e1b..03b6735 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -406,9 +406,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 d6d9cf8..9fcd82b 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -154,7 +154,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,
@@ -2835,33 +2834,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.
- *
- * Deprecated: 0.34.8
- */
-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
  *
@@ -8123,11 +8095,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;
@@ -10744,9 +10716,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;
@@ -10864,20 +10833,13 @@ vte_terminal_set_property (GObject *object,
                         vte_terminal_set_background_image (terminal, g_value_get_object (value));
                         G_GNUC_END_IGNORE_DEPRECATIONS;
                         break;
-                case PROP_BACKGROUND_OPACITY:
-                        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-                        vte_terminal_set_opacity (terminal, g_value_get_double (value) * (double) 
G_MAXUINT16);
-                        G_GNUC_END_IGNORE_DEPRECATIONS;
-                        break;
                 case PROP_BACKGROUND_SATURATION:
                         G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
                         vte_terminal_set_background_saturation (terminal, g_value_get_double (value));
                         G_GNUC_END_IGNORE_DEPRECATIONS;
                         break;
                 case PROP_BACKGROUND_TINT_COLOR:
-                        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-                        vte_terminal_set_background_tint_color (terminal, g_value_get_boxed (value));
-                        G_GNUC_END_IGNORE_DEPRECATIONS;
+                        vte_terminal_set_background_tint_color_rgba (terminal, g_value_get_boxed (value));
                         break;
                 case PROP_BACKGROUND_TRANSPARENT:
                         G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
@@ -11649,24 +11611,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
-         *
-         * Deprecated: 0.34.8
-         */
-        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
@@ -11708,7 +11652,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));
      
         /**
@@ -12480,17 +12424,16 @@ vte_terminal_background_update(VteTerminal *terminal)
 
        entry = _vte_terminal_get_color(terminal, VTE_DEFAULT_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);
 
        color.red = entry->red / 65535.;
        color.green = entry->green / 65535.;
        color.blue = entry->blue / 65535.;
-       color.alpha = terminal->pvt->bg_opacity / 65535.;
+        color.alpha = terminal->pvt->bg_tint_color.alpha;
 
-       _vte_draw_set_background_solid (terminal->pvt->draw, 
-                                       color.red, color.green, color.blue, color.alpha);
+        _vte_draw_set_background_solid (terminal->pvt->draw, &color);
 
        /* 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. */
@@ -12602,9 +12545,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
+ * @rgba: (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
@@ -12617,36 +12560,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
- *
- * Deprecated: 0.34.8
+ * Since: 0.38
  */
 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");
 
diff --git a/src/vte.h b/src/vte.h
index 386a3ec..15a4299 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -272,6 +272,9 @@ void vte_terminal_set_colors_rgba(VteTerminal *terminal,
 
 void vte_terminal_set_default_colors(VteTerminal *terminal);
 
+void vte_terminal_set_background_tint_color_rgba(VteTerminal *terminal,
+                                                 const GdkRGBA *rgba);
+
 /* Set whether or not the cursor blinks. */
 void vte_terminal_set_cursor_blink_mode(VteTerminal *terminal,
                                        VteTerminalCursorBlinkMode mode);
diff --git a/src/vteapp.c b/src/vteapp.c
index 07e546e..5a3605b 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,
@@ -776,8 +777,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);
 
@@ -896,8 +897,7 @@ main(int argc, char **argv)
        if (transparent) {
                vte_terminal_set_background_transparent(terminal,
                                                        TRUE);
-                vte_terminal_set_background_tint_color(terminal, &tint);
-                vte_terminal_set_opacity(terminal, 0xdddd);
+                vte_terminal_set_background_tint_color_rgba(terminal, &tint);
         }
         G_GNUC_END_IGNORE_DEPRECATIONS;
 
diff --git a/src/vtebg.c b/src/vtebg.c
index ec5f77e..0ce4269 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;
@@ -256,14 +256,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)
 {
@@ -347,7 +339,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
@@ -358,7 +350,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;
@@ -366,7 +358,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) {
@@ -410,7 +402,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)
 {
@@ -420,6 +412,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;
@@ -503,12 +496,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 b2e9ff9..a9d37d1 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 e235262..87050fa 100644
--- a/src/vtedraw.c
+++ b/src/vtedraw.c
@@ -825,18 +825,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
@@ -844,7 +841,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 a797e78..2b20705 100644
--- a/src/vtedraw.h
+++ b/src/vtedraw.h
@@ -78,15 +78,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]