package ocgtk

  1. Overview
  2. Docs
OCaml bindings for GTK 4

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1-preview2.tar.gz
sha256=4e50fdb5093136a10fc8ffbe388e44cbcb70d52f8afdd48863ec7e22580ff054

doc/ocgtk.gsk/Ocgtk_gsk/Gsk/Wrappers/Path_builder/index.html

Module Wrappers.Path_builder

type t = [ `path_builder ] Gobject.obj

`GskPathBuilder` is an auxiliary object for constructing `GskPath` objects.

A path is constructed like this:

|<!-- language="C" --> GskPath * construct_path (void) { GskPathBuilder *builder; builder = gsk_path_builder_new (); // add contours to the path here return gsk_path_builder_free_to_path (builder); |

Adding contours to the path can be done in two ways. The easiest option is to use the `gsk_path_builder_add_*` group of functions that add predefined contours to the current path, either common shapes like method@Gsk.PathBuilder.add_circle or by adding from other paths like method@Gsk.PathBuilder.add_path.

The `gsk_path_builder_add_*` methods always add complete contours, and do not use or modify the current point.

The other option is to define each line and curve manually with the `gsk_path_builder_*_to` group of functions. You start with a call to method@Gsk.PathBuilder.move_to to set the starting point and then use multiple calls to any of the drawing functions to move the pen along the plane. Once you are done, you can call method@Gsk.PathBuilder.close to close the path by connecting it back with a line to the starting point.

This is similar to how paths are drawn in Cairo.

Note that `GskPathBuilder` will reduce the degree of added Bézier curves as much as possible, to simplify rendering.

val new_ : unit -> t

Create a new PathBuilder

val to_path : t -> [ `path ] Gobject.obj

Creates a new `GskPath` from the given builder.

The given `GskPathBuilder` is reset once this function returns; you cannot call this function multiple times on the same builder instance.

This function is intended primarily for language bindings. C code should use method@Gsk.PathBuilder.free_to_path.

val svg_arc_to : t -> float -> float -> float -> bool -> bool -> float -> float -> unit

Implements arc-to according to the SVG spec.

A convenience function that implements the SVG arc_to(https://www.w3.org/TR/SVG11/paths.html#PathDataEllipticalArcCommands) functionality.

After this, @x, @y will be the new current point.

val rel_svg_arc_to : t -> float -> float -> float -> bool -> bool -> float -> float -> unit

Implements arc-to according to the SVG spec.

All coordinates are given relative to the current point.

This is the relative version of method@Gsk.PathBuilder.svg_arc_to.

val rel_quad_to : t -> float -> float -> float -> float -> unit

Adds a quadratic Bézier curve(https://en.wikipedia.org/wiki/B%C3%A9zier_curve) from the current point to @x2, @y2 with @x1, @y1 the control point.

All coordinates are given relative to the current point.

This is the relative version of method@Gsk.PathBuilder.quad_to.

val rel_move_to : t -> float -> float -> unit

Starts a new contour by placing the pen at @x, @y relative to the current point.

This is the relative version of method@Gsk.PathBuilder.move_to.

val rel_line_to : t -> float -> float -> unit

Draws a line from the current point to a point offset from it by @x, @y and makes it the new current point.

This is the relative version of method@Gsk.PathBuilder.line_to.

val rel_html_arc_to : t -> float -> float -> float -> float -> float -> unit

Implements arc-to according to the HTML Canvas spec.

All coordinates are given relative to the current point.

This is the relative version of method@Gsk.PathBuilder.html_arc_to.

val rel_cubic_to : t -> float -> float -> float -> float -> float -> float -> unit

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 method@Gsk.PathBuilder.cubic_to.

val rel_conic_to : t -> float -> float -> float -> float -> float -> unit

Adds a conic curve(https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline) from the current point to @x2, @y2 with the given @weight and @x1, @y1 as the control point.

All coordinates are given relative to the current point.

This is the relative version of method@Gsk.PathBuilder.conic_to.

val rel_arc_to : t -> float -> float -> float -> float -> unit

Adds an elliptical arc from the current point to @x2, @y2 with @x1, @y1 determining the tangent directions.

All coordinates are given relative to the current point.

This is the relative version of method@Gsk.PathBuilder.arc_to.

val ref : t -> t

Acquires a reference on the given builder.

This function is intended primarily for language bindings. `GskPathBuilder` objects should not be kept around.

val quad_to : t -> float -> float -> float -> float -> unit

Adds a quadratic Bézier curve(https://en.wikipedia.org/wiki/B%C3%A9zier_curve) from the current point to @x2, @y2 with @x1, @y1 as the control point.

After this, @x2, @y2 will be the new current point.

<picture> <source srcset="quad-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Quad To" src="quad-light.png"> </picture>

val move_to : t -> float -> float -> unit

Starts a new contour by placing the pen at @x, @y.

If this function is called twice in succession, the first call will result in a contour made up of a single point. The second call will start a new contour.

val line_to : t -> float -> float -> unit

Draws a line from the current point to @x, @y and makes it the new current point.

<picture> <source srcset="line-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Line To" src="line-light.png"> </picture>

val html_arc_to : t -> float -> float -> float -> float -> float -> unit

Implements arc-to according to the HTML Canvas spec.

A convenience function that implements the HTML arc_to(https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-arcto-dev) functionality.

After this, the current point will be the point where the circle with the given radius touches the line from @x1, @y1 to @x2, @y2.

val get_current_point : t -> Ocgtk_graphene.Graphene.Wrappers.Point.t

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`. Note that this is different from cairo, which starts out without a current point.

val cubic_to : t -> float -> float -> float -> float -> float -> float -> unit

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.

<picture> <source srcset="cubic-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Cubic To" src="cubic-light.png"> </picture>

val conic_to : t -> float -> float -> float -> float -> float -> unit

Adds a conic curve(https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline) from the current point to @x2, @y2 with the given @weight and @x1, @y1 as the control point.

The weight determines how strongly the curve is pulled towards the control point. A conic with weight 1 is identical to a quadratic Bézier curve with the same points.

Conic curves can be used to draw ellipses and circles. They are also known as rational quadratic Bézier curves.

After this, @x2, @y2 will be the new current point.

<picture> <source srcset="conic-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Conic To" src="conic-light.png"> </picture>

val close : t -> unit

Ends the current contour with a line back to the start point.

Note that this is different from calling method@Gsk.PathBuilder.line_to with the start point in that the contour will be closed. A closed contour behaves differently from an open one. When stroking, its start and end point are considered connected, so they will be joined via the line join, and not ended with line caps.

val arc_to : t -> float -> float -> float -> float -> unit

Adds an elliptical arc from the current point to @x2, @y2 with @x1, @y1 determining the tangent directions.

After this, @x2, @y2 will be the new current point.

Note: Two points and their tangents do not determine a unique ellipse, so GSK just picks one. If you need more precise control, use method@Gsk.PathBuilder.conic_to or method@Gsk.PathBuilder.svg_arc_to.

<picture> <source srcset="arc-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Arc To" src="arc-light.png"> </picture>

val add_segment : t -> [ `path ] Gobject.obj -> [ `path_point ] Gobject.obj -> [ `path_point ] Gobject.obj -> unit

Adds to @self the segment of @path from @start to @end.

If @start is equal to or after @end, the path will first add the segment from @start to the end of the path, and then add the segment from the beginning to @end. If the path is closed, these segments will be connected.

Note that this method always adds a path with the given start point and end point. To add a closed path, use method@Gsk.PathBuilder.add_path.

val add_rounded_rect : t -> [ `rounded_rect ] Gobject.obj -> unit

Adds @rect as a new contour to the path built in @self.

The path is going around the rectangle in clockwise direction.

val add_reverse_path : t -> [ `path ] Gobject.obj -> unit

Appends all of @path to the builder, in reverse order.

val add_rect : t -> Ocgtk_graphene.Graphene.Wrappers.Rect.t -> unit

Adds @rect as a new contour to the path built by the builder.

The path is going around the rectangle in clockwise direction.

If the the width or height are 0, the path will be a closed horizontal or vertical line. If both are 0, it'll be a closed dot.

val add_path : t -> [ `path ] Gobject.obj -> unit

Appends all of @path to the builder.

val add_layout : t -> Ocgtk_pango.Pango.Wrappers.Layout.t -> unit

Adds the outlines for the glyphs in @layout to the builder.

val add_circle : t -> Ocgtk_graphene.Graphene.Wrappers.Point.t -> float -> unit

Adds a circle with the @center and @radius.

The path is going around the circle in clockwise direction.

If @radius is zero, the contour will be a closed point.

val add_cairo_path : t -> Ocgtk_cairo.Cairo.Wrappers.Path.t -> unit

Adds a Cairo path to the builder.

You can use cairo_copy_path() to access the path from a Cairo context.

val get_type : unit -> Gobject.Type.t