processing/
environment.rs1use glium;
2use glium::glutin;
3
4use {Screen, ScreenType};
5use errors::ProcessingErr;
6
7impl<'a> Screen<'a> {
8 #[inline]
11 pub fn reset_cursor(&mut self) -> Result<(), ProcessingErr> {
12 match self.display {
13 ScreenType::Window(ref d) => (*d).gl_window().set_cursor_state(glutin::CursorState::Normal).map_err(|e| ProcessingErr::CursorStateNotSet(e))?,
14 _ => (),
15 };
16 self.curr_cursor = glium::glutin::MouseCursor::Default;
17 match self.display {
18 ScreenType::Window(ref d) => {
19 (*d).gl_window().set_cursor(
20 glium::glutin::MouseCursor::Default,
21 )
22 }
23 _ => (),
24 };
25
26 Ok(())
27 }
28
29 #[inline]
33 pub fn cursor(&mut self, cursor_type: &str) -> Result<(), ProcessingErr> {
34 match self.display {
35 ScreenType::Window(ref d) => (*d).gl_window().set_cursor_state(glutin::CursorState::Normal).map_err(|e| ProcessingErr::CursorStateNotSet(e))?,
36 _ => (),
37 };
38 if cursor_type == "HAND" {
39 self.curr_cursor = glium::glutin::MouseCursor::Hand;
40 } else if cursor_type == "ARROW" {
41 self.curr_cursor = glium::glutin::MouseCursor::Arrow;
42 } else if cursor_type == "CROSS" {
43 self.curr_cursor = glium::glutin::MouseCursor::Crosshair;
44 } else if cursor_type == "MOVE" {
45 self.curr_cursor = glium::glutin::MouseCursor::Move;
46 } else if cursor_type == "TEXT" {
47 self.curr_cursor = glium::glutin::MouseCursor::Text;
48 } else if cursor_type == "WAIT" {
49 self.curr_cursor = glium::glutin::MouseCursor::Wait;
50 }
51 match self.display {
52 ScreenType::Window(ref d) => (*d).gl_window().set_cursor(self.curr_cursor),
53 _ => (),
54 };
55
56 Ok(())
57 }
58
59 #[inline]
61 pub fn focused(&mut self) -> bool {
62 let mut focused = false;
63 self.events_loop.poll_events(|event| match event {
64 glutin::Event::WindowEvent { event, .. } => {
65 match event {
66 glutin::WindowEvent::Focused(_) => {
67 focused = true;
68 }
69 _ => (),
70 }
71 }
72 _ => (),
73 });
74
75 focused
76 }
77
78 #[inline]
80 pub fn frame_count(&self) -> isize {
81 self.frame_count
82 }
83
84 #[inline]
86 pub fn get_frame_rate(&self) -> isize {
87 self.frame_rate
88 }
89
90 #[inline]
92 pub fn set_frame_rate(&mut self, f_rate: isize) {
93 self.frame_rate = f_rate;
94 }
95
96 #[inline]
98 pub fn height(&self) -> u32 {
99 self.height
100 }
101
102 #[inline]
104 pub fn no_cursor(&mut self) -> Result<(), ProcessingErr> {
105 match self.display {
106 ScreenType::Window(ref d) => (*d).gl_window().set_cursor_state(glutin::CursorState::Hide).map_err(|e| ProcessingErr::CursorStateNotSet(e))?,
107 _ => (),
108 };
109
110 Ok(())
111 }
112
113 #[inline]
116 pub fn no_smooth(&mut self) {
117 self.draw_params = glium::draw_parameters::DrawParameters {
118 smooth: None,
119 ..self.draw_params.clone()
120 };
121 }
122
123 #[inline]
125 pub fn smooth(&mut self) {
126 self.draw_params = glium::draw_parameters::DrawParameters {
127 smooth: Some(glium::draw_parameters::Smooth::Nicest),
128 ..self.draw_params.clone()
129 };
130 }
131
132 #[inline]
134 pub fn width(&self) -> u32 {
135 self.width
136 }
137}