pathbuilder: Add relative path commands

And gsk_path_builder_get_current_point().

They will be needed by the string parser.
This commit is contained in:
Benjamin Otte
2020-11-28 14:52:17 +01:00
committed by Matthias Clasen
parent eed54eac7a
commit 2c2ee6a27a
2 changed files with 122 additions and 0 deletions

View File

@@ -281,6 +281,25 @@ gsk_path_builder_add_contour (GskPathBuilder *self,
self->contours = g_slist_prepend (self->contours, contour);
}
/**
* gsk_path_builder_get_current_point:
* @self: a #GskPathBuilder
*
* Gets the current point. The current point is used for relative
* drawing commands and updated after every operation.
*
* When the builder is created, the default current point is set to (0, 0).
*
* Returns: (transfer none): The current point
**/
const graphene_point_t *
gsk_path_builder_get_current_point (GskPathBuilder *self)
{
g_return_val_if_fail (self != NULL, NULL);
return &self->current_point;
}
/**
* gsk_path_builder_add_path:
* @self: a #GskPathBuilder
@@ -381,6 +400,29 @@ gsk_path_builder_move_to (GskPathBuilder *self,
gsk_path_builder_ensure_current (self);
}
/**
* gsk_path_builder_rel_move_to:
* @self: a #GskPathBuilder
* @x: x offset
* @y: y offset
*
* Starts a new contour by placing the pen at @x, @y relative to the current
* point.
*
* This is the relative version of gsk_path_builder_move_to().
**/
void
gsk_path_builder_rel_move_to (GskPathBuilder *self,
float x,
float y)
{
g_return_if_fail (self != NULL);
gsk_path_builder_move_to (self,
self->current_point.x + x,
self->current_point.y + y);
}
/**
* gsk_path_builder_line_to:
* @self: a #GskPathBuilder
@@ -409,6 +451,29 @@ gsk_path_builder_line_to (GskPathBuilder *self,
});
}
/**
* gsk_path_builder_rel_line_to:
* @self: a #GskPathBuilder
* @x: x offset
* @y: y offset
*
* Draws a line from the current point to a point offset to it by @x, @y
* and makes it the new current point.
*
* This is the relative version of gsk_path_builder_line_to().
**/
void
gsk_path_builder_rel_line_to (GskPathBuilder *self,
float x,
float y)
{
g_return_if_fail (self != NULL);
gsk_path_builder_line_to (self,
self->current_point.x + x,
self->current_point.y + y);
}
/**
* gsk_path_builder_curve_to:
* @self: a #GskPathBuilder
@@ -422,6 +487,8 @@ gsk_path_builder_line_to (GskPathBuilder *self,
* Adds a [cubic Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
* from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control
* points.
*
* After this, @x3, @y3 will be the new current point.
**/
void
gsk_path_builder_curve_to (GskPathBuilder *self,
@@ -444,6 +511,42 @@ gsk_path_builder_curve_to (GskPathBuilder *self,
});
}
/**
* gsk_path_builder_rel_curve_to:
* @self: a #GskPathBuilder
* @x1: x offset of first control point
* @y1: y offset of first control point
* @x2: x offset of second control point
* @y2: y offset of second control point
* @x3: x offset of the end of the curve
* @y3: y offset of the end of the curve
*
* Adds a [cubic Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
* from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control
* points. All coordinates are given relative to the current point.
*
* This is the relative version of gsk_path_builder_curve_to().
**/
void
gsk_path_builder_rel_curve_to (GskPathBuilder *self,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
{
g_return_if_fail (self != NULL);
gsk_path_builder_curve_to (self,
self->current_point.x + x1,
self->current_point.y + y1,
self->current_point.x + x2,
self->current_point.y + y2,
self->current_point.x + x3,
self->current_point.y + y3);
}
/**
* gsk_path_builder_close:
* @self: a #GskPathBuilder

View File

@@ -45,6 +45,9 @@ GskPath * gsk_path_builder_free_to_path (GskPathBuilder
GDK_AVAILABLE_IN_ALL
GskPath * gsk_path_builder_to_path (GskPathBuilder *self) G_GNUC_WARN_UNUSED_RESULT;
GDK_AVAILABLE_IN_ALL
const graphene_point_t *gsk_path_builder_get_current_point (GskPathBuilder *self);
GDK_AVAILABLE_IN_ALL
void gsk_path_builder_add_path (GskPathBuilder *self,
GskPath *path);
@@ -61,10 +64,18 @@ void gsk_path_builder_move_to (GskPathBuilder
float x,
float y);
GDK_AVAILABLE_IN_ALL
void gsk_path_builder_rel_move_to (GskPathBuilder *self,
float x,
float y);
GDK_AVAILABLE_IN_ALL
void gsk_path_builder_line_to (GskPathBuilder *self,
float x,
float y);
GDK_AVAILABLE_IN_ALL
void gsk_path_builder_rel_line_to (GskPathBuilder *self,
float x,
float y);
GDK_AVAILABLE_IN_ALL
void gsk_path_builder_curve_to (GskPathBuilder *self,
float x1,
float y1,
@@ -73,6 +84,14 @@ void gsk_path_builder_curve_to (GskPathBuilder
float x3,
float y3);
GDK_AVAILABLE_IN_ALL
void gsk_path_builder_rel_curve_to (GskPathBuilder *self,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3);
GDK_AVAILABLE_IN_ALL
void gsk_path_builder_close (GskPathBuilder *self);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GskPathBuilder, gsk_path_builder_unref)