gsk4/auto/path_builder.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{Path, PathPoint, RoundedRect, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// Constructs [`Path`][crate::Path] objects.
10 ///
11 /// A path is constructed like this:
12 ///
13 /// **⚠️ The following code is in c ⚠️**
14 ///
15 /// ```c
16 /// GskPath *
17 /// construct_path (void)
18 /// {
19 /// GskPathBuilder *builder;
20 ///
21 /// builder = gsk_path_builder_new ();
22 ///
23 /// // add contours to the path here
24 ///
25 /// return gsk_path_builder_free_to_path (builder);
26 /// ```
27 ///
28 /// Adding contours to the path can be done in two ways.
29 /// The easiest option is to use the `gsk_path_builder_add_*` group
30 /// of functions that add predefined contours to the current path,
31 /// either common shapes like [`add_circle()`][Self::add_circle()]
32 /// or by adding from other paths like [`add_path()`][Self::add_path()].
33 ///
34 /// The `gsk_path_builder_add_*` methods always add complete contours,
35 /// and do not use or modify the current point.
36 ///
37 /// The other option is to define each line and curve manually with
38 /// the `gsk_path_builder_*_to` group of functions. You start with
39 /// a call to [`move_to()`][Self::move_to()] to set the starting point
40 /// and then use multiple calls to any of the drawing functions to
41 /// move the pen along the plane. Once you are done, you can call
42 /// [`close()`][Self::close()] to close the path by connecting it
43 /// back with a line to the starting point.
44 ///
45 /// This is similar to how paths are drawn in Cairo.
46 ///
47 /// Note that [`PathBuilder`][crate::PathBuilder] will reduce the degree of added Bézier
48 /// curves as much as possible, to simplify rendering.
49 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
50 pub struct PathBuilder(Shared<ffi::GskPathBuilder>);
51
52 match fn {
53 ref => |ptr| ffi::gsk_path_builder_ref(ptr),
54 unref => |ptr| ffi::gsk_path_builder_unref(ptr),
55 type_ => || ffi::gsk_path_builder_get_type(),
56 }
57}
58
59impl PathBuilder {
60 /// Create a new [`PathBuilder`][crate::PathBuilder] object.
61 ///
62 /// The resulting builder would create an empty [`Path`][crate::Path].
63 /// Use addition functions to add types to it.
64 ///
65 /// # Returns
66 ///
67 /// a new [`PathBuilder`][crate::PathBuilder]
68 #[doc(alias = "gsk_path_builder_new")]
69 pub fn new() -> PathBuilder {
70 assert_initialized_main_thread!();
71 unsafe { from_glib_full(ffi::gsk_path_builder_new()) }
72 }
73
74 /// Adds a circle as a new contour.
75 ///
76 /// The path is going around the circle in clockwise direction.
77 ///
78 /// If @radius is zero, the contour will be a closed point.
79 /// ## `center`
80 /// the center of the circle
81 /// ## `radius`
82 /// the radius of the circle
83 #[doc(alias = "gsk_path_builder_add_circle")]
84 pub fn add_circle(&self, center: &graphene::Point, radius: f32) {
85 unsafe {
86 ffi::gsk_path_builder_add_circle(
87 self.to_glib_none().0,
88 center.to_glib_none().0,
89 radius,
90 );
91 }
92 }
93
94 /// Adds the outlines for the glyphs in @layout to the builder.
95 /// ## `layout`
96 /// the pango layout to add
97 #[doc(alias = "gsk_path_builder_add_layout")]
98 pub fn add_layout(&self, layout: &pango::Layout) {
99 unsafe {
100 ffi::gsk_path_builder_add_layout(self.to_glib_none().0, layout.to_glib_none().0);
101 }
102 }
103
104 /// Appends all of @path to the builder.
105 /// ## `path`
106 /// the path to append
107 #[doc(alias = "gsk_path_builder_add_path")]
108 pub fn add_path(&self, path: &Path) {
109 unsafe {
110 ffi::gsk_path_builder_add_path(self.to_glib_none().0, path.to_glib_none().0);
111 }
112 }
113
114 /// Adds a rectangle as a new contour.
115 ///
116 /// The path is going around the rectangle in clockwise direction.
117 ///
118 /// If the the width or height are 0, the path will be a closed
119 /// horizontal or vertical line. If both are 0, it'll be a closed dot.
120 /// ## `rect`
121 /// the rectangle to create a path for
122 #[doc(alias = "gsk_path_builder_add_rect")]
123 pub fn add_rect(&self, rect: &graphene::Rect) {
124 unsafe {
125 ffi::gsk_path_builder_add_rect(self.to_glib_none().0, rect.to_glib_none().0);
126 }
127 }
128
129 /// Appends all of @path to the builder, in reverse order.
130 /// ## `path`
131 /// the path to append
132 #[doc(alias = "gsk_path_builder_add_reverse_path")]
133 pub fn add_reverse_path(&self, path: &Path) {
134 unsafe {
135 ffi::gsk_path_builder_add_reverse_path(self.to_glib_none().0, path.to_glib_none().0);
136 }
137 }
138
139 /// Adds a rounded rectangle as a new contour.
140 ///
141 /// The path is going around the rectangle in clockwise direction.
142 /// ## `rect`
143 /// the rounded rect
144 #[doc(alias = "gsk_path_builder_add_rounded_rect")]
145 pub fn add_rounded_rect(&self, rect: &RoundedRect) {
146 unsafe {
147 ffi::gsk_path_builder_add_rounded_rect(self.to_glib_none().0, rect.to_glib_none().0);
148 }
149 }
150
151 /// Adds a segment of a path to the builder.
152 ///
153 /// If @start is equal to or after @end, the path will first add the
154 /// segment from @start to the end of the path, and then add the segment
155 /// from the beginning to @end. If the path is closed, these segments
156 /// will be connected.
157 ///
158 /// Note that this method always adds a path with the given start point
159 /// and end point. To add a closed path, use [`add_path()`][Self::add_path()].
160 /// ## `path`
161 /// the path to take the segment to
162 /// ## `start`
163 /// the point on @path to start at
164 /// ## `end`
165 /// the point on @path to end at
166 #[doc(alias = "gsk_path_builder_add_segment")]
167 pub fn add_segment(&self, path: &Path, start: &PathPoint, end: &PathPoint) {
168 unsafe {
169 ffi::gsk_path_builder_add_segment(
170 self.to_glib_none().0,
171 path.to_glib_none().0,
172 start.to_glib_none().0,
173 end.to_glib_none().0,
174 );
175 }
176 }
177
178 /// Adds an elliptical arc from the current point to @x2, @y2
179 /// with @x1, @y1 determining the tangent directions.
180 ///
181 /// After this, @x2, @y2 will be the new current point.
182 ///
183 /// Note: Two points and their tangents do not determine
184 /// a unique ellipse, so GSK just picks one. If you need more
185 /// precise control, use [`conic_to()`][Self::conic_to()]
186 /// or [`svg_arc_to()`][Self::svg_arc_to()].
187 ///
188 /// <picture>
189 /// <source srcset="arc-dark.png" media="(prefers-color-scheme: dark)">
190 /// <img alt="Arc To" src="arc-light.png">
191 /// </picture>
192 /// ## `x1`
193 /// x coordinate of first control point
194 /// ## `y1`
195 /// y coordinate of first control point
196 /// ## `x2`
197 /// x coordinate of second control point
198 /// ## `y2`
199 /// y coordinate of second control point
200 #[doc(alias = "gsk_path_builder_arc_to")]
201 pub fn arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
202 unsafe {
203 ffi::gsk_path_builder_arc_to(self.to_glib_none().0, x1, y1, x2, y2);
204 }
205 }
206
207 /// Ends the current contour with a line back to the start point.
208 ///
209 /// Note that this is different from calling [`line_to()`][Self::line_to()]
210 /// with the start point in that the contour will be closed. A closed
211 /// contour behaves differently from an open one. When stroking, its
212 /// start and end point are considered connected, so they will be
213 /// joined via the line join, and not ended with line caps.
214 #[doc(alias = "gsk_path_builder_close")]
215 pub fn close(&self) {
216 unsafe {
217 ffi::gsk_path_builder_close(self.to_glib_none().0);
218 }
219 }
220
221 /// Adds a [conic curve](https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline)
222 /// from the current point to @x2, @y2 with the given @weight and @x1, @y1 as the
223 /// control point.
224 ///
225 /// The weight determines how strongly the curve is pulled towards the control point.
226 /// A conic with weight 1 is identical to a quadratic Bézier curve with the same points,
227 /// a conic with weight 0 is identical to a straight line from the start point to
228 /// the end point.
229 ///
230 /// Conic curves can be used to draw ellipses and circles. They are also known as
231 /// rational quadratic Bézier curves.
232 ///
233 /// After this, @x2, @y2 will be the new current point.
234 ///
235 /// <picture>
236 /// <source srcset="conic-dark.png" media="(prefers-color-scheme: dark)">
237 /// <img alt="Conic To" src="conic-light.png">
238 /// </picture>
239 /// ## `x1`
240 /// x coordinate of control point
241 /// ## `y1`
242 /// y coordinate of control point
243 /// ## `x2`
244 /// x coordinate of the end of the curve
245 /// ## `y2`
246 /// y coordinate of the end of the curve
247 /// ## `weight`
248 /// weight of the control point, must be non-negative
249 #[doc(alias = "gsk_path_builder_conic_to")]
250 pub fn conic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, weight: f32) {
251 unsafe {
252 ffi::gsk_path_builder_conic_to(self.to_glib_none().0, x1, y1, x2, y2, weight);
253 }
254 }
255
256 /// Adds a [cubic Bézier curve](https://en.wikipedia.org/wiki/B`C3``A9zier_curve`)
257 /// from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control
258 /// points.
259 ///
260 /// After this, @x3, @y3 will be the new current point.
261 ///
262 /// <picture>
263 /// <source srcset="cubic-dark.png" media="(prefers-color-scheme: dark)">
264 /// <img alt="Cubic To" src="cubic-light.png">
265 /// </picture>
266 /// ## `x1`
267 /// x coordinate of first control point
268 /// ## `y1`
269 /// y coordinate of first control point
270 /// ## `x2`
271 /// x coordinate of second control point
272 /// ## `y2`
273 /// y coordinate of second control point
274 /// ## `x3`
275 /// x coordinate of the end of the curve
276 /// ## `y3`
277 /// y coordinate of the end of the curve
278 #[doc(alias = "gsk_path_builder_cubic_to")]
279 pub fn cubic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32) {
280 unsafe {
281 ffi::gsk_path_builder_cubic_to(self.to_glib_none().0, x1, y1, x2, y2, x3, y3);
282 }
283 }
284
285 /// Gets the current point.
286 ///
287 /// The current point is used for relative drawing commands and
288 /// updated after every operation.
289 ///
290 /// When the builder is created, the default current point is set
291 /// to `0, 0`. Note that this is different from cairo, which starts
292 /// out without a current point.
293 ///
294 /// # Returns
295 ///
296 /// the current point
297 #[doc(alias = "gsk_path_builder_get_current_point")]
298 #[doc(alias = "get_current_point")]
299 pub fn current_point(&self) -> graphene::Point {
300 unsafe {
301 from_glib_none(ffi::gsk_path_builder_get_current_point(
302 self.to_glib_none().0,
303 ))
304 }
305 }
306
307 /// Implements arc-to according to the HTML Canvas spec.
308 ///
309 /// A convenience function that implements the
310 /// [HTML arc_to](https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-arcto-dev)
311 /// functionality.
312 ///
313 /// After this, the current point will be the point where
314 /// the circle with the given radius touches the line from
315 /// @x1, @y1 to @x2, @y2.
316 /// ## `x1`
317 /// x coordinate of first control point
318 /// ## `y1`
319 /// y coordinate of first control point
320 /// ## `x2`
321 /// x coordinate of second control point
322 /// ## `y2`
323 /// y coordinate of second control point
324 /// ## `radius`
325 /// radius of the circle
326 #[doc(alias = "gsk_path_builder_html_arc_to")]
327 pub fn html_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32) {
328 unsafe {
329 ffi::gsk_path_builder_html_arc_to(self.to_glib_none().0, x1, y1, x2, y2, radius);
330 }
331 }
332
333 /// Draws a line from the current point to @x, @y and makes it
334 /// the new current point.
335 ///
336 /// <picture>
337 /// <source srcset="line-dark.png" media="(prefers-color-scheme: dark)">
338 /// <img alt="Line To" src="line-light.png">
339 /// </picture>
340 /// ## `x`
341 /// x coordinate
342 /// ## `y`
343 /// y coordinate
344 #[doc(alias = "gsk_path_builder_line_to")]
345 pub fn line_to(&self, x: f32, y: f32) {
346 unsafe {
347 ffi::gsk_path_builder_line_to(self.to_glib_none().0, x, y);
348 }
349 }
350
351 /// Starts a new contour by placing the pen at @x, @y.
352 ///
353 /// If this function is called twice in succession, the first
354 /// call will result in a contour made up of a single point.
355 /// The second call will start a new contour.
356 /// ## `x`
357 /// x coordinate
358 /// ## `y`
359 /// y coordinate
360 #[doc(alias = "gsk_path_builder_move_to")]
361 pub fn move_to(&self, x: f32, y: f32) {
362 unsafe {
363 ffi::gsk_path_builder_move_to(self.to_glib_none().0, x, y);
364 }
365 }
366
367 /// Adds a [quadratic Bézier curve](https://en.wikipedia.org/wiki/B`C3``A9zier_curve`)
368 /// from the current point to @x2, @y2 with @x1, @y1 as the control point.
369 ///
370 /// After this, @x2, @y2 will be the new current point.
371 ///
372 /// <picture>
373 /// <source srcset="quad-dark.png" media="(prefers-color-scheme: dark)">
374 /// <img alt="Quad To" src="quad-light.png">
375 /// </picture>
376 /// ## `x1`
377 /// x coordinate of control point
378 /// ## `y1`
379 /// y coordinate of control point
380 /// ## `x2`
381 /// x coordinate of the end of the curve
382 /// ## `y2`
383 /// y coordinate of the end of the curve
384 #[doc(alias = "gsk_path_builder_quad_to")]
385 pub fn quad_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
386 unsafe {
387 ffi::gsk_path_builder_quad_to(self.to_glib_none().0, x1, y1, x2, y2);
388 }
389 }
390
391 /// Adds an elliptical arc from the current point to @x2, @y2
392 /// with @x1, @y1 determining the tangent directions.
393 ///
394 /// All coordinates are given relative to the current point.
395 ///
396 /// This is the relative version of [`arc_to()`][Self::arc_to()].
397 /// ## `x1`
398 /// x coordinate of first control point
399 /// ## `y1`
400 /// y coordinate of first control point
401 /// ## `x2`
402 /// x coordinate of second control point
403 /// ## `y2`
404 /// y coordinate of second control point
405 #[doc(alias = "gsk_path_builder_rel_arc_to")]
406 pub fn rel_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
407 unsafe {
408 ffi::gsk_path_builder_rel_arc_to(self.to_glib_none().0, x1, y1, x2, y2);
409 }
410 }
411
412 /// Adds a [conic curve](https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline)
413 /// from the current point to @x2, @y2 with the given @weight and @x1, @y1 as the
414 /// control point.
415 ///
416 /// All coordinates are given relative to the current point.
417 ///
418 /// This is the relative version of [`conic_to()`][Self::conic_to()].
419 /// ## `x1`
420 /// x offset of control point
421 /// ## `y1`
422 /// y offset of control point
423 /// ## `x2`
424 /// x offset of the end of the curve
425 /// ## `y2`
426 /// y offset of the end of the curve
427 /// ## `weight`
428 /// weight of the curve, must be non-negative
429 #[doc(alias = "gsk_path_builder_rel_conic_to")]
430 pub fn rel_conic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, weight: f32) {
431 unsafe {
432 ffi::gsk_path_builder_rel_conic_to(self.to_glib_none().0, x1, y1, x2, y2, weight);
433 }
434 }
435
436 /// Adds a [cubic Bézier curve](https://en.wikipedia.org/wiki/B`C3``A9zier_curve`)
437 /// from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control
438 /// points.
439 ///
440 /// All coordinates are given relative to the current point.
441 ///
442 /// This is the relative version of [`cubic_to()`][Self::cubic_to()].
443 /// ## `x1`
444 /// x offset of first control point
445 /// ## `y1`
446 /// y offset of first control point
447 /// ## `x2`
448 /// x offset of second control point
449 /// ## `y2`
450 /// y offset of second control point
451 /// ## `x3`
452 /// x offset of the end of the curve
453 /// ## `y3`
454 /// y offset of the end of the curve
455 #[doc(alias = "gsk_path_builder_rel_cubic_to")]
456 pub fn rel_cubic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32) {
457 unsafe {
458 ffi::gsk_path_builder_rel_cubic_to(self.to_glib_none().0, x1, y1, x2, y2, x3, y3);
459 }
460 }
461
462 /// Implements arc-to according to the HTML Canvas spec.
463 ///
464 /// All coordinates are given relative to the current point.
465 ///
466 /// This is the relative version of [`html_arc_to()`][Self::html_arc_to()].
467 /// ## `x1`
468 /// x coordinate of first control point
469 /// ## `y1`
470 /// y coordinate of first control point
471 /// ## `x2`
472 /// x coordinate of second control point
473 /// ## `y2`
474 /// y coordinate of second control point
475 /// ## `radius`
476 /// radius of the circle
477 #[doc(alias = "gsk_path_builder_rel_html_arc_to")]
478 pub fn rel_html_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32) {
479 unsafe {
480 ffi::gsk_path_builder_rel_html_arc_to(self.to_glib_none().0, x1, y1, x2, y2, radius);
481 }
482 }
483
484 /// Draws a line from the current point to a point offset from it
485 /// by @x, @y and makes it the new current point.
486 ///
487 /// This is the relative version of [`line_to()`][Self::line_to()].
488 /// ## `x`
489 /// x offset
490 /// ## `y`
491 /// y offset
492 #[doc(alias = "gsk_path_builder_rel_line_to")]
493 pub fn rel_line_to(&self, x: f32, y: f32) {
494 unsafe {
495 ffi::gsk_path_builder_rel_line_to(self.to_glib_none().0, x, y);
496 }
497 }
498
499 /// Starts a new contour by placing the pen at @x, @y
500 /// relative to the current point.
501 ///
502 /// This is the relative version of [`move_to()`][Self::move_to()].
503 /// ## `x`
504 /// x offset
505 /// ## `y`
506 /// y offset
507 #[doc(alias = "gsk_path_builder_rel_move_to")]
508 pub fn rel_move_to(&self, x: f32, y: f32) {
509 unsafe {
510 ffi::gsk_path_builder_rel_move_to(self.to_glib_none().0, x, y);
511 }
512 }
513
514 /// Adds a [quadratic Bézier curve](https://en.wikipedia.org/wiki/B`C3``A9zier_curve`)
515 /// from the current point to @x2, @y2 with @x1, @y1 the control point.
516 ///
517 /// All coordinates are given relative to the current point.
518 ///
519 /// This is the relative version of [`quad_to()`][Self::quad_to()].
520 /// ## `x1`
521 /// x offset of control point
522 /// ## `y1`
523 /// y offset of control point
524 /// ## `x2`
525 /// x offset of the end of the curve
526 /// ## `y2`
527 /// y offset of the end of the curve
528 #[doc(alias = "gsk_path_builder_rel_quad_to")]
529 pub fn rel_quad_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
530 unsafe {
531 ffi::gsk_path_builder_rel_quad_to(self.to_glib_none().0, x1, y1, x2, y2);
532 }
533 }
534
535 /// Implements arc-to according to the SVG spec.
536 ///
537 /// All coordinates are given relative to the current point.
538 ///
539 /// This is the relative version of [`svg_arc_to()`][Self::svg_arc_to()].
540 /// ## `rx`
541 /// x radius
542 /// ## `ry`
543 /// y radius
544 /// ## `x_axis_rotation`
545 /// the rotation of the ellipsis
546 /// ## `large_arc`
547 /// whether to add the large arc
548 /// ## `positive_sweep`
549 /// whether to sweep in the positive direction
550 /// ## `x`
551 /// x coordinate of the endpoint
552 /// ## `y`
553 /// y coordinate of the endpoint
554 #[doc(alias = "gsk_path_builder_rel_svg_arc_to")]
555 pub fn rel_svg_arc_to(
556 &self,
557 rx: f32,
558 ry: f32,
559 x_axis_rotation: f32,
560 large_arc: bool,
561 positive_sweep: bool,
562 x: f32,
563 y: f32,
564 ) {
565 unsafe {
566 ffi::gsk_path_builder_rel_svg_arc_to(
567 self.to_glib_none().0,
568 rx,
569 ry,
570 x_axis_rotation,
571 large_arc.into_glib(),
572 positive_sweep.into_glib(),
573 x,
574 y,
575 );
576 }
577 }
578
579 /// Implements arc-to according to the SVG spec.
580 ///
581 /// A convenience function that implements the
582 /// [SVG arc_to](https://www.w3.org/TR/SVG11/paths.html#PathDataEllipticalArcCommands)
583 /// functionality.
584 ///
585 /// After this, @x, @y will be the new current point.
586 /// ## `rx`
587 /// x radius
588 /// ## `ry`
589 /// y radius
590 /// ## `x_axis_rotation`
591 /// the rotation of the ellipsis
592 /// ## `large_arc`
593 /// whether to add the large arc
594 /// ## `positive_sweep`
595 /// whether to sweep in the positive direction
596 /// ## `x`
597 /// x coordinate of the endpoint
598 /// ## `y`
599 /// y coordinate of the endpoint
600 #[doc(alias = "gsk_path_builder_svg_arc_to")]
601 pub fn svg_arc_to(
602 &self,
603 rx: f32,
604 ry: f32,
605 x_axis_rotation: f32,
606 large_arc: bool,
607 positive_sweep: bool,
608 x: f32,
609 y: f32,
610 ) {
611 unsafe {
612 ffi::gsk_path_builder_svg_arc_to(
613 self.to_glib_none().0,
614 rx,
615 ry,
616 x_axis_rotation,
617 large_arc.into_glib(),
618 positive_sweep.into_glib(),
619 x,
620 y,
621 );
622 }
623 }
624
625 /// Creates a new path from the given builder.
626 ///
627 /// The given [`PathBuilder`][crate::PathBuilder] is reset to the initial state once this
628 /// function returns. Calling this function again on the same builder
629 /// instance will therefore produce an empty path, not a copy of the same
630 /// path.
631 ///
632 /// This function is intended primarily for language bindings.
633 /// C code should use `Gsk::PathBuilder::free_to_path()`.
634 ///
635 /// # Returns
636 ///
637 /// the newly created path
638 /// with all the contours added to the builder
639 #[doc(alias = "gsk_path_builder_to_path")]
640 pub fn to_path(&self) -> Path {
641 unsafe { from_glib_full(ffi::gsk_path_builder_to_path(self.to_glib_none().0)) }
642 }
643}
644
645#[cfg(feature = "v4_14")]
646#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
647impl Default for PathBuilder {
648 fn default() -> Self {
649 Self::new()
650 }
651}