]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssimagelinear.c
GtkWidget::draw() - Document how to get the dirty region
[~andy/gtk] / gtk / gtkcssimagelinear.c
index bd80d5f8353c156afd7bd78cea8119cc6bb324c5..0bf89e7d8b13e620b07c11b0bc39b978a806d0e4 100644 (file)
 
 #include <math.h>
 
+#include "gtkcsscolorvalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssrgbavalueprivate.h"
 #include "gtkcssprovider.h"
-#include "gtksymboliccolorprivate.h"
 
 G_DEFINE_TYPE (GtkCssImageLinear, _gtk_css_image_linear, GTK_TYPE_CSS_IMAGE)
 
@@ -40,28 +40,36 @@ gtk_css_image_linear_get_start_end (GtkCssImageLinear *linear,
   double pos;
   guint i;
       
-  stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, 0);
-  if (stop->offset == NULL)
-    *start = 0;
-  else
-    *start = _gtk_css_number_value_get (stop->offset, length) / length;
-
-  *end = *start;
-
-  for (i = 0; i < linear->stops->len; i++)
+  if (linear->repeating)
     {
-      stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
-      
+      stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, 0);
       if (stop->offset == NULL)
-        continue;
+        *start = 0;
+      else
+        *start = _gtk_css_number_value_get (stop->offset, length) / length;
 
-      pos = _gtk_css_number_value_get (stop->offset, length) / length;
+      *end = *start;
 
-      *end = MAX (pos, *end);
+      for (i = 0; i < linear->stops->len; i++)
+        {
+          stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
+          
+          if (stop->offset == NULL)
+            continue;
+
+          pos = _gtk_css_number_value_get (stop->offset, length) / length;
+
+          *end = MAX (pos, *end);
+        }
+      
+      if (stop->offset == NULL)
+        *end = MAX (*end, 1.0);
+    }
+  else
+    {
+      *start = 0;
+      *end = 1;
     }
-  
-  if (stop->offset == NULL)
-    *end = MAX (*end, 1.0);
 }
 
 static void
@@ -315,7 +323,7 @@ gtk_css_image_linear_parse (GtkCssImage  *image,
   do {
     GtkCssImageLinearColorStop stop;
 
-    stop.color = _gtk_css_symbolic_value_new (parser);
+    stop.color = _gtk_css_color_value_parse (parser);
     if (stop.color == NULL)
       return FALSE;
 
@@ -525,6 +533,34 @@ fail:
   return GTK_CSS_IMAGE_CLASS (_gtk_css_image_linear_parent_class)->transition (start_image, end_image, property_id, progress);
 }
 
+static gboolean
+gtk_css_image_linear_equal (GtkCssImage *image1,
+                            GtkCssImage *image2)
+{
+  GtkCssImageLinear *linear1 = GTK_CSS_IMAGE_LINEAR (image1);
+  GtkCssImageLinear *linear2 = GTK_CSS_IMAGE_LINEAR (image2);
+  guint i;
+
+  if (linear1->repeating != linear2->repeating ||
+      !_gtk_css_value_equal (linear1->angle, linear2->angle) ||
+      linear1->stops->len != linear2->stops->len)
+    return FALSE;
+
+  for (i = 0; i < linear1->stops->len; i++)
+    {
+      GtkCssImageLinearColorStop *stop1, *stop2;
+
+      stop1 = &g_array_index (linear1->stops, GtkCssImageLinearColorStop, i);
+      stop2 = &g_array_index (linear2->stops, GtkCssImageLinearColorStop, i);
+
+      if (!_gtk_css_value_equal0 (stop1->offset, stop2->offset) ||
+          !_gtk_css_value_equal (stop1->color, stop2->color))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
 static void
 gtk_css_image_linear_dispose (GObject *object)
 {
@@ -555,6 +591,7 @@ _gtk_css_image_linear_class_init (GtkCssImageLinearClass *klass)
   image_class->parse = gtk_css_image_linear_parse;
   image_class->print = gtk_css_image_linear_print;
   image_class->compute = gtk_css_image_linear_compute;
+  image_class->equal = gtk_css_image_linear_equal;
   image_class->transition = gtk_css_image_linear_transition;
 
   object_class->dispose = gtk_css_image_linear_dispose;