[gtk/wip/otte/canvas: 32/36] canvas: Add gtk_canvas_vector_to_string()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/canvas: 32/36] canvas: Add gtk_canvas_vector_to_string()
- Date: Tue, 5 Jul 2022 05:41:42 +0000 (UTC)
commit 7a50bec7024743ca2ed65c8f581fa9423bdc291e
Author: Benjamin Otte <otte redhat com>
Date: Tue Jul 5 05:17:10 2022 +0200
canvas: Add gtk_canvas_vector_to_string()
For debugging for now, but maybe I'm gonna parse this later.
gtk/gtkcanvasvector.c | 14 +++++++++
gtk/gtkcanvasvector.h | 5 +++
gtk/gtkcanvasvectorimpl.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+)
---
diff --git a/gtk/gtkcanvasvector.c b/gtk/gtkcanvasvector.c
index 905f6c547c..8ba16b073f 100644
--- a/gtk/gtkcanvasvector.c
+++ b/gtk/gtkcanvasvector.c
@@ -144,6 +144,20 @@ gtk_canvas_vector_new_distance (const GtkCanvasVector *from,
return self;
}
+char *
+gtk_canvas_vector_to_string (const GtkCanvasVector *self)
+{
+ GString *string;
+
+ g_return_val_if_fail (self != NULL, NULL);
+
+ string = g_string_new ("");
+
+ gtk_canvas_vector_print (self, string);
+
+ return g_string_free (string, FALSE);
+}
+
GtkCanvasVector *
gtk_canvas_vector_copy (const GtkCanvasVector *self)
{
diff --git a/gtk/gtkcanvasvector.h b/gtk/gtkcanvasvector.h
index bd031ecec9..7af8fc2f7b 100644
--- a/gtk/gtkcanvasvector.h
+++ b/gtk/gtkcanvasvector.h
@@ -43,6 +43,11 @@ void gtk_canvas_vector_free (GtkCanvasVector
GDK_AVAILABLE_IN_ALL
gboolean gtk_canvas_vector_eval (const GtkCanvasVector *self,
graphene_vec2_t *result)
G_GNUC_WARN_UNUSED_RESULT;
+GDK_AVAILABLE_IN_ALL
+char * gtk_canvas_vector_to_string (const GtkCanvasVector *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_canvas_vector_print (const GtkCanvasVector *self,
+ GString *string);
GDK_AVAILABLE_IN_ALL
GtkCanvasVector * gtk_canvas_vector_new (float x,
diff --git a/gtk/gtkcanvasvectorimpl.c b/gtk/gtkcanvasvectorimpl.c
index 4eeb8c398c..dd57bfb74b 100644
--- a/gtk/gtkcanvasvectorimpl.c
+++ b/gtk/gtkcanvasvectorimpl.c
@@ -37,6 +37,8 @@ struct _GtkCanvasVectorClass
void (* copy) (GtkCanvasVector *self,
const GtkCanvasVector *source);
void (* finish) (GtkCanvasVector *self);
+ void (* print) (const GtkCanvasVector *self,
+ GString *string);
gboolean (* eval) (const GtkCanvasVector *self,
graphene_vec2_t *result);
};
@@ -56,6 +58,13 @@ gtk_canvas_vector_invalid_finish (GtkCanvasVector *vector)
{
}
+static void
+gtk_canvas_vector_invalid_print (const GtkCanvasVector *vector,
+ GString *string)
+{
+ g_string_append (string, "#error");
+}
+
static gboolean
gtk_canvas_vector_invalid_eval (const GtkCanvasVector *vector,
graphene_vec2_t *result)
@@ -68,6 +77,7 @@ static const GtkCanvasVectorClass GTK_CANVAS_VECTOR_INVALID_CLASS =
"GtkCanvasVectorInvalid",
gtk_canvas_vector_invalid_copy,
gtk_canvas_vector_invalid_finish,
+ gtk_canvas_vector_invalid_print,
gtk_canvas_vector_invalid_eval,
};
@@ -100,6 +110,17 @@ gtk_canvas_vector_constant_finish (GtkCanvasVector *vector)
{
}
+static void
+gtk_canvas_vector_constant_print (const GtkCanvasVector *vector,
+ GString *string)
+{
+ const GtkCanvasVectorConstant *self = &vector->constant;
+
+ g_string_append_printf (string, "[%g, %g]",
+ graphene_vec2_get_x (&self->value),
+ graphene_vec2_get_y (&self->value));
+}
+
static gboolean
gtk_canvas_vector_constant_eval (const GtkCanvasVector *vector,
graphene_vec2_t *result)
@@ -116,6 +137,7 @@ static const GtkCanvasVectorClass GTK_CANVAS_VECTOR_CONSTANT_CLASS =
"GtkCanvasVectorConstant",
gtk_canvas_vector_constant_copy,
gtk_canvas_vector_constant_finish,
+ gtk_canvas_vector_constant_print,
gtk_canvas_vector_constant_eval,
};
@@ -161,6 +183,27 @@ gtk_canvas_vector_sum_finish (GtkCanvasVector *vector)
g_free (self->summands);
}
+static void
+gtk_canvas_vector_sum_print (const GtkCanvasVector *vector,
+ GString *string)
+{
+ const GtkCanvasVectorSum *self = &vector->sum;
+ gsize i;
+
+ for (i = 0; i < self->n_summands; i++)
+ {
+ if (i > 0)
+ g_string_append (string, " + ");
+ if (!graphene_vec2_equal (&self->summands[i].scale, graphene_vec2_one()))
+ {
+ g_string_append_printf (string, "[%g, %g] * ",
+ graphene_vec2_get_x (&self->summands[i].scale),
+ graphene_vec2_get_y (&self->summands[i].scale));
+ }
+ gtk_canvas_vector_print (&self->summands[i].value, string);
+ }
+}
+
static gboolean
gtk_canvas_vector_sum_eval (const GtkCanvasVector *vector,
graphene_vec2_t *result)
@@ -190,6 +233,7 @@ static const GtkCanvasVectorClass GTK_CANVAS_VECTOR_SUM_CLASS =
"GtkCanvasVectorSum",
gtk_canvas_vector_sum_copy,
gtk_canvas_vector_sum_finish,
+ gtk_canvas_vector_sum_print,
gtk_canvas_vector_sum_eval,
};
@@ -264,6 +308,17 @@ gtk_canvas_vector_multiply_finish (GtkCanvasVector *vector)
gtk_canvas_vector_free (self->b);
}
+static void
+gtk_canvas_vector_multiply_print (const GtkCanvasVector *vector,
+ GString *string)
+{
+ const GtkCanvasVectorMultiply *self = &vector->multiply;
+
+ gtk_canvas_vector_print (self->a, string);
+ g_string_append (string, " * ");
+ gtk_canvas_vector_print (self->b, string);
+}
+
static gboolean
gtk_canvas_vector_multiply_eval (const GtkCanvasVector *vector,
graphene_vec2_t *result)
@@ -284,6 +339,7 @@ static const GtkCanvasVectorClass GTK_CANVAS_VECTOR_MULTIPLY_CLASS =
"GtkCanvasVectorMultiply",
gtk_canvas_vector_multiply_copy,
gtk_canvas_vector_multiply_finish,
+ gtk_canvas_vector_multiply_print,
gtk_canvas_vector_multiply_eval,
};
@@ -324,6 +380,17 @@ gtk_canvas_vector_variable_finish (GtkCanvasVector *vector)
g_rc_box_release (self->variable);
}
+static void
+gtk_canvas_vector_variable_print (const GtkCanvasVector *vector,
+ GString *string)
+{
+ const GtkCanvasVectorVariable *self = &vector->variable;
+
+ g_string_append (string, "(");
+ gtk_canvas_vector_print (self->variable, string);
+ g_string_append (string, ")");
+}
+
static gboolean
gtk_canvas_vector_variable_eval (const GtkCanvasVector *vector,
graphene_vec2_t *result)
@@ -338,6 +405,7 @@ static const GtkCanvasVectorClass GTK_CANVAS_VECTOR_VARIABLE_CLASS =
"GtkCanvasVectorVariable",
gtk_canvas_vector_variable_copy,
gtk_canvas_vector_variable_finish,
+ gtk_canvas_vector_variable_print,
gtk_canvas_vector_variable_eval,
};
@@ -418,3 +486,13 @@ gtk_canvas_vector_eval (const GtkCanvasVector *self,
return FALSE;
}
+void
+gtk_canvas_vector_print (const GtkCanvasVector *self,
+ GString *string)
+{
+ g_return_if_fail (self != NULL);
+ g_return_if_fail (string != NULL);
+
+ self->class->print (self, string);
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]