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::{ffi, Path, PathPoint, RoundedRect};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// An auxiliary object for constructing [`Path`][crate::Path] objects.
10 ///
11 /// A path is constructed like this:
12 ///
13 ///
14 ///
15 /// **⚠️ The following code is in C ⚠️**
16 ///
17 /// ```C
18 /// GskPath *
19 /// construct_path (void)
20 /// {
21 /// GskPathBuilder *builder;
22 ///
23 /// builder = gsk_path_builder_new ();
24 ///
25 /// // add contours to the path here
26 ///
27 /// return gsk_path_builder_free_to_path (builder);
28 /// ```
29 ///
30 /// Adding contours to the path can be done in two ways.
31 /// The easiest option is to use the `gsk_path_builder_add_*` group
32 /// of functions that add predefined contours to the current path,
33 /// either common shapes like [`add_circle()`][Self::add_circle()]
34 /// or by adding from other paths like [`add_path()`][Self::add_path()].
35 ///
36 /// The `gsk_path_builder_add_*` methods always add complete contours,
37 /// and do not use or modify the current point.
38 ///
39 /// The other option is to define each line and curve manually with
40 /// the `gsk_path_builder_*_to` group of functions. You start with
41 /// a call to [`move_to()`][Self::move_to()] to set the starting point
42 /// and then use multiple calls to any of the drawing functions to
43 /// move the pen along the plane. Once you are done, you can call
44 /// [`close()`][Self::close()] to close the path by connecting it
45 /// back with a line to the starting point.
46 ///
47 /// This is similar to how paths are drawn in Cairo.
48 ///
49 /// Note that [`PathBuilder`][crate::PathBuilder] will reduce the degree of added Bézier
50 /// curves as much as possible, to simplify rendering.
51 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
52 pub struct PathBuilder(Shared<ffi::GskPathBuilder>);
53
54 match fn {
55 ref => |ptr| ffi::gsk_path_builder_ref(ptr),
56 unref => |ptr| ffi::gsk_path_builder_unref(ptr),
57 type_ => || ffi::gsk_path_builder_get_type(),
58 }
59}
60
61impl PathBuilder {
62 /// Create a new [`PathBuilder`][crate::PathBuilder] object.
63 ///
64 /// The resulting builder would create an empty [`Path`][crate::Path].
65 /// Use addition functions to add types to it.
66 ///
67 /// # Returns
68 ///
69 /// a new [`PathBuilder`][crate::PathBuilder]
70 #[doc(alias = "gsk_path_builder_new")]
71 pub fn new() -> PathBuilder {
72 assert_initialized_main_thread!();
73 unsafe { from_glib_full(ffi::gsk_path_builder_new()) }
74 }
75
76 /// Adds a circle as a new contour.
77 ///
78 /// The path is going around the circle in clockwise direction.
79 ///
80 /// If @radius is zero, the contour will be a closed point.
81 /// ## `center`
82 /// the center of the circle
83 /// ## `radius`
84 /// the radius of the circle
85 #[doc(alias = "gsk_path_builder_add_circle")]
86 pub fn add_circle(&self, center: &graphene::Point, radius: f32) {
87 unsafe {
88 ffi::gsk_path_builder_add_circle(
89 self.to_glib_none().0,
90 center.to_glib_none().0,
91 radius,
92 );
93 }
94 }
95
96 /// Adds the outlines for the glyphs in @layout to the builder.
97 /// ## `layout`
98 /// the pango layout to add
99 #[doc(alias = "gsk_path_builder_add_layout")]
100 pub fn add_layout(&self, layout: &pango::Layout) {
101 unsafe {
102 ffi::gsk_path_builder_add_layout(self.to_glib_none().0, layout.to_glib_none().0);
103 }
104 }
105
106 /// Appends all of @path to the builder.
107 /// ## `path`
108 /// the path to append
109 #[doc(alias = "gsk_path_builder_add_path")]
110 pub fn add_path(&self, path: &Path) {
111 unsafe {
112 ffi::gsk_path_builder_add_path(self.to_glib_none().0, path.to_glib_none().0);
113 }
114 }
115
116 /// Adds a rectangle as a new contour.
117 ///
118 /// The path is going around the rectangle in clockwise direction.
119 ///
120 /// If the the width or height are 0, the path will be a closed
121 /// horizontal or vertical line. If both are 0, it'll be a closed dot.
122 /// ## `rect`
123 /// the rectangle to create a path for
124 #[doc(alias = "gsk_path_builder_add_rect")]
125 pub fn add_rect(&self, rect: &graphene::Rect) {
126 unsafe {
127 ffi::gsk_path_builder_add_rect(self.to_glib_none().0, rect.to_glib_none().0);
128 }
129 }
130
131 /// Appends all of @path to the builder, in reverse order.
132 /// ## `path`
133 /// the path to append
134 #[doc(alias = "gsk_path_builder_add_reverse_path")]
135 pub fn add_reverse_path(&self, path: &Path) {
136 unsafe {
137 ffi::gsk_path_builder_add_reverse_path(self.to_glib_none().0, path.to_glib_none().0);
138 }
139 }
140
141 /// Adds a rounded rectangle as a new contour.
142 ///
143 /// The path is going around the rectangle in clockwise direction.
144 /// ## `rect`
145 /// the rounded rect
146 #[doc(alias = "gsk_path_builder_add_rounded_rect")]
147 pub fn add_rounded_rect(&self, rect: &RoundedRect) {
148 unsafe {
149 ffi::gsk_path_builder_add_rounded_rect(self.to_glib_none().0, rect.to_glib_none().0);
150 }
151 }
152
153 /// Adds a segment of a path to the builder.
154 ///
155 /// If @start is equal to or after @end, the path will first add the
156 /// segment from @start to the end of the path, and then add the segment
157 /// from the beginning to @end. If the path is closed, these segments
158 /// will be connected.
159 ///
160 /// Note that this method always adds a path with the given start point
161 /// and end point. To add a closed path, use [`add_path()`][Self::add_path()].
162 /// ## `path`
163 /// the path to take the segment to
164 /// ## `start`
165 /// the point on @path to start at
166 /// ## `end`
167 /// the point on @path to end at
168 #[doc(alias = "gsk_path_builder_add_segment")]
169 pub fn add_segment(&self, path: &Path, start: &PathPoint, end: &PathPoint) {
170 unsafe {
171 ffi::gsk_path_builder_add_segment(
172 self.to_glib_none().0,
173 path.to_glib_none().0,
174 start.to_glib_none().0,
175 end.to_glib_none().0,
176 );
177 }
178 }
179
180 /// Adds an elliptical arc from the current point to @x2, @y2
181 /// with @x1, @y1 determining the tangent directions.
182 ///
183 /// After this, @x2, @y2 will be the new current point.
184 ///
185 /// Note: Two points and their tangents do not determine
186 /// a unique ellipse, so GSK just picks one. If you need more
187 /// precise control, use [`conic_to()`][Self::conic_to()]
188 /// or [`svg_arc_to()`][Self::svg_arc_to()].
189 ///
190 /// <picture>
191 /// <source srcset="arc-dark.png" media="(prefers-color-scheme: dark)">
192 /// <img alt="Arc To" src="arc-light.png">
193 /// </picture>
194 /// ## `x1`
195 /// x coordinate of first control point
196 /// ## `y1`
197 /// y coordinate of first control point
198 /// ## `x2`
199 /// x coordinate of second control point
200 /// ## `y2`
201 /// y coordinate of second control point
202 #[doc(alias = "gsk_path_builder_arc_to")]
203 pub fn arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
204 unsafe {
205 ffi::gsk_path_builder_arc_to(self.to_glib_none().0, x1, y1, x2, y2);
206 }
207 }
208
209 /// Ends the current contour with a line back to the start point.
210 ///
211 /// Note that this is different from calling [`line_to()`][Self::line_to()]
212 /// with the start point in that the contour will be closed. A closed
213 /// contour behaves differently from an open one. When stroking, its
214 /// start and end point are considered connected, so they will be
215 /// joined via the line join, and not ended with line caps.
216 #[doc(alias = "gsk_path_builder_close")]
217 pub fn close(&self) {
218 unsafe {
219 ffi::gsk_path_builder_close(self.to_glib_none().0);
220 }
221 }
222
223 /// Adds a [conic curve](https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline)
224 /// from the current point to @x2, @y2 with the given @weight and @x1, @y1 as the
225 /// control point.
226 ///
227 /// The weight determines how strongly the curve is pulled towards the control point.
228 /// A conic with weight 1 is identical to a quadratic Bézier curve with the same points.
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 greater than zero
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 greater than zero
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 once this function returns;
628 /// you cannot call this function multiple times on the same builder
629 /// instance.
630 ///
631 /// This function is intended primarily for language bindings.
632 /// C code should use `Gsk::PathBuilder::free_to_path()`.
633 ///
634 /// # Returns
635 ///
636 /// the newly created path
637 /// with all the contours added to the builder
638 #[doc(alias = "gsk_path_builder_to_path")]
639 pub fn to_path(&self) -> Path {
640 unsafe { from_glib_full(ffi::gsk_path_builder_to_path(self.to_glib_none().0)) }
641 }
642}
643
644#[cfg(feature = "v4_14")]
645#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
646impl Default for PathBuilder {
647 fn default() -> Self {
648 Self::new()
649 }
650}