1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use context::Context;
use error::GameResult;
use graphics;
use graphics::Point2;
#[derive(Clone, Debug)]
pub struct MouseContext {
last_position: Point2,
}
impl MouseContext {
pub fn new() -> Self {
Self {
last_position: Point2::origin(),
}
}
pub(crate) fn set_last_position(&mut self, p: Point2) {
self.last_position = p;
}
}
impl Default for MouseContext {
fn default() -> Self {
Self::new()
}
}
pub fn get_grabbed(ctx: &Context) -> bool {
graphics::get_window(ctx).grab()
}
pub fn set_grabbed(ctx: &mut Context, grabbed: bool) {
graphics::get_window_mut(ctx).set_grab(grabbed)
}
pub fn get_relative_mode(ctx: &Context) -> bool {
ctx.sdl_context.mouse().relative_mouse_mode()
}
pub fn set_relative_mode(ctx: &Context, mode: bool) {
ctx.sdl_context.mouse().set_relative_mouse_mode(mode)
}
pub fn get_position(ctx: &Context) -> GameResult<Point2> {
Ok(ctx.mouse_context.last_position)
}
pub fn set_position(ctx: &Context, point: Point2) {
let window = graphics::get_window(ctx);
ctx.sdl_context
.mouse()
.warp_mouse_in_window(window, point.x as i32, point.y as i32)
}