[gtk/path-tests: 31/32] curve2: Add a way to compare to cairo




commit d9710c49819e9f839bca032bd69a7e379e0d185e
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Dec 17 23:56:12 2020 -0500

    curve2: Add a way to compare to cairo

 tests/curve2.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
---
diff --git a/tests/curve2.c b/tests/curve2.c
index 80d99467c0..619f8464c8 100644
--- a/tests/curve2.c
+++ b/tests/curve2.c
@@ -28,6 +28,7 @@ struct _DemoWidget
   GskFillRule fill_rule;
 
   graphene_rect_t bounds;
+  gboolean show_cairo;
 };
 
 struct _DemoWidgetClass
@@ -118,6 +119,19 @@ demo_widget_snapshot (GtkWidget   *widget,
 
   if (self->do_stroke)
     {
+      if (self->show_cairo)
+        {
+          cairo_t *cr;
+
+          graphene_rect_init (&bounds, 0, 0, width, height);
+          cr = gtk_snapshot_append_cairo (snapshot, &bounds);
+          gsk_path_to_cairo (self->path, cr);
+          gsk_stroke_to_cairo (self->stroke, cr);
+          cairo_set_source_rgba (cr, 0, 0, 1, 0.2);
+          cairo_stroke (cr);
+          cairo_destroy (cr);
+        }
+
       if (self->inside)
         {
            gtk_snapshot_push_fill (snapshot, self->stroke_path, self->fill_rule);
@@ -443,6 +457,14 @@ bb_toggled (GtkCheckButton *button,
   gtk_widget_queue_draw (GTK_WIDGET (self));
 }
 
+static void
+cairo_toggled (GtkCheckButton *button,
+               DemoWidget      *self)
+{
+  self->show_cairo = gtk_check_button_get_active (button);
+  gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
 static void
 stroke_toggled (GtkCheckButton *button,
                 DemoWidget      *self)
@@ -664,6 +686,10 @@ main (int argc, char *argv[])
   g_signal_connect (spin, "value-changed", G_CALLBACK (dash_offset_changed), demo);
   gtk_grid_attach (GTK_GRID (grid), spin, 1, 10, 1, 1);
 
+  toggle = gtk_check_button_new_with_label ("Show cairo");
+  g_signal_connect (toggle, "toggled", G_CALLBACK (cairo_toggled), demo);
+  gtk_grid_attach (GTK_GRID (grid), toggle, 1, 11, 1, 1);
+
   entry = gtk_entry_new ();
   g_signal_connect (entry, "activate", G_CALLBACK (activate), demo);
   gtk_box_append (GTK_BOX (box), entry);


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