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