[gimp/gtk3-port: 130/230] app: port the about dialog to GtkStyleContext



commit e0e492a12f0571945a273b27f0d0e4ff411ec3ba
Author: Michael Natterer <mitch gimp org>
Date:   Mon Dec 20 22:29:15 2010 +0100

    app: port the about dialog to GtkStyleContext

 app/dialogs/about-dialog.c |   80 ++++++++++++++++++++++++++-----------------
 1 files changed, 48 insertions(+), 32 deletions(-)
---
diff --git a/app/dialogs/about-dialog.c b/app/dialogs/about-dialog.c
index da5fda4..dccbee5 100644
--- a/app/dialogs/about-dialog.c
+++ b/app/dialogs/about-dialog.c
@@ -275,15 +275,20 @@ about_dialog_anim_draw (GtkWidget       *widget,
                         cairo_t         *cr,
                         GimpAboutDialog *dialog)
 {
-  GtkStyle      *style = gtk_widget_get_style (widget);
-  GtkAllocation  allocation;
-  gint           x, y;
-  gint           width, height;
+  GtkStyleContext *style = gtk_widget_get_style_context (widget);
+  GtkAllocation    allocation;
+  GdkRGBA          color;
+  gint             x, y;
+  gint             width, height;
 
   if (! dialog->visible)
     return FALSE;
 
-  gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]);
+  gtk_style_context_save (style);
+  gtk_style_context_add_class (style, GTK_STYLE_CLASS_ENTRY);
+  gtk_style_context_get_color (style, 0, &color);
+  gdk_cairo_set_source_rgba (cr, &color);
+  gtk_style_context_restore (style);
 
   gtk_widget_get_allocation (widget, &allocation);
   pango_layout_get_pixel_size (dialog->layout, &width, &height);
@@ -336,14 +341,15 @@ insert_spacers (const gchar *string)
 }
 
 static void inline
-mix_colors (const GdkColor *start,
-            const GdkColor *end,
-            GdkColor       *target,
-            gdouble         pos)
+mix_colors (const GdkRGBA *start,
+            const GdkRGBA *end,
+            GdkRGBA       *target,
+            gdouble        pos)
 {
   target->red   = start->red   * (1.0 - pos) + end->red   * pos;
   target->green = start->green * (1.0 - pos) + end->green * pos;
   target->blue  = start->blue  * (1.0 - pos) + end->blue  * pos;
+  target->alpha = start->alpha * (1.0 - pos) + end->alpha * pos;
 }
 
 static void
@@ -351,22 +357,26 @@ decorate_text (GimpAboutDialog *dialog,
                gint             anim_type,
                gdouble          time)
 {
-  GtkStyle       *style = gtk_widget_get_style (dialog->anim_area);
-  const gchar    *text;
-  const gchar    *ptr;
-  gint            letter_count = 0;
-  gint            text_length  = 0;
-  gint            text_bytelen = 0;
-  gint            cluster_start, cluster_end;
-  gunichar        unichr;
-  PangoAttrList  *attrlist = NULL;
-  PangoAttribute *attr;
-  PangoRectangle  irect = {0, 0, 0, 0};
-  PangoRectangle  lrect = {0, 0, 0, 0};
-  GdkColor        mix;
-
-  mix_colors (style->bg + GTK_STATE_NORMAL,
-              style->fg + GTK_STATE_NORMAL, &mix, time);
+  GtkStyleContext *style = gtk_widget_get_style_context (dialog->anim_area);
+  const gchar     *text;
+  const gchar     *ptr;
+  gint             letter_count = 0;
+  gint             text_length  = 0;
+  gint             text_bytelen = 0;
+  gint             cluster_start, cluster_end;
+  gunichar         unichr;
+  PangoAttrList   *attrlist = NULL;
+  PangoAttribute  *attr;
+  PangoRectangle   irect = {0, 0, 0, 0};
+  PangoRectangle   lrect = {0, 0, 0, 0};
+  GdkRGBA          fg;
+  GdkRGBA          bg;
+  GdkRGBA          mix;
+
+  gtk_style_context_get_color (style, 0, &fg);
+  gtk_style_context_get_background_color (style, 0, &bg);
+
+  mix_colors (&bg, &fg, &mix, time);
 
   text = pango_layout_get_text (dialog->layout);
   g_return_if_fail (text != NULL);
@@ -382,14 +392,18 @@ decorate_text (GimpAboutDialog *dialog,
   switch (anim_type)
     {
     case 0: /* Fade in */
-      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
+      attr = pango_attr_foreground_new (mix.red   * 0xffff,
+                                        mix.green * 0xffff,
+                                        mix.blue  * 0xffff);
       attr->start_index = 0;
       attr->end_index = text_bytelen;
       pango_attr_list_insert (attrlist, attr);
       break;
 
     case 1: /* Fade in, spread */
-      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
+      attr = pango_attr_foreground_new (mix.red   * 0xffff,
+                                        mix.green * 0xffff,
+                                        mix.blue  * 0xffff);
       attr->start_index = 0;
       attr->end_index = text_bytelen;
       pango_attr_list_change (attrlist, attr);
@@ -415,7 +429,9 @@ decorate_text (GimpAboutDialog *dialog,
       break;
 
     case 2: /* Fade in, sinewave */
-      attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
+      attr = pango_attr_foreground_new (mix.red   * 0xffff,
+                                        mix.green * 0xffff,
+                                        mix.blue  * 0xffff);
       attr->start_index = 0;
       attr->end_index = text_bytelen;
       pango_attr_list_change (attrlist, attr);
@@ -462,15 +478,15 @@ decorate_text (GimpAboutDialog *dialog,
           else
             pos = ((gdouble) (letter_count - border)) / 15;
 
-          mix_colors (style->fg + GTK_STATE_NORMAL,
-                      style->bg + GTK_STATE_NORMAL,
-                      &mix, pos);
+          mix_colors (&fg, &bg, &mix, pos);
 
           ptr = g_utf8_next_char (ptr);
 
           cluster_end = ptr - text;
 
-          attr = pango_attr_foreground_new (mix.red, mix.green, mix.blue);
+          attr = pango_attr_foreground_new (mix.red   * 0xffff,
+                                            mix.green * 0xffff,
+                                            mix.blue  * 0xffff);
           attr->start_index = cluster_start;
           attr->end_index = cluster_end;
           pango_attr_list_change (attrlist, attr);


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