[gimp/gtk3-port: 149/237] app: port the about dialog to GtkStyleContext



commit 9cb30808c231b68bf3663042c629c626e9c47773
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 d0fc05e..85d8208 100644
--- a/app/dialogs/about-dialog.c
+++ b/app/dialogs/about-dialog.c
@@ -152,13 +152,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);
     }
@@ -271,15 +271,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);
@@ -332,14 +337,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
@@ -347,22 +353,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);
@@ -378,14 +388,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);
@@ -411,7 +425,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);
@@ -458,15 +474,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]