[gtk/wip/matthiasc/lottie-stroke: 45/51] Add line width in the curve demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/lottie-stroke: 45/51] Add line width in the curve demo
- Date: Tue, 1 Dec 2020 17:28:02 +0000 (UTC)
commit 11f404815f01ad6c996d63ccf4533d03deb02b6a
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Nov 30 18:55:47 2020 -0500
Add line width in the curve demo
This is getting a bit confusing, maybe.
We have stroke width, which is the size of the
stroke shape, and line width, which is the thickness
with which we draw its outline.
Also, use a fill node instead of a stroke node,
to see how well it works to replace stroking paths
with fill stroke paths.
tests/curve2.c | 39 ++++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
---
diff --git a/tests/curve2.c b/tests/curve2.c
index c3178d11e7..74a9f16d74 100644
--- a/tests/curve2.c
+++ b/tests/curve2.c
@@ -14,6 +14,7 @@ struct _DemoWidget
graphene_point_t point2;
graphene_vec2_t tangent;
double start, end;
+ float line_width;
gboolean track;
gboolean show_bounding_box;
@@ -126,15 +127,19 @@ demo_widget_snapshot (GtkWidget *widget,
gtk_snapshot_pop (snapshot);
}
- stroke = gsk_stroke_new (1.0);
- gtk_snapshot_push_stroke (snapshot, self->stroke_path, stroke);
+ stroke = gsk_stroke_new (self->line_width);
+ path = gsk_path_to_stroke (self->stroke_path, stroke);
+ gtk_snapshot_push_fill (snapshot, path, GSK_FILL_RULE_WINDING);
+ gsk_path_unref (path);
gtk_snapshot_append_color (snapshot,
- &(GdkRGBA){ 0, 0, 0, 1},
+ &(GdkRGBA){ 0, 0, 0, 0.2},
&GRAPHENE_RECT_INIT (0, 0, width, height ));
gtk_snapshot_pop (snapshot);
+ gsk_stroke_free (stroke);
+ stroke = gsk_stroke_new (1);
gtk_snapshot_push_stroke (snapshot, self->path, stroke);
gtk_snapshot_append_color (snapshot,
@@ -146,7 +151,7 @@ demo_widget_snapshot (GtkWidget *widget,
}
else
{
- stroke = gsk_stroke_new (1.0);
+ stroke = gsk_stroke_new (self->line_width);
gtk_snapshot_push_stroke (snapshot, self->path, stroke);
gsk_stroke_free (stroke);
@@ -355,6 +360,8 @@ init_demo (DemoWidget *demo,
gsk_path_builder_move_to (builder, 300, 150);
gsk_path_builder_curve_to (builder, 300, 50, 400, 50, 400, 150);
gsk_path_builder_curve_to (builder, 400, 250, 500, 250, 500, 150);
+ gsk_path_builder_line_to (builder, 600, 150);
+ gsk_path_builder_line_to (builder, 530, 190);
path = gsk_path_builder_free_to_path (builder);
demo_widget_set_path (demo, path);
@@ -365,6 +372,7 @@ init_demo (DemoWidget *demo,
gsk_path_unref (path);
demo->stroke = gsk_stroke_new (20);
+ demo->line_width = 1;
}
static void
@@ -456,13 +464,21 @@ limit_changed (GtkSpinButton *spin,
}
static void
-width_changed (GtkSpinButton *spin,
- DemoWidget *self)
+stroke_width_changed (GtkSpinButton *spin,
+ DemoWidget *self)
{
gsk_stroke_set_line_width (self->stroke, gtk_spin_button_get_value (spin));
update_stroke_path (self);
}
+static void
+line_width_changed (GtkSpinButton *spin,
+ DemoWidget *self)
+{
+ self->line_width = gtk_spin_button_get_value (spin);
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
int
main (int argc, char *argv[])
{
@@ -473,7 +489,7 @@ main (int argc, char *argv[])
gtk_init ();
window = gtk_window_new ();
- gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
+ gtk_window_set_default_size (GTK_WINDOW (window), 700, 500);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_window_set_child (GTK_WINDOW (window), box);
@@ -530,12 +546,17 @@ main (int argc, char *argv[])
g_signal_connect (spin, "value-changed", G_CALLBACK (limit_changed), demo);
gtk_grid_attach (GTK_GRID (grid), spin, 1, 6, 1, 1);
- gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Line width:"), 0, 7, 1, 1);
+ gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Stroke width:"), 0, 7, 1, 1);
spin = gtk_spin_button_new_with_range (1, 40, 1);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 20);
- g_signal_connect (spin, "value-changed", G_CALLBACK (width_changed), demo);
+ g_signal_connect (spin, "value-changed", G_CALLBACK (stroke_width_changed), demo);
gtk_grid_attach (GTK_GRID (grid), spin, 1, 7, 1, 1);
+ gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Line width:"), 0, 8, 1, 1);
+ spin = gtk_spin_button_new_with_range (1, 20, 1);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 1);
+ g_signal_connect (spin, "value-changed", G_CALLBACK (line_width_changed), demo);
+ gtk_grid_attach (GTK_GRID (grid), spin, 1, 8, 1, 1);
entry = gtk_entry_new ();
g_signal_connect (entry, "activate", G_CALLBACK (activate), demo);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]