[gtk/wip/otte/paintable: 49/62] css: Implement support for dynamic values



commit 3b6193c53d54773fc210a7f0077ae84f5c1dc1b3
Author: Benjamin Otte <otte redhat com>
Date:   Tue Feb 13 08:22:34 2018 +0100

    css: Implement support for dynamic values
    
    This adds a new GtkStyleAnimation called GtkCssDynamic (for lack of a
    better name) that is spawned whenever at least one dynamic value is part
    of the GtkCssStyle.

 gtk/gtkcssanimatedstyle.c  | 23 ++++++++++++
 gtk/gtkcssdynamic.c        | 93 ++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssdynamicprivate.h | 57 ++++++++++++++++++++++++++++
 gtk/meson.build            |  1 +
 4 files changed, 174 insertions(+)
---
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 6325007bb6..0dcd16c029 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -23,6 +23,7 @@
 
 #include "gtkcssanimationprivate.h"
 #include "gtkcssarrayvalueprivate.h"
+#include "gtkcssdynamicprivate.h"
 #include "gtkcssenumvalueprivate.h"
 #include "gtkcssinheritvalueprivate.h"
 #include "gtkcssinitialvalueprivate.h"
@@ -151,6 +152,27 @@ gtk_css_animated_style_get_intrinsic_value (GtkCssAnimatedStyle *style,
   return gtk_css_style_get_value (style->style, id);
 }
 
+static GSList *
+gtk_css_animated_style_create_dynamic (GSList      *animations,
+                                       GtkCssStyle *style,
+                                       gint64       timestamp)
+{
+  guint i;
+
+  /* XXX: Check animations if they have dynamic values */
+
+  for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++)
+    {
+      if (gtk_css_value_is_dynamic (gtk_css_style_get_value (style, i)))
+        {
+          animations = g_slist_append (animations, gtk_css_dynamic_new (timestamp));
+          break;
+        }
+    }
+
+  return animations;
+}
+
 /* TRANSITIONS */
 
 typedef struct _TransitionInfo TransitionInfo;
@@ -432,6 +454,7 @@ gtk_css_animated_style_new (GtkCssStyle      *base_style,
   if (previous_style != NULL)
     animations = gtk_css_animated_style_create_css_transitions (animations, base_style, timestamp, 
previous_style);
   animations = gtk_css_animated_style_create_css_animations (animations, base_style, parent_style, 
timestamp, provider, previous_style);
+  animations = gtk_css_animated_style_create_dynamic (animations, base_style, timestamp);
 
   if (animations == NULL)
     return g_object_ref (base_style);
diff --git a/gtk/gtkcssdynamic.c b/gtk/gtkcssdynamic.c
new file mode 100644
index 0000000000..1d06c1c1fc
--- /dev/null
+++ b/gtk/gtkcssdynamic.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2018 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#include "config.h"
+
+#include "gtkcssdynamicprivate.h"
+
+#include "gtkprogresstrackerprivate.h"
+
+G_DEFINE_TYPE (GtkCssDynamic, gtk_css_dynamic, GTK_TYPE_STYLE_ANIMATION)
+
+static GtkStyleAnimation *
+gtk_css_dynamic_advance (GtkStyleAnimation    *style_animation,
+                         gint64                timestamp)
+{
+  return gtk_css_dynamic_new (timestamp);
+}
+
+static void
+gtk_css_dynamic_apply_values (GtkStyleAnimation    *style_animation,
+                              GtkCssAnimatedStyle  *style)
+{
+  GtkCssDynamic *dynamic = GTK_CSS_DYNAMIC (style_animation);
+  guint i;
+
+  for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++)
+    {
+      GtkCssValue *value, *dynamic_value;
+      
+      value = gtk_css_style_get_value (GTK_CSS_STYLE (style), i);
+      dynamic_value = gtk_css_value_get_dynamic_value (value, dynamic->timestamp);
+      if (value != dynamic_value)
+        gtk_css_animated_style_set_animated_value (style, i, dynamic_value);
+      gtk_css_value_unref (dynamic_value);
+    }
+}
+
+static gboolean
+gtk_css_dynamic_is_finished (GtkStyleAnimation *style_animation)
+{
+  return FALSE;
+}
+
+static gboolean
+gtk_css_dynamic_is_static (GtkStyleAnimation *style_animation)
+{
+  return FALSE;
+}
+
+static void
+gtk_css_dynamic_class_init (GtkCssDynamicClass *klass)
+{
+  GtkStyleAnimationClass *animation_class = GTK_STYLE_ANIMATION_CLASS (klass);
+
+  animation_class->advance = gtk_css_dynamic_advance;
+  animation_class->apply_values = gtk_css_dynamic_apply_values;
+  animation_class->is_finished = gtk_css_dynamic_is_finished;
+  animation_class->is_static = gtk_css_dynamic_is_static;
+}
+
+static void
+gtk_css_dynamic_init (GtkCssDynamic *dynamic)
+{
+}
+
+GtkStyleAnimation *
+gtk_css_dynamic_new (gint64 timestamp)
+{
+  GtkCssDynamic *dynamic;
+
+  dynamic = g_object_new (GTK_TYPE_CSS_DYNAMIC, NULL);
+
+  dynamic->timestamp = timestamp;
+
+  return GTK_STYLE_ANIMATION (dynamic);
+}
+
diff --git a/gtk/gtkcssdynamicprivate.h b/gtk/gtkcssdynamicprivate.h
new file mode 100644
index 0000000000..5b91baa32c
--- /dev/null
+++ b/gtk/gtkcssdynamicprivate.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2018 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#ifndef __GTK_CSS_DYNAMIC_PRIVATE_H__
+#define __GTK_CSS_DYNAMIC_PRIVATE_H__
+
+#include "gtkstyleanimationprivate.h"
+
+#include "gtkprogresstrackerprivate.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CSS_DYNAMIC           (gtk_css_dynamic_get_type ())
+#define GTK_CSS_DYNAMIC(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_DYNAMIC, 
GtkCssDynamic))
+#define GTK_CSS_DYNAMIC_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_DYNAMIC, 
GtkCssDynamicClass))
+#define GTK_IS_CSS_DYNAMIC(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_DYNAMIC))
+#define GTK_IS_CSS_DYNAMIC_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_DYNAMIC))
+#define GTK_CSS_DYNAMIC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_DYNAMIC, 
GtkCssDynamicClass))
+
+typedef struct _GtkCssDynamic           GtkCssDynamic;
+typedef struct _GtkCssDynamicClass      GtkCssDynamicClass;
+
+struct _GtkCssDynamic
+{
+  GtkStyleAnimation   parent;
+
+  gint64              timestamp;
+};
+
+struct _GtkCssDynamicClass
+{
+  GtkStyleAnimationClass parent_class;
+};
+
+GType                   gtk_css_dynamic_get_type        (void) G_GNUC_CONST;
+
+GtkStyleAnimation *     gtk_css_dynamic_new             (gint64 timestamp);
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_DYNAMIC_PRIVATE_H__ */
diff --git a/gtk/meson.build b/gtk/meson.build
index 92d4c0b434..9559906dc0 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -34,6 +34,7 @@ gtk_private_sources = files([
   'gtkcsscolorvalue.c',
   'gtkcsscornervalue.c',
   'gtkcssdimensionvalue.c',
+  'gtkcssdynamic.c',
   'gtkcsseasevalue.c',
   'gtkcssenumvalue.c',
   'gtkcssfiltervalue.c',


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