Skip to main content

gdk/auto/
cursor.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::{CursorType, Display, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A [`Cursor`][crate::Cursor] represents a cursor. Its contents are private.
10    ///
11    /// This is an Abstract Base Class, you cannot instantiate it.
12    ///
13    /// ## Properties
14    ///
15    ///
16    /// #### `cursor-type`
17    ///  Readable | Writable | Construct Only
18    ///
19    ///
20    /// #### `display`
21    ///  Readable | Writable | Construct Only
22    #[doc(alias = "GdkCursor")]
23    pub struct Cursor(Object<ffi::GdkCursor>);
24
25    match fn {
26        type_ => || ffi::gdk_cursor_get_type(),
27    }
28}
29
30impl Cursor {
31    /// Creates a new cursor from the set of builtin cursors.
32    /// ## `display`
33    /// the [`Display`][crate::Display] for which the cursor will be created
34    /// ## `cursor_type`
35    /// cursor to create
36    ///
37    /// # Returns
38    ///
39    /// a new [`Cursor`][crate::Cursor], or [`None`] on failure
40    #[doc(alias = "gdk_cursor_new_for_display")]
41    #[doc(alias = "new_for_display")]
42    pub fn for_display(display: &Display, cursor_type: CursorType) -> Option<Cursor> {
43        skip_assert_initialized!();
44        unsafe {
45            from_glib_full(ffi::gdk_cursor_new_for_display(
46                display.to_glib_none().0,
47                cursor_type.into_glib(),
48            ))
49        }
50    }
51
52    /// Creates a new cursor by looking up `name` in the current cursor
53    /// theme.
54    ///
55    /// A recommended set of cursor names that will work across different
56    /// platforms can be found in the CSS specification:
57    /// - "none"
58    /// - ![](default_cursor.png) "default"
59    /// - ![](help_cursor.png) "help"
60    /// - ![](pointer_cursor.png) "pointer"
61    /// - ![](context_menu_cursor.png) "context-menu"
62    /// - ![](progress_cursor.png) "progress"
63    /// - ![](wait_cursor.png) "wait"
64    /// - ![](cell_cursor.png) "cell"
65    /// - ![](crosshair_cursor.png) "crosshair"
66    /// - ![](text_cursor.png) "text"
67    /// - ![](vertical_text_cursor.png) "vertical-text"
68    /// - ![](alias_cursor.png) "alias"
69    /// - ![](copy_cursor.png) "copy"
70    /// - ![](no_drop_cursor.png) "no-drop"
71    /// - ![](move_cursor.png) "move"
72    /// - ![](not_allowed_cursor.png) "not-allowed"
73    /// - ![](grab_cursor.png) "grab"
74    /// - ![](grabbing_cursor.png) "grabbing"
75    /// - ![](all_scroll_cursor.png) "all-scroll"
76    /// - ![](col_resize_cursor.png) "col-resize"
77    /// - ![](row_resize_cursor.png) "row-resize"
78    /// - ![](n_resize_cursor.png) "n-resize"
79    /// - ![](e_resize_cursor.png) "e-resize"
80    /// - ![](s_resize_cursor.png) "s-resize"
81    /// - ![](w_resize_cursor.png) "w-resize"
82    /// - ![](ne_resize_cursor.png) "ne-resize"
83    /// - ![](nw_resize_cursor.png) "nw-resize"
84    /// - ![](sw_resize_cursor.png) "sw-resize"
85    /// - ![](se_resize_cursor.png) "se-resize"
86    /// - ![](ew_resize_cursor.png) "ew-resize"
87    /// - ![](ns_resize_cursor.png) "ns-resize"
88    /// - ![](nesw_resize_cursor.png) "nesw-resize"
89    /// - ![](nwse_resize_cursor.png) "nwse-resize"
90    /// - ![](zoom_in_cursor.png) "zoom-in"
91    /// - ![](zoom_out_cursor.png) "zoom-out"
92    ///
93    /// Additionally, the following cursor names are supported, which are
94    /// not in the CSS specification:
95    /// - ![](dnd_ask_cursor.png) "dnd-ask"
96    /// - ![](all_resize_cursor.png) "all-resize"
97    /// ## `display`
98    /// the [`Display`][crate::Display] for which the cursor will be created
99    /// ## `name`
100    /// the name of the cursor
101    ///
102    /// # Returns
103    ///
104    /// a new [`Cursor`][crate::Cursor], or [`None`] if there is no
105    ///  cursor with the given name
106    #[doc(alias = "gdk_cursor_new_from_name")]
107    #[doc(alias = "new_from_name")]
108    pub fn from_name(display: &Display, name: &str) -> Option<Cursor> {
109        skip_assert_initialized!();
110        unsafe {
111            from_glib_full(ffi::gdk_cursor_new_from_name(
112                display.to_glib_none().0,
113                name.to_glib_none().0,
114            ))
115        }
116    }
117
118    /// Creates a new cursor from a pixbuf.
119    ///
120    /// Not all GDK backends support RGBA cursors. If they are not
121    /// supported, a monochrome approximation will be displayed.
122    /// The functions [`Display::supports_cursor_alpha()`][crate::Display::supports_cursor_alpha()] and
123    /// [`Display::supports_cursor_color()`][crate::Display::supports_cursor_color()] can be used to determine
124    /// whether RGBA cursors are supported;
125    /// [`Display::default_cursor_size()`][crate::Display::default_cursor_size()] and
126    /// [`Display::maximal_cursor_size()`][crate::Display::maximal_cursor_size()] give information about
127    /// cursor sizes.
128    ///
129    /// If `x` or `y` are `-1`, the pixbuf must have
130    /// options named “x_hot” and “y_hot”, resp., containing
131    /// integer values between `0` and the width resp. height of
132    /// the pixbuf. (Since: 3.0)
133    ///
134    /// On the X backend, support for RGBA cursors requires a
135    /// sufficently new version of the X Render extension.
136    /// ## `display`
137    /// the [`Display`][crate::Display] for which the cursor will be created
138    /// ## `pixbuf`
139    /// the [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] containing the cursor image
140    /// ## `x`
141    /// the horizontal offset of the “hotspot” of the cursor.
142    /// ## `y`
143    /// the vertical offset of the “hotspot” of the cursor.
144    ///
145    /// # Returns
146    ///
147    /// a new [`Cursor`][crate::Cursor].
148    #[doc(alias = "gdk_cursor_new_from_pixbuf")]
149    #[doc(alias = "new_from_pixbuf")]
150    pub fn from_pixbuf(display: &Display, pixbuf: &gdk_pixbuf::Pixbuf, x: i32, y: i32) -> Cursor {
151        skip_assert_initialized!();
152        unsafe {
153            from_glib_full(ffi::gdk_cursor_new_from_pixbuf(
154                display.to_glib_none().0,
155                pixbuf.to_glib_none().0,
156                x,
157                y,
158            ))
159        }
160    }
161
162    /// Creates a new cursor from a cairo image surface.
163    ///
164    /// Not all GDK backends support RGBA cursors. If they are not
165    /// supported, a monochrome approximation will be displayed.
166    /// The functions [`Display::supports_cursor_alpha()`][crate::Display::supports_cursor_alpha()] and
167    /// [`Display::supports_cursor_color()`][crate::Display::supports_cursor_color()] can be used to determine
168    /// whether RGBA cursors are supported;
169    /// [`Display::default_cursor_size()`][crate::Display::default_cursor_size()] and
170    /// [`Display::maximal_cursor_size()`][crate::Display::maximal_cursor_size()] give information about
171    /// cursor sizes.
172    ///
173    /// On the X backend, support for RGBA cursors requires a
174    /// sufficently new version of the X Render extension.
175    /// ## `display`
176    /// the [`Display`][crate::Display] for which the cursor will be created
177    /// ## `surface`
178    /// the cairo image surface containing the cursor pixel data
179    /// ## `x`
180    /// the horizontal offset of the “hotspot” of the cursor
181    /// ## `y`
182    /// the vertical offset of the “hotspot” of the cursor
183    ///
184    /// # Returns
185    ///
186    /// a new [`Cursor`][crate::Cursor].
187    #[doc(alias = "gdk_cursor_new_from_surface")]
188    #[doc(alias = "new_from_surface")]
189    pub fn from_surface(display: &Display, surface: &cairo::Surface, x: f64, y: f64) -> Cursor {
190        skip_assert_initialized!();
191        unsafe {
192            from_glib_full(ffi::gdk_cursor_new_from_surface(
193                display.to_glib_none().0,
194                mut_override(surface.to_glib_none().0),
195                x,
196                y,
197            ))
198        }
199    }
200
201    /// Returns the cursor type for this cursor.
202    ///
203    /// # Returns
204    ///
205    /// a [`CursorType`][crate::CursorType]
206    #[doc(alias = "gdk_cursor_get_cursor_type")]
207    #[doc(alias = "get_cursor_type")]
208    #[doc(alias = "cursor-type")]
209    pub fn cursor_type(&self) -> CursorType {
210        unsafe { from_glib(ffi::gdk_cursor_get_cursor_type(self.to_glib_none().0)) }
211    }
212
213    /// Returns the display on which the [`Cursor`][crate::Cursor] is defined.
214    ///
215    /// # Returns
216    ///
217    /// the [`Display`][crate::Display] associated to `self`
218    #[doc(alias = "gdk_cursor_get_display")]
219    #[doc(alias = "get_display")]
220    pub fn display(&self) -> Display {
221        unsafe { from_glib_none(ffi::gdk_cursor_get_display(self.to_glib_none().0)) }
222    }
223
224    /// Returns a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] with the image used to display the cursor.
225    ///
226    /// Note that depending on the capabilities of the windowing system and
227    /// on the cursor, GDK may not be able to obtain the image data. In this
228    /// case, [`None`] is returned.
229    ///
230    /// # Returns
231    ///
232    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] representing
233    ///  `self`, or [`None`]
234    #[doc(alias = "gdk_cursor_get_image")]
235    #[doc(alias = "get_image")]
236    pub fn image(&self) -> Option<gdk_pixbuf::Pixbuf> {
237        unsafe { from_glib_full(ffi::gdk_cursor_get_image(self.to_glib_none().0)) }
238    }
239
240    /// Returns a cairo image surface with the image used to display the cursor.
241    ///
242    /// Note that depending on the capabilities of the windowing system and
243    /// on the cursor, GDK may not be able to obtain the image data. In this
244    /// case, [`None`] is returned.
245    ///
246    /// # Returns
247    ///
248    /// a [`cairo::Surface`][crate::cairo::Surface]
249    ///  representing `self`, or [`None`]
250    ///
251    /// ## `x_hot`
252    /// Location to store the hotspot x position,
253    ///  or [`None`]
254    ///
255    /// ## `y_hot`
256    /// Location to store the hotspot y position,
257    ///  or [`None`]
258    #[doc(alias = "gdk_cursor_get_surface")]
259    #[doc(alias = "get_surface")]
260    pub fn surface(&self) -> (Option<cairo::Surface>, f64, f64) {
261        unsafe {
262            let mut x_hot = std::mem::MaybeUninit::uninit();
263            let mut y_hot = std::mem::MaybeUninit::uninit();
264            let ret = from_glib_full(ffi::gdk_cursor_get_surface(
265                self.to_glib_none().0,
266                x_hot.as_mut_ptr(),
267                y_hot.as_mut_ptr(),
268            ));
269            (ret, x_hot.assume_init(), y_hot.assume_init())
270        }
271    }
272}