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 cairo;
6use gdk_pixbuf;
7use gdk_sys;
8use glib::translate::*;
9use std::fmt;
10use std::mem;
11use CursorType;
12use Display;
13
14glib_wrapper! {
15    pub struct Cursor(Object<gdk_sys::GdkCursor, CursorClass>);
16
17    match fn {
18        get_type => || gdk_sys::gdk_cursor_get_type(),
19    }
20}
21
22impl Cursor {
23    #[cfg_attr(feature = "v3_16", deprecated)]
24    pub fn new(cursor_type: CursorType) -> Cursor {
25        assert_initialized_main_thread!();
26        unsafe { from_glib_full(gdk_sys::gdk_cursor_new(cursor_type.to_glib())) }
27    }
28
29    pub fn new_for_display(display: &Display, cursor_type: CursorType) -> Cursor {
30        skip_assert_initialized!();
31        unsafe {
32            from_glib_full(gdk_sys::gdk_cursor_new_for_display(
33                display.to_glib_none().0,
34                cursor_type.to_glib(),
35            ))
36        }
37    }
38
39    pub fn new_from_name(display: &Display, name: &str) -> Option<Cursor> {
40        skip_assert_initialized!();
41        unsafe {
42            from_glib_full(gdk_sys::gdk_cursor_new_from_name(
43                display.to_glib_none().0,
44                name.to_glib_none().0,
45            ))
46        }
47    }
48
49    pub fn new_from_pixbuf(
50        display: &Display,
51        pixbuf: &gdk_pixbuf::Pixbuf,
52        x: i32,
53        y: i32,
54    ) -> Cursor {
55        skip_assert_initialized!();
56        unsafe {
57            from_glib_full(gdk_sys::gdk_cursor_new_from_pixbuf(
58                display.to_glib_none().0,
59                pixbuf.to_glib_none().0,
60                x,
61                y,
62            ))
63        }
64    }
65
66    pub fn new_from_surface(display: &Display, surface: &cairo::Surface, x: f64, y: f64) -> Cursor {
67        skip_assert_initialized!();
68        unsafe {
69            from_glib_full(gdk_sys::gdk_cursor_new_from_surface(
70                display.to_glib_none().0,
71                mut_override(surface.to_glib_none().0),
72                x,
73                y,
74            ))
75        }
76    }
77
78    pub fn get_cursor_type(&self) -> CursorType {
79        unsafe { from_glib(gdk_sys::gdk_cursor_get_cursor_type(self.to_glib_none().0)) }
80    }
81
82    pub fn get_display(&self) -> Display {
83        unsafe { from_glib_none(gdk_sys::gdk_cursor_get_display(self.to_glib_none().0)) }
84    }
85
86    pub fn get_image(&self) -> Option<gdk_pixbuf::Pixbuf> {
87        unsafe { from_glib_full(gdk_sys::gdk_cursor_get_image(self.to_glib_none().0)) }
88    }
89
90    pub fn get_surface(&self) -> (Option<cairo::Surface>, f64, f64) {
91        unsafe {
92            let mut x_hot = mem::uninitialized();
93            let mut y_hot = mem::uninitialized();
94            let ret = from_glib_full(gdk_sys::gdk_cursor_get_surface(
95                self.to_glib_none().0,
96                &mut x_hot,
97                &mut y_hot,
98            ));
99            (ret, x_hot, y_hot)
100        }
101    }
102}
103
104impl fmt::Display for Cursor {
105    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
106        write!(f, "Cursor")
107    }
108}