[gtk/wip/otte/lottie: 39/86] xxx: demo
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/lottie: 39/86] xxx: demo
- Date: Thu, 24 Dec 2020 05:39:28 +0000 (UTC)
commit 4da2adfa0c30a4f9bd96230f864e53448d26416b
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 6005da5fe2..ab4791a032 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]