processing/
environment.rs

1use glium;
2use glium::glutin;
3
4use {Screen, ScreenType};
5use errors::ProcessingErr;
6
7impl<'a> Screen<'a> {
8	/// Change the cursor back to the default that is used when a new Screen is made.
9	/// This is operating system dependent, but is usually an arrow.
10    #[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	/// Change the cursor. Possible types are "HAND", "ARROW", "CROSS", "MOVE", "TEXT",
30	/// and "WAIT", all following the convention of Processing. These will probably be
31	/// changed to enums in the future.
32    #[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	/// Test if this screen is the currently focused screen.
60    #[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	/// How many frames have already been revealed.
79    #[inline]
80    pub fn frame_count(&self) -> isize {
81        self.frame_count
82    }
83
84	/// What is the current framerate of the screen.
85    #[inline]
86    pub fn get_frame_rate(&self) -> isize {
87        self.frame_rate
88    }
89
90	/// Change the framerate of the screen.
91    #[inline]
92    pub fn set_frame_rate(&mut self, f_rate: isize) {
93        self.frame_rate = f_rate;
94    }
95
96	/// What is the height of the screen.
97    #[inline]
98    pub fn height(&self) -> u32 {
99        self.height
100    }
101
102	/// Disable the cursor so that it cannot be seen.
103    #[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	/// Draw shapes without antialiasing, so that individual pixels can be more readily
114	/// observed.
115    #[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	/// Draw shapes with antialiasing for a more pleasing visual appearence.
124    #[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	/// What is the width of the screen.
133    #[inline]
134    pub fn width(&self) -> u32 {
135        self.width
136    }
137}