[gimp/gtk3-port: 167/215] app: port the about dialog to GtkStyleContext



commit 280fac5df8fdb89a9eba2a848c1361a5c29e5b36
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 |   84 ++++++++++++++++++++++++++------------------
 1 files changed, 50 insertions(+), 34 deletions(-)
---
diff --git a/app/dialogs/about-dialog.c b/app/dialogs/about-dialog.c
index 05fb08f..88f7ddc 100644
--- a/app/dialogs/about-dialog.c
+++ b/app/dialogs/about-dialog.c
@@ -145,13 +145,13 @@ about_dialog_create (GimpContext *context)
       container = gtk_dialog_get_content_area (GTK_DIALOG (widget));
       children = gtk_container_get_children (GTK_CONTAINER (container));
 
-      if (GTK_IS_VBOX (children->data))
+      if (GTK_IS_BOX (children->data))
         {
           about_dialog_add_animation (children->data, dialog);
           about_dialog_add_message (children->data);
         }
       else
-        g_warning ("%s: ooops, no vbox in this container?", G_STRLOC);
+        g_warning ("%s: ooops, no box in this container?", G_STRLOC);
 
       g_list_free (children);
     }
@@ -269,15 +269,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);
@@ -330,14 +335,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
@@ -345,22 +351,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);
@@ -376,14 +386,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);
@@ -409,7 +423,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);
@@ -456,15 +472,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]