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 /// /picture
179 /// ## `x1`
180 /// x coordinate of first control point
181 /// ## `y1`
182 /// y coordinate of first control point
183 /// ## `x2`
184 /// x coordinate of second control point
185 /// ## `y2`
186 /// y coordinate of second control point
187 #[doc(alias = "gsk_path_builder_arc_to")]
188 pub fn arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
189 unsafe {
190 ffi::gsk_path_builder_arc_to(self.to_glib_none().0, x1, y1, x2, y2);
191 }
192 }
193
194 /// Ends the current contour with a line back to the start point.
195 ///
196 /// Note that this is different from calling [`line_to()`][Self::line_to()]
197 /// with the start point in that the contour will be closed. A closed
198 /// contour behaves differently from an open one. When stroking, its
199 /// start and end point are considered connected, so they will be
200 /// joined via the line join, and not ended with line caps.
201 #[doc(alias = "gsk_path_builder_close")]
202 pub fn close(&self) {
203 unsafe {
204 ffi::gsk_path_builder_close(self.to_glib_none().0);
205 }
206 }
207
208 /// /picture
209 /// ## `x1`
210 /// x coordinate of control point
211 /// ## `y1`
212 /// y coordinate of control point
213 /// ## `x2`
214 /// x coordinate of the end of the curve
215 /// ## `y2`
216 /// y coordinate of the end of the curve
217 /// ## `weight`
218 /// weight of the control point, must be greater than zero
219 #[doc(alias = "gsk_path_builder_conic_to")]
220 pub fn conic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, weight: f32) {
221 unsafe {
222 ffi::gsk_path_builder_conic_to(self.to_glib_none().0, x1, y1, x2, y2, weight);
223 }
224 }
225
226 /// /picture
227 /// ## `x1`
228 /// x coordinate of first control point
229 /// ## `y1`
230 /// y coordinate of first control point
231 /// ## `x2`
232 /// x coordinate of second control point
233 /// ## `y2`
234 /// y coordinate of second control point
235 /// ## `x3`
236 /// x coordinate of the end of the curve
237 /// ## `y3`
238 /// y coordinate of the end of the curve
239 #[doc(alias = "gsk_path_builder_cubic_to")]
240 pub fn cubic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32) {
241 unsafe {
242 ffi::gsk_path_builder_cubic_to(self.to_glib_none().0, x1, y1, x2, y2, x3, y3);
243 }
244 }
245
246 /// Gets the current point.
247 ///
248 /// The current point is used for relative drawing commands and
249 /// updated after every operation.
250 ///
251 /// When the builder is created, the default current point is set
252 /// to `0, 0`. Note that this is different from cairo, which starts
253 /// out without a current point.
254 ///
255 /// # Returns
256 ///
257 /// the current point
258 #[doc(alias = "gsk_path_builder_get_current_point")]
259 #[doc(alias = "get_current_point")]
260 pub fn current_point(&self) -> graphene::Point {
261 unsafe {
262 from_glib_none(ffi::gsk_path_builder_get_current_point(
263 self.to_glib_none().0,
264 ))
265 }
266 }
267
268 /// Implements arc-to according to the HTML Canvas spec.
269 ///
270 /// A convenience function that implements the
271 /// [HTML arc_to](https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-arcto-dev)
272 /// functionality.
273 ///
274 /// After this, the current point will be the point where
275 /// the circle with the given radius touches the line from
276 /// @x1, @y1 to @x2, @y2.
277 /// ## `x1`
278 /// x coordinate of first control point
279 /// ## `y1`
280 /// y coordinate of first control point
281 /// ## `x2`
282 /// x coordinate of second control point
283 /// ## `y2`
284 /// y coordinate of second control point
285 /// ## `radius`
286 /// radius of the circle
287 #[doc(alias = "gsk_path_builder_html_arc_to")]
288 pub fn html_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32) {
289 unsafe {
290 ffi::gsk_path_builder_html_arc_to(self.to_glib_none().0, x1, y1, x2, y2, radius);
291 }
292 }
293
294 /// /picture
295 /// ## `x`
296 /// x coordinate
297 /// ## `y`
298 /// y coordinate
299 #[doc(alias = "gsk_path_builder_line_to")]
300 pub fn line_to(&self, x: f32, y: f32) {
301 unsafe {
302 ffi::gsk_path_builder_line_to(self.to_glib_none().0, x, y);
303 }
304 }
305
306 /// Starts a new contour by placing the pen at @x, @y.
307 ///
308 /// If this function is called twice in succession, the first
309 /// call will result in a contour made up of a single point.
310 /// The second call will start a new contour.
311 /// ## `x`
312 /// x coordinate
313 /// ## `y`
314 /// y coordinate
315 #[doc(alias = "gsk_path_builder_move_to")]
316 pub fn move_to(&self, x: f32, y: f32) {
317 unsafe {
318 ffi::gsk_path_builder_move_to(self.to_glib_none().0, x, y);
319 }
320 }
321
322 /// /picture
323 /// ## `x1`
324 /// x coordinate of control point
325 /// ## `y1`
326 /// y coordinate of control point
327 /// ## `x2`
328 /// x coordinate of the end of the curve
329 /// ## `y2`
330 /// y coordinate of the end of the curve
331 #[doc(alias = "gsk_path_builder_quad_to")]
332 pub fn quad_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
333 unsafe {
334 ffi::gsk_path_builder_quad_to(self.to_glib_none().0, x1, y1, x2, y2);
335 }
336 }
337
338 /// Adds an elliptical arc from the current point to @x2, @y2
339 /// with @x1, @y1 determining the tangent directions.
340 ///
341 /// All coordinates are given relative to the current point.
342 ///
343 /// This is the relative version of [`arc_to()`][Self::arc_to()].
344 /// ## `x1`
345 /// x coordinate of first control point
346 /// ## `y1`
347 /// y coordinate of first control point
348 /// ## `x2`
349 /// x coordinate of second control point
350 /// ## `y2`
351 /// y coordinate of second control point
352 #[doc(alias = "gsk_path_builder_rel_arc_to")]
353 pub fn rel_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
354 unsafe {
355 ffi::gsk_path_builder_rel_arc_to(self.to_glib_none().0, x1, y1, x2, y2);
356 }
357 }
358
359 /// Adds a [conic curve](https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline)
360 /// from the current point to @x2, @y2 with the given @weight and @x1, @y1 as the
361 /// control point.
362 ///
363 /// All coordinates are given relative to the current point.
364 ///
365 /// This is the relative version of [`conic_to()`][Self::conic_to()].
366 /// ## `x1`
367 /// x offset of control point
368 /// ## `y1`
369 /// y offset of control point
370 /// ## `x2`
371 /// x offset of the end of the curve
372 /// ## `y2`
373 /// y offset of the end of the curve
374 /// ## `weight`
375 /// weight of the curve, must be greater than zero
376 #[doc(alias = "gsk_path_builder_rel_conic_to")]
377 pub fn rel_conic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, weight: f32) {
378 unsafe {
379 ffi::gsk_path_builder_rel_conic_to(self.to_glib_none().0, x1, y1, x2, y2, weight);
380 }
381 }
382
383 /// Adds a [cubic Bézier curve](https://en.wikipedia.org/wiki/B`C3``A9zier_curve`)
384 /// from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control
385 /// points.
386 ///
387 /// All coordinates are given relative to the current point.
388 ///
389 /// This is the relative version of [`cubic_to()`][Self::cubic_to()].
390 /// ## `x1`
391 /// x offset of first control point
392 /// ## `y1`
393 /// y offset of first control point
394 /// ## `x2`
395 /// x offset of second control point
396 /// ## `y2`
397 /// y offset of second control point
398 /// ## `x3`
399 /// x offset of the end of the curve
400 /// ## `y3`
401 /// y offset of the end of the curve
402 #[doc(alias = "gsk_path_builder_rel_cubic_to")]
403 pub fn rel_cubic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32) {
404 unsafe {
405 ffi::gsk_path_builder_rel_cubic_to(self.to_glib_none().0, x1, y1, x2, y2, x3, y3);
406 }
407 }
408
409 /// Implements arc-to according to the HTML Canvas spec.
410 ///
411 /// All coordinates are given relative to the current point.
412 ///
413 /// This is the relative version of [`html_arc_to()`][Self::html_arc_to()].
414 /// ## `x1`
415 /// x coordinate of first control point
416 /// ## `y1`
417 /// y coordinate of first control point
418 /// ## `x2`
419 /// x coordinate of second control point
420 /// ## `y2`
421 /// y coordinate of second control point
422 /// ## `radius`
423 /// radius of the circle
424 #[doc(alias = "gsk_path_builder_rel_html_arc_to")]
425 pub fn rel_html_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32) {
426 unsafe {
427 ffi::gsk_path_builder_rel_html_arc_to(self.to_glib_none().0, x1, y1, x2, y2, radius);
428 }
429 }
430
431 /// Draws a line from the current point to a point offset from it
432 /// by @x, @y and makes it the new current point.
433 ///
434 /// This is the relative version of [`line_to()`][Self::line_to()].
435 /// ## `x`
436 /// x offset
437 /// ## `y`
438 /// y offset
439 #[doc(alias = "gsk_path_builder_rel_line_to")]
440 pub fn rel_line_to(&self, x: f32, y: f32) {
441 unsafe {
442 ffi::gsk_path_builder_rel_line_to(self.to_glib_none().0, x, y);
443 }
444 }
445
446 /// Starts a new contour by placing the pen at @x, @y
447 /// relative to the current point.
448 ///
449 /// This is the relative version of [`move_to()`][Self::move_to()].
450 /// ## `x`
451 /// x offset
452 /// ## `y`
453 /// y offset
454 #[doc(alias = "gsk_path_builder_rel_move_to")]
455 pub fn rel_move_to(&self, x: f32, y: f32) {
456 unsafe {
457 ffi::gsk_path_builder_rel_move_to(self.to_glib_none().0, x, y);
458 }
459 }
460
461 /// Adds a [quadratic Bézier curve](https://en.wikipedia.org/wiki/B`C3``A9zier_curve`)
462 /// from the current point to @x2, @y2 with @x1, @y1 the control point.
463 ///
464 /// All coordinates are given relative to the current point.
465 ///
466 /// This is the relative version of [`quad_to()`][Self::quad_to()].
467 /// ## `x1`
468 /// x offset of control point
469 /// ## `y1`
470 /// y offset of control point
471 /// ## `x2`
472 /// x offset of the end of the curve
473 /// ## `y2`
474 /// y offset of the end of the curve
475 #[doc(alias = "gsk_path_builder_rel_quad_to")]
476 pub fn rel_quad_to(&self, x1: f32, y1: f32, x2: f32, y2: f32) {
477 unsafe {
478 ffi::gsk_path_builder_rel_quad_to(self.to_glib_none().0, x1, y1, x2, y2);
479 }
480 }
481
482 /// Implements arc-to according to the SVG spec.
483 ///
484 /// All coordinates are given relative to the current point.
485 ///
486 /// This is the relative version of [`svg_arc_to()`][Self::svg_arc_to()].
487 /// ## `rx`
488 /// x radius
489 /// ## `ry`
490 /// y radius
491 /// ## `x_axis_rotation`
492 /// the rotation of the ellipsis
493 /// ## `large_arc`
494 /// whether to add the large arc
495 /// ## `positive_sweep`
496 /// whether to sweep in the positive direction
497 /// ## `x`
498 /// x coordinate of the endpoint
499 /// ## `y`
500 /// y coordinate of the endpoint
501 #[doc(alias = "gsk_path_builder_rel_svg_arc_to")]
502 pub fn rel_svg_arc_to(
503 &self,
504 rx: f32,
505 ry: f32,
506 x_axis_rotation: f32,
507 large_arc: bool,
508 positive_sweep: bool,
509 x: f32,
510 y: f32,
511 ) {
512 unsafe {
513 ffi::gsk_path_builder_rel_svg_arc_to(
514 self.to_glib_none().0,
515 rx,
516 ry,
517 x_axis_rotation,
518 large_arc.into_glib(),
519 positive_sweep.into_glib(),
520 x,
521 y,
522 );
523 }
524 }
525
526 /// Implements arc-to according to the SVG spec.
527 ///
528 /// A convenience function that implements the
529 /// [SVG arc_to](https://www.w3.org/TR/SVG11/paths.html#PathDataEllipticalArcCommands)
530 /// functionality.
531 ///
532 /// After this, @x, @y will be the new current point.
533 /// ## `rx`
534 /// x radius
535 /// ## `ry`
536 /// y radius
537 /// ## `x_axis_rotation`
538 /// the rotation of the ellipsis
539 /// ## `large_arc`
540 /// whether to add the large arc
541 /// ## `positive_sweep`
542 /// whether to sweep in the positive direction
543 /// ## `x`
544 /// x coordinate of the endpoint
545 /// ## `y`
546 /// y coordinate of the endpoint
547 #[doc(alias = "gsk_path_builder_svg_arc_to")]
548 pub fn svg_arc_to(
549 &self,
550 rx: f32,
551 ry: f32,
552 x_axis_rotation: f32,
553 large_arc: bool,
554 positive_sweep: bool,
555 x: f32,
556 y: f32,
557 ) {
558 unsafe {
559 ffi::gsk_path_builder_svg_arc_to(
560 self.to_glib_none().0,
561 rx,
562 ry,
563 x_axis_rotation,
564 large_arc.into_glib(),
565 positive_sweep.into_glib(),
566 x,
567 y,
568 );
569 }
570 }
571
572 /// Creates a new path from the given builder.
573 ///
574 /// The given [`PathBuilder`][crate::PathBuilder] is reset to the initial state once this
575 /// function returns. Calling this function again on the same builder
576 /// instance will therefore produce an empty path, not a copy of the same
577 /// path.
578 ///
579 /// This function is intended primarily for language bindings.
580 /// C code should use `Gsk::PathBuilder::free_to_path()`.
581 ///
582 /// # Returns
583 ///
584 /// the newly created path
585 /// with all the contours added to the builder
586 #[doc(alias = "gsk_path_builder_to_path")]
587 pub fn to_path(&self) -> Path {
588 unsafe { from_glib_full(ffi::gsk_path_builder_to_path(self.to_glib_none().0)) }
589 }
590}
591
592#[cfg(feature = "v4_14")]
593#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
594impl Default for PathBuilder {
595 fn default() -> Self {
596 Self::new()
597 }
598}