[gtk/wip/matthiasc/lottie-stroke: 23/60] xxx: demo




commit 6707aeabb968c00d23adf3bca3180cb298cac34b
Author: Benjamin Otte <otte redhat com>
Date:   Wed Nov 25 00:15:15 2020 +0100

    xxx: demo

 demos/gtk-demo/path_text.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
---
diff --git a/demos/gtk-demo/path_text.c b/demos/gtk-demo/path_text.c
index 1fa6fa4edb..22e57f3eed 100644
--- a/demos/gtk-demo/path_text.c
+++ b/demos/gtk-demo/path_text.c
@@ -28,6 +28,7 @@ struct _GtkPathWidget
   graphene_point_t points[4];
 
   guint active_point;
+  float line_closest;
 
   GskPath *line_path;
   GskPathMeasure *line_measure;
@@ -297,6 +298,23 @@ gtk_path_widget_snapshot (GtkWidget   *widget,
       gtk_snapshot_append_color (snapshot, &(GdkRGBA) { 0, 0, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, width, 
height));
       gtk_snapshot_pop (snapshot);
 
+      gsk_path_unref (path);
+    }
+
+  if (self->line_closest >= 0)
+    {
+      GskPathBuilder *builder;
+      graphene_point_t closest;
+
+      builder = gsk_path_builder_new ();
+      gsk_path_measure_get_point (self->line_measure, self->line_closest, &closest, NULL);
+      gsk_path_builder_add_circle (builder, &closest, POINT_SIZE);
+      path = gsk_path_builder_free_to_path (builder);
+
+      gtk_snapshot_push_fill (snapshot, path, GSK_FILL_RULE_WINDING);
+      gtk_snapshot_append_color (snapshot, &(GdkRGBA) { 0, 0, 1, 1 }, &GRAPHENE_RECT_INIT (0, 0, width, 
height));
+      gtk_snapshot_pop (snapshot);
+
       gsk_path_unref (path);
     }
 }
@@ -471,6 +489,30 @@ drag_update (GtkGestureDrag *drag,
   gtk_widget_queue_draw (GTK_WIDGET (self));
 }
 
+static void
+pointer_motion (GtkEventControllerMotion *controller,
+                double                    x,
+                double                    y,
+                GtkPathWidget            *self)
+{
+  gsk_path_measure_get_closest_point_full (self->line_measure,
+                                           &GRAPHENE_POINT_INIT (x, y),
+                                           INFINITY,
+                                           &self->line_closest,
+                                           NULL, NULL, NULL);
+
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
+static void
+pointer_leave (GtkEventControllerMotion *controller,
+               GtkPathWidget            *self)
+{
+  self->line_closest = -1;
+
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
 static void
 gtk_path_widget_init (GtkPathWidget *self)
 {
@@ -480,9 +522,16 @@ gtk_path_widget_init (GtkPathWidget *self)
   g_signal_connect (controller, "drag-begin", G_CALLBACK (drag_begin), self);
   g_signal_connect (controller, "drag-update", G_CALLBACK (drag_update), self);
   g_signal_connect (controller, "drag-end", G_CALLBACK (drag_update), self);
+  gtk_widget_add_controller (GTK_WIDGET (self), controller);
 
+  controller = GTK_EVENT_CONTROLLER (gtk_event_controller_motion_new ());
+  g_signal_connect (controller, "enter", G_CALLBACK (pointer_motion), self);
+  g_signal_connect (controller, "motion", G_CALLBACK (pointer_motion), self);
+  g_signal_connect (controller, "leave", G_CALLBACK (pointer_leave), self);
   gtk_widget_add_controller (GTK_WIDGET (self), controller);
 
+  self->line_closest = -1;
+
   self->points[0] = GRAPHENE_POINT_INIT (0.1, 0.9);
   self->points[1] = GRAPHENE_POINT_INIT (0.3, 0.1);
   self->points[2] = GRAPHENE_POINT_INIT (0.7, 0.1);


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