Skip to main content

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