gsk4/auto/transform.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::{TransformCategory, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// Describes a 3D transform.
10 ///
11 /// Unlike [`graphene::Matrix`][crate::graphene::Matrix], [`Transform`][crate::Transform] retains the steps in how
12 /// a transform was constructed, and allows inspecting them. It is modeled
13 /// after the way CSS describes transforms.
14 ///
15 /// [`Transform`][crate::Transform] objects are immutable and cannot be changed after creation.
16 /// This means code can safely expose them as properties of objects without
17 /// having to worry about others changing them.
18 #[derive(Debug, PartialOrd, Ord, Hash)]
19 pub struct Transform(Shared<ffi::GskTransform>);
20
21 match fn {
22 ref => |ptr| ffi::gsk_transform_ref(ptr),
23 unref => |ptr| ffi::gsk_transform_unref(ptr),
24 type_ => || ffi::gsk_transform_get_type(),
25 }
26}
27
28impl Transform {
29 /// Creates a new identity transform.
30 ///
31 /// This function is meant to be used by language
32 /// bindings. For C code, this is equivalent to using `NULL`.
33 ///
34 /// # Returns
35 ///
36 /// A new identity transform
37 #[doc(alias = "gsk_transform_new")]
38 pub fn new() -> Transform {
39 assert_initialized_main_thread!();
40 unsafe { from_glib_full(ffi::gsk_transform_new()) }
41 }
42
43 #[doc(alias = "gsk_transform_equal")]
44 fn equal(&self, second: &Transform) -> bool {
45 unsafe {
46 from_glib(ffi::gsk_transform_equal(
47 self.to_glib_none().0,
48 second.to_glib_none().0,
49 ))
50 }
51 }
52
53 /// Returns the category this transform belongs to.
54 ///
55 /// # Returns
56 ///
57 /// The category of the transform
58 #[doc(alias = "gsk_transform_get_category")]
59 #[doc(alias = "get_category")]
60 pub fn category(&self) -> TransformCategory {
61 unsafe { from_glib(ffi::gsk_transform_get_category(self.to_glib_none().0)) }
62 }
63
64 /// Multiplies @self with the given @matrix.
65 ///
66 /// This function consumes @self. Use `Gsk::Transform::ref()` first
67 /// if you want to keep it around.
68 /// ## `matrix`
69 /// the matrix to multiply @self with
70 ///
71 /// # Returns
72 ///
73 /// The new transform
74 #[doc(alias = "gsk_transform_matrix")]
75 #[must_use]
76 pub fn matrix(self, matrix: &graphene::Matrix) -> Transform {
77 unsafe {
78 from_glib_full(ffi::gsk_transform_matrix(
79 self.into_glib_ptr(),
80 matrix.to_glib_none().0,
81 ))
82 }
83 }
84
85 /// Applies a perspective projection transform.
86 ///
87 /// This transform scales points in X and Y based on their Z value,
88 /// scaling points with positive Z values away from the origin, and
89 /// those with negative Z values towards the origin. Points
90 /// on the z=0 plane are unchanged.
91 ///
92 /// This function consumes @self. Use `Gsk::Transform::ref()` first
93 /// if you want to keep it around.
94 /// ## `depth`
95 /// distance of the z=0 plane. Lower values give a more
96 /// flattened pyramid and therefore a more pronounced
97 /// perspective effect.
98 ///
99 /// # Returns
100 ///
101 /// The new transform
102 #[doc(alias = "gsk_transform_perspective")]
103 #[must_use]
104 pub fn perspective(self, depth: f32) -> Transform {
105 unsafe { from_glib_full(ffi::gsk_transform_perspective(self.into_glib_ptr(), depth)) }
106 }
107
108 /// = GSK_TRANSFORM_CATEGORY_2D
109 ///
110 /// to check.
111 ///
112 /// The returned values are a subset of the full 4x4 matrix that
113 /// is computed by [`to_matrix()`][Self::to_matrix()] and have the
114 /// following layout:
115 ///
116 /// ```text
117 /// | xx yx | | a b 0 |
118 /// | xy yy | = | c d 0 |
119 /// | dx dy | | tx ty 1 |
120 /// ```
121 ///
122 /// This function can be used to convert between a [`Transform`][crate::Transform]
123 /// and a matrix type from other 2D drawing libraries, in particular
124 /// Cairo.
125 ///
126 /// # Returns
127 ///
128 ///
129 /// ## `out_xx`
130 /// return location for the xx member
131 ///
132 /// ## `out_yx`
133 /// return location for the yx member
134 ///
135 /// ## `out_xy`
136 /// return location for the xy member
137 ///
138 /// ## `out_yy`
139 /// return location for the yy member
140 ///
141 /// ## `out_dx`
142 /// return location for the x0 member
143 ///
144 /// ## `out_dy`
145 /// return location for the y0 member
146 #[doc(alias = "gsk_transform_to_2d")]
147 pub fn to_2d(&self) -> (f32, f32, f32, f32, f32, f32) {
148 unsafe {
149 let mut out_xx = std::mem::MaybeUninit::uninit();
150 let mut out_yx = std::mem::MaybeUninit::uninit();
151 let mut out_xy = std::mem::MaybeUninit::uninit();
152 let mut out_yy = std::mem::MaybeUninit::uninit();
153 let mut out_dx = std::mem::MaybeUninit::uninit();
154 let mut out_dy = std::mem::MaybeUninit::uninit();
155 ffi::gsk_transform_to_2d(
156 self.to_glib_none().0,
157 out_xx.as_mut_ptr(),
158 out_yx.as_mut_ptr(),
159 out_xy.as_mut_ptr(),
160 out_yy.as_mut_ptr(),
161 out_dx.as_mut_ptr(),
162 out_dy.as_mut_ptr(),
163 );
164 (
165 out_xx.assume_init(),
166 out_yx.assume_init(),
167 out_xy.assume_init(),
168 out_yy.assume_init(),
169 out_dx.assume_init(),
170 out_dy.assume_init(),
171 )
172 }
173 }
174
175 /// = GSK_TRANSFORM_CATEGORY_2D
176 ///
177 /// to check.
178 ///
179 /// # Returns
180 ///
181 ///
182 /// ## `out_skew_x`
183 /// return location for the skew factor
184 /// in the x direction
185 ///
186 /// ## `out_skew_y`
187 /// return location for the skew factor
188 /// in the y direction
189 ///
190 /// ## `out_scale_x`
191 /// return location for the scale
192 /// factor in the x direction
193 ///
194 /// ## `out_scale_y`
195 /// return location for the scale
196 /// factor in the y direction
197 ///
198 /// ## `out_angle`
199 /// return location for the rotation angle
200 ///
201 /// ## `out_dx`
202 /// return location for the translation
203 /// in the x direction
204 ///
205 /// ## `out_dy`
206 /// return location for the translation
207 /// in the y direction
208 #[cfg(feature = "v4_6")]
209 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
210 #[doc(alias = "gsk_transform_to_2d_components")]
211 pub fn to_2d_components(&self) -> (f32, f32, f32, f32, f32, f32, f32) {
212 unsafe {
213 let mut out_skew_x = std::mem::MaybeUninit::uninit();
214 let mut out_skew_y = std::mem::MaybeUninit::uninit();
215 let mut out_scale_x = std::mem::MaybeUninit::uninit();
216 let mut out_scale_y = std::mem::MaybeUninit::uninit();
217 let mut out_angle = std::mem::MaybeUninit::uninit();
218 let mut out_dx = std::mem::MaybeUninit::uninit();
219 let mut out_dy = std::mem::MaybeUninit::uninit();
220 ffi::gsk_transform_to_2d_components(
221 self.to_glib_none().0,
222 out_skew_x.as_mut_ptr(),
223 out_skew_y.as_mut_ptr(),
224 out_scale_x.as_mut_ptr(),
225 out_scale_y.as_mut_ptr(),
226 out_angle.as_mut_ptr(),
227 out_dx.as_mut_ptr(),
228 out_dy.as_mut_ptr(),
229 );
230 (
231 out_skew_x.assume_init(),
232 out_skew_y.assume_init(),
233 out_scale_x.assume_init(),
234 out_scale_y.assume_init(),
235 out_angle.assume_init(),
236 out_dx.assume_init(),
237 out_dy.assume_init(),
238 )
239 }
240 }
241
242 /// = GSK_TRANSFORM_CATEGORY_2D_AFFINE
243 ///
244 /// to check.
245 ///
246 /// # Returns
247 ///
248 ///
249 /// ## `out_scale_x`
250 /// return location for the scale
251 /// factor in the x direction
252 ///
253 /// ## `out_scale_y`
254 /// return location for the scale
255 /// factor in the y direction
256 ///
257 /// ## `out_dx`
258 /// return location for the translation
259 /// in the x direction
260 ///
261 /// ## `out_dy`
262 /// return location for the translation
263 /// in the y direction
264 #[doc(alias = "gsk_transform_to_affine")]
265 pub fn to_affine(&self) -> (f32, f32, f32, f32) {
266 unsafe {
267 let mut out_scale_x = std::mem::MaybeUninit::uninit();
268 let mut out_scale_y = std::mem::MaybeUninit::uninit();
269 let mut out_dx = std::mem::MaybeUninit::uninit();
270 let mut out_dy = std::mem::MaybeUninit::uninit();
271 ffi::gsk_transform_to_affine(
272 self.to_glib_none().0,
273 out_scale_x.as_mut_ptr(),
274 out_scale_y.as_mut_ptr(),
275 out_dx.as_mut_ptr(),
276 out_dy.as_mut_ptr(),
277 );
278 (
279 out_scale_x.assume_init(),
280 out_scale_y.assume_init(),
281 out_dx.assume_init(),
282 out_dy.assume_init(),
283 )
284 }
285 }
286
287 /// Computes the 4x4 matrix for the transform.
288 ///
289 /// The previous value of @out_matrix will be ignored.
290 ///
291 /// # Returns
292 ///
293 ///
294 /// ## `out_matrix`
295 /// return location for the matrix
296 #[doc(alias = "gsk_transform_to_matrix")]
297 pub fn to_matrix(&self) -> graphene::Matrix {
298 unsafe {
299 let mut out_matrix = graphene::Matrix::uninitialized();
300 ffi::gsk_transform_to_matrix(self.to_glib_none().0, out_matrix.to_glib_none_mut().0);
301 out_matrix
302 }
303 }
304
305 /// Converts the transform into a human-readable string.
306 ///
307 /// The resulting string can be parsed with [`parse()`][Self::parse()].
308 ///
309 /// This is a wrapper around `Gsk::Transform::print()`.
310 ///
311 /// # Returns
312 ///
313 /// A new string for @self
314 #[doc(alias = "gsk_transform_to_string")]
315 #[doc(alias = "to_string")]
316 pub fn to_str(&self) -> glib::GString {
317 unsafe { from_glib_full(ffi::gsk_transform_to_string(self.to_glib_none().0)) }
318 }
319
320 /// = GSK_TRANSFORM_CATEGORY_2D_TRANSLATE
321 ///
322 /// to check.
323 ///
324 /// # Returns
325 ///
326 ///
327 /// ## `out_dx`
328 /// return location for the translation
329 /// in the x direction
330 ///
331 /// ## `out_dy`
332 /// return location for the translation
333 /// in the y direction
334 #[doc(alias = "gsk_transform_to_translate")]
335 pub fn to_translate(&self) -> (f32, f32) {
336 unsafe {
337 let mut out_dx = std::mem::MaybeUninit::uninit();
338 let mut out_dy = std::mem::MaybeUninit::uninit();
339 ffi::gsk_transform_to_translate(
340 self.to_glib_none().0,
341 out_dx.as_mut_ptr(),
342 out_dy.as_mut_ptr(),
343 );
344 (out_dx.assume_init(), out_dy.assume_init())
345 }
346 }
347
348 /// Transforms a rectangle using the given transform.
349 ///
350 /// The result is the bounding box containing the coplanar quad.
351 ///
352 /// The input and output rect may point to the same rectangle.
353 /// ## `rect`
354 /// the rectangle to transform
355 ///
356 /// # Returns
357 ///
358 ///
359 /// ## `out_rect`
360 /// return location for the bounds
361 /// of the transformed rectangle
362 #[doc(alias = "gsk_transform_transform_bounds")]
363 pub fn transform_bounds(&self, rect: &graphene::Rect) -> graphene::Rect {
364 unsafe {
365 let mut out_rect = graphene::Rect::uninitialized();
366 ffi::gsk_transform_transform_bounds(
367 self.to_glib_none().0,
368 rect.to_glib_none().0,
369 out_rect.to_glib_none_mut().0,
370 );
371 out_rect
372 }
373 }
374
375 /// Transforms a point using the given transform.
376 /// ## `point`
377 /// the point to transform
378 ///
379 /// # Returns
380 ///
381 ///
382 /// ## `out_point`
383 /// return location for
384 /// the transformed point
385 #[doc(alias = "gsk_transform_transform_point")]
386 pub fn transform_point(&self, point: &graphene::Point) -> graphene::Point {
387 unsafe {
388 let mut out_point = graphene::Point::uninitialized();
389 ffi::gsk_transform_transform_point(
390 self.to_glib_none().0,
391 point.to_glib_none().0,
392 out_point.to_glib_none_mut().0,
393 );
394 out_point
395 }
396 }
397}
398
399impl Default for Transform {
400 fn default() -> Self {
401 Self::new()
402 }
403}
404
405impl PartialEq for Transform {
406 #[inline]
407 fn eq(&self, other: &Self) -> bool {
408 self.equal(other)
409 }
410}
411
412impl Eq for Transform {}
413
414impl std::fmt::Display for Transform {
415 #[inline]
416 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
417 f.write_str(&self.to_str())
418 }
419}