[gtk+/wip/css: 164/167] themingengine: Split out the border drawing function



commit 93f8182b1bfccc86bf86f7efd3b3bc535a4a099b
Author: Benjamin Otte <otte redhat com>
Date:   Sun Jan 8 02:41:30 2012 +0100

    themingengine: Split out the border drawing function

 gtk/gtkthemingengine.c |  209 +++++++++++++++++++++++++----------------------
 1 files changed, 111 insertions(+), 98 deletions(-)
---
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 34523db..728e960 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -1587,85 +1587,15 @@ render_frame_stroke (cairo_t       *cr,
 }
 
 static void
-render_frame_internal (GtkThemingEngine *engine,
-                       cairo_t          *cr,
-                       gdouble           x,
-                       gdouble           y,
-                       gdouble           width,
-                       gdouble           height,
-                       guint             hidden_side,
-                       GtkJunctionSides  junction)
+render_border (cairo_t       *cr,
+               GtkRoundedBox *border_box,
+               GtkBorder     *border,
+               guint          hidden_side,
+               GdkRGBA        colors[4],
+               GtkBorderStyle border_style[4])
 {
-  GtkStateFlags state;
-  GtkBorderStyle border_style[4];
-  GtkRoundedBox border_box;
-  gdouble progress;
-  gboolean running;
-  GtkBorder border;
-  GdkRGBA *alloc_colors[4];
-  GdkRGBA colors[4];
   guint i, j;
 
-  state = gtk_theming_engine_get_state (engine);
-
-  gtk_theming_engine_get_border (engine, state, &border);
-  gtk_theming_engine_hide_border_sides (&border, hidden_side);
-
-  gtk_theming_engine_get (engine, state,
-                          "border-top-style", &border_style[0],
-                          "border-right-style", &border_style[1],
-                          "border-bottom-style", &border_style[2],
-                          "border-left-style", &border_style[3],
-                          "border-top-color", &alloc_colors[0],
-                          "border-right-color", &alloc_colors[1],
-                          "border-bottom-color", &alloc_colors[2],
-                          "border-left-color", &alloc_colors[3],
-                          NULL);
-
-  running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
-
-  if (running)
-    {
-      GtkStateFlags other_state;
-      GdkRGBA *other_colors[4];
-
-      if (state & GTK_STATE_FLAG_PRELIGHT)
-        {
-          other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
-          progress = 1 - progress;
-        }
-      else
-        other_state = state | GTK_STATE_FLAG_PRELIGHT;
-
-      gtk_theming_engine_get (engine, other_state,
-                              "border-top-color", &other_colors[0],
-                              "border-right-color", &other_colors[1],
-                              "border-bottom-color", &other_colors[2],
-                              "border-left-color", &other_colors[3],
-                              NULL);
-
-      for (i = 0; i < 4; i++)
-        {
-          colors[i].red = CLAMP (alloc_colors[i]->red + ((other_colors[i]->red - alloc_colors[i]->red) * progress), 0, 1);
-          colors[i].green = CLAMP (alloc_colors[i]->green + ((other_colors[i]->green - alloc_colors[i]->green) * progress), 0, 1);
-          colors[i].blue = CLAMP (alloc_colors[i]->blue + ((other_colors[i]->blue - alloc_colors[i]->blue) * progress), 0, 1);
-          colors[i].alpha = CLAMP (alloc_colors[i]->alpha + ((other_colors[i]->alpha - alloc_colors[i]->alpha) * progress), 0, 1);
-          gdk_rgba_free (other_colors[i]);
-          gdk_rgba_free (alloc_colors[i]);
-        }
-    }
-  else
-    {
-      for (i = 0; i < 4; i++)
-        {
-          colors[i] = *alloc_colors[i];
-          gdk_rgba_free (alloc_colors[i]);
-        }
-    }
-
-  _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
-  _gtk_rounded_box_apply_border_radius (&border_box, engine, state, junction);
-
   cairo_save (cr);
 
   cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
@@ -1702,7 +1632,7 @@ render_frame_internal (GtkThemingEngine *engine,
                   dont_draw |= (1 << j);
               }
             
-            render_frame_stroke (cr, &border_box, &border, colors, dont_draw, border_style[i]);
+            render_frame_stroke (cr, border_box, border, colors, dont_draw, border_style[i]);
           }
           break;
         case GTK_BORDER_STYLE_DOUBLE:
@@ -1718,19 +1648,19 @@ render_frame_internal (GtkThemingEngine *engine,
                 else
                   dont_draw |= (1 << j);
               }
-            other_border.top = (border.top + 2) / 3;
-            other_border.right = (border.right + 2) / 3;
-            other_border.bottom = (border.bottom + 2) / 3;
-            other_border.left = (border.left + 2) / 3;
+            other_border.top = (border->top + 2) / 3;
+            other_border.right = (border->right + 2) / 3;
+            other_border.bottom = (border->bottom + 2) / 3;
+            other_border.left = (border->left + 2) / 3;
             
-            render_frame_fill (cr, &border_box, &other_border, colors, dont_draw);
+            render_frame_fill (cr, border_box, &other_border, colors, dont_draw);
             
-            other_box = border_box;
+            other_box = *border_box;
             _gtk_rounded_box_shrink (&other_box,
-                                     border.top - other_border.top,
-                                     border.right - other_border.right,
-                                     border.bottom - other_border.bottom,
-                                     border.left - other_border.left);
+                                     border->top - other_border.top,
+                                     border->right - other_border.right,
+                                     border->bottom - other_border.bottom,
+                                     border->left - other_border.left);
             render_frame_fill (cr, &other_box, &other_border, colors, dont_draw);
           }
         case GTK_BORDER_STYLE_GROOVE:
@@ -1754,21 +1684,21 @@ render_frame_internal (GtkThemingEngine *engine,
                 else
                   dont_draw |= (1 << j);
               }
-            other_border.top = border.top / 2;
-            other_border.right = border.right / 2;
-            other_border.bottom = border.bottom / 2;
-            other_border.left = border.left / 2;
+            other_border.top = border->top / 2;
+            other_border.right = border->right / 2;
+            other_border.bottom = border->bottom / 2;
+            other_border.left = border->left / 2;
             
-            render_frame_fill (cr, &border_box, &other_border, colors, dont_draw);
+            render_frame_fill (cr, border_box, &other_border, colors, dont_draw);
             
-            other_box = border_box;
+            other_box = *border_box;
             _gtk_rounded_box_shrink (&other_box,
                                      other_border.top, other_border.right,
                                      other_border.bottom, other_border.left);
-            other_border.top = border.top - other_border.top;
-            other_border.right = border.right - other_border.right;
-            other_border.bottom = border.bottom - other_border.bottom;
-            other_border.left = border.left - other_border.left;
+            other_border.top = border->top - other_border.top;
+            other_border.right = border->right - other_border.right;
+            other_border.bottom = border->bottom - other_border.bottom;
+            other_border.left = border->left - other_border.left;
             render_frame_fill (cr, &other_box, &other_border, other_colors, dont_draw);
           }
           break;
@@ -1778,12 +1708,95 @@ render_frame_internal (GtkThemingEngine *engine,
         }
     }
   
-  render_frame_fill (cr, &border_box, &border, colors, hidden_side);
+  render_frame_fill (cr, border_box, border, colors, hidden_side);
 
   cairo_restore (cr);
 }
 
 static void
+render_frame_internal (GtkThemingEngine *engine,
+                       cairo_t          *cr,
+                       gdouble           x,
+                       gdouble           y,
+                       gdouble           width,
+                       gdouble           height,
+                       guint             hidden_side,
+                       GtkJunctionSides  junction)
+{
+  GtkStateFlags state;
+  GtkBorderStyle border_style[4];
+  GtkRoundedBox border_box;
+  gdouble progress;
+  gboolean running;
+  GtkBorder border;
+  GdkRGBA *alloc_colors[4];
+  GdkRGBA colors[4];
+  guint i;
+
+  state = gtk_theming_engine_get_state (engine);
+
+  gtk_theming_engine_get_border (engine, state, &border);
+  gtk_theming_engine_hide_border_sides (&border, hidden_side);
+
+  gtk_theming_engine_get (engine, state,
+                          "border-top-style", &border_style[0],
+                          "border-right-style", &border_style[1],
+                          "border-bottom-style", &border_style[2],
+                          "border-left-style", &border_style[3],
+                          "border-top-color", &alloc_colors[0],
+                          "border-right-color", &alloc_colors[1],
+                          "border-bottom-color", &alloc_colors[2],
+                          "border-left-color", &alloc_colors[3],
+                          NULL);
+
+  running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+
+  if (running)
+    {
+      GtkStateFlags other_state;
+      GdkRGBA *other_colors[4];
+
+      if (state & GTK_STATE_FLAG_PRELIGHT)
+        {
+          other_state = state & ~(GTK_STATE_FLAG_PRELIGHT);
+          progress = 1 - progress;
+        }
+      else
+        other_state = state | GTK_STATE_FLAG_PRELIGHT;
+
+      gtk_theming_engine_get (engine, other_state,
+                              "border-top-color", &other_colors[0],
+                              "border-right-color", &other_colors[1],
+                              "border-bottom-color", &other_colors[2],
+                              "border-left-color", &other_colors[3],
+                              NULL);
+
+      for (i = 0; i < 4; i++)
+        {
+          colors[i].red = CLAMP (alloc_colors[i]->red + ((other_colors[i]->red - alloc_colors[i]->red) * progress), 0, 1);
+          colors[i].green = CLAMP (alloc_colors[i]->green + ((other_colors[i]->green - alloc_colors[i]->green) * progress), 0, 1);
+          colors[i].blue = CLAMP (alloc_colors[i]->blue + ((other_colors[i]->blue - alloc_colors[i]->blue) * progress), 0, 1);
+          colors[i].alpha = CLAMP (alloc_colors[i]->alpha + ((other_colors[i]->alpha - alloc_colors[i]->alpha) * progress), 0, 1);
+          gdk_rgba_free (other_colors[i]);
+          gdk_rgba_free (alloc_colors[i]);
+        }
+    }
+  else
+    {
+      for (i = 0; i < 4; i++)
+        {
+          colors[i] = *alloc_colors[i];
+          gdk_rgba_free (alloc_colors[i]);
+        }
+    }
+
+  _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
+  _gtk_rounded_box_apply_border_radius (&border_box, engine, state, junction);
+
+  render_border (cr, &border_box, &border, hidden_side, colors, border_style);
+}
+
+static void
 gtk_theming_engine_render_frame (GtkThemingEngine *engine,
                                  cairo_t          *cr,
                                  gdouble           x,



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