[gtk/path-tests: 122/125] curve2: Add a way to compare to cairo




commit e56668e87032f796c09f2feeb5b34022f4d881a2
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 ac7410606d..6b16222d7d 100644
--- a/tests/curve2.c
+++ b/tests/curve2.c
@@ -29,6 +29,7 @@ struct _DemoWidget
   gboolean do_fill;
 
   graphene_rect_t bounds;
+  gboolean show_cairo;
 };
 
 struct _DemoWidgetClass
@@ -119,6 +120,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->do_fill && self->inside)
         {
            gtk_snapshot_push_fill (snapshot, self->stroke_path, self->fill_rule);
@@ -444,6 +458,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)
@@ -679,6 +701,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, row++, 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, row++, 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]