summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-11-20 21:51:25 -0500
committerMatthias Clasen <mclasen@redhat.com>2020-11-21 08:47:43 -0500
commit01abd68455a0a39f325207de303345ea76e08b3d (patch)
treed5a26ba55ddb274a095adbb92636d56f6e801067
parent267c1a277c2304ae0a3fddb71f64a0ea9a448539 (diff)
downloadgtk+-01abd68455a0a39f325207de303345ea76e08b3d.tar.gz
Add more api
Add curve_editor_get_path.
-rw-r--r--tests/curve-editor.c73
-rw-r--r--tests/curve-editor.h2
2 files changed, 49 insertions, 26 deletions
diff --git a/tests/curve-editor.c b/tests/curve-editor.c
index 5b278bdff8..cc0040152e 100644
--- a/tests/curve-editor.c
+++ b/tests/curve-editor.c
@@ -609,8 +609,41 @@ curve_editor_init (CurveEditor *self)
}
static void
+curve_editor_add_path (CurveEditor *self,
+ GskPathBuilder *builder)
+{
+ int i;
+
+ gsk_path_builder_move_to (builder, self->points[0].x, self->points[0].y);
+ for (i = 1; i < self->n_points; i += 3)
+ {
+ switch (self->point_data[i / 3].op)
+ {
+ case MOVE:
+ gsk_path_builder_move_to (builder,
+ self->points[(i + 2) % self->n_points].x, self->points[(i + 2) % self->n_points].y);
+ break;
+
+ case LINE:
+ gsk_path_builder_line_to (builder,
+ self->points[(i + 2) % self->n_points].x, self->points[(i + 2) % self->n_points].y);
+ break;
+
+ case CURVE:
+ gsk_path_builder_curve_to (builder,
+ self->points[i].x, self->points[i].y,
+ self->points[(i + 1) % self->n_points].x, self->points[(i + 1) % self->n_points].y,
+ self->points[(i + 2) % self->n_points].x, self->points[(i + 2) % self->n_points].y);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ }
+}
+
+static void
curve_editor_snapshot (GtkWidget *widget,
- GtkSnapshot *snapshot)
+ GtkSnapshot *snapshot)
{
CurveEditor *self = (CurveEditor *)widget;
GskPathBuilder *builder;
@@ -662,31 +695,7 @@ curve_editor_snapshot (GtkWidget *widget,
/* Add the curve itself */
- gsk_path_builder_move_to (builder, self->points[0].x, self->points[0].y);
- for (i = 1; i < self->n_points; i += 3)
- {
- switch (self->point_data[i / 3].op)
- {
- case MOVE:
- gsk_path_builder_move_to (builder,
- self->points[(i + 2) % self->n_points].x, self->points[(i + 2) % self->n_points].y);
- break;
-
- case LINE:
- gsk_path_builder_line_to (builder,
- self->points[(i + 2) % self->n_points].x, self->points[(i + 2) % self->n_points].y);
- break;
-
- case CURVE:
- gsk_path_builder_curve_to (builder,
- self->points[i].x, self->points[i].y,
- self->points[(i + 1) % self->n_points].x, self->points[(i + 1) % self->n_points].y,
- self->points[(i + 2) % self->n_points].x, self->points[(i + 2) % self->n_points].y);
- break;
- default:
- g_assert_not_reached ();
- }
- }
+ curve_editor_add_path (self, builder);
/* Stroke everything we have so far */
@@ -1012,3 +1021,15 @@ curve_editor_set_path (CurveEditor *self,
gtk_widget_queue_draw (GTK_WIDGET (self));
}
+
+GskPath *
+curve_editor_get_path (CurveEditor *self)
+{
+ GskPathBuilder *builder;
+
+ builder = gsk_path_builder_new ();
+
+ curve_editor_add_path (self, builder);
+
+ return gsk_path_builder_free_to_path (builder);
+}
diff --git a/tests/curve-editor.h b/tests/curve-editor.h
index e26247ba2b..5daf1c0114 100644
--- a/tests/curve-editor.h
+++ b/tests/curve-editor.h
@@ -15,4 +15,6 @@ void curve_editor_set_edit (CurveEditor *self,
void curve_editor_set_path (CurveEditor *self,
GskPath *path);
+GskPath * curve_editor_get_path (CurveEditor *self);
+
G_END_DECLS