[gtk/matthiasc/lottie2] Add a visual test for closest points
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/lottie2] Add a visual test for closest points
- Date: Thu, 26 Nov 2020 00:28:04 +0000 (UTC)
commit f35172ae45aebf63b6b7a9195692cfb99437cfac
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Nov 25 19:26:22 2020 -0500
Add a visual test for closest points
This is fun and a good debugging aid.
tests/curve2.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
---
diff --git a/tests/curve2.c b/tests/curve2.c
index 0f594d597f..b5da0fc433 100644
--- a/tests/curve2.c
+++ b/tests/curve2.c
@@ -7,6 +7,8 @@ struct _DemoWidget
{
GtkWidget parent_instance;
GskPath *path;
+ GskPathMeasure *measure;
+ double x, y;
};
struct _DemoWidgetClass
@@ -16,9 +18,25 @@ struct _DemoWidgetClass
G_DEFINE_TYPE (DemoWidget, demo_widget, GTK_TYPE_WIDGET)
+static void
+motion (GtkEventControllerMotion *controller,
+ double x,
+ double y,
+ DemoWidget *self)
+{
+ self->x = x;
+ self->y = y;
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
static void
demo_widget_init (DemoWidget *self)
{
+ GtkEventController *controller;
+
+ controller = gtk_event_controller_motion_new ();
+ g_signal_connect (controller, "motion", G_CALLBACK (motion), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), controller);
}
static void
@@ -28,6 +46,9 @@ demo_widget_snapshot (GtkWidget *widget,
DemoWidget *self = DEMO_WIDGET (widget);
int width, height;
GskStroke *stroke;
+ graphene_point_t point;
+ GskPathBuilder *builder;
+ GskPath *path;
if (!self->path)
return;
@@ -44,6 +65,32 @@ demo_widget_snapshot (GtkWidget *widget,
&GRAPHENE_RECT_INIT (0, 0, width, height ));
gtk_snapshot_pop (snapshot);
+
+ gsk_path_measure_get_closest_point (self->measure,
+ &GRAPHENE_POINT_INIT (self->x, self->y),
+ &point);
+
+ builder = gsk_path_builder_new ();
+ gsk_path_builder_add_circle (builder, &point, 10);
+ path = gsk_path_builder_free_to_path (builder);
+
+ gtk_snapshot_push_fill (snapshot, path, 0);
+ gtk_snapshot_append_color (snapshot,
+ &(GdkRGBA){ 1, 0, 0, 1},
+ &GRAPHENE_RECT_INIT (0, 0, width, height ));
+ gtk_snapshot_pop (snapshot);
+
+ stroke = gsk_stroke_new (1.0);
+ gtk_snapshot_push_stroke (snapshot, path, stroke);
+ gsk_stroke_free (stroke);
+
+ 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);
}
static void
@@ -79,6 +126,10 @@ demo_widget_set_path (DemoWidget *self,
{
g_clear_pointer (&self->path, gsk_path_unref);
self->path = gsk_path_ref (path);
+
+ g_clear_pointer (&self->measure, gsk_path_measure_unref);
+ self->measure = gsk_path_measure_new (self->path);
+
gtk_widget_queue_draw (GTK_WIDGET (self));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]