1use gdk_sys;
6use glib::translate::*;
7
8#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct EventButton(::Event);
10
11event_wrapper!(EventButton, GdkEventButton);
12event_subtype!(
13 EventButton,
14 gdk_sys::GDK_BUTTON_PRESS
15 | gdk_sys::GDK_DOUBLE_BUTTON_PRESS
16 | gdk_sys::GDK_TRIPLE_BUTTON_PRESS
17 | gdk_sys::GDK_BUTTON_RELEASE
18);
19
20impl EventButton {
21 pub fn get_position(&self) -> (f64, f64) {
22 let x = self.as_ref().x;
23 let y = self.as_ref().y;
24 (x, y)
25 }
26
27 pub fn get_state(&self) -> ::ModifierType {
28 from_glib(self.as_ref().state)
29 }
30
31 pub fn get_time(&self) -> u32 {
32 self.as_ref().time
33 }
34
35 pub fn get_button(&self) -> u32 {
36 self.as_ref().button
37 }
38
39 pub fn get_device(&self) -> Option<::Device> {
40 unsafe { from_glib_none(self.as_ref().device) }
41 }
42
43 pub fn get_axes(&self) -> Option<(f64, f64)> {
44 let axes = self.as_ref().axes;
45
46 if axes.is_null() {
47 None
48 } else {
49 unsafe { Some((*axes, *axes.offset(1))) }
50 }
51 }
52
53 pub fn get_root(&self) -> (f64, f64) {
54 let x_root = self.as_ref().x_root;
55 let y_root = self.as_ref().y_root;
56 (x_root, y_root)
57 }
58}