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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
use glium;
use glium::glutin;

use {Screen, ScreenType};
use errors::ProcessingErr;

impl<'a> Screen<'a> {
	/// Change the cursor back to the default that is used when a new Screen is made.
	/// This is operating system dependent, but is usually an arrow.
    #[inline]
    pub fn reset_cursor(&mut self) -> Result<(), ProcessingErr> {
        match self.display {
            ScreenType::Window(ref d) => (*d).gl_window().set_cursor_state(glutin::CursorState::Normal).map_err(|e| ProcessingErr::CursorStateNotSet(e))?,
            _ => (),
        };
        self.curr_cursor = glium::glutin::MouseCursor::Default;
        match self.display {
            ScreenType::Window(ref d) => {
                (*d).gl_window().set_cursor(
                    glium::glutin::MouseCursor::Default,
                )
            }
            _ => (),
        };
        
        Ok(())
    }

	/// Change the cursor. Possible types are "HAND", "ARROW", "CROSS", "MOVE", "TEXT",
	/// and "WAIT", all following the convention of Processing. These will probably be
	/// changed to enums in the future.
    #[inline]
    pub fn cursor(&mut self, cursor_type: &str) -> Result<(), ProcessingErr> {
        match self.display {
            ScreenType::Window(ref d) => (*d).gl_window().set_cursor_state(glutin::CursorState::Normal).map_err(|e| ProcessingErr::CursorStateNotSet(e))?,
            _ => (),
        };
        if cursor_type == "HAND" {
            self.curr_cursor = glium::glutin::MouseCursor::Hand;
        } else if cursor_type == "ARROW" {
            self.curr_cursor = glium::glutin::MouseCursor::Arrow;
        } else if cursor_type == "CROSS" {
            self.curr_cursor = glium::glutin::MouseCursor::Crosshair;
        } else if cursor_type == "MOVE" {
            self.curr_cursor = glium::glutin::MouseCursor::Move;
        } else if cursor_type == "TEXT" {
            self.curr_cursor = glium::glutin::MouseCursor::Text;
        } else if cursor_type == "WAIT" {
            self.curr_cursor = glium::glutin::MouseCursor::Wait;
        }
        match self.display {
            ScreenType::Window(ref d) => (*d).gl_window().set_cursor(self.curr_cursor),
            _ => (),
        };
        
        Ok(())
    }

	/// Test if this screen is the currently focused screen.
    #[inline]
    pub fn focused(&mut self) -> bool {
        let mut focused = false;
        self.events_loop.poll_events(|event| match event {
            glutin::Event::WindowEvent { event, .. } => {
                match event {
                    glutin::WindowEvent::Focused(_) => {
                        focused = true;
                    }
                    _ => (),
                }
            }
            _ => (),
        });

        focused
    }

	/// How many frames have already been revealed.
    #[inline]
    pub fn frame_count(&self) -> isize {
        self.frame_count
    }

	/// What is the current framerate of the screen.
    #[inline]
    pub fn get_frame_rate(&self) -> isize {
        self.frame_rate
    }

	/// Change the framerate of the screen.
    #[inline]
    pub fn set_frame_rate(&mut self, f_rate: isize) {
        self.frame_rate = f_rate;
    }

	/// What is the height of the screen.
    #[inline]
    pub fn height(&self) -> u32 {
        self.height
    }

	/// Disable the cursor so that it cannot be seen.
    #[inline]
    pub fn no_cursor(&mut self) -> Result<(), ProcessingErr> {
        match self.display {
            ScreenType::Window(ref d) => (*d).gl_window().set_cursor_state(glutin::CursorState::Hide).map_err(|e| ProcessingErr::CursorStateNotSet(e))?,
            _ => (),
        };
        
        Ok(())
    }

	/// Draw shapes without antialiasing, so that individual pixels can be more readily
	/// observed.
    #[inline]
    pub fn no_smooth(&mut self) {
        self.draw_params = glium::draw_parameters::DrawParameters {
            smooth: None,
            ..self.draw_params.clone()
        };
    }

	/// Draw shapes with antialiasing for a more pleasing visual appearence.
    #[inline]
    pub fn smooth(&mut self) {
        self.draw_params = glium::draw_parameters::DrawParameters {
            smooth: Some(glium::draw_parameters::Smooth::Nicest),
            ..self.draw_params.clone()
        };
    }

	/// What is the width of the screen.
    #[inline]
    pub fn width(&self) -> u32 {
        self.width
    }
}