[gtk+/wip/cssvalue: 88/141] cssvalue: Add _gtk_css_value_transition()



commit 96e9c3d80bdc23a6a2cde8fab10339cab2204ccc
Author: Benjamin Otte <otte redhat com>
Date:   Fri Mar 30 17:47:26 2012 +0200

    cssvalue: Add _gtk_css_value_transition()
    
    Returns a value that transitions between start and end or %NULL if the
    values cannot be transitioned.
    
    So far, all implementations but numbers and rgba return NULL.

 gtk/gtkcssarrayvalue.c   |    9 +++++++++
 gtk/gtkcssenumvalue.c    |   13 +++++++++++++
 gtk/gtkcssimagevalue.c   |    9 +++++++++
 gtk/gtkcssinheritvalue.c |    9 +++++++++
 gtk/gtkcssinitialvalue.c |    9 +++++++++
 gtk/gtkcssnumbervalue.c  |   15 +++++++++++++++
 gtk/gtkcssrgbavalue.c    |   17 +++++++++++++++++
 gtk/gtkcssshadowvalue.c  |    9 +++++++++
 gtk/gtkcssstringvalue.c  |    9 +++++++++
 gtk/gtkcssvalue.c        |   23 +++++++++++++++++++++++
 gtk/gtkcssvalueprivate.h |    6 ++++++
 11 files changed, 128 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssarrayvalue.c b/gtk/gtkcssarrayvalue.c
index 922fdfd..5260eaf 100644
--- a/gtk/gtkcssarrayvalue.c
+++ b/gtk/gtkcssarrayvalue.c
@@ -59,6 +59,14 @@ gtk_css_value_array_equal (const GtkCssValue *value1,
   return TRUE;
 }
 
+static GtkCssValue *
+gtk_css_value_array_transition (GtkCssValue *start,
+                                GtkCssValue *end,
+                                double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_array_print (const GtkCssValue *value,
                            GString           *string)
@@ -82,6 +90,7 @@ gtk_css_value_array_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
   gtk_css_value_array_free,
   gtk_css_value_array_equal,
+  gtk_css_value_array_transition,
   gtk_css_value_array_print
 };
 
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c
index 6e3ce56..dba01da 100644
--- a/gtk/gtkcssenumvalue.c
+++ b/gtk/gtkcssenumvalue.c
@@ -42,6 +42,14 @@ gtk_css_value_enum_equal (const GtkCssValue *enum1,
   return enum1 == enum2;
 }
 
+static GtkCssValue *
+gtk_css_value_enum_transition (GtkCssValue *start,
+                               GtkCssValue *end,
+                               double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_enum_print (const GtkCssValue *value,
                           GString           *string)
@@ -54,6 +62,7 @@ gtk_css_value_enum_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_BORDER_STYLE = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
@@ -107,6 +116,7 @@ _gtk_css_border_style_value_get (const GtkCssValue *value)
 static const GtkCssValueClass GTK_CSS_VALUE_FONT_STYLE = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
@@ -153,6 +163,7 @@ _gtk_css_font_style_value_get (const GtkCssValue *value)
 static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
@@ -198,6 +209,7 @@ _gtk_css_font_variant_value_get (const GtkCssValue *value)
 static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
@@ -261,6 +273,7 @@ _gtk_css_font_weight_value_get (const GtkCssValue *value)
 static const GtkCssValueClass GTK_CSS_VALUE_AREA = {
   gtk_css_value_enum_free,
   gtk_css_value_enum_equal,
+  gtk_css_value_enum_transition,
   gtk_css_value_enum_print
 };
 
diff --git a/gtk/gtkcssimagevalue.c b/gtk/gtkcssimagevalue.c
index f9028ae..0beb3fe 100644
--- a/gtk/gtkcssimagevalue.c
+++ b/gtk/gtkcssimagevalue.c
@@ -40,6 +40,14 @@ gtk_css_value_image_equal (const GtkCssValue *value1,
   return value1->image == value2->image;
 }
 
+static GtkCssValue *
+gtk_css_value_image_transition (GtkCssValue *start,
+                                GtkCssValue *end,
+                                double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_image_print (const GtkCssValue *value,
                            GString           *string)
@@ -53,6 +61,7 @@ gtk_css_value_image_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
   gtk_css_value_image_free,
   gtk_css_value_image_equal,
+  gtk_css_value_image_transition,
   gtk_css_value_image_print
 };
 
diff --git a/gtk/gtkcssinheritvalue.c b/gtk/gtkcssinheritvalue.c
index 427f7ec..692ec58 100644
--- a/gtk/gtkcssinheritvalue.c
+++ b/gtk/gtkcssinheritvalue.c
@@ -37,6 +37,14 @@ gtk_css_value_inherit_equal (const GtkCssValue *value1,
   return TRUE;
 }
 
+static GtkCssValue *
+gtk_css_value_inherit_transition (GtkCssValue *start,
+                                  GtkCssValue *end,
+                                  double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_inherit_print (const GtkCssValue *value,
                              GString           *string)
@@ -47,6 +55,7 @@ gtk_css_value_inherit_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
   gtk_css_value_inherit_free,
   gtk_css_value_inherit_equal,
+  gtk_css_value_inherit_transition,
   gtk_css_value_inherit_print
 };
 
diff --git a/gtk/gtkcssinitialvalue.c b/gtk/gtkcssinitialvalue.c
index 73fd38b..640e4c5 100644
--- a/gtk/gtkcssinitialvalue.c
+++ b/gtk/gtkcssinitialvalue.c
@@ -37,6 +37,14 @@ gtk_css_value_initial_equal (const GtkCssValue *value1,
   return TRUE;
 }
 
+static GtkCssValue *
+gtk_css_value_initial_transition (GtkCssValue *start,
+                                  GtkCssValue *end,
+                                  double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_initial_print (const GtkCssValue *value,
                              GString           *string)
@@ -47,6 +55,7 @@ gtk_css_value_initial_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
   gtk_css_value_initial_free,
   gtk_css_value_initial_equal,
+  gtk_css_value_initial_transition,
   gtk_css_value_initial_print
 };
 
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c
index 19e4c1d..106fd76 100644
--- a/gtk/gtkcssnumbervalue.c
+++ b/gtk/gtkcssnumbervalue.c
@@ -41,6 +41,20 @@ gtk_css_value_number_equal (const GtkCssValue *number1,
          number1->value == number2->value;
 }
 
+static GtkCssValue *
+gtk_css_value_number_transition (GtkCssValue *start,
+                                 GtkCssValue *end,
+                                 double       progress)
+{
+  /* FIXME: This needs to be supported at least for percentages,
+   * but for that we kinda need to support calc(5px + 50%) */
+  if (start->unit != end->unit)
+    return NULL;
+
+  return _gtk_css_number_value_new (start->value + (end->value - start->value) * progress,
+                                    start->unit);
+}
+
 static void
 gtk_css_value_number_print (const GtkCssValue *number,
                             GString           *string)
@@ -73,6 +87,7 @@ gtk_css_value_number_print (const GtkCssValue *number,
 static const GtkCssValueClass GTK_CSS_VALUE_NUMBER = {
   gtk_css_value_number_free,
   gtk_css_value_number_equal,
+  gtk_css_value_number_transition,
   gtk_css_value_number_print
 };
 
diff --git a/gtk/gtkcssrgbavalue.c b/gtk/gtkcssrgbavalue.c
index f11f8b7..61d8b1f 100644
--- a/gtk/gtkcssrgbavalue.c
+++ b/gtk/gtkcssrgbavalue.c
@@ -40,6 +40,22 @@ gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
   return gdk_rgba_equal (&rgba1->rgba, &rgba2->rgba);
 }
 
+static GtkCssValue *
+gtk_css_value_rgba_transition (GtkCssValue *start,
+                               GtkCssValue *end,
+                               double       progress)
+{
+  GdkRGBA transition;
+
+  progress = CLAMP (progress, 0, 1);
+  transition.red = start->rgba.red + (end->rgba.red - start->rgba.red) * progress;
+  transition.green = start->rgba.green + (end->rgba.green - start->rgba.green) * progress;
+  transition.blue = start->rgba.blue + (end->rgba.blue - start->rgba.blue) * progress;
+  transition.alpha = start->rgba.alpha + (end->rgba.alpha - start->rgba.alpha) * progress;
+
+  return _gtk_css_rgba_value_new_from_rgba (&transition);
+}
+
 static void
 gtk_css_value_rgba_print (const GtkCssValue *rgba,
                           GString           *string)
@@ -52,6 +68,7 @@ gtk_css_value_rgba_print (const GtkCssValue *rgba,
 static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
   gtk_css_value_rgba_free,
   gtk_css_value_rgba_equal,
+  gtk_css_value_rgba_transition,
   gtk_css_value_rgba_print
 };
 
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 370e1db..2898a78 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -129,6 +129,14 @@ gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
   return shadow1 == shadow2;
 }
 
+static GtkCssValue *
+gtk_css_value_shadow_transition (GtkCssValue *start,
+                                 GtkCssValue *end,
+                                 double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_shadow_print (const GtkCssValue *shadow,
                             GString           *string)
@@ -159,6 +167,7 @@ gtk_css_value_shadow_print (const GtkCssValue *shadow,
 static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
   gtk_css_value_shadow_free,
   gtk_css_value_shadow_equal,
+  gtk_css_value_shadow_transition,
   gtk_css_value_shadow_print
 };
 
diff --git a/gtk/gtkcssstringvalue.c b/gtk/gtkcssstringvalue.c
index 16debf9..aaa3ebb 100644
--- a/gtk/gtkcssstringvalue.c
+++ b/gtk/gtkcssstringvalue.c
@@ -39,6 +39,14 @@ gtk_css_value_string_equal (const GtkCssValue *value1,
   return g_strcmp0 (value1->string, value2->string) == 0;
 }
 
+static GtkCssValue *
+gtk_css_value_string_transition (GtkCssValue *start,
+                                 GtkCssValue *end,
+                                 double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_string_print (const GtkCssValue *value,
                             GString           *str)
@@ -83,6 +91,7 @@ gtk_css_value_string_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
   gtk_css_value_string_free,
   gtk_css_value_string_equal,
+  gtk_css_value_string_transition,
   gtk_css_value_string_print
 };
 
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index bddad5d..912375b 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -61,6 +61,14 @@ gtk_css_value_default_equal (const GtkCssValue *value1,
   return FALSE;
 }
 
+static GtkCssValue *
+gtk_css_value_default_transition (GtkCssValue *start,
+                                  GtkCssValue *end,
+                                  double       progress)
+{
+  return NULL;
+}
+
 static void
 gtk_css_value_default_print (const GtkCssValue *value,
                              GString           *string)
@@ -75,6 +83,7 @@ gtk_css_value_default_print (const GtkCssValue *value,
 static const GtkCssValueClass GTK_CSS_VALUE_DEFAULT = {
   gtk_css_value_default_free,
   gtk_css_value_default_equal,
+  gtk_css_value_default_transition,
   gtk_css_value_default_print
 };
 
@@ -366,6 +375,20 @@ _gtk_css_value_equal (const GtkCssValue *value1,
   return value1->class->equal (value1, value2);
 }
 
+GtkCssValue *
+_gtk_css_value_transition (GtkCssValue *start,
+                           GtkCssValue *end,
+                           double       progress)
+{
+  g_return_val_if_fail (start != NULL, FALSE);
+  g_return_val_if_fail (end != NULL, FALSE);
+
+  if (start->class != end->class)
+    return NULL;
+
+  return start->class->transition (start, end, progress);
+}
+
 void
 _gtk_css_value_print (const GtkCssValue *value,
                       GString           *string)
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index 7d8448c..6e2e89c 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -49,6 +49,9 @@ struct _GtkCssValueClass {
 
   gboolean      (* equal)                             (const GtkCssValue          *value1,
                                                        const GtkCssValue          *value2);
+  GtkCssValue * (* transition)                        (GtkCssValue                *start,
+                                                       GtkCssValue                *end,
+                                                       double                      progress);
   void          (* print)                             (const GtkCssValue          *value,
                                                        GString                    *string);
 };
@@ -64,6 +67,9 @@ void         _gtk_css_value_unref                     (GtkCssValue
 
 gboolean     _gtk_css_value_equal                     (const GtkCssValue          *value1,
                                                        const GtkCssValue          *value2);
+GtkCssValue *_gtk_css_value_transition                (GtkCssValue                *start,
+                                                       GtkCssValue                *end,
+                                                       double                      progress);
 
 void         _gtk_css_value_print                     (const GtkCssValue          *value,
                                                        GString                    *string);



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