gdk4/surface.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, prelude::*, Surface};
6
7// rustdoc-stripper-ignore-next
8/// Trait containing manually implemented methods of
9/// [`Surface`](crate::Surface).
10pub trait SurfaceExtManual: IsA<Surface> + 'static {
11 /// Create a new Cairo surface that is as compatible as possible with the
12 /// given @self.
13 ///
14 /// For example the new surface will have the same fallback resolution
15 /// and font options as @self. Generally, the new surface will also
16 /// use the same backend as @self, unless that is not possible for
17 /// some reason. The type of the returned surface may be examined with
18 /// cairo_surface_get_type().
19 ///
20 /// Initially the surface contents are all 0 (transparent if contents
21 /// have transparency, black otherwise.)
22 ///
23 /// This function always returns a valid pointer, but it will return a
24 /// pointer to a “nil” surface if @other is already in an error state
25 /// or any other error occurs.
26 ///
27 /// # Deprecated since 4.12
28 ///
29 /// Create a suitable cairo image surface yourself
30 /// ## `content`
31 /// the content for the new surface
32 /// ## `width`
33 /// width of the new surface
34 /// ## `height`
35 /// height of the new surface
36 ///
37 /// # Returns
38 ///
39 /// a pointer to the newly allocated surface. The caller
40 /// owns the surface and should call cairo_surface_destroy() when done
41 /// with it.
42 #[doc(alias = "gdk_surface_create_similar_surface")]
43 fn create_similar_surface(
44 &self,
45 content: cairo::Content,
46 width: i32,
47 height: i32,
48 ) -> cairo::Surface {
49 unsafe {
50 from_glib_full(ffi::gdk_surface_create_similar_surface(
51 self.as_ref().to_glib_none().0,
52 content.into(),
53 width,
54 height,
55 ))
56 }
57 }
58
59 // Returns true if the coordinates were successfully translated
60 /// Translates coordinates between two surfaces.
61 ///
62 /// Note that this only works if @to and @self are popups or
63 /// transient-for to the same toplevel (directly or indirectly).
64 /// ## `to`
65 /// the target surface
66 /// ## `x`
67 /// coordinates to translate
68 /// ## `y`
69 /// coordinates to translate
70 ///
71 /// # Returns
72 ///
73 /// [`true`] if the coordinates were successfully translated
74 #[doc(alias = "gdk_surface_translate_coordinates")]
75 fn translate_coordinates(&self, to: &Surface, mut x: f64, mut y: f64) -> bool {
76 unsafe {
77 from_glib(ffi::gdk_surface_translate_coordinates(
78 self.as_ref().to_glib_none().0,
79 to.to_glib_none().0,
80 &mut x,
81 &mut y,
82 ))
83 }
84 }
85}
86
87impl<O: IsA<Surface>> SurfaceExtManual for O {}