[gtk/wip/otte/lottie: 72/79] xxx path)_fill




commit d0495ab8b1af40b9bce95603890068651ddded5f
Author: Benjamin Otte <otte redhat com>
Date:   Fri Dec 11 00:43:55 2020 +0100

    xxx path)_fill

 demos/gtk-demo/path_fill.c | 58 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)
---
diff --git a/demos/gtk-demo/path_fill.c b/demos/gtk-demo/path_fill.c
index fbb48f040e..e3d608218e 100644
--- a/demos/gtk-demo/path_fill.c
+++ b/demos/gtk-demo/path_fill.c
@@ -8,6 +8,7 @@
 #include <gtk/gtk.h>
 
 #include "paintable.h"
+#include "gsk/gskpathdashprivate.h"
 
 #define GTK_TYPE_PATH_PAINTABLE (gtk_path_paintable_get_type ())
 G_DECLARE_FINAL_TYPE (GtkPathPaintable, gtk_path_paintable, GTK, PATH_PAINTABLE, GObject)
@@ -60,7 +61,7 @@ gtk_path_paintable_snapshot (GdkPaintable *paintable,
 #if 0
   gtk_snapshot_push_fill (snapshot, self->path, GSK_FILL_RULE_WINDING);
 #else
-  GskStroke *stroke = gsk_stroke_new (4.0);
+  GskStroke *stroke = gsk_stroke_new (2.0);
   gtk_snapshot_push_stroke (snapshot, self->path, stroke);
   gsk_stroke_free (stroke);
 #endif
@@ -215,6 +216,46 @@ create_path_from_text (GtkWidget *widget)
   return result;
 }
 
+static gboolean
+build_path (GskPathOperation        op,
+            const graphene_point_t *pts,
+            gsize                   n_pts,
+            float                   weight,
+            gpointer                user_data)
+{
+  GskPathBuilder *builder = user_data;
+
+  switch (op)
+  {
+    case GSK_PATH_MOVE:
+      gsk_path_builder_move_to (builder, pts[0].x, pts[0].y);
+      break;
+
+    case GSK_PATH_CLOSE:
+      gsk_path_builder_close (builder);
+      break;
+
+    case GSK_PATH_LINE:
+      gsk_path_builder_line_to (builder, pts[1].x, pts[1].y);
+      break;
+
+    case GSK_PATH_CURVE:
+      gsk_path_builder_curve_to (builder, pts[1].x, pts[1].y, pts[2].x, pts[2].y, pts[3].x, pts[3].y);
+      break;
+
+    case GSK_PATH_CONIC:
+      gsk_path_builder_conic_to (builder, pts[1].x, pts[1].y, pts[2].x, pts[2].y, weight);
+      break;
+
+    default:
+      g_assert_not_reached ();
+      break;
+  }
+
+  return TRUE;
+}
+
+
 static gboolean
 update_path (GtkWidget     *widget,
              GdkFrameClock *frame_clock,
@@ -225,12 +266,26 @@ update_path (GtkWidget     *widget,
   GskPath *path;
   graphene_point_t pos;
   graphene_vec2_t tangent;
+  GskStroke *stroke;
 
   builder = gsk_path_builder_new ();
   gsk_path_builder_add_segment (builder,
                                 measure,
+#if 1
+                                0.0, gsk_path_measure_get_length (measure));
+#else
                                 progress > 1 ? (progress - 1) * gsk_path_measure_get_length (measure) : 0.0,
                                 (progress < 1 ? progress : 1.0) * gsk_path_measure_get_length (measure));
+#endif
+
+  path = gsk_path_builder_free_to_path (builder);
+
+  stroke = gsk_stroke_new (1);
+  gsk_stroke_set_dash (stroke, (float[2]) { 10, 5 }, 2);
+  gsk_stroke_set_dash_offset (stroke, - (gdk_frame_clock_get_frame_time (frame_clock) % G_USEC_PER_SEC) * 
15. / G_USEC_PER_SEC);
+  builder = gsk_path_builder_new ();
+  gsk_path_dash (path, stroke, 0.2, build_path, builder);
+  gsk_path_unref (path);
 
   gsk_path_measure_get_point (measure,
                               (progress > 1 ? (progress - 1) : progress) * gsk_path_measure_get_length 
(measure),
@@ -240,6 +295,7 @@ update_path (GtkWidget     *widget,
   gsk_path_builder_line_to (builder, pos.x + 3 * graphene_vec2_get_y (&tangent), pos.y + 3 * 
graphene_vec2_get_x (&tangent));
   gsk_path_builder_line_to (builder, pos.x - 3 * graphene_vec2_get_y (&tangent), pos.y - 3 * 
graphene_vec2_get_x (&tangent));
   gsk_path_builder_close (builder);
+
   path = gsk_path_builder_free_to_path (builder);
 
   gtk_path_paintable_set_path (GTK_PATH_PAINTABLE (gtk_picture_get_paintable (GTK_PICTURE (widget))),


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